Re: how to read 1 char from standard in?
From: Floyd L. Davidson (floyd_at_barrow.com)
Date: Mon, 23 Aug 2004 02:27:59 -0800
Last2Know <email@example.com> wrote:
>On Sun, 22 Aug 2004 18:48:53 -0800, Floyd L. Davidson wrote:
>>>>> Thanks, that does it.
>>>> One thing, shouldnt something like this be part of the stdlib for linux or
>>>> at least in a normally included or normally distributed lib for linux? It
>>>> just seems like it must be a very common need.
>>>It has been standardized for Unix. It's just not part of libc
>>>and the non-portable parts of the link above are not intrinsic
>>>to the desired functionality.
>> What parts are either non-portable, or not intrinsic to the
>> desired functionality?
>The ioctl call mainly. Also select() should come from
>/usr/include/sys/select.h in modern POSIX code.
The Open Group Base Specifications Issue 6, IEEE Std 1003.1,
2004 Edition, available online at
The POSIX man page for select() specifies that <sys/time.h> is
the appropriate header to include for select(). The Linux man
pages on my system (possibly years out of date) specify <unistd.h>.
The FIONREAD ioctl command is not POSIX. And it is true that in
the example code cited that is only used in the kbhit()
function, which in not part of the OP's requested functionality.
Indeed, kbhit() could be re-written using the same POSIX
functions that getch() uses, though obviously it would not be an
However, even though FIONREAD is not essential to the OP's
request, it is 1) useful and closely related (which is why it is
bundled with the getch() example) and 2) FIONREAD is available
on not only Linux but all modern variations of unix.
Hence, the example is in fact *very* portable.
Hence, as I've said elsewhere, portability is not the problem.
The problem is that the example is not a general solution, but
rather one specific example which can be used as a model. It
does well for that purpose, but would not be appropriate as a
library function. The "problem" is there would need to be half
a dozen or more functions to fit all potential program needs.
-- FloydL. Davidson <http://web.newsguy.com/floyd_davidson> Ukpeagvik (Barrow, Alaska) firstname.lastname@example.org