OrionUserland
Barry Importing existing Orion Userland 19aefaa (2 years, 4 months ago)#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <fcntl.h> #include <string.h> #include <sys/stat.h> #include <dirent.h> /* Main function */ int main(int argc, char *argv[]) { int fd, sz, i; char *buf; struct stat statbuf; if (argc < 2) { printf("Usage: %s <file> [<file>...]\n"); return 0; } for (i = 1; i < argc; i++) { fd = open(argv[i], O_RDONLY); if (fd < 0) { printf("%s: %s: ", argv[0], argv[i]); perror(NULL); continue; } stat(argv[i], &statbuf); if (S_ISREG(statbuf.mode)) { sz = lseek(fd, 0, SEEK_END); buf = malloc(sz + 1); lseek(fd, 0, SEEK_SET); read(fd, buf, sz); printf("%s", buf); free(buf); } close(fd); } return 0; }