in reply to non-destructive read on stdin
To make this work rolling your own, you need to pull all input from a single routine, a getchar() routine, and that routine needs to have an extra buffer that you can put characters back into, when you don't want them yet. getchar() takes bytes from that extra buffer, in order, and only when the extra buffer's empty does it go to STDIN itself.
This is the only way to maintain the sequence of characters comming in. If you try to load them back in by stuffing them into STDIN, then you will always have a race condition where a new character typed in can get stuffed in after you took characters out, but before you put them back in. This will happen rarely and unpredictably, and possibly more often when the system is loaded. It will probably not show up in testing.
Update: Looks like I misunderstood what the OP wanted. I should have read "process" as "OS process", which makes sense to do, but I missed it. Oh well, it was a decent answer to a different question, I think. (And thanks to [id://betterworld] for pointing out the error.)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: non-destructive read on stdin
by betterworld (Curate) on Aug 02, 2006 at 01:41 UTC |