This is the mail archive of the newlib@sources.redhat.com mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: How to handle terminal I/O


Mats Liljegren wrote:
> 
> Hi all,
> 
> I'm trying to get my system functions correctly, especially read and
> fstat. I'd like reading to be done character by character, but output
> should be line based.
> 
> How do I get this behaviour?

In RTEMS, we have layered this all on top of system calls.  One of the
things you can get to this way is serial device drivers that support
termios.

Historically, the system calls were implemented solely to provide
a libgloss interface.  

> Right now, fstat does the following:
> int fstat( int file, struct stat st )
> {
>         switch( file )
>         {
>         case 0:
>         case 1:
>         case 2:
>                 st->st_blksize = 0;
>                 st->st_mode = S_IFCHR;
>                 break;
>         default:
>                 errno = EINVAL;
>                 return -1;
>         }
> 
>         return 0;
> }
> 
> and isatty looks like follows:
> 
> int isatty( int file )
> {
>         return 1;
> }
> 
> But any call to getchar() ends up reading 1023 bytes with a call to
> read. Not much of command line editing is possible with such a
> behaviour...

You can use setvbuf() to modify this behavior and go into non-buffered
mode.  Look at the code in the stdio directory.  In particular, 
setvbuf.c and refill.c where the libgloss read() is called.
 
> Best regards,
>   Mats

-- 
Joel Sherrill, Ph.D.             Director of Research & Development
joel@OARcorp.com                 On-Line Applications Research
Ask me about RTEMS: a free RTOS  Huntsville AL 35805
   Support Available             (256) 722-9985

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]