/** * Example program cat'ing a file * * Compile with: $ gcc -Wall -o cat cat.c */ #include #include #include #include typedef struct __blk128_t { uint64_t hi; uint64_t lo; } blk128_t; #define BUFSZ (sizeof(uint64_t) << 1) int main(int argc, char *argv[]) { if (argc < 2) { printf("usage: %s \n", argv[0]); return 0; } int fd = open(argv[1], O_RDONLY); if (fd == -1) { printf("Could not open file '%s'\n", argv[1]); return 1; } /* Declare buffer */ blk128_t blk = {0, 0}; size_t n = 0; size_t t = 0; for (; (n = read(fd, &blk, BUFSZ)) > 0; t += n) { write(STDOUT_FILENO, &blk, n); } printf("\nbytes: %lu\n", t); close(fd); return 0; }