Re: how to read 1 char from standard in?

From: Floyd L. Davidson (floyd_at_barrow.com)
Date: 08/23/04


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


Relevant Pages

  • Re: ADC mux charge injection on commercial DAQ boards
    ... It's driven by some fundament real and percieved difference between software and hardware. ... In addition because of the perceived simplicity of changing the SW, the specifications for SW are often fuzzy, incompletely thought out and more grandiose than is necessary to do the required job. ... Often the rest of the specified functionality is unnecessary or completely different functionality will be more useful. ... A good design will be done with an eye to exapnding capabilities in the future, an excellent design will succed in having a sufficiently general base that future modifications fit in cleanly, an exceptional design will be so simple and clean that it doesn't require changes since additional functionality can be built out of the existing functionality. ...
    (sci.electronics.design)
  • Re: ADC mux charge injection on commercial DAQ boards
    ... This is more than just a design philosophy difference. ... than hardware. ... These characteristics of SW specifications make ... different functionality will be more useful. ...
    (sci.electronics.design)
  • [PATCH 22/30] hpsa: use scan_start and scan_finished entry points for scanning
    ... route the CCISS_REGNEWD ioctl and sysfs triggering of same functionality ...
    (Linux-Kernel)
  • Re: Replacement for C-function ioctl?
    ... an extension by hand. ... Perhaps rather than writing glue to ioctl, ... towards a general API for the type of functionality one wants to do, ...
    (comp.lang.tcl)
  • [PATCH 2/2] ext4: Add EXT4_IOC_TRIM ioctl to handle batched discard
    ... core vfs ioctl. ... Since we still need to access to this functionality this ... commit adds ext4 specific ioctl EXT4_IOC_TRIM to dispatch ... __u64 start; ...
    (Linux-Kernel)