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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [language/] [c/] [libc/] [stdio/] [v2_0/] [include/] [io.inl] - Blame information for rev 174

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 unneback
#ifndef CYGONCE_LIBC_STDIO_IO_INL
2
#define CYGONCE_LIBC_STDIO_IO_INL
3
//========================================================================
4
//
5
//      io.inl
6
//
7
//      Internal C library stdio io interface inlines
8
//
9
//========================================================================
10
//####ECOSGPLCOPYRIGHTBEGIN####
11
// -------------------------------------------
12
// This file is part of eCos, the Embedded Configurable Operating System.
13
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
14
//
15
// eCos is free software; you can redistribute it and/or modify it under
16
// the terms of the GNU General Public License as published by the Free
17
// Software Foundation; either version 2 or (at your option) any later version.
18
//
19
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
20
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
21
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
22
// for more details.
23
//
24
// You should have received a copy of the GNU General Public License along
25
// with eCos; if not, write to the Free Software Foundation, Inc.,
26
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
27
//
28
// As a special exception, if other files instantiate templates or use macros
29
// or inline functions from this file, or you compile this file and link it
30
// with other works to produce a work based on this file, this file does not
31
// by itself cause the resulting work to be covered by the GNU General Public
32
// License. However the source code for this file must still be made available
33
// in accordance with section (3) of the GNU General Public License.
34
//
35
// This exception does not invalidate any other reasons why a work based on
36
// this file might be covered by the GNU General Public License.
37
//
38
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
39
// at http://sources.redhat.com/ecos/ecos-license/
40
// -------------------------------------------
41
//####ECOSGPLCOPYRIGHTEND####
42
//========================================================================
43
//#####DESCRIPTIONBEGIN####
44
//
45
// Author(s):     nickg
46
// Contributors:
47
// Date:          2000-06-30
48
// Purpose:
49
// Description:
50
// Usage:         #include 
51
//
52
//####DESCRIPTIONEND####
53
//
54
//========================================================================
55
 
56
// CONFIGURATION
57
 
58
#include    // Configuration header
59
 
60
//========================================================================
61
// INCLUDES
62
 
63
#include 
64
 
65
//========================================================================
66
// FileIO versions of IO functions
67
 
68
#ifdef CYGPKG_LIBC_STDIO_FILEIO
69
 
70
inline Cyg_ErrNo cyg_stdio_open( const char *filename,
71
                                 const Cyg_StdioStream::OpenMode rw,
72
                                 const cyg_bool binary,
73
                                 const cyg_bool append,
74
                                 cyg_stdio_handle_t *dev)
75
{
76
    mode_t mode = 0;
77
    int fd;
78
 
79
    switch( rw )
80
    {
81
    case Cyg_StdioStream::CYG_STREAM_WRITE:
82
        mode = O_WRONLY|O_CREAT|O_TRUNC;
83
        break;
84
    case Cyg_StdioStream::CYG_STREAM_READ:
85
        mode = O_RDONLY;
86
        break;
87
    case Cyg_StdioStream::CYG_STREAM_READWRITE:
88
        mode = O_RDWR;
89
        break;
90
    }
91
 
92
    if( append )
93
    {
94
        mode |= O_APPEND;
95
        mode &= ~O_TRUNC;
96
    }
97
 
98
    fd = open( filename, mode );
99
 
100
    if( fd < 0 )
101
        return errno;
102
 
103
    *dev = fd;
104
    return ENOERR;
105
}
106
 
107
inline Cyg_ErrNo cyg_stdio_close( cyg_stdio_handle_t dev )
108
{
109
    if( close( dev ) != ENOERR )
110
        return errno;
111
    return ENOERR;
112
}
113
 
114
inline Cyg_ErrNo cyg_stdio_read( cyg_stdio_handle_t dev,
115
                                 void *buffer, cyg_uint32 *len )
116
{
117
    if( dev != CYG_STDIO_HANDLE_NULL )
118
    {
119
        ssize_t done = read( dev, buffer, *len );
120
 
121
        if( done < 0 )
122
        {
123
            *len = 0;
124
            return errno;
125
        }
126
 
127
        *len = done;
128
    }
129
    // If the device is NULL, just return EOF indication
130
    else *len = 0;
131
 
132
    return ENOERR;
133
}
134
 
