Can I make ungetc unblock a blocking fgetc call?
Posted
by Paul Beckingham
on Stack Overflow
See other posts from Stack Overflow
or by Paul Beckingham
Published on 2010-04-12T05:16:08Z
Indexed on
2010/04/12
5:23 UTC
Read the original article
Hit count: 273
I would like to stuff an 'A' character back into stdin using ungetc on receipt of SIGUSR1. Imagine that I have a good reason for doing this.
When calling foo(), the blocking read in stdin is not interrupted by the ungetc call on receipt of the signal. While I didn't expect this to work as is, I wonder if there is a way to achieve this - does anyone have suggestions?
void handler (int sig) { ungetc ('A', stdin); } void foo () { signal (SIGUSR1, handler); while ((key = fgetc (stdin)) != EOF) { ... } }
© Stack Overflow or respective owner