Hey gang!
I'm not sure if this is bash specific, and I do want it to work as a multi-platform ansi compliant utility.
The program takes input from stdin, so eg:
Code:
echo "some data" | theprogram
However, once that data is piped in and saved in a buffer, some user input is needed:
Code:
#include <stdio.h>
int main(void) {
char buffer[4096], ch;
int c = 0;
/* get data from input pipe */
while ((ch = getchar())) {
if (feof(stdin) || c == 4096) break;
buffer[c++] = ch;
}
/* data complete, now: */
clearerr(stdin);
while ((ch = getchar())) {
printf("%d ",ch);
}
return 0;
}
The feof() happens, but after that there is a continuous and unstoppable stream of EOF characters:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...etc.
I can't off the top of my head think of a utility which accepts from stdin then switches to a TLI-ish control after the EOF, maybe this is why.
I've tried fclose() on stdin, forking, etc but nothing helps. I can't use threads because it must be cross-platform.
Is this just a no-go?