X-Git-Url: https://scm.lunaixsky.com/lunaix-os.git/blobdiff_plain/f044ca812256b421e793c4335ce1ffed74710a70..8fce4520de1f257819b16f9253fa28dcdae743f4:/lunaix-os/usr/cat/main.c?ds=sidebyside diff --git a/lunaix-os/usr/cat/main.c b/lunaix-os/usr/cat/main.c new file mode 100644 index 0000000..0a15f8c --- /dev/null +++ b/lunaix-os/usr/cat/main.c @@ -0,0 +1,31 @@ +#include +#include +#include +#include + +#define BUFSIZE 4096 + +static char buffer[BUFSIZE]; + +int +main(int argc, const char* argv[]) +{ + int fd = 0; + unsigned int size = 0; + for (int i = 1; i < argc; i++) { + fd = open(argv[i], FO_RDONLY); + if (fd < 0) { + printf("open failed: %s (error: %d)", argv[i], fd); + continue; + } + + do { + size = read(fd, buffer, BUFSIZE); + write(stdout, buffer, size); + } while (size == BUFSIZE); + + close(fd); + } + + return 0; +} \ No newline at end of file