URL
https://opencores.org/ocsvn/openrisc/openrisc/trunk
Subversion Repositories openrisc
Compare Revisions
- This comparison shows the changes necessary to convert path
/openrisc/trunk/rtos/ecos-2.0/packages/language/c/libc/stdio/v2_0/include
- from Rev 27 to Rev 174
- ↔ Reverse comparison
Rev 27 → Rev 174
/stdiosupp.hxx
0,0 → 1,83
#ifndef CYGONCE_LIBC_STDIO_STDIOSUPP_HXX |
#define CYGONCE_LIBC_STDIO_STDIOSUPP_HXX |
//======================================================================== |
// |
// stdiosupp.hxx |
// |
// Support for C library standard I/O routines |
// |
//======================================================================== |
//####ECOSGPLCOPYRIGHTBEGIN#### |
// ------------------------------------------- |
// This file is part of eCos, the Embedded Configurable Operating System. |
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc. |
// |
// eCos is free software; you can redistribute it and/or modify it under |
// the terms of the GNU General Public License as published by the Free |
// Software Foundation; either version 2 or (at your option) any later version. |
// |
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY |
// WARRANTY; without even the implied warranty of MERCHANTABILITY or |
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
// for more details. |
// |
// You should have received a copy of the GNU General Public License along |
// with eCos; if not, write to the Free Software Foundation, Inc., |
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
// |
// As a special exception, if other files instantiate templates or use macros |
// or inline functions from this file, or you compile this file and link it |
// with other works to produce a work based on this file, this file does not |
// by itself cause the resulting work to be covered by the GNU General Public |
// License. However the source code for this file must still be made available |
// in accordance with section (3) of the GNU General Public License. |
// |
// This exception does not invalidate any other reasons why a work based on |
// this file might be covered by the GNU General Public License. |
// |
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc. |
// at http://sources.redhat.com/ecos/ecos-license/ |
// ------------------------------------------- |
//####ECOSGPLCOPYRIGHTEND#### |
//======================================================================== |
//#####DESCRIPTIONBEGIN#### |
// |
// Author(s): jlarmour |
// Contributors: |
// Date: 2000-04-19 |
// Purpose: |
// Description: |
// Usage: #include <cyg/libc/stdio/stdiosupp.hxx> |
// |
//####DESCRIPTIONEND#### |
// |
//======================================================================== |
|
// CONFIGURATION |
|
#include <pkgconf/libc_stdio.h> // Configuration header |
|
// INCLUDES |
|
#include <cyg/infra/cyg_type.h> // common type definitions and support |
#include <stdio.h> // Main standard I/O header |
#include <cyg/libc/stdio/stream.hxx>// Cyg_StdioStream |
|
// FUNCTION PROTOTYPES |
|
//======================================================================== |
|
// Miscellaneous support functions |
|
externC cyg_stdio_handle_t |
Cyg_libc_stdio_find_filename( const char *filename, |
const Cyg_StdioStream::OpenMode rw, |
const cyg_bool binary, |
const cyg_bool append ); |
|
externC Cyg_ErrNo |
cyg_libc_stdio_flush_all_but( Cyg_StdioStream *not_this_stream ); |
|
#endif // CYGONCE_LIBC_STDIOL_STDIOSUPP_HXX multiple inclusion protection |
|
// EOF stdiosupp.hxx |
/stream.hxx
0,0 → 1,321
#ifndef CYGONCE_LIBC_STDIO_STREAM_HXX |
#define CYGONCE_LIBC_STDIO_STREAM_HXX |
//======================================================================== |
// |
// stream.hxx |
// |
// Internal C library stdio stream interface definitions |
// |
//======================================================================== |
//####ECOSGPLCOPYRIGHTBEGIN#### |
// ------------------------------------------- |
// This file is part of eCos, the Embedded Configurable Operating System. |
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc. |
// |
// eCos is free software; you can redistribute it and/or modify it under |
// the terms of the GNU General Public License as published by the Free |
// Software Foundation; either version 2 or (at your option) any later version. |
// |
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY |
// WARRANTY; without even the implied warranty of MERCHANTABILITY or |
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
// for more details. |
// |
// You should have received a copy of the GNU General Public License along |
// with eCos; if not, write to the Free Software Foundation, Inc., |
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
// |
// As a special exception, if other files instantiate templates or use macros |
// or inline functions from this file, or you compile this file and link it |
// with other works to produce a work based on this file, this file does not |
// by itself cause the resulting work to be covered by the GNU General Public |
// License. However the source code for this file must still be made available |
// in accordance with section (3) of the GNU General Public License. |
// |
// This exception does not invalidate any other reasons why a work based on |
// this file might be covered by the GNU General Public License. |
// |
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc. |
// at http://sources.redhat.com/ecos/ecos-license/ |
// ------------------------------------------- |
//####ECOSGPLCOPYRIGHTEND#### |
//======================================================================== |
//#####DESCRIPTIONBEGIN#### |
// |
// Author(s): jlarmour |
// Contributors: |
// Date: 2001-03-16 |
// Purpose: |
// Description: |
// Usage: #include <cyg/libc/stdio/stream.hxx> |
// |
//####DESCRIPTIONEND#### |
// |
//======================================================================== |
|
// CONFIGURATION |
|
#include <pkgconf/libc_stdio.h> // Configuration header |
|
// INCLUDES |
|
#include <cyg/infra/cyg_type.h> // Common project-wide type definitions |
#include <cyg/infra/cyg_ass.h> // Get assertion macros, as appropriate |
#include <errno.h> // Cyg_ErrNo |
#include <stdio.h> // fpos_t and IOBUF defines |
#include <cyg/libc/stdio/io.hxx> // Physical IO support |
#include <cyg/libc/stdio/streambuf.hxx> // Stdio stream file buffers |
|
#ifdef CYGSEM_LIBC_STDIO_THREAD_SAFE_STREAMS |
#include <pkgconf/kernel.h> |
#include <cyg/kernel/mutex.hxx> // Cyg_Mutex |
#endif |
|
// TYPE DEFINITIONS |
|
class Cyg_StdioStream; |
__externC Cyg_ErrNo |
cyg_libc_stdio_flush_all_but( Cyg_StdioStream * ); |
|
class Cyg_StdioStream |
{ |
friend int setvbuf( FILE *, char *, int, size_t ); |
friend Cyg_ErrNo |
cyg_libc_stdio_flush_all_but( Cyg_StdioStream * ); |
|
private: |
|
// error status for this file |
Cyg_ErrNo error; |
|
|
cyg_stdio_handle_t my_device; |
|
#ifdef CYGFUN_LIBC_STDIO_ungetc |
cyg_uint8 unread_char_buf; |
#endif |
|
#ifdef CYGSEM_LIBC_STDIO_WANT_BUFFERED_IO |
Cyg_StdioStreamBuffer io_buf; // read/write buffer |
#endif |
cyg_uint8 readbuf_char; // a one character emergency "buffer" |
// only used when configured to not buffer |
// (i.e. !CYGSEM_LIBC_STDIO_WANT_BUFFERED_IO) |
// or set at runtime to not buffer (i.e. |
// buffering mode is _IONBF) |
|
// some flags indicating the state of the file. Some of it is internal |
// state, which should not be public. Use bitfields to save |
// space, which means using "unsigned int" rather than cyg_uintX |
struct { |
unsigned int at_eof : 1; // Have we reached eof? |
|
unsigned int opened_for_read : 1; // opened_for_read and |
|
unsigned int opened_for_write : 1; // opened_for_write can |
// be set simultaneously |
|
unsigned int binary : 1; // opened for binary or |
// text mode? |
|
#ifdef CYGFUN_LIBC_STDIO_ungetc |
unsigned int unread_char_buf_in_use : 1; // unget buf in use? |
#endif |
|
#ifdef CYGSEM_LIBC_STDIO_WANT_BUFFERED_IO |
unsigned int buffering : 1; // Is this file buffered? |
|
unsigned int line_buffering : 1; // If so, is it line |
// buffered? If it is |
// buffered, but NOT line |
// buffered, it must be |
// fully buffered |
|
unsigned int last_buffer_op_was_read : 1; // did we last read from |
// the buffer. If not we |
// must have written |
#endif |
unsigned int readbuf_char_in_use : 1; // is the above |
// readbuf_char in use? |
|
} flags; |
|
// current position for reading/writing |
fpos_t position; |
|
#ifdef CYGSEM_LIBC_STDIO_THREAD_SAFE_STREAMS |
Cyg_Mutex stream_lock; // used for locking this stream |
#endif // ifdef CYGSEM_LIBC_STDIO_THREAD_SAFE_STREAMS |
|
#ifdef CYGDBG_USE_ASSERTS |
// a value to check that this class is hopefully valid |
cyg_ucount32 magic_validity_word; |
#endif |
|
public: |
// different modes when constructing (i.e. opening). |
typedef enum { |
CYG_STREAM_READ, |
CYG_STREAM_WRITE, |
CYG_STREAM_READWRITE |
} OpenMode; |
|
// CONSTRUCTORS |
|
// This constructs the stream - effectively opens the file. This is |
// used for static initialisation, and actually calls construct below |
// |
// dev is a valid Cyg_Device_Table_t, although it does not have to |
// be a member of the device table object itself |
// |
// open_mode is one of CYG_STREAM_READ, CYG_STREAM_WRITE or |
// CYG_STREAM_READWRITE |
// |
// append is true if the file position should be set at EOF on opening |
// |
// binary is true if this is a binary stream. Otherwise it is a text |
// stream and character conversions (especially newline) may occur |
// |
// buffer_mode is one of _IONBF, _IOLBF, _IOFBF (from <stdio.h>) |
// If buffer_mode is _IONBF, buffer_size should still be set to 0 |
// and buffer_addr to NULL. If buffering is not configured, none |
// of buffer_mode, buffer_size and buffer_addr have any effect |
// |
// buffer_size is the size of buffer to use |
// |
// buffer_addr is the address of a user supplied buffer. By default |
// (when NULL) a system one is provided. |
// |
// The "return code" is set by assignment to the error member of this |
// stream - use the get_error() method to check |
|
Cyg_StdioStream( cyg_stdio_handle_t dev, OpenMode open_mode, |
cyg_bool append, cyg_bool binary, int buffer_mode, |
cyg_ucount32 buffer_size=BUFSIZ, |
cyg_uint8 *buffer_addr=NULL ); |
|
Cyg_StdioStream( OpenMode open_mode, |
cyg_ucount32 buffer_size=BUFSIZ, |
cyg_uint8 *buffer_addr=NULL ); |
|
private: |
void initialize( cyg_stdio_handle_t dev, OpenMode open_mode, |
cyg_bool append, cyg_bool binary, int buffer_mode, |
cyg_ucount32 buffer_size=BUFSIZ, |
cyg_uint8 *buffer_addr=NULL ); |
public: |
|
// DESTRUCTOR |
|
~Cyg_StdioStream(); |
|
|
// MEMBER FUNCTIONS |
|
// Close the stream. This should be called before the destructor, |
// so we can see and report any errors produced. |
Cyg_ErrNo close(); |
|
// Refill read buffer from the stream - note this blocks until |
// something arrives on the stream |
Cyg_ErrNo |
refill_read_buffer( void ); |
|
|
// Read not more than buffer_length bytes from the read buffer into the |
// user buffer. |
// The number of bytes put into the user buffer is written |
// into *bytes_read |
Cyg_ErrNo |
read( cyg_uint8 *user_buffer, cyg_ucount32 buffer_length, |
cyg_ucount32 *bytes_read ); |
|
|
// Read a single byte from the stream. Returns EAGAIN if no character |
// available or EEOF if end of file (as well as setting the EOF state) |
Cyg_ErrNo |
read_byte( cyg_uint8 *c ); |
|
// Read a single byte from the stream, but don't remove it. Returns |
// EAGAIN if no character available or EEOF if end of file (as well |
// as setting the EOF state) |
Cyg_ErrNo |
peek_byte( cyg_uint8 *c ); |
|
|
// Return a byte into the stream - basically the same as ungetc() |
Cyg_ErrNo |
unread_byte( cyg_uint8 c ); |
|
// the number of bytes available to read without needing to refill the |
// buffer |
cyg_ucount32 |
bytes_available_to_read( void ); |
|
Cyg_ErrNo |
write( const cyg_uint8 *buffer, cyg_ucount32 buffer_length, |
cyg_ucount32 *bytes_written ); |
|
Cyg_ErrNo |
write_byte( cyg_uint8 c ); |
|
|
Cyg_ErrNo |
flush_output( void ); |
|
Cyg_ErrNo |
flush_output_unlocked( void ); |
|
// prevent multiple access in thread safe mode |
|
// lock_me() returns false if it couldn't be locked, which could |
// happen if the file descriptor is bad |
|
cyg_bool |
lock_me( void ); |
|
// trylock_me() returns false if it couldn't be locked, probably |
// because it is already locked |
cyg_bool |
trylock_me( void ); |
|
void |
unlock_me( void ); |
|
// get error status for this file |
Cyg_ErrNo |
get_error( void ); |
|
// set error status for this file. |
void |
set_error( Cyg_ErrNo errno_to_set ); |
|
// are we at EOF? true means we are, false means no |
cyg_bool |
get_eof_state( void ); |
|
// Set whether we are at EOF. |
void |
set_eof_state( cyg_bool eof_to_set ); |
|
// retrieve position |
Cyg_ErrNo |
get_position( fpos_t *pos ); |
|
// set absolute position. whence is SEEK_SET, SEEK_CUR, or SEEK_END |
Cyg_ErrNo |
set_position( fpos_t pos, int whence ); |
|
// Return my_device |
cyg_stdio_handle_t get_dev() { return my_device; }; |
|
CYGDBG_DEFINE_CHECK_THIS |
}; |
|
// INLINE FUNCTIONS |
|
#include <cyg/libc/stdio/stream.inl> |
|
#endif // CYGONCE_LIBC_STDIO_STREAM_HXX multiple inclusion protection |
|
// EOF stream.hxx |
/stdio.inl
0,0 → 1,159
#ifndef CYGONCE_LIBC_STDIO_STDIO_INL |
#define CYGONCE_LIBC_STDIO_STDIO_INL |
//=========================================================================== |
// |
// stdio.inl |
// |
// ANSI standard I/O routines - inlined functions |
// |
//=========================================================================== |
//####ECOSGPLCOPYRIGHTBEGIN#### |
// ------------------------------------------- |
// This file is part of eCos, the Embedded Configurable Operating System. |
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc. |
// |
// eCos is free software; you can redistribute it and/or modify it under |
// the terms of the GNU General Public License as published by the Free |
// Software Foundation; either version 2 or (at your option) any later version. |
// |
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY |
// WARRANTY; without even the implied warranty of MERCHANTABILITY or |
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
// for more details. |
// |
// You should have received a copy of the GNU General Public License along |
// with eCos; if not, write to the Free Software Foundation, Inc., |
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
// |
// As a special exception, if other files instantiate templates or use macros |
// or inline functions from this file, or you compile this file and link it |
// with other works to produce a work based on this file, this file does not |
// by itself cause the resulting work to be covered by the GNU General Public |
// License. However the source code for this file must still be made available |
// in accordance with section (3) of the GNU General Public License. |
// |
// This exception does not invalidate any other reasons why a work based on |
// this file might be covered by the GNU General Public License. |
// |
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc. |
// at http://sources.redhat.com/ecos/ecos-license/ |
// ------------------------------------------- |
//####ECOSGPLCOPYRIGHTEND#### |
//=========================================================================== |
//#####DESCRIPTIONBEGIN#### |
// |
// Author(s): jlarmour |
// Contributors: |
// Date: 2000-04-19 |
// Purpose: |
// Description: |
// Usage: Do not include this file directly - use #include <stdio.h> |
// |
//####DESCRIPTIONEND#### |
// |
//=========================================================================== |
|
// CONFIGURATION |
|
#include <pkgconf/libc_stdio.h> // Configuration header |
|
// INCLUDES |
|
#include <cyg/infra/cyg_type.h> // Common type definitions and support |
#include <stddef.h> // NULL and size_t from compiler |
#include <stdarg.h> // va_list |
#include <stdio.h> // Just be sure it has been included |
#include <errno.h> // Definition of error codes and errno |
#include <string.h> // Definition of strerror() for perror() |
#include <limits.h> // INT_MAX |
|
// INLINE FUNCTION DEFINITIONS |
|
//=========================================================================== |
|
// 7.9.5 File access functions |
|
extern __inline__ void |
setbuf( FILE *stream, char *buf ) |
{ |
if (buf == NULL) |
setvbuf( stream, NULL, _IONBF, 0 ); |
else |
// NB: Should use full buffering by default ordinarily, but in |
// the current system we're always connected to an interactive |
// terminal, so use line buffering |
setvbuf( stream, buf, _IOLBF, BUFSIZ ); |
|
} // setbuf() |
|
//=========================================================================== |
|
// 7.9.6 Formatted input/output functions |
|
extern __inline__ int |
vfprintf( FILE *stream, const char *format, va_list arg ) |
{ |
return vfnprintf(stream, INT_MAX, format, arg); |
} // vfprintf() |
|
|
extern __inline__ int |
vprintf( const char *format, va_list arg ) |
{ |
return vfnprintf(stdout, INT_MAX, format, arg); |
} // vprintf() |
|
|
extern __inline__ int |
vsprintf( char *s, const char *format, va_list arg ) |
{ |
return vsnprintf(s, INT_MAX, format, arg); |
} // vsprintf() |
|
|
//=========================================================================== |
|
// 7.9.7 Character input/output functions |
|
extern __inline__ int |
puts( const char *s ) |
{ |
int rc; |
|
rc = fputs( s, stdout ); |
|
if (rc >= 0) |
rc = fputc('\n', stdout ); |
|
return rc; |
} // puts() |
|
|
//=========================================================================== |
|
// 7.9.10 Error-handling functions |
|
extern __inline__ void |
perror( const char *s ) |
{ |
if (s && *s) |
fprintf( stderr, "%s: %s\n", s, strerror(errno) ); |
else |
fputs( strerror(errno), stderr ); |
|
} // perror() |
|
//=========================================================================== |
|
// Other non-ANSI functions |
|
extern __inline__ int |
vscanf( const char *format, va_list arg ) |
{ |
return vfscanf( stdin, format, arg ); |
} // vscanf() |
|
|
#endif // CYGONCE_LIBC_STDIO_STDIO_INL multiple inclusion protection |
|
// EOF stdio.inl |
/stdiofiles.inl
0,0 → 1,126
#ifndef CYGONCE_LIBC_STDIO_STDIOFILES_INL |
#define CYGONCE_LIBC_STDIO_STDIOFILES_INL |
//======================================================================== |
// |
// stdiofiles.inl |
// |
// ISO C library stdio central file inlines |
// |
//======================================================================== |
//####ECOSGPLCOPYRIGHTBEGIN#### |
// ------------------------------------------- |
// This file is part of eCos, the Embedded Configurable Operating System. |
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc. |
// |
// eCos is free software; you can redistribute it and/or modify it under |
// the terms of the GNU General Public License as published by the Free |
// Software Foundation; either version 2 or (at your option) any later version. |
// |
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY |
// WARRANTY; without even the implied warranty of MERCHANTABILITY or |
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
// for more details. |
// |
// You should have received a copy of the GNU General Public License along |
// with eCos; if not, write to the Free Software Foundation, Inc., |
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
// |
// As a special exception, if other files instantiate templates or use macros |
// or inline functions from this file, or you compile this file and link it |
// with other works to produce a work based on this file, this file does not |
// by itself cause the resulting work to be covered by the GNU General Public |
// License. However the source code for this file must still be made available |
// in accordance with section (3) of the GNU General Public License. |
// |
// This exception does not invalidate any other reasons why a work based on |
// this file might be covered by the GNU General Public License. |
// |
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc. |
// at http://sources.redhat.com/ecos/ecos-license/ |
// ------------------------------------------- |
//####ECOSGPLCOPYRIGHTEND#### |
//======================================================================== |
//#####DESCRIPTIONBEGIN#### |
// |
// Author(s): jlarmour |
// Contributors: |
// Date: 2000-04-19 |
// Purpose: |
// Description: |
// Usage: Do not include this file directly. Instead use: |
// #include <cyg/libc/stdio/stdiofiles.hxx> |
// |
//####DESCRIPTIONEND#### |
// |
//======================================================================== |
|
// CONFIGURATION |
|
#include <pkgconf/libc_stdio.h> // libc stdio configuration |
|
// INCLUDES |
|
#include <cyg/infra/cyg_type.h> // cyg_bool |
#include <cyg/infra/cyg_ass.h> // Assert interface |
#include <cyg/libc/stdio/stdiofiles.hxx> // header for this file |
#include <cyg/libc/stdio/stream.hxx> // Cyg_StdioStream |
|
#ifdef CYGSEM_LIBC_STDIO_THREAD_SAFE_STREAMS |
# include <cyg/kernel/mutex.hxx> // mutexes |
#endif |
|
// INLINE METHODS |
|
inline Cyg_StdioStream * |
Cyg_libc_stdio_files::get_file_stream( fd_t fd ) |
{ |
CYG_PRECONDITION( (fd < FOPEN_MAX), |
"Attempt to open larger file descriptor than FOPEN_MAX!" ); |
|
return files[fd]; |
|
} // Cyg_libc_stdio_files::get_file_stream() |
|
inline void |
Cyg_libc_stdio_files::set_file_stream( fd_t fd, Cyg_StdioStream *stream ) |
{ |
CYG_PRECONDITION( (fd < FOPEN_MAX), |
"Attempt to set larger file descriptor than FOPEN_MAX!" ); |
|
files[fd] = stream; |
|
} // Cyg_libc_stdio_files::set_file_stream() |
|
|
inline cyg_bool |
Cyg_libc_stdio_files::lock(void) |
{ |
# ifdef CYGSEM_LIBC_STDIO_THREAD_SAFE_STREAMS |
return files_lock.lock(); |
# else |
return true; |
# endif |
} // Cyg_libc_stdio_files::lock() |
|
inline cyg_bool |
Cyg_libc_stdio_files::trylock(void) |
{ |
# ifdef CYGSEM_LIBC_STDIO_THREAD_SAFE_STREAMS |
return files_lock.trylock(); |
# else |
return true; |
# endif |
} // Cyg_libc_stdio_files::trylock() |
|
inline void |
Cyg_libc_stdio_files::unlock(void) |
{ |
# ifdef CYGSEM_LIBC_STDIO_THREAD_SAFE_STREAMS |
files_lock.unlock(); |
# endif |
} // Cyg_libc_stdio_files::unlock() |
|
|
#endif // CYGONCE_LIBC_STDIO_STDIOFILES_INL multiple inclusion protection |
|
// EOF stdiofiles.inl |
/io.inl
0,0 → 1,255
#ifndef CYGONCE_LIBC_STDIO_IO_INL |
#define CYGONCE_LIBC_STDIO_IO_INL |
//======================================================================== |
// |
// io.inl |
// |
// Internal C library stdio io interface inlines |
// |
//======================================================================== |
//####ECOSGPLCOPYRIGHTBEGIN#### |
// ------------------------------------------- |
// This file is part of eCos, the Embedded Configurable Operating System. |
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc. |
// |
// eCos is free software; you can redistribute it and/or modify it under |
// the terms of the GNU General Public License as published by the Free |
// Software Foundation; either version 2 or (at your option) any later version. |
// |
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY |
// WARRANTY; without even the implied warranty of MERCHANTABILITY or |
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
// for more details. |
// |
// You should have received a copy of the GNU General Public License along |
// with eCos; if not, write to the Free Software Foundation, Inc., |
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
// |
// As a special exception, if other files instantiate templates or use macros |
// or inline functions from this file, or you compile this file and link it |
// with other works to produce a work based on this file, this file does not |
// by itself cause the resulting work to be covered by the GNU General Public |
// License. However the source code for this file must still be made available |
// in accordance with section (3) of the GNU General Public License. |
// |
// This exception does not invalidate any other reasons why a work based on |
// this file might be covered by the GNU General Public License. |
// |
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc. |
// at http://sources.redhat.com/ecos/ecos-license/ |
// ------------------------------------------- |
//####ECOSGPLCOPYRIGHTEND#### |
//======================================================================== |
//#####DESCRIPTIONBEGIN#### |
// |
// Author(s): nickg |
// Contributors: |
// Date: 2000-06-30 |
// Purpose: |
// Description: |
// Usage: #include <cyg/libc/stdio/io.hxx> |
// |
//####DESCRIPTIONEND#### |
// |
//======================================================================== |
|
// CONFIGURATION |
|
#include <pkgconf/libc_stdio.h> // Configuration header |
|
//======================================================================== |
// INCLUDES |
|
#include <cyg/libc/stdio/io.hxx> |
|
//======================================================================== |
// FileIO versions of IO functions |
|
#ifdef CYGPKG_LIBC_STDIO_FILEIO |
|
inline Cyg_ErrNo cyg_stdio_open( const char *filename, |
const Cyg_StdioStream::OpenMode rw, |
const cyg_bool binary, |
const cyg_bool append, |
cyg_stdio_handle_t *dev) |
{ |
mode_t mode = 0; |
int fd; |
|
switch( rw ) |
{ |
case Cyg_StdioStream::CYG_STREAM_WRITE: |
mode = O_WRONLY|O_CREAT|O_TRUNC; |
break; |
case Cyg_StdioStream::CYG_STREAM_READ: |
mode = O_RDONLY; |
break; |
case Cyg_StdioStream::CYG_STREAM_READWRITE: |
mode = O_RDWR; |
break; |
} |
|
if( append ) |
{ |
mode |= O_APPEND; |
mode &= ~O_TRUNC; |
} |
|
fd = open( filename, mode ); |
|
if( fd < 0 ) |
return errno; |
|
*dev = fd; |
return ENOERR; |
} |
|
inline Cyg_ErrNo cyg_stdio_close( cyg_stdio_handle_t dev ) |
{ |
if( close( dev ) != ENOERR ) |
return errno; |
return ENOERR; |
} |
|
inline Cyg_ErrNo cyg_stdio_read( cyg_stdio_handle_t dev, |
void *buffer, cyg_uint32 *len ) |
{ |
if( dev != CYG_STDIO_HANDLE_NULL ) |
{ |
ssize_t done = read( dev, buffer, *len ); |
|
if( done < 0 ) |
{ |
*len = 0; |
return errno; |
} |
|
*len = done; |
} |
// If the device is NULL, just return EOF indication |
else *len = 0; |
|
return ENOERR; |
} |
|
inline Cyg_ErrNo cyg_stdio_write( cyg_stdio_handle_t dev, |
const void *buffer, cyg_uint32 *len ) |
{ |
if( dev != CYG_STDIO_HANDLE_NULL ) |
{ |
ssize_t done = write( dev, buffer, *len ); |
|
if( done < 0 ) |
{ |
*len = 0; |
return errno; |
} |
|
*len = done; |
} |
// if the device is NULL, just absorb all writes. |
|
return ENOERR; |
} |
|
inline Cyg_ErrNo cyg_stdio_lseek( cyg_stdio_handle_t dev, |
off_t *pos, int whence ) |
{ |
off_t newpos = lseek( dev, *pos, whence ); |
|
if( newpos < 0 ) |
return errno; |
|
*pos = newpos; |
|
return ENOERR; |
} |
|
inline Cyg_ErrNo cyg_stdio_flush( cyg_stdio_handle_t dev ) |
{ |
int err = fsync( dev ); |
|
if( err < 0 ) |
return errno; |
|
return ENOERR; |
} |
|
inline cyg_bool cyg_stdio_interactive( cyg_stdio_handle_t dev ) |
{ |
struct stat buf; |
int err; |
|
err = fstat( dev, &buf ); |
|
// If we get an error, assume interactive. |
if( err < 0 ) |
return true; |
|
if( S_ISCHR(buf.st_mode) ) |
return true; |
|
return false; |
} |
|
|
#endif // CYGPKG_LIBC_STDIO_FILEIO |
|
//======================================================================== |
// Direct IO versions of IO functions |
|
#ifndef CYGPKG_LIBC_STDIO_FILEIO |
|
inline Cyg_ErrNo cyg_stdio_open( const char *filename, |
const Cyg_StdioStream::OpenMode rw, |
const cyg_bool binary, |
const cyg_bool append, |
cyg_stdio_handle_t *dev) |
{ |
return cyg_io_lookup( filename, dev ); |
} |
|
inline Cyg_ErrNo cyg_stdio_close( cyg_stdio_handle_t dev ) |
{ |
// Devices do not get closed |
return ENOERR; |
} |
|
inline Cyg_ErrNo cyg_stdio_read( cyg_stdio_handle_t dev, |
void *buffer, cyg_uint32 *len ) |
{ |
return cyg_io_read( dev, buffer, len ); |
} |
|
inline Cyg_ErrNo cyg_stdio_write( cyg_stdio_handle_t dev, |
const void *buffer, cyg_uint32 *len ) |
{ |
return cyg_io_write( dev, buffer, len ); |
} |
|
inline cyg_uint32 cyg_stdio_lseek( cyg_stdio_handle_t dev, |
cyg_uint32 *pos, int whence ) |
{ |
// No seeking in raw devices, just return fake success |
return ENOERR; |
} |
|
inline Cyg_ErrNo cyg_stdio_flush( cyg_stdio_handle_t dev ) |
{ |
return cyg_io_get_config(dev, |
CYG_IO_GET_CONFIG_SERIAL_OUTPUT_DRAIN, |
NULL, NULL); |
} |
|
inline cyg_bool cyg_stdio_interactive( cyg_stdio_handle_t dev ) |
{ |
return true; |
} |
|
|
#endif // !CYGPKG_LIBC_STDIO_FILEIO |
|
//======================================================================== |
#endif // CYGONCE_LIBC_STDIO_IO_INL multiple inclusion protection |
// EOF io.inl |
|
/stdio.h
0,0 → 1,308
#ifndef CYGONCE_LIBC_STDIO_STDIO_H |
#define CYGONCE_LIBC_STDIO_STDIO_H |
//======================================================================== |
// |
// stdio.h |
// |
// ISO C standard I/O routines - with some POSIX 1003.1 extensions |
// |
//======================================================================== |
//####ECOSGPLCOPYRIGHTBEGIN#### |
// ------------------------------------------- |
// This file is part of eCos, the Embedded Configurable Operating System. |
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc. |
// |
// eCos is free software; you can redistribute it and/or modify it under |
// the terms of the GNU General Public License as published by the Free |
// Software Foundation; either version 2 or (at your option) any later version. |
// |
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY |
// WARRANTY; without even the implied warranty of MERCHANTABILITY or |
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
// for more details. |
// |
// You should have received a copy of the GNU General Public License along |
// with eCos; if not, write to the Free Software Foundation, Inc., |
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
// |
// As a special exception, if other files instantiate templates or use macros |
// or inline functions from this file, or you compile this file and link it |
// with other works to produce a work based on this file, this file does not |
// by itself cause the resulting work to be covered by the GNU General Public |
// License. However the source code for this file must still be made available |
// in accordance with section (3) of the GNU General Public License. |
// |
// This exception does not invalidate any other reasons why a work based on |
// this file might be covered by the GNU General Public License. |
// |
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc. |
// at http://sources.redhat.com/ecos/ecos-license/ |
// ------------------------------------------- |
//####ECOSGPLCOPYRIGHTEND#### |
//======================================================================== |
//#####DESCRIPTIONBEGIN#### |
// |
// Author(s): jlarmour |
// Contributors: |
// Date: 2000-04-19 |
// Purpose: ISO C standard I/O routines |
// Description: |
// Usage: Do not include this file directly - use #include <stdio.h> |
// |
//####DESCRIPTIONEND#### |
// |
//======================================================================== |
|
// CONFIGURATION |
|
#include <pkgconf/libc_stdio.h> // Configuration header |
|
// INCLUDES |
|
#include <cyg/infra/cyg_type.h> // common type definitions and support |
#include <stdarg.h> // va_list from compiler |
|
// CONSTANTS |
|
// Some of these values are odd to ensure that asserts have better effect |
// should spurious values be passed to functions expecting these constants. |
|
// _IOFBF, _IOLBF, and _IONBF specify full, line or no buffering when used |
// with setvbuf() - ISO C standard chap 7.9.1 |
|
#define _IOFBF (-2) |
#define _IOLBF (-4) |
#define _IONBF (-8) |
|
// EOF is a macro defined to any negative integer constant - ISO C standard |
// chap. 7.9.1 |
#define EOF (-1) |
|
// SEEK_CUR, SEEK_END and SEEK_SET are used with fseek() as position |
// anchors - ISO C standard chap. 7.9.1 |
#define SEEK_SET 0 |
#define SEEK_CUR 1 |
#define SEEK_END 2 |
|
|
// TYPE DEFINITIONS |
|
// A type capable of specifying uniquely every file position - ISO C |
// standard chap 7.9.1 |
typedef cyg_ucount32 fpos_t; |
|
|
// FILE is just cast to an address here. It is uncast internally to the |
// C library in stream.hxx as the C++ Cyg_StdioStream class. |
// Optional run-time checking can be enabled to ensure that the cast is |
// valid, using the standard assertion functionality. |
// |
// The array size is irrelevant other than being more than 8, and is present |
// to stop references to FILEs being marked as able to be put in the small |
// data section. We can't just mark it as in the ".data" section as on some |
// targets it may actually be ".common". |
typedef CYG_ADDRESS FILE[9999]; |
|
// EXTERNAL VARIABLES |
|
// Default file streams for input/output. These only need to be |
// expressions, not l-values - ISO C standard chap. 7.9.1 |
// |
// CYGPRI_LIBC_STDIO_NO_DEFAULT_STREAMS is used when initializing |
// stdin/out/err privately inside the C library |
|
#ifndef CYGPRI_LIBC_STDIO_NO_DEFAULT_STREAMS |
__externC FILE *stdin, *stdout, *stderr; |
#endif |
|
// FUNCTION PROTOTYPES |
|
//======================================================================== |
|
// ISO C 7.9.5 File access functions |
|
externC int |
fclose( FILE * /* stream */ ); |
|
externC int |
fflush( FILE * /* stream */ ); |
|
externC FILE * |
fopen( const char * /* filename */, const char * /* mode */ ); |
|
externC FILE * |
freopen( const char * /* filename */, const char * /* mode */, |
FILE * /* stream */ ); |
|
externC void |
setbuf( FILE * /* stream */, char * /* buffer */ ); |
|
externC int |
setvbuf( FILE * /* stream */, char * /* buffer */, int /* mode */, |
size_t /* size */ ); |
|
//======================================================================== |
|
// ISO C 7.9.6 Formatted input/output functions |
|
externC int |
fprintf( FILE * /* stream */, const char * /* format */, ... ); |
|
externC int |
fscanf( FILE * /* stream */, const char * /* format */, ... ); |
|
externC int |
printf( const char * /* format */, ... ); |
|
externC int |
scanf( const char * /* format */, ... ); |
|
externC int |
sprintf( char * /* str */, const char * /* format */, ... ); |
|
externC int |
sscanf( const char * /* str */, const char * /* format */, ... ); |
|
externC int |
vfprintf( FILE * /* stream */, const char * /* format */, |
va_list /* args */ ); |
|
externC int |
vprintf( const char * /* format */, va_list /* args */ ); |
|
externC int |
vsprintf( char * /* str */, const char * /* format */, |
va_list /* args */ ); |
|
//======================================================================== |
|
// ISO C 7.9.7 Character input/output functions |
|
externC int |
fgetc( FILE * /* stream */ ); |
|
externC char * |
fgets( char * /* str */, int /* length */, FILE * /* stream */ ); |
|
externC int |
fputc( int /* c */, FILE * /* stream */ ); |
|
externC int |
putc( int /* c */, FILE * /* stream */ ); |
|
externC int |
putchar( int /* c */ ); |
|
externC int |
fputs( const char * /* str */, FILE * /* stream */ ); |
|
externC char * |
gets( char * ); |
|
externC int |
getc( FILE * /* stream */ ); |
|
externC int |
getchar( void ); |
|
externC int |
puts( const char * /* str */ ); |
|
externC int |
ungetc( int /* c */, FILE * /* stream */ ); |
|
// no function equivalent is required for getchar() or putchar(), so we can |
// just #define them |
|
#define getchar() fgetc( stdin ) |
|
#define putchar(__c) fputc(__c, stdout) |
|
//======================================================================== |
|
// ISO C 7.9.8 Direct input/output functions |
|
externC size_t |
fread( void * /* ptr */, size_t /* object_size */, |
size_t /* num_objects */, FILE * /* stream */ ); |
|
externC size_t |
fwrite( const void * /* ptr */, size_t /* object_size */, |
size_t /* num_objects */, FILE * /* stream */ ); |
|
//======================================================================== |
|
// ISO C 7.9.9 File positioning functions |
|
externC int |
fgetpos( FILE * /* stream */, fpos_t * /* pos */ ); |
|
externC int |
fseek( FILE * /* stream */, long int /* offset */, int /* whence */ ); |
|
externC int |
fsetpos( FILE * /* stream */, const fpos_t * /* pos */ ); |
|
externC long int |
ftell( FILE * /* stream */ ); |
|
externC void |
rewind( FILE * /* stream */ ); |
|
//======================================================================== |
|
// ISO C 7.9.10 Error-handling functions |
|
externC void |
clearerr( FILE * /* stream */ ); |
|
externC int |
feof( FILE * /* stream */ ); |
|
externC int |
ferror( FILE * /* stream */ ); |
|
externC void |
perror( const char * /* prefix_str */ ); |
|
//======================================================================== |
|
// Other non-ISO C functions |
|
externC int |
fnprintf( FILE * /* stream */, size_t /* length */, |
const char * /* format */, ... ) CYGBLD_ATTRIB_PRINTF_FORMAT(3, 4); |
|
externC int |
snprintf( char * /* str */, size_t /* length */, const char * /* format */, |
... ) CYGBLD_ATTRIB_PRINTF_FORMAT(3, 4); |
|
externC int |
vfnprintf( FILE * /* stream */, size_t /* length */, |
const char * /* format */, va_list /* args */ ); |
|
externC int |
vsnprintf( char * /* str */, size_t /* length */, |
const char * /* format */, va_list /* args */ ); |
|
externC int |
vscanf( const char * /* format */, va_list /* args */ ); |
|
externC int |
vsscanf( const char * /* str */, const char * /* format */, |
va_list /* args */ ); |
|
externC int |
vfscanf( FILE * /* stream */, const char * /* format */, |
va_list /* args */ ); |
|
|
// INLINE FUNCTIONS |
|
#ifdef CYGIMP_LIBC_STDIO_INLINES |
# include <cyg/libc/stdio/stdio.inl> |
#endif |
|
#endif // CYGONCE_LIBC_STDIO_STDIO_H multiple inclusion protection |
|
// EOF stdio.h |
/streambuf.inl
0,0 → 1,186
#ifndef CYGONCE_LIBC_STDIO_STREAMBUF_INL |
#define CYGONCE_LIBC_STDIO_STREAMBUF_INL |
//=========================================================================== |
// |
// streambuf.inl |
// |
// Internal C library stdio stream buffer inline functions |
// |
//=========================================================================== |
//####ECOSGPLCOPYRIGHTBEGIN#### |
// ------------------------------------------- |
// This file is part of eCos, the Embedded Configurable Operating System. |
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc. |
// |
// eCos is free software; you can redistribute it and/or modify it under |
// the terms of the GNU General Public License as published by the Free |
// Software Foundation; either version 2 or (at your option) any later version. |
// |
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY |
// WARRANTY; without even the implied warranty of MERCHANTABILITY or |
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
// for more details. |
// |
// You should have received a copy of the GNU General Public License along |
// with eCos; if not, write to the Free Software Foundation, Inc., |
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
// |
// As a special exception, if other files instantiate templates or use macros |
// or inline functions from this file, or you compile this file and link it |
// with other works to produce a work based on this file, this file does not |
// by itself cause the resulting work to be covered by the GNU General Public |
// License. However the source code for this file must still be made available |
// in accordance with section (3) of the GNU General Public License. |
// |
// This exception does not invalidate any other reasons why a work based on |
// this file might be covered by the GNU General Public License. |
// |
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc. |
// at http://sources.redhat.com/ecos/ecos-license/ |
// ------------------------------------------- |
//####ECOSGPLCOPYRIGHTEND#### |
//=========================================================================== |
//#####DESCRIPTIONBEGIN#### |
// |
// Author(s): jlarmour |
// Contributors: |
// Date: 2000-04-19 |
// Purpose: |
// Description: |
// Usage: Do not include this file directly, instead |
// #include <cyg/libc/stdio/streambuf.hxx> |
// |
//####DESCRIPTIONEND#### |
// |
//=========================================================================== |
|
// CONFIGURATION |
|
#include <pkgconf/libc_stdio.h> // Configuration header |
|
// Include buffered I/O? |
#if defined(CYGSEM_LIBC_STDIO_WANT_BUFFERED_IO) |
|
|
// INCLUDES |
|
#include <cyg/infra/cyg_type.h> // Common project-wide type definitions |
#include <cyg/infra/cyg_ass.h> // Assertion support |
#include <errno.h> // Cyg_ErrNo |
#include <stdio.h> // fpos_t and iobuf defines |
#include <stdlib.h> // free() |
#include <cyg/libc/stdio/streambuf.hxx> // header for this file, just in case |
#include <limits.h> // INT_MAX |
|
// FUNCTIONS |
|
inline |
Cyg_StdioStreamBuffer::Cyg_StdioStreamBuffer( cyg_ucount32 size, |
cyg_uint8 *new_buffer ) : |
#if defined(CYGSEM_LIBC_STDIO_SETVBUF_MALLOC) |
call_free(false), |
buffer_bottom( NULL ), |
buffer_size(0), |
#else |
buffer_bottom( static_buffer ), |
buffer_size(sizeof(static_buffer)), |
#endif |
buffer_top(NULL), |
current_buffer_position(NULL) |
{ |
// NB Many of the above members in the initialisation list may seem |
// unnecessary, but it is to ensure a defined state if e.g. the malloc |
// in set_buffer() should fail |
|
(void)set_buffer(size, new_buffer); |
} // Cyg_StdioStreamBuffer constructor |
|
|
inline |
Cyg_StdioStreamBuffer::~Cyg_StdioStreamBuffer() |
{ |
#ifdef CYGSEM_LIBC_STDIO_SETVBUF_MALLOC |
if ((buffer_bottom != NULL) && call_free) |
free( buffer_bottom ); |
#endif |
} // Cyg_StdioStreamBuffer destructor |
|
|
inline cyg_ucount32 |
Cyg_StdioStreamBuffer::get_buffer_space_used( void ) |
{ |
return (buffer_top - current_buffer_position); |
} // get_buffer_space_used() |
|
|
inline cyg_count32 |
Cyg_StdioStreamBuffer::get_buffer_size( void ) |
{ |
#ifdef CYGSEM_LIBC_STDIO_DYNAMIC_SETVBUF |
if (buffer_bottom==NULL) |
return -1; |
#endif |
return buffer_size; |
} // get_buffer_size() |
|
|
inline cyg_ucount32 |
Cyg_StdioStreamBuffer::get_buffer_addr_to_read( cyg_uint8 **buffer ) |
{ |
*buffer = current_buffer_position; |
|
return (buffer_top - current_buffer_position); |
} // get_buffer_addr_to_read() |
|
inline void |
Cyg_StdioStreamBuffer::set_bytes_read( cyg_ucount32 bytes ) |
{ |
cyg_uint8 *buffer_max = &buffer_bottom[ get_buffer_size() ]; |
|
current_buffer_position += bytes; |
|
// INT_MAX is used by some callers to mean infinite. |
CYG_ASSERT( (current_buffer_position <= buffer_top) |
|| (get_buffer_size() == INT_MAX), |
"read too many bytes from buffer" ); |
|
if (current_buffer_position == buffer_max) |
current_buffer_position = buffer_top = &buffer_bottom[0]; |
|
} // set_bytes_read() |
|
|
inline cyg_ucount32 |
Cyg_StdioStreamBuffer::get_buffer_addr_to_write( cyg_uint8 **buffer ) |
{ |
cyg_uint8 *buffer_max = &buffer_bottom[ get_buffer_size() ]; |
|
*buffer = buffer_top; |
|
return (buffer_max - buffer_top); |
} // get_buffer_addr_to_write() |
|
|
inline void |
Cyg_StdioStreamBuffer::set_bytes_written( cyg_ucount32 bytes ) |
{ |
buffer_top += bytes; |
|
// INT_MAX is used by some callers to mean infinite. |
CYG_ASSERT( (buffer_top <= &buffer_bottom[ get_buffer_size() ]) |
|| (get_buffer_size() == INT_MAX), |
"wrote too many bytes into buffer" ); |
} // set_bytes_written() |
|
|
inline void |
Cyg_StdioStreamBuffer::drain_buffer( void ) |
{ |
buffer_top = current_buffer_position = &buffer_bottom[0]; |
} // drain_buffer() |
|
#endif // if defined(CYGSEM_LIBC_STDIO_WANT_BUFFERED_IO) |
|
#endif // CYGONCE_LIBC_STDIO_STREAMBUF_INL multiple inclusion protection |
|
// EOF streambuf.inl |
/stdiofiles.hxx
0,0 → 1,117
#ifndef CYGONCE_LIBC_STDIO_STDIOFILES_HXX |
#define CYGONCE_LIBC_STDIO_STDIOFILES_HXX |
//======================================================================== |
// |
// stdiofiles.hxx |
// |
// ISO C library stdio central file access |
// |
//======================================================================== |
//####ECOSGPLCOPYRIGHTBEGIN#### |
// ------------------------------------------- |
// This file is part of eCos, the Embedded Configurable Operating System. |
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc. |
// |
// eCos is free software; you can redistribute it and/or modify it under |
// the terms of the GNU General Public License as published by the Free |
// Software Foundation; either version 2 or (at your option) any later version. |
// |
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY |
// WARRANTY; without even the implied warranty of MERCHANTABILITY or |
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
// for more details. |
// |
// You should have received a copy of the GNU General Public License along |
// with eCos; if not, write to the Free Software Foundation, Inc., |
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
// |
// As a special exception, if other files instantiate templates or use macros |
// or inline functions from this file, or you compile this file and link it |
// with other works to produce a work based on this file, this file does not |
// by itself cause the resulting work to be covered by the GNU General Public |
// License. However the source code for this file must still be made available |
// in accordance with section (3) of the GNU General Public License. |
// |
// This exception does not invalidate any other reasons why a work based on |
// this file might be covered by the GNU General Public License. |
// |
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc. |
// at http://sources.redhat.com/ecos/ecos-license/ |
// ------------------------------------------- |
//####ECOSGPLCOPYRIGHTEND#### |
//======================================================================== |
//#####DESCRIPTIONBEGIN#### |
// |
// Author(s): jlarmour |
// Contributors: |
// Date: 2000-04-19 |
// Purpose: |
// Description: |
// Usage: #include <cyg/libc/stdio/stdiosupp.hxx> |
// |
//####DESCRIPTIONEND#### |
// |
//======================================================================== |
|
// CONFIGURATION |
|
#include <pkgconf/libc_stdio.h> // libc stdio configuration |
|
// INCLUDES |
|
#include <cyg/infra/cyg_type.h> // cyg_bool, cyg_ucount8, cyg_ucount16 |
#include <cyg/libc/stdio/stream.hxx> // Cyg_StdioStream |
|
#ifdef CYGSEM_LIBC_STDIO_THREAD_SAFE_STREAMS |
# include <cyg/kernel/mutex.hxx> // mutexes |
#endif |
|
// CLASSES |
|
class Cyg_libc_stdio_files |
{ |
// List of open files - global for now |
static |
Cyg_StdioStream *files[FOPEN_MAX]; |
|
# ifdef CYGSEM_LIBC_STDIO_THREAD_SAFE_STREAMS |
// lock for the above |
static |
Cyg_Mutex files_lock; |
# endif |
|
public: |
|
# if FOPEN_MAX < 256 |
typedef cyg_ucount8 fd_t; |
# else |
typedef cyg_ucount16 fd_t; |
# endif |
|
static Cyg_StdioStream * |
get_file_stream( fd_t fd ); |
|
static void |
set_file_stream( fd_t fd, Cyg_StdioStream *stream ); |
|
|
// the following functions lock(), trylock() and unlock() do nothing |
// if we haven't got thread-safe streams |
static cyg_bool |
lock(void); |
|
static cyg_bool |
trylock(void); |
|
static void |
unlock(void); |
|
}; // class Cyg_libc_stdio_files |
|
|
// Inline functions for this class |
#include <cyg/libc/stdio/stdiofiles.inl> |
|
#endif // CYGONCE_LIBC_STDIO_STDIOFILES_HXX multiple inclusion protection |
|
// EOF stdiofiles.hxx |
/stream.inl
0,0 → 1,482
#ifndef CYGONCE_LIBC_STDIO_STREAM_INL |
#define CYGONCE_LIBC_STDIO_STREAM_INL |
//======================================================================== |
// |
// stream.inl |
// |
// Inline functions for internal C library stdio stream interface |
// |
//======================================================================== |
//####ECOSGPLCOPYRIGHTBEGIN#### |
// ------------------------------------------- |
// This file is part of eCos, the Embedded Configurable Operating System. |
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc. |
// |
// eCos is free software; you can redistribute it and/or modify it under |
// the terms of the GNU General Public License as published by the Free |
// Software Foundation; either version 2 or (at your option) any later version. |
// |
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY |
// WARRANTY; without even the implied warranty of MERCHANTABILITY or |
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
// for more details. |
// |
// You should have received a copy of the GNU General Public License along |
// with eCos; if not, write to the Free Software Foundation, Inc., |
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
// |
// As a special exception, if other files instantiate templates or use macros |
// or inline functions from this file, or you compile this file and link it |
// with other works to produce a work based on this file, this file does not |
// by itself cause the resulting work to be covered by the GNU General Public |
// License. However the source code for this file must still be made available |
// in accordance with section (3) of the GNU General Public License. |
// |
// This exception does not invalidate any other reasons why a work based on |
// this file might be covered by the GNU General Public License. |
// |
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc. |
// at http://sources.redhat.com/ecos/ecos-license/ |
// ------------------------------------------- |
//####ECOSGPLCOPYRIGHTEND#### |
//======================================================================== |
//#####DESCRIPTIONBEGIN#### |
// |
// Author(s): jlarmour |
// Contributors: |
// Date: 2000-04-19 |
// Purpose: |
// Description: |
// Usage: Do not include this file - |
// #include <cyg/libc/stdio/stream.hxx> instead. |
// |
//####DESCRIPTIONEND#### |
// |
//======================================================================== |
|
// CONFIGURATION |
|
#include <pkgconf/libc_stdio.h> // Configuration header |
|
// INCLUDES |
|
#include <cyg/infra/cyg_type.h> // Common project-wide type definitions |
#include <stddef.h> // NULL and size_t from compiler |
#include <errno.h> // Error codes |
#include <cyg/libc/stdio/stream.hxx> // Just be sure that this really is |
// included |
|
#include <cyg/libc/stdio/io.inl> // I/O system inlines |
|
// FUNCTIONS |
|
#ifdef CYGDBG_USE_ASSERTS |
inline cyg_bool |
Cyg_StdioStream::check_this( cyg_assert_class_zeal zeal ) const |
{ |
// check that it has the magic word set meaning it is valid. |
if ( magic_validity_word != 0x7b4321ce ) |
return false; |
return true; |
} // check_this() |
|
#endif // ifdef CYGDBG_USE_ASSERTS |
|
|
|
// LOCKING FUNCTIONS |
|
// returns true on success |
inline cyg_bool |
Cyg_StdioStream::lock_me( void ) |
{ |
CYG_ASSERTCLASS( this, "Stream object is not a valid stream!" ); |
|
#ifdef CYGSEM_LIBC_STDIO_THREAD_SAFE_STREAMS |
return stream_lock.lock(); |
#else |
// otherwise it "worked" |
return true; |
#endif |
|
} // lock_me() |
|
|
// returns true on success |
inline cyg_bool |
Cyg_StdioStream::trylock_me( void ) |
{ |
CYG_ASSERTCLASS( this, "Stream object is not a valid stream!" ); |
|
#ifdef CYGSEM_LIBC_STDIO_THREAD_SAFE_STREAMS |
return stream_lock.trylock(); |
#else |
// otherwise it "worked" |
return true; |
#endif |
|
} // lock_me() |
|
|
inline void |
Cyg_StdioStream::unlock_me( void ) |
{ |
CYG_ASSERTCLASS( this, "Stream object is not a valid stream!" ); |
|
#ifdef CYGSEM_LIBC_STDIO_THREAD_SAFE_STREAMS |
stream_lock.unlock(); |
#endif |
} // unlock_me() |
|
|
// DESTRUCTOR |
|
inline Cyg_ErrNo |
Cyg_StdioStream::close() |
{ |
Cyg_ErrNo err = ENOERR; |
|
if (!lock_me()) |
return EBADF; |
|
if( my_device != CYG_STDIO_HANDLE_NULL ) |
{ |
flush_output_unlocked(); |
|
err = cyg_stdio_close( my_device ); |
|
if( err == ENOERR ) |
my_device = CYG_STDIO_HANDLE_NULL; |
} |
|
unlock_me(); |
|
return err; |
} // close() |
|
inline |
Cyg_StdioStream::~Cyg_StdioStream() |
{ |
CYG_ASSERTCLASS( this, "Stream object is not a valid stream!" ); |
|
// Close the device if it has not already been closed. |
if( my_device != CYG_STDIO_HANDLE_NULL ) |
close(); |
|
#ifdef CYGDBG_USE_ASSERTS |
magic_validity_word = 0xbadbad; |
#endif |
} // Cyg_StdioStream destructor |
|
|
// MEMBER FUNCTIONS |
|
|
// this is currently just a wrapper around write, but having this interface |
// leaves scope for optimisations in future |
inline Cyg_ErrNo |
Cyg_StdioStream::write_byte( cyg_uint8 c ) |
{ |
cyg_ucount32 dummy_bytes_written; |
Cyg_ErrNo err; |
|
CYG_ASSERTCLASS( this, "Stream object is not a valid stream!" ); |
|
err = write( &c, 1, &dummy_bytes_written ); |
|
CYG_ASSERT( (err!=ENOERR) || (dummy_bytes_written==1), |
"Single byte not written, but no error returned!" ); |
|
return err; |
} // write_byte() |
|
|
inline Cyg_ErrNo |
Cyg_StdioStream::unread_byte( cyg_uint8 c ) |
{ |
CYG_ASSERTCLASS( this, "Stream object is not a valid stream!" ); |
|
#ifdef CYGFUN_LIBC_STDIO_ungetc |
if (!lock_me()) |
return EBADF; // assume file is now invalid |
|
if (flags.unread_char_buf_in_use) { |
unlock_me(); |
return ENOMEM; |
} // if |
|
flags.unread_char_buf_in_use = true; |
unread_char_buf = c; |
|
// can't be at EOF any more |
flags.at_eof = false; |
|
if (position) // position is always 0 for certain devices |
--position; |
|
unlock_me(); |
|
return ENOERR; |
|
#else // ifdef CYGFUN_LIBC_STDIO_ungetc |
|
return ENOSYS; |
#endif // ifdef CYGFUN_LIBC_STDIO_ungetc |
} // unread_byte() |
|
|
inline cyg_ucount32 |
Cyg_StdioStream::bytes_available_to_read( void ) |
{ |
cyg_ucount32 bytes=0; |
|
CYG_ASSERTCLASS( this, "Stream object is not a valid stream!" ); |
|
#ifdef CYGFUN_LIBC_STDIO_ungetc |
if (flags.unread_char_buf_in_use) |
++bytes; |
#endif |
|
#ifdef CYGSEM_LIBC_STDIO_WANT_BUFFERED_IO |
|
// either the last operation was a read, which attempted to read bytes |
// into the buffer, or there are no bytes in the buffer |
|
if (flags.buffering) { |
if (flags.last_buffer_op_was_read == true) |
bytes += io_buf.get_buffer_space_used(); |
} |
else |
|
#endif |
|
if (flags.readbuf_char_in_use) |
++bytes; |
|
return bytes; |
} // bytes_available_to_read() |
|
|
|
inline Cyg_ErrNo |
Cyg_StdioStream::flush_output( void ) |
{ |
Cyg_ErrNo err; |
|
CYG_ASSERTCLASS( this, "Stream object is not a valid stream!" ); |
|
if (!lock_me()) |
return EBADF; // assume file is now invalid |
|
err = flush_output_unlocked(); |
|
unlock_me(); |
|
return err; |
} // flush_output() |
|
|
// get error status for this file |
inline Cyg_ErrNo |
Cyg_StdioStream::get_error( void ) |
{ |
Cyg_ErrNo err_temp; |
|
CYG_ASSERTCLASS( this, "Stream object is not a valid stream!" ); |
|
if (!lock_me()) |
return EBADF; // well, we've certainly got an error now! |
|
err_temp = error; |
|
unlock_me(); |
|
return err_temp; |
} // get_error() |
|
|
// set error status for this file |
inline void |
Cyg_StdioStream::set_error( Cyg_ErrNo errno_to_set ) |
{ |
CYG_ASSERTCLASS( this, "Stream object is not a valid stream!" ); |
|
if (!lock_me()) |
{ |
errno = EBADF; // best we can do - we can't trust error to be there |
return; |
} // if |
|
errno = error = errno_to_set; |
|
if ( EEOF == error ) |
flags.at_eof = 1; |
|
unlock_me(); |
} // set_error() |
|
|
// are we at EOF? true means we are, false means no |
inline cyg_bool |
Cyg_StdioStream::get_eof_state( void ) |
{ |
cyg_bool eof_temp; |
|
CYG_ASSERTCLASS( this, "Stream object is not a valid stream!" ); |
|
if (!lock_me()) |
return false; // not much we can do here |
|
eof_temp = flags.at_eof; |
|
unlock_me(); |
|
return eof_temp; |
} // get_eof_state() |
|
|
// Set whether we are at EOF. |
inline void |
Cyg_StdioStream::set_eof_state( cyg_bool eof_to_set ) |
{ |
CYG_ASSERTCLASS( this, "Stream object is not a valid stream!" ); |
|
if (!lock_me()) |
return; // not much we can do here |
|
flags.at_eof = eof_to_set; |
|
unlock_me(); |
} // set_eof_state() |
|
|
// retrieve position |
inline Cyg_ErrNo |
Cyg_StdioStream::get_position( fpos_t *pos ) |
{ |
CYG_ASSERTCLASS( this, "Stream object is not a valid stream!" ); |
|
if (!lock_me()) |
return EBADF; // assume file is now invalid |
|
*pos = position; |
|
unlock_me(); |
|
return ENOERR; |
|
} // get_position() |
|
|
// set absolute position |
inline Cyg_ErrNo |
Cyg_StdioStream::set_position( fpos_t pos, int whence ) |
{ |
CYG_ASSERTCLASS( this, "Stream object is not a valid stream!" ); |
|
#ifndef CYGPKG_LIBC_STDIO_FILEIO |
// this is currently a workaround until we have real files |
// this will be corrected when we decide the true filesystem interface |
|
Cyg_ErrNo err; |
cyg_uint8 c; |
|
if ((whence != SEEK_CUR) || pos < 0) |
return ENOSYS; |
|
if (!lock_me()) |
return EBADF; // assume file is now invalid |
|
// Drain read buffer |
|
for ( ; pos > 0 ; pos-- ) { |
err = read_byte( &c ); |
if (err == EAGAIN) |
err=refill_read_buffer(); |
|
// if read_byte retured error, or refill_read_buffer returned error |
if (err) { |
unlock_me(); |
return err; |
} // if |
} // for |
|
unlock_me(); |
|
return ENOERR; |
|
#else |
|
if (!lock_me()) |
return EBADF; // assume file is now invalid |
|
if ( whence != SEEK_END ) { |
off_t bytesavail = (off_t)bytes_available_to_read(); |
off_t abspos = (whence == SEEK_CUR) ? position + pos : pos; |
off_t posdiff = abspos - position; |
|
if ( posdiff >= 0 && bytesavail > posdiff ) { |
// can just "seek" within the existing buffer |
#ifdef CYGFUN_LIBC_STDIO_ungetc |
if (posdiff>0 && flags.unread_char_buf_in_use) { |
flags.unread_char_buf_in_use = false; |
posdiff--; |
} |
#endif |
#ifdef CYGSEM_LIBC_STDIO_WANT_BUFFERED_IO |
if (posdiff>0 && flags.buffering) { |
io_buf.set_bytes_read(posdiff); |
posdiff=0; |
} else |
#endif |
if (posdiff>0 && flags.readbuf_char_in_use) { |
flags.readbuf_char_in_use = false; |
posdiff--; |
} |
CYG_ASSERT(posdiff==0, "Failed to seek within buffer correctly"); |
|
position = abspos; |
unlock_me(); |
return ENOERR; |
} // endif (bytesavail > posdiff) |
|
if (whence == SEEK_CUR) { |
position += bytesavail; |
} |
} //endif (whence != SEEK_END) |
|
Cyg_ErrNo err; |
off_t newpos=pos; |
|
err = cyg_stdio_lseek( my_device, &newpos, whence ); |
|
if( err == ENOERR ) |
{ |
// Clean out the buffer. Flush output if any present, |
// and clear any input out of input buffer and any ungot |
// chars from unread buffer. |
|
err = flush_output_unlocked(); |
io_buf.drain_buffer(); |
#ifdef CYGFUN_LIBC_STDIO_ungetc |
flags.unread_char_buf_in_use = false; |
#endif |
|
// Clear EOF indicator. |
flags.at_eof = false; |
|
// update stream pos |
position = newpos; |
} |
|
unlock_me(); |
|
return err; |
#endif |
|
} // set_position() |
|
|
#endif // CYGONCE_LIBC_STDIO_STREAM_INL multiple inclusion protection |
|
// EOF stream.inl |
/io.hxx
0,0 → 1,90
#ifndef CYGONCE_LIBC_STDIO_IO_HXX |
#define CYGONCE_LIBC_STDIO_IO_HXX |
//======================================================================== |
// |
// io.hxx |
// |
// Internal C library stdio io interface definitions |
// |
//======================================================================== |
//####ECOSGPLCOPYRIGHTBEGIN#### |
// ------------------------------------------- |
// This file is part of eCos, the Embedded Configurable Operating System. |
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc. |
// |
// eCos is free software; you can redistribute it and/or modify it under |
// the terms of the GNU General Public License as published by the Free |
// Software Foundation; either version 2 or (at your option) any later version. |
// |
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY |
// WARRANTY; without even the implied warranty of MERCHANTABILITY or |
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
// for more details. |
// |
// You should have received a copy of the GNU General Public License along |
// with eCos; if not, write to the Free Software Foundation, Inc., |
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
// |
// As a special exception, if other files instantiate templates or use macros |
// or inline functions from this file, or you compile this file and link it |
// with other works to produce a work based on this file, this file does not |
// by itself cause the resulting work to be covered by the GNU General Public |
// License. However the source code for this file must still be made available |
// in accordance with section (3) of the GNU General Public License. |
// |
// This exception does not invalidate any other reasons why a work based on |
// this file might be covered by the GNU General Public License. |
// |
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc. |
// at http://sources.redhat.com/ecos/ecos-license/ |
// ------------------------------------------- |
//####ECOSGPLCOPYRIGHTEND#### |
//======================================================================== |
//#####DESCRIPTIONBEGIN#### |
// |
// Author(s): nickg |
// Contributors: |
// Date: 2000-06-30 |
// Purpose: |
// Description: |
// Usage: #include <cyg/libc/stdio/io.hxx> |
// |
//####DESCRIPTIONEND#### |
// |
//======================================================================== |
|
// CONFIGURATION |
|
#include <pkgconf/libc_stdio.h> // Configuration header |
|
//======================================================================== |
// INCLUDES |
|
#include <cyg/infra/cyg_type.h> // Common project-wide type definitions |
#include <cyg/infra/cyg_ass.h> // Get assertion macros, as appropriate |
#include <errno.h> // Cyg_ErrNo |
|
#ifdef CYGPKG_LIBC_STDIO_FILEIO |
#include <unistd.h> |
#include <fcntl.h> |
#include <sys/stat.h> |
#include <errno.h> |
#else |
#include <cyg/io/io.h> // Device I/O support |
#include <cyg/io/config_keys.h> // CYG_IO_GET_CONFIG_SERIAL_OUTPUT_DRAIN |
#endif |
|
//======================================================================== |
// Stream handle type |
|
#ifdef CYGPKG_LIBC_STDIO_FILEIO |
typedef int cyg_stdio_handle_t; |
#define CYG_STDIO_HANDLE_NULL -1 |
#else |
typedef cyg_io_handle_t cyg_stdio_handle_t; |
#define CYG_STDIO_HANDLE_NULL 0 |
#endif |
|
//======================================================================== |
#endif // CYGONCE_LIBC_STDIO_IO_HXX multiple inclusion protection |
// EOF io.hxx |
/streambuf.hxx
0,0 → 1,164
#ifndef CYGONCE_LIBC_STDIO_STREAMBUF_HXX |
#define CYGONCE_LIBC_STDIO_STREAMBUF_HXX |
//=========================================================================== |
// |
// streambuf.hxx |
// |
// Internal C library stdio stream buffer interface definitions |
// |
//=========================================================================== |
//####ECOSGPLCOPYRIGHTBEGIN#### |
// ------------------------------------------- |
// This file is part of eCos, the Embedded Configurable Operating System. |
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc. |
// |
// eCos is free software; you can redistribute it and/or modify it under |
// the terms of the GNU General Public License as published by the Free |
// Software Foundation; either version 2 or (at your option) any later version. |
// |
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY |
// WARRANTY; without even the implied warranty of MERCHANTABILITY or |
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
// for more details. |
// |
// You should have received a copy of the GNU General Public License along |
// with eCos; if not, write to the Free Software Foundation, Inc., |
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
// |
// As a special exception, if other files instantiate templates or use macros |
// or inline functions from this file, or you compile this file and link it |
// with other works to produce a work based on this file, this file does not |
// by itself cause the resulting work to be covered by the GNU General Public |
// License. However the source code for this file must still be made available |
// in accordance with section (3) of the GNU General Public License. |
// |
// This exception does not invalidate any other reasons why a work based on |
// this file might be covered by the GNU General Public License. |
// |
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc. |
// at http://sources.redhat.com/ecos/ecos-license/ |
// ------------------------------------------- |
//####ECOSGPLCOPYRIGHTEND#### |
//=========================================================================== |
//#####DESCRIPTIONBEGIN#### |
// |
// Author(s): jlarmour |
// Contributors: |
// Date: 2000-04-19 |
// Purpose: |
// Description: This file implements the buffer class used by Cyg_StdioStream |
// for file buffers. It is simple, and not thread-safe - that |
// is better done at a higher level for our purposes. |
// Usage: #include <cyg/libc/stdio/streambuf.hxx> |
// |
//####DESCRIPTIONEND#### |
// |
//=========================================================================== |
|
// CONFIGURATION |
|
#include <pkgconf/libc_stdio.h> // Configuration header |
|
// Include buffered I/O? |
#if defined(CYGSEM_LIBC_STDIO_WANT_BUFFERED_IO) |
|
|
// INCLUDES |
|
#include <cyg/infra/cyg_type.h> // Common project-wide type definitions |
#include <errno.h> // Cyg_ErrNo |
|
|
// TYPE DEFINITIONS |
|
|
class Cyg_StdioStreamBuffer |
{ |
private: |
// Buffering data |
|
#if defined(CYGSEM_LIBC_STDIO_SETVBUF_MALLOC) |
cyg_bool call_free; // should we free the old buffer if set_buffer is |
// called? |
#else |
cyg_uint8 static_buffer[BUFSIZ]; // Static buffer used when we cannot |
// use malloc()/free(). |
#endif |
|
cyg_uint8 *buffer_bottom; |
|
cyg_ucount32 buffer_size; |
|
cyg_uint8 *buffer_top; |
|
cyg_uint8 *current_buffer_position; |
|
public: |
|
// CONSTRUCTORS |
|
// You can change the size, or even supply your own buffer, although |
// this only has an effect with dynamic buffers. Otherwise it is |
// silently ignored |
Cyg_StdioStreamBuffer( cyg_ucount32 size=BUFSIZ, |
cyg_uint8 *new_buffer=NULL ); |
|
|
// DESTRUCTORS |
|
~Cyg_StdioStreamBuffer(); |
|
// METHODS |
|
// Set up the buffer. As with the constructor, supplying a new_buffer |
// only has an effect with dynamic buffers, although EINVAL is returned |
// in that case. ENOMEM may also be returned |
Cyg_ErrNo |
set_buffer( cyg_ucount32 size=BUFSIZ, cyg_uint8 *new_buffer=NULL ); |
|
// Find out how much buffer space is in use |
cyg_ucount32 |
get_buffer_space_used( void ); |
|
|
// What total size is the current buffer set to be. Can be -1 if the |
// the buffer is invalid |
cyg_count32 |
get_buffer_size( void ); |
|
|
// get buffer address to read from, and return the number of bytes |
// available to read |
cyg_ucount32 |
get_buffer_addr_to_read( cyg_uint8 **buffer ); |
|
// when finished reading from said space, tell the buffer how much was |
// actually read |
void |
set_bytes_read( cyg_ucount32 bytes ); |
|
// return address of buffer that can be used to write into, and its |
// available capacity |
cyg_ucount32 |
get_buffer_addr_to_write( cyg_uint8 **buffer ); |
|
// when finished writing into said space, tell the buffer how much was |
// actually written |
void |
set_bytes_written( cyg_ucount32 bytes ); |
|
// just empty the whole buffer contents |
void |
drain_buffer( void ); |
}; // class Cyg_StdioStreamBuffer |
|
// INLINE FUNCTIONS |
|
#include <cyg/libc/stdio/streambuf.inl> |
|
|
#endif // if defined(CYGSEM_LIBC_STDIO_WANT_BUFFERED_IO) |
|
#endif // CYGONCE_LIBC_STDIO_STREAMBUF_HXX multiple inclusion protection |
|
// EOF streambuf.hxx |