mardi 25 mars 2014

Re: Read from stdin without affecting stream position topic




On 03/25/2014 12:00 PM, fabio wrote:
> Hello,
>
> I have this code:
>
> fd_set rfds;
> struct timeval tv;
> FD_ZERO(&rfds);
> FD_SET(0, &rfds);
> tv.tv_sec = 0; tv.tv_usec = 0;
> int retval = select(1, &rfds, NULL, NULL, &tv);


FD_ZERO, FD_SET, and select() are not defined by the C standard. If
you've defined them elsewhere, knowing what those definitions are could
make a big difference in the answer to your question. If you are using
the POSIX features with those names, the best place to get a good
answers to such problems is comp.unix.programmer.

> if (retval && retval!=-1)
> {
> ....
> }
>
> I check if the stdin is ready to be read without blocking


The C standard does not say anything about non-blocking reads - the
POSIX standard does. That's another reason to go to comp.unix.programmer
with this question.
What you're asking for doesn't sound feasible, I suspect you'll have to
find a different approach to your problem. However, while I know a fair
amount about POSIX, I haven't had to worry about such things, so I could
be mistaken - that's why I recommend going to the experts.





Aucun commentaire:

Enregistrer un commentaire