mirror of
https://gitlab.com/sortix/sortix.git
synced 2023-02-13 20:55:38 -05:00
cat(1) now writes to /dev/tty.
Someone really ought to implement stdout.
This commit is contained in:
parent
46c0cc6a12
commit
7a9afd66fe
1 changed files with 23 additions and 2 deletions
|
@ -5,10 +5,27 @@
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <libmaxsi/sortix-keyboard.h>
|
#include <libmaxsi/sortix-keyboard.h>
|
||||||
|
|
||||||
|
bool writeall(int fd, const void* buffer, size_t len)
|
||||||
|
{
|
||||||
|
const char* buf = (const char*) buffer;
|
||||||
|
while ( len )
|
||||||
|
{
|
||||||
|
ssize_t byteswritten = write(fd, buf, len);
|
||||||
|
if ( byteswritten < 0 ) { return false; }
|
||||||
|
buf += byteswritten;
|
||||||
|
len -= byteswritten;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
int cat(int argc, char* argv[])
|
int cat(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
int result = 0;
|
int result = 0;
|
||||||
|
|
||||||
|
int outfd = open("/dev/tty", O_WRONLY | O_APPEND);
|
||||||
|
if ( outfd < 0 ) { printf("%s: %s: %s\n", argv[0], "/dev/tty", strerror(errno)); return 1; }
|
||||||
|
|
||||||
for ( int i = 1; i < argc; i++ )
|
for ( int i = 1; i < argc; i++ )
|
||||||
{
|
{
|
||||||
int fd = open(argv[i], O_RDONLY);
|
int fd = open(argv[i], O_RDONLY);
|
||||||
|
@ -31,8 +48,12 @@ int cat(int argc, char* argv[])
|
||||||
result = 1;
|
result = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
buffer[bytesread] = 0;
|
if ( !writeall(outfd, buffer, bytesread) )
|
||||||
printf("%s", buffer);
|
{
|
||||||
|
printf("%s: /dev/tty: %s\n", argv[0], strerror(errno));
|
||||||
|
result = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
} while ( true );
|
} while ( true );
|
||||||
|
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
Loading…
Add table
Reference in a new issue