ATF-devel archive

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

Re: atf_io_readline() timeouts even if I type '\n'



On May 27, 2008, at 22:32 , Stathis Kamperis wrote:

Hi people.

I use inside a test case the following code snippet:

   err = atf_dynstr_init(&line);
    if (!atf_is_error(err)) {
        err = atf_io_readline(fileno(stdin), &line);
        if (!atf_is_error(err)) {
            printf("%s\n", atf_dynstr_cstring(&line));
        }
    }
    atf_dynstr_fini(&line);

When I compile and run the program, even if I type chars and then hit
`ENTER', atf_io_readline() doesn't return.
If I ktruss it, it hangs in setitimer() and unhangs when timeout expires.

It works for me under OS X. Does the tests/atf/atf-c/t_io:readline test case pass on your system? Which system is it?

Am I missing something _really_ fundamental or is there an issue indeed?

atf_io_readline is just crap. Also be aware that if you mix stdio calls with raw file descriptor calls, you can run into trouble. stdio does internal buffering whereas raw file descriptors do not. So, if you did any fscanf call or similar before the call to atf_io_readline, you may not get anything because stdio may already have got it.

You can use STDIN_FILENO instead of fileno(stdin) to get rid of one call to stdio, and then get rid of all other stdio calls that mess with stdin.

Kind regards.


Home | Main Index | Thread Index | Old Index