Given this straightforward file named foo.c:
#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[])
{
for (int i = 0; i < argc; ++i) printf("argv[%d]=%s", i, argv[i]);
printf("\n");
if (argc == 2 && !strcmp(argv[1], "-")) {
char buf[1024] = {};
printf("enter a line: ");
if (fgets(buf, sizeof buf, stdin))
printf("[%s]\n", buf);
else
printf("fgets failed");
}
return 0;
}
The following command does what I would expect (it allows me to type in a line of input):
$ tcc -run foo.c -
But if I try to read foo.c from stdin then foo.c itself is unable to read, b.c. stdin is already closed:
$ cat foo.c | tcc -run - -
I tried duplicating fd 0 in _tcc_open() but that didn't work. Suggestions welcome.
if (strcmp(filename, "-") == 0) {
fd = dup(0), filename = "<stdin>";
...
Thanks - Eric