OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [trunk/] [gnu-src/] [newlib-1.18.0/] [libgloss/] [or32/] [read.c] - Blame information for rev 645

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 207 jeremybenn
/* read.c. Implementation of the _read syscall for newlib
2
 
3
   Copyright (C) 2004, Jacob Bower
4
   Copyright (C) 2010, Embecosm Limited <info@embecosm.com>
5
 
6
   Contributor Jeremy Bennett <jeremy.bennett@embecosm.com>
7
 
8
   This file is part of Newlib.
9
 
10
   The original work by Jacob Bower is provided as-is without any kind of
11
   warranty. Use it at your own risk!
12
 
13
   All subsequent work is bound by version 3 of the GPL as follows.
14
 
15
   This program is free software; you can redistribute it and/or modify it
16
   under the terms of the GNU General Public License as published by the Free
17
   Software Foundation; either version 3 of the License, or (at your option)
18
   any later version.
19
 
20
   This program is distributed in the hope that it will be useful, but WITHOUT
21
   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
22
   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
23
   more details.
24
 
25
   You should have received a copy of the GNU General Public License along
26
   with this program.  If not, see <http:#www.gnu.org/licenses/>.             */
27
/* -------------------------------------------------------------------------- */
28
/* This program is commented throughout in a fashion suitable for processing
29
   with Doxygen.                                                              */
30
/* -------------------------------------------------------------------------- */
31
 
32
#include <errno.h>
33
#include <unistd.h>
34
 
35 527 julius
#include "or1k-support.h"
36 207 jeremybenn
 
37
#undef errno
38
extern int  errno;
39
 
40
 
41
/* -------------------------------------------------------------------------- */
42
/*!Read from a file.
43
 
44 507 julius
   Depending on board support, we may attempt to read from UART.
45 207 jeremybenn
 
46
   Remember that this function is *not* reentrant, so no static state should
47
   be held.
48
 
49
   @param[in] file  The fileno to read.
50 507 julius
   @param[in] buf   Buffer into which to read.
51 207 jeremybenn
   @param[in] len   Number of bytes to read.
52
 
53
   @return  0 to indicate EOF if the file is stdin, otherwise -1 to indicate
54
            failure, with an error code in the global variable errno.         */
55
/* -------------------------------------------------------------------------- */
56
int
57
_read (int   file,
58 507 julius
       char *buf,
59 207 jeremybenn
       int   len)
60
{
61 507 julius
        if (STDIN_FILENO == file)
62
        {
63
 
64
                if (BOARD_HAS_UART)
65
                {
66
                        /* UART supported. Read from it */
67
 
68
 
69
                        int  i;
70
 
71
                        for (i = 0; i < len; i++)
72
                        {
73
                                buf[i] = __uart_getc ();
74
#ifdef UART_AUTO_ECHO
75
                                __uart_putc (buf[i]);
76
#endif
77
                                /* Return partial buffer if we get EOL */
78
                                if ('\n' == buf[i])
79
                                {
80
                                        return  i;
81
                                }
82
                        }
83
 
84
                        return  i;                      /* Filled the buffer */
85
                }
86
                else
87
                {
88
                        return  0;                       /* EOF */
89
                }
90
        }
91
        else
92
        {
93
                errno = EBADF;
94
                return  -1;
95
        }
96 207 jeremybenn
}       /* _read () */

powered by: WebSVN 2.1.0

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