OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-stable/] [newlib-1.18.0/] [libgloss/] [or32/] [read.c] - Diff between revs 207 and 507

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 207 Rev 507
Line 30... Line 30...
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
 
 
#include <errno.h>
#include <errno.h>
#include <unistd.h>
#include <unistd.h>
 
 
 
#include "or1k-support.h"
 
 
#undef errno
#undef errno
extern int  errno;
extern int  errno;
 
 
 
 
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/*!Read from a file.
/*!Read from a file.
 
 
   We don't support reading. However for stdin, it's better if we return 0
   Depending on board support, we may attempt to read from UART.
   (indicating EOF) rather than fail.
 
 
 
   Remember that this function is *not* reentrant, so no static state should
   Remember that this function is *not* reentrant, so no static state should
   be held.
   be held.
 
 
   @param[in] file  The fileno to read.
   @param[in] file  The fileno to read.
   @param[in] ptr   Buffer into which to read.
   @param[in] buf   Buffer into which to read.
   @param[in] len   Number of bytes to read.
   @param[in] len   Number of bytes to read.
 
 
   @return  0 to indicate EOF if the file is stdin, otherwise -1 to indicate
   @return  0 to indicate EOF if the file is stdin, otherwise -1 to indicate
            failure, with an error code in the global variable errno.         */
            failure, with an error code in the global variable errno.         */
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int
int
_read (int   file,
_read (int   file,
       char *ptr,
       char *buf,
       int   len)
       int   len)
{
{
  if (STDIN_FILENO == file)
  if (STDIN_FILENO == file)
    {
    {
 
 
 
                if (BOARD_HAS_UART)
 
                {
 
                        /* UART supported. Read from it */
 
 
 
 
 
                        int  i;
 
 
 
                        for (i = 0; i < len; i++)
 
                        {
 
                                buf[i] = __uart_getc ();
 
#ifdef UART_AUTO_ECHO
 
                                __uart_putc (buf[i]);
 
#endif
 
                                /* Return partial buffer if we get EOL */
 
                                if ('\n' == buf[i])
 
                                {
 
                                        return  i;
 
                                }
 
                        }
 
 
 
                        return  i;                      /* Filled the buffer */
 
                }
 
                else
 
                {
      return  0;                 /* EOF */
      return  0;                 /* EOF */
    }
    }
 
        }
  else
  else
    {
    {
      errno = EBADF;
      errno = EBADF;
      return  -1;
      return  -1;
    }
    }

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.