Services and Modeling for Embedded Software Development
Embecosm divider strip
Prev  Next

5.3.9.  Determine the Nature of a Stream, isatty

For a namespace clean function, implement _isatty, otherwise implement isatty. The detailed implementation will depend on the file handling functionality available.

This specifically checks whether a stream is a terminal. The minimal implementation only has the single output stream, which is to the console, so always returns 1.

int
_isatty (int   file)
{
  return  1;

}       /* _isatty () */
	  
[Caution]Caution

Contrary to the standard libc documentation, this applies to any stream, not just output streams.

The OpenRISC 1000  version gives a little more detail, setting errno if the stream is not standard output, standard error or (for the UART version of the BSP) standard input.

#include <errno.h>
#include <unistd.h>

#undef ERRNO
extern int  errno;

int
_isatty (int   file)
{
  if ((file == STDOUT_FILENO) || (file == STDERR_FILENO))
    {
      return  1;
    }
  else
    {
      errno = EBADF;
      return  -1;
    }
}       /* _isatty () */
	  

The UART version is almost identical, but also succeeds for standard input.

Embecosm divider strip