+++ /dev/null
-#include <fcntl.h>\r
-#include <stdlib.h>\r
-#include <stdio.h>\r
-#include <sys/stat.h>\r
-#include <sys/types.h>\r
-#include <errno.h>\r
-\r
-#ifndef STDOUT_FILENO\r
-#define STDOUT_FILENO 1\r
-#endif\r
-\r
-typedef unsigned char byte_t;\r
-\r
-int\r
-main(int argc, char* argv[])\r
-{\r
- FILE* stream;\r
- struct stat s = {0};\r
- char* buffer;\r
- int i = 0;\r
- char c;\r
- int failed;\r
-\r
- stream = fopen(argv[1], "r");\r
-\r
- if(!stream)\r
- {\r
- fprintf(stderr, "fopen() failed withe the error %d\n", errno);\r
- return EXIT_FAILURE;\r
- }\r
- \r
- if(stat(argv[1], &s) < 0)\r
- {\r
- fclose(stream);\r
- fprintf(stderr, "stat() failed withe the error %d\n", errno);\r
- return EXIT_FAILURE;\r
- }\r
- \r
- \r
- if(!(buffer = (byte_t*) calloc(s.st_size + 1, sizeof(byte_t))))\r
- {\r
- fclose(stream);\r
- fprintf(stderr, "calloc() failed withe the error %d\n", errno);\r
- return EXIT_FAILURE;\r
- }\r
- \r
- \r
- while((c = getc(stream)) != EOF)\r
- if((int)c != 13)\r
- buffer[i++] = c;\r
- \r
- failed = ferror(stream);\r
- \r
- if(!failed || buffer)\r
- write(STDOUT_FILENO, buffer, strlen(buffer));\r
- \r
- fclose(stream);\r
- free(buffer);\r
- \r
- return failed ? EXIT_FAILURE : EXIT_SUCCESS;\r
- \r
-}\r
-\r
+++ /dev/null
-#include <fcntl.h>\r
-#include <stdlib.h>\r
-#include <stdio.h>\r
-#include <sys/stat.h>\r
-#include <sys/types.h>\r
-#include <errno.h>\r
-\r
-#ifndef STDIN_FILENO\r
-#define STDIN_FILENO 0\r
-#endif\r
-\r
-int\r
-main(int argc, char* argv[])\r
-{\r
- size_t number_of_bytes_to_read = 4096;\r
- int number_of_bytes_readed = 0;\r
- char buffer[4096] = {0};\r
- int failed = 0;\r
- int fd;\r
- \r
- if((fd = creat(argv[1], _S_IREAD | _S_IWRITE)) < 0)\r
- {\r
- fprintf(stderr,"creat() failed with the error %d\n",errno);\r
- return EXIT_FAILURE;\r
- }\r
- \r
- do\r
- {\r
- number_of_bytes_readed = read(STDIN_FILENO, buffer, number_of_bytes_to_read);\r
- \r
- if(number_of_bytes_readed < 0 && errno != EINTR && errno != EAGAIN) \r
- {\r
- fprintf(stderr, "read failure %d\n", errno);\r
- failed = 1;\r
- break;\r
- }\r
- \r
- if(number_of_bytes_readed > 0) \r
- {\r
- write(fd, buffer, strlen(buffer));\r
- memset(buffer, 0, number_of_bytes_to_read);\r
- }\r
- \r
- \r
- }while(number_of_bytes_readed);\r
- \r
- close(fd);\r
- \r
- return failed ? EXIT_FAILURE : EXIT_SUCCESS;\r
- \r
-}\r
-\r