This is the mail archive of the
newlib@sources.redhat.com
mailing list for the newlib project.
Re: How to handle terminal I/O
- To: Mats Liljegren <mats dot liljegren at enea dot se>
- Subject: Re: How to handle terminal I/O
- From: Joel Sherrill <joel dot sherrill at OARcorp dot com>
- Date: Thu, 07 Sep 2000 18:44:25 -0500
- CC: newlib <newlib at sources dot redhat dot com>
- Organization: OAR Corporation
- References: <39AFA816.A6F80226@enea.se>
- Reply-To: joel dot sherrill at OARcorp dot com
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