tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Tinycc-devel] "tcc -run -" closes stdin so that program itself can't re


From: Eric Raible
Subject: [Tinycc-devel] "tcc -run -" closes stdin so that program itself can't read from stdin
Date: Tue, 28 Nov 2023 23:20:56 -0800

tcc version 0.9.28rc 2023-11-27 mob@0655fd9 (x86_64 Linux)

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

reply via email to

[Prev in Thread] Current Thread [Next in Thread]