135
inline Cyg_ErrNo cyg_stdio_write( cyg_stdio_handle_t dev,
136
                                 const void *buffer, cyg_uint32 *len )
137
{
138
    if( dev != CYG_STDIO_HANDLE_NULL )
139
    {
140
        ssize_t done = write( dev, buffer, *len );
141
 
142
        if( done < 0 )
143
        {
144
            *len = 0;
145
            return errno;
146
        }
147
 
148
        *len = done;
149
    }
150
    // if the device is NULL, just absorb all writes.
151
 
152
    return ENOERR;
153
}
154
 
155
inline Cyg_ErrNo cyg_stdio_lseek( cyg_stdio_handle_t dev,
156
                                  off_t *pos, int whence )
157
{
158
    off_t newpos = lseek( dev, *pos, whence );
159
 
160
    if( newpos < 0 )
161
        return errno;
162
 
163
    *pos = newpos;
164
 
165
    return ENOERR;
166
}
167
 
168
inline Cyg_ErrNo cyg_stdio_flush( cyg_stdio_handle_t dev )
169
{
170
    int err = fsync( dev );
171
 
172
    if( err < 0 )
173
        return errno;
174
 
175
    return ENOERR;
176
}
177
 
178
inline cyg_bool cyg_stdio_interactive( cyg_stdio_handle_t dev )
179
{
180
    struct stat buf;
181
    int err;
182
 
183
    err = fstat( dev, &buf );
184
 
185
    // If we get an error, assume interactive.
186
    if( err < 0 )
187
        return true;
188
 
189
    if( S_ISCHR(buf.st_mode) )
190
        return true;
191
 
192
    return false;
193
}
194
 
195
 
196
#endif // CYGPKG_LIBC_STDIO_FILEIO
197
 
198
//========================================================================
199
// Direct IO versions of IO functions
200
 
201
#ifndef CYGPKG_LIBC_STDIO_FILEIO
202
 
203
inline Cyg_ErrNo cyg_stdio_open( const char *filename,
204
                                 const Cyg_StdioStream::OpenMode rw,
205
                                 const cyg_bool binary,
206
                                 const cyg_bool append,
207
                                 cyg_stdio_handle_t *dev)
208
{
209
    return cyg_io_lookup( filename, dev );
210
}
211
 
212
inline Cyg_ErrNo cyg_stdio_close( cyg_stdio_handle_t dev )
213
{
214
    // Devices do not get closed
215
    return ENOERR;
216
}
217
 
218
inline Cyg_ErrNo cyg_stdio_read( cyg_stdio_handle_t dev,
219
                                 void *buffer, cyg_uint32 *len )
220
{
221
    return cyg_io_read( dev, buffer, len );
222
}
223
 
224
inline Cyg_ErrNo cyg_stdio_write( cyg_stdio_handle_t dev,
225
                                 const void *buffer, cyg_uint32 *len )
226
{
227
    return cyg_io_write( dev, buffer, len );
228
}
229
 
230
inline cyg_uint32 cyg_stdio_lseek( cyg_stdio_handle_t dev,
231
                                  cyg_uint32 *pos, int whence )
232
{
233
    // No seeking in raw devices, just return fake success
234
    return ENOERR;
235
}
236
 
237
inline Cyg_ErrNo cyg_stdio_flush( cyg_stdio_handle_t dev )
238
{
239
    return cyg_io_get_config(dev,
240
                             CYG_IO_GET_CONFIG_SERIAL_OUTPUT_DRAIN,
241
                             NULL, NULL);
242
}
243
 
244
inline cyg_bool cyg_stdio_interactive( cyg_stdio_handle_t dev )
245
{
246
    return true;
247
}
248
 
249
 
250
#endif // !CYGPKG_LIBC_STDIO_FILEIO
251
 
252
//========================================================================
253
#endif // CYGONCE_LIBC_STDIO_IO_INL multiple inclusion protection
254
// EOF io.inl
255
 

powered by: WebSVN 2.1.0

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