4 #include <sys/stat.h>
\r
5 #include <sys/types.h>
\r
8 #ifndef STDOUT_FILENO
\r
9 #define STDOUT_FILENO 1
\r
12 typedef unsigned char byte_t;
\r
15 main(int argc, char* argv[])
\r
18 struct stat s = {0};
\r
24 stream = fopen(argv[1], "r");
\r
28 fprintf(stderr, "fopen() failed withe the error %d\n", errno);
\r
29 return EXIT_FAILURE;
\r
32 if(stat(argv[1], &s) < 0)
\r
35 fprintf(stderr, "stat() failed withe the error %d\n", errno);
\r
36 return EXIT_FAILURE;
\r
40 if(!(buffer = (byte_t*) calloc(s.st_size + 1, sizeof(byte_t))))
\r
43 fprintf(stderr, "calloc() failed withe the error %d\n", errno);
\r
44 return EXIT_FAILURE;
\r
48 while((c = getc(stream)) != EOF)
\r
52 failed = ferror(stream);
\r
54 if(!failed || buffer)
\r
55 write(STDOUT_FILENO, buffer, strlen(buffer));
\r
60 return failed ? EXIT_FAILURE : EXIT_SUCCESS;
\r