5 /* open/read/write/close */
8 /** If buffer is too small to hold entire string, it is incremented by this value */
12 * Program reads entire lines of text from the standard input and pass them
13 * to the process2 using created pipe.
16 /** Currently fetched from stdin character */
19 /** Buffer used to store line of characters */
22 /** Current buffer length*/
23 int buffer_length = 0;
25 /** Index of the current character */
29 * Temporary buffer used as a proxy between
30 * checking memory allocation and copying data to real buffer
34 /** Named pipe used to communnicate with process2 */
35 char * write_pipe = "/tmp/process1pipe";
37 /** File descriptor of pipe */
40 mkfifo(write_pipe, 0666);
42 file_descriptor = open(write_pipe, O_WRONLY);
44 fprintf(stderr, "[%s] Init!\n", "process1");
50 * Check if current index is bigger than current buffer size.
51 * If so increment buffer size. On error release memory, and set
54 if (i >= buffer_length) {
56 buffer_length += BUFFER_STEP;
57 tmp = (char*) realloc(buffer, buffer_length);
59 fprintf(stderr, "[%s] Memory allocation problem on read!\n", "process1");
67 * If there were no errors or it was not just an empty newline:
70 if (c != EOF || ((i == 0) && (c == 10))) {
71 /* If newline has been found
72 * return entire string and release the memory
74 if (c == 10 && (i != 0)) {
76 write(file_descriptor, buffer, strlen(buffer));
77 fprintf(stderr, "[%s] buffer: %s/%d\n", "process1", buffer, strlen(buffer));
87 * Normal character, add it to the buffer
93 /* Used only for debugging..*/
95 printf("c: %c/%d, i: %d, bl: %d\n", c, c, i, buffer_length);