Re: how to read 1 char from standard in?
From: Floyd L. Davidson (floyd_at_barrow.com)
Date: 08/23/04
- Next message: Floyd L. Davidson: "Re: how to read 1 char from standard in?"
- Previous message: Graeme Hinchliffe: "Re: is this difficulty?"
- In reply to: Last2Know: "Re: how to read 1 char from standard in?"
- Next in thread: Villy Kruse: "Re: how to read 1 char from standard in?"
- Reply: Villy Kruse: "Re: how to read 1 char from standard in?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 23 Aug 2004 02:27:59 -0800
Last2Know <grokkalot@yahoo.com> wrote:
>On Sun, 22 Aug 2004 18:48:53 -0800, Floyd L. Davidson wrote:
>>>>>>
>>>> http://www.daimi.au.dk/~kasperd/comp.os.linux.development.faq.html#termios
>>>>>>
>>>>> Thanks, that does it.
>>>>> Eric
>>>>
>>>> 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
<http://www.unix.org/single_unix_specification/>
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
elegant solution.
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) floyd@barrow.com
- Next message: Floyd L. Davidson: "Re: how to read 1 char from standard in?"
- Previous message: Graeme Hinchliffe: "Re: is this difficulty?"
- In reply to: Last2Know: "Re: how to read 1 char from standard in?"
- Next in thread: Villy Kruse: "Re: how to read 1 char from standard in?"
- Reply: Villy Kruse: "Re: how to read 1 char from standard in?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|