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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [language/] [c/] [libc/] [stdio/] [current/] [include/] [io.inl] - Blame information for rev 786

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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