Jeff Johnston
Fri Jan 4 18:32:00 GMT 2008

Jeff Johnston wrote:
> Vincent Rivière wrote:
>> Jeff Johnston a wrote :
>>> _isatty is not one of the fundamental syscalls required by newlib.  
>>> Remember that newlib's historical origin was to support embedded 
>>> platforms and it only required a small set of syscalls to support 
>>> the ANSI C plus miscellaneous functions.  There is a rough isatty() 
>>> implementation in libc/posix that uses fstat, not _isatty.
>>> Platforms that have wanted it have typically just done so directly 
>>> in their libgloss implementation or libc/sys (used before libgloss 
>>> was created) or they use the libc/posix implementation or they use 
>>> the default libgloss/isatty.c version (always returns 1) or they let 
>>> libnosys resolve it (always returns 0) just to allow tests to link/run.
>> I understand.
>> But there are 2 problems :
>> 1) isatty() is currently fundamental, because without it, a simple 
>> printf() cannot link !
>> isatty() is used at the bottom of libc/stdio/makebuf.c
>> 2) The isatty() implementation in libgloss/libnosys/isatty.c uses the 
>> wrong errno. It should only #include <errno.h>, without #undef errno, 
>> extern int errno.
> Hmm, there are huge inconsistencies here.  The isatty syscall hasn't 
> been made compulsory like the other newlib syscalls in that there is 
> neither _isatty or _isatty_r calls in the library, but it should have 
> been or at the very least, something like the libc/posix isatty 
> implementation should have been exposed to be overridden if desired.
> The isatty in libnosys should probably be changed to be consistent 
> with other libnosys syscalls and implement _isatty.
> It will take some unravelling to see if adding _isatty_r will break 
> things or not for existing platforms.  For example, Cygwin is using 
> the libc/posix isatty and also uses libc/syscalls which would override 
> libc/posix in the case of the same object name.
> I need to look at this a bit.
> -- Jeff J.
Ok, I have checked in patches to both libgloss and newlib.  I have 
tested x86-linux and mn10300.  It should work the same as before for 
Cygwin and powerpcle-*-pe because the libc/posix directory supplies 
isatty which calls _isatty which is also supplied in libc/posix.  The 
two stdio routines now call _isatty_r which is always supplied in 
libc/reent and calls either _isatty_r or _isatty.  Again, Cygwin should 
not see a change since it will end up calling the _isatty implementation 
in libc/posix.

For x86-linux, it was also using libc/posix.  I added a new isatty 
implementation in sys/linux which will override the posix definition.  
It works fine according to the test I performed.  I might in the future 
want to not use the lib/posix directory and have the isatty also name 

I changed various libgloss implementations to rename isatty to be 
_isatty.  Thus, they should hook up with _isatty_r as desired.  These 
platforms were using the libc/syscalls directory which now has a isatty 
implemenation.  Libnosys is also renamed its isatty to be _isatty.  
Consistent now.

If anybody finds a problem,  just post it here.

-- Jeff J.

More information about the Newlib mailing list