OpenCores
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/src/common
    from Rev 27 to Rev 174
    Reverse comparison

Rev 27 → Rev 174

/setvbuf.cxx
0,0 → 1,129
//===========================================================================
//
// setvbuf.cxx
//
// Implementation of C library buffering setup as per ANSI 7.9.5.6
//
//===========================================================================
//####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-20
// Purpose:
// Description:
// Usage:
//
//####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 <stdio.h> // header for setvbuf()
#include <cyg/libc/stdio/stream.hxx>// C libray streams
 
// FUNCTIONS
 
 
externC int
setvbuf( FILE *stream, char *buf, int mode, size_t size )
{
#ifdef CYGSEM_LIBC_STDIO_WANT_BUFFERED_IO
 
Cyg_StdioStream *real_stream = (Cyg_StdioStream *)stream;
Cyg_ErrNo err;
#ifdef CYGSEM_LIBC_STDIO_THREAD_SAFE_STREAMS
if ( !real_stream->lock_me() ) {
errno = EBADF;
return EBADF;
} // if
#endif
 
err = real_stream->io_buf.set_buffer( (cyg_ucount32) size,
(cyg_uint8 *) buf );
if (!err) {
switch (mode) {
case _IONBF:
CYG_ASSERT( (size == 0) && (buf == NULL),
"No buffering wanted but size/address specified!" );
real_stream->flags.buffering = false;
real_stream->flags.line_buffering = false;
break;
case _IOLBF:
real_stream->flags.buffering = true;
real_stream->flags.line_buffering = true;
break;
case _IOFBF:
real_stream->flags.buffering = true;
real_stream->flags.line_buffering = false;
break;
default:
err = EINVAL;
break;
} // switch
} // if
 
#ifdef CYGSEM_LIBC_STDIO_THREAD_SAFE_STREAMS
real_stream->unlock_me();
#endif
if (err) {
errno = err;
return err;
} // if
return 0;
 
#else // ifdef CYGSEM_LIBC_STDIO_WANT_BUFFERED_IO
 
errno = ENOSUPP;
return ENOSUPP;
 
#endif // ifdef CYGSEM_LIBC_STDIO_WANT_BUFFERED_IO
 
} // setvbuf()
 
// EOF setvbuf.cxx
/feof.cxx
0,0 → 1,92
//========================================================================
//
// feof.cxx
//
// Implementations of ISO C feof(), ferror(), clearerr() 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: 2001-03-16
// Purpose: Implementations of ISO C feof(), ferror(), clearerr()
// functions
// Description:
// Usage:
//
//####DESCRIPTIONEND####
//
//========================================================================
 
// CONFIGURATION
 
#include <pkgconf/libc_stdio.h> // Configuration header
 
// INCLUDES
 
#include <cyg/infra/cyg_type.h> // Common type definitions and support
#include <stdio.h> // Header for this file
#include <cyg/libc/stdio/stream.hxx> // Cyg_StdioStream class
 
externC int
feof( FILE *stream )
{
Cyg_StdioStream *real_stream = (Cyg_StdioStream *)stream;
 
return (real_stream->get_eof_state() != 0);
} // feof()
 
externC int
ferror( FILE *stream )
{
Cyg_StdioStream *real_stream = (Cyg_StdioStream *)stream;
 
return (real_stream->get_error() != 0);
} // ferror()
 
externC void
clearerr( FILE *stream )
{
Cyg_StdioStream *real_stream = (Cyg_StdioStream *)stream;
 
real_stream->set_error(0);
real_stream->set_eof_state(false);
} // clearerr()
 
 
 
// EOF feof.cxx
/stdin.cxx
0,0 → 1,110
//========================================================================
//
// stdin.cxx
//
// Initialization of stdin stream for ISO C library
//
//========================================================================
//####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-20
// Purpose: Initialization of stdin stream for ISO C library
// Description: We put all this in a separate file in the hope that if
// no-one uses stdin, then it is not included in the image
// Usage:
//
//####DESCRIPTIONEND####
//
//========================================================================
 
// CONFIGURATION
 
#include <pkgconf/libc_stdio.h> // Configuration header
 
// Don't let us get the stream definitions of stdin/out/err from stdio.h
// since we are going to break the type safety :-(
#define CYGPRI_LIBC_STDIO_NO_DEFAULT_STREAMS
 
// And we don't need the stdio inlines, which will otherwise complain if
// stdin/out/err are not available
#ifdef CYGIMP_LIBC_STDIO_INLINES
# undef CYGIMP_LIBC_STDIO_INLINES
#endif
 
// INCLUDES
 
#include <cyg/infra/cyg_type.h> // Common type definitions and support
#include <cyg/libc/stdio/stream.hxx> // Cyg_StdioStream class
#include <cyg/libc/stdio/stdiofiles.hxx> // C library files
#include <cyg/libc/stdio/stdiosupp.hxx> // Cyg_libc_stdio_find_filename()
 
// CONSTANTS
 
// Use default libc priority to allow it to be the fd 0 if necessary
#define PRIO (CYG_INIT_LIBC)
 
// STATICS
 
Cyg_StdioStream
cyg_libc_stdio_stdin CYGBLD_ATTRIB_INIT_PRI(PRIO) = Cyg_StdioStream(
Cyg_libc_stdio_find_filename(CYGDAT_LIBC_STDIO_DEFAULT_CONSOLE,
Cyg_StdioStream::CYG_STREAM_READ, false, false),
Cyg_StdioStream::CYG_STREAM_READ, false, false, _IOLBF );
 
 
// CLASSES
 
// This is a dummy class just so we can execute arbitrary code when
// stdin is requested
 
class cyg_libc_dummy_stdin_init_class {
public:
cyg_libc_dummy_stdin_init_class(void) {
Cyg_libc_stdio_files::set_file_stream(0, &cyg_libc_stdio_stdin);
}
};
 
// And here's an instance of the class just to make the code run
static cyg_libc_dummy_stdin_init_class cyg_libc_dummy_stdin_init
CYGBLD_ATTRIB_INIT_PRI(PRIO);
 
// and finally stdin itself
__externC Cyg_StdioStream * const stdin;
Cyg_StdioStream * const stdin=&cyg_libc_stdio_stdin;
 
// EOF stdin.cxx
/stdout.cxx
0,0 → 1,110
//========================================================================
//
// stdout.cxx
//
// Initialization of stdout stream for ISO C library
//
//========================================================================
//####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-20
// Purpose: Initialization of stdout stream for ISO C library
// Description: We put all this in a separate file in the hope that if
// no-one uses stdout, then it is not included in the image
// Usage:
//
//####DESCRIPTIONEND####
//
//========================================================================
 
// CONFIGURATION
 
#include <pkgconf/libc_stdio.h> // Configuration header
 
// Don't let us get the stream definitions of stdin/out/err from stdio.h
// since we are going to break the type safety :-(
#define CYGPRI_LIBC_STDIO_NO_DEFAULT_STREAMS
 
// And we don't need the stdio inlines, which will otherwise complain if
// stdin/out/err are not available
#ifdef CYGIMP_LIBC_STDIO_INLINES
# undef CYGIMP_LIBC_STDIO_INLINES
#endif
 
// INCLUDES
 
#include <cyg/infra/cyg_type.h> // Common type definitions and support
#include <cyg/libc/stdio/stream.hxx> // Cyg_StdioStream class
#include <cyg/libc/stdio/stdiofiles.hxx> // C library files
#include <cyg/libc/stdio/stdiosupp.hxx> // Cyg_libc_stdio_find_filename()
 
// CONSTANTS
 
// add 1 to the priority to allow it to be the fd 1 if necessary
#define PRIO (CYG_INIT_LIBC+1)
 
// STATICS
 
Cyg_StdioStream
cyg_libc_stdio_stdout CYGBLD_ATTRIB_INIT_PRI(PRIO) = Cyg_StdioStream(
Cyg_libc_stdio_find_filename(CYGDAT_LIBC_STDIO_DEFAULT_CONSOLE,
Cyg_StdioStream::CYG_STREAM_WRITE,
false, false),
Cyg_StdioStream::CYG_STREAM_WRITE, false, false, _IOLBF );
 
// CLASSES
 
// This is a dummy class just so we can execute arbitrary code when
// stdout is requested
 
class cyg_libc_dummy_stdout_init_class {
public:
cyg_libc_dummy_stdout_init_class(void) {
Cyg_libc_stdio_files::set_file_stream(1, &cyg_libc_stdio_stdout);
}
};
 
// And here's an instance of the class just to make the code run
static cyg_libc_dummy_stdout_init_class cyg_libc_dummy_stdout_init
CYGBLD_ATTRIB_INIT_PRI(PRIO);
 
// and finally stdout itself
__externC Cyg_StdioStream * const stdout;
Cyg_StdioStream * const stdout=&cyg_libc_stdio_stdout;
 
// EOF stdout.cxx
/ungetc.cxx
0,0 → 1,94
//===========================================================================
//
// ungetc.cxx
//
// ANSI Stdio ungetc() function
//
//===========================================================================
//####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-20
// Purpose:
// Description:
// Usage:
//
//####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 <stdio.h> // header for this file
#include <errno.h> // error codes
#include <cyg/libc/stdio/stream.hxx> // Cyg_StdioStream
 
 
// FUNCTIONS
 
externC int
ungetc( int c, FILE *stream )
{
Cyg_StdioStream *real_stream = (Cyg_StdioStream *)stream;
Cyg_ErrNo err;
cyg_uint8 real_c;
if (c == EOF)
return EOF;
 
real_c = (cyg_uint8) c;
 
err = real_stream->unread_byte( real_c );
 
if (err)
{
errno = err;
return EOF;
} // if
return (int)real_c;
 
} // ungetc()
 
// EOF ungetc.cxx
/sprintf.cxx
0,0 → 1,82
//===========================================================================
//
// sprintf.cxx
//
// ANSI Stdio sprintf() function
//
//===========================================================================
//####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-20
// Purpose:
// Description:
// Usage:
//
//####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 <stdio.h> // header for this file
#include <limits.h> // INT_MAX
 
// FUNCTIONS
 
externC int
sprintf( char *s, const char *format, ... )
{
int rc; // return code
va_list ap; // for variable args
 
va_start(ap, format); // init specifying last non-var arg
 
rc = vsnprintf(s, INT_MAX, format, ap);
 
va_end(ap); // end var args
 
return rc;
} // sprintf()
 
// EOF sprintf.cxx
/fflush.cxx
0,0 → 1,151
//========================================================================
//
// fflush.cxx
//
// Implementation of C library file flush function as per ANSI 7.9.5.2
//
//========================================================================
//####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-20
// Purpose: Provides ISO C fflush() function
// Description:
// Usage:
//
//####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 <stdio.h> // header for fflush()
#include <cyg/libc/stdio/stream.hxx>// C library streams
#include <cyg/libc/stdio/stdiofiles.hxx> // C library files
#include <cyg/libc/stdio/stdiosupp.hxx> // support for stdio
 
// FUNCTIONS
 
// flush all but one stream
externC Cyg_ErrNo
cyg_libc_stdio_flush_all_but( Cyg_StdioStream *not_this_stream )
{
cyg_bool files_flushed[FOPEN_MAX] = { false }; // sets all to 0
cyg_bool loop_again, looped = false;
cyg_ucount32 i;
Cyg_ErrNo err=ENOERR;
Cyg_StdioStream *stream;
 
do {
loop_again = false;
 
for (i=0; (i<FOPEN_MAX) && !err; i++) {
if (files_flushed[i] == false) {
stream = Cyg_libc_stdio_files::get_file_stream(i);
if ((stream == NULL) || (stream == not_this_stream)) {
// if it isn't a valid stream, set its entry in the
// list of files flushed since we don't want to
// flush it
// Ditto if its the one we're meant to miss
files_flushed[i] = true;
} // if
else {
// valid stream
#ifdef CYGSEM_LIBC_STDIO_WANT_BUFFERED_IO
// only buffers which we've written to need flushing
if ( !stream->flags.last_buffer_op_was_read)
#endif
{
// we try to flush the first time through so that
// everything is flushed that can be flushed.
// The second time through we should just wait
// in case some other lowerpri thread has locked the
// stream, otherwise we will spin needlessly and
// never let the lower pri thread run!
if ( (looped && stream->lock_me()) ||
stream->trylock_me() ) {
err = stream->flush_output_unlocked();
stream->unlock_me();
files_flushed[i] = true;
} // if
else {
loop_again = true;
looped = true;
}
}
} // else
} // if
} // for
} // do
while(loop_again && !err);
return err;
} // cyg_libc_stdio_flush_all_but()
 
externC int
fflush( FILE *stream )
{
Cyg_StdioStream *real_stream = (Cyg_StdioStream *)stream;
Cyg_ErrNo err;
 
if (stream == NULL) { // tells us to flush ALL streams
err = cyg_libc_stdio_flush_all_but(NULL);
} // if
else {
err = real_stream->flush_output();
} // else
 
if (err) {
errno = err;
return EOF;
} // if
 
return 0;
 
} // fflush()
// EOF fflush.cxx
/streambuf.cxx
0,0 → 1,141
//===========================================================================
//
// streambuf.cxx
//
// C library stdio stream buffer 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-20
// Purpose:
// Description:
// Usage:
//
//####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 <stdlib.h> // malloc() and free()
#include <cyg/libc/stdio/streambuf.hxx> // header for this file, just in case
 
// FUNCTIONS
Cyg_ErrNo
Cyg_StdioStreamBuffer::set_buffer( cyg_ucount32 size,
cyg_uint8 *new_buffer )
{
#ifdef CYGSEM_LIBC_STDIO_DYNAMIC_SETVBUF
// user-supplied buffer?
if (new_buffer != NULL) {
CYG_CHECK_DATA_PTR(new_buffer, "new_buffer not valid");
#ifdef CYGSEM_LIBC_STDIO_SETVBUF_MALLOC
// first check if we were responsible for the old buffer
if (call_free) {
free(buffer_bottom);
call_free = false;
}
#endif
buffer_bottom = new_buffer;
}
#ifdef CYGSEM_LIBC_STDIO_SETVBUF_MALLOC
else if ( size != buffer_size ) { // as long as its different from
// what we've got now
cyg_uint8 *malloced_buf;
 
malloced_buf = (cyg_uint8 * )malloc( size );
if (malloced_buf == NULL)
return ENOMEM;
 
// should the old buffer be freed? This waits till after we know
// whether the malloc succeeded
if (call_free)
free( buffer_bottom );
buffer_bottom = malloced_buf;
 
call_free=true;
 
} // else if
#else
// Here we have not been given a new buffer, but have been given
// a new buffer size. If possible, we just shrink what we already
// have.
else if( size > buffer_size )
return EINVAL;
#endif
#else // ifdef CYGSEM_LIBC_STDIO_DYNAMIC_SETVBUF
// In this config we can't use a different buffer, or set a
// size greater than now. We can pretend to shrink it though
// Note on the next line we compare it with the size of static_buffer
// and not the current size, as that's what is the limiting factor
if ( (new_buffer != NULL) || (size > sizeof(static_buffer)) )
return EINVAL;
#endif // ifdef CYGSEM_LIBC_STDIO_DYNAMIC_SETVBUF
buffer_top = current_buffer_position = &buffer_bottom[0];
buffer_size = size;
return ENOERR;
} // set_buffer()
 
 
#endif // if defined(CYGSEM_LIBC_STDIO_WANT_BUFFERED_IO)
 
 
// EOF streambuf.cxx
/vsnprintf.cxx
0,0 → 1,152
//===========================================================================
//
// vsnprintf.cxx
//
// ANSI Stdio vsnprintf() function
//
//===========================================================================
//####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: jlarmour
// Date: 1998-02-13
// Purpose:
// Description:
// Usage:
//
//####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 <stdio.h> // header for this file
#include <errno.h> // error codes
#include <cyg/io/devtab.h> // Device table
#include <cyg/libc/stdio/stream.hxx>// Cyg_StdioStream
 
#include <cyg/libc/stdio/io.inl> // I/O system inlines
 
#ifndef CYGPKG_LIBC_STDIO_FILEIO
 
// FUNCTIONS
 
static Cyg_ErrNo
str_write(cyg_stdio_handle_t handle, const void *buf, cyg_uint32 *len)
{
cyg_devtab_entry_t *dev = (cyg_devtab_entry_t *)handle;
cyg_uint8 **str_p = (cyg_uint8 **)dev->priv;
cyg_ucount32 i;
 
// I suspect most strings passed to vsnprintf will be relatively short,
// so we just take the simple approach rather than have the overhead
// of calling memcpy etc.
 
// simply copy string until we run out of user space
 
for (i = 0; i < *len; i++, (*str_p)++ )
{
**str_p = *((cyg_uint8 *)buf + i);
} // for
 
*len = i;
 
return ENOERR;
} // str_write()
 
static DEVIO_TABLE(devio_table,
str_write, // write
NULL, // read
NULL, // select
NULL, // get_config
NULL); // set_config
 
externC int
vsnprintf( char *s, size_t size, const char *format, va_list arg )
{
int rc;
// construct a fake device with the address of the string we've
// been passed as its private data. This way we can use the data
// directly
DEVTAB_ENTRY_NO_INIT(strdev,
"strdev", // Name
NULL, // Dependent name (layered device)
&devio_table, // I/O function table
NULL, // Init
NULL, // Lookup
&s); // private
Cyg_StdioStream my_stream( &strdev, Cyg_StdioStream::CYG_STREAM_WRITE,
false, false, _IONBF, 0, NULL );
rc = vfnprintf( (FILE *)&my_stream, size, format, arg );
 
// Null-terminate it, but note that s has been changed by str_write(), so
// that it now points to the end of the string
s[0] = '\0';
 
return rc;
 
} // vsnprintf()
 
#else
 
externC int
vsnprintf( char *s, size_t size, const char *format, va_list arg )
{
int rc;
 
Cyg_StdioStream my_stream( Cyg_StdioStream::CYG_STREAM_WRITE,
size, (cyg_uint8 *)s );
rc = vfnprintf( (FILE *)&my_stream, size, format, arg );
 
if( rc > 0 )
s[rc] = '\0';
 
return rc;
 
} // vsnprintf()
 
#endif
 
// EOF vsnprintf.cxx
/stdiosupp.cxx
0,0 → 1,83
//===========================================================================
//
// stdiosupp.cxx
//
// Helper C library functions for standard I/O
//
//===========================================================================
//####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-20
// Purpose:
// Description:
// Usage:
//
//####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 <cyg/libc/stdio/io.hxx> // I/O system
#include <cyg/libc/stdio/stdiosupp.hxx> // Header for this file
 
#include <cyg/libc/stdio/io.inl> // I/O system inlines
 
//externC void cyg_io_init(void);
 
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 )
{
cyg_stdio_handle_t dev = CYG_STDIO_HANDLE_NULL;
 
cyg_stdio_open(filename, rw, binary, append, &dev);
return dev;
} // Cyg_libc_stdio_find_filename()
 
 
// EOF stdiosupp.cxx
/stream.cxx
0,0 → 1,692
//========================================================================
//
// stream.cxx
//
// Implementations of internal C library stdio stream 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-20
// Purpose:
// Description:
// Usage:
//
//####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> // Assertion infrastructure
#include <stddef.h> // NULL and size_t from compiler
#include <errno.h> // Error codes
#include <string.h> // memcpy() and memset()
#include <cyg/libc/stdio/stream.hxx> // Header for this file
#include <cyg/libc/stdio/stdiosupp.hxx> // Stdio support functions
 
 
#include <cyg/libc/stdio/io.inl> // I/O system inlines
 
 
// FUNCTIONS
 
Cyg_StdioStream::Cyg_StdioStream(cyg_stdio_handle_t dev,
OpenMode open_mode,
cyg_bool append, cyg_bool binary,
int buffer_mode, cyg_ucount32 buffer_size,
cyg_uint8 *buffer_addr )
#ifdef CYGSEM_LIBC_STDIO_WANT_BUFFERED_IO
: io_buf( buffer_size, buffer_addr )
#endif
{
initialize( dev, open_mode, append, binary, buffer_mode,
buffer_size, buffer_addr);
}
 
void Cyg_StdioStream::initialize(cyg_stdio_handle_t dev,
OpenMode open_mode,
cyg_bool append, cyg_bool binary,
int buffer_mode, cyg_ucount32 buffer_size,
cyg_uint8 *buffer_addr )
{
 
#ifdef CYGDBG_USE_ASSERTS
magic_validity_word = 0xbadbad;
#endif
 
my_device = dev;
 
// Clear all flags
memset( &flags, 0, sizeof(flags) );
 
switch (open_mode) {
case CYG_STREAM_READ:
flags.opened_for_read = true;
break;
case CYG_STREAM_WRITE:
flags.opened_for_write = true;
break;
case CYG_STREAM_READWRITE:
flags.opened_for_read = true;
flags.opened_for_write = true;
break;
default:
error=EINVAL;
return;
} // switch
if (flags.opened_for_write) {
#if 0
// FIXME: need some replacement for this
if (!my_device->write_blocking) {
error = EDEVNOSUPP;
return;
} // if
#endif
#ifdef CYGSEM_LIBC_STDIO_WANT_BUFFERED_IO
flags.last_buffer_op_was_read = false;
#endif
} // if
 
 
if (flags.opened_for_read) {
#if 0
// FIXME: need some replacement for this
if (!my_device->read_blocking) {
error = EDEVNOSUPP;
return;
} // if
#endif
 
// NB also if opened for read AND write, then say last op was read
#ifdef CYGSEM_LIBC_STDIO_WANT_BUFFERED_IO
flags.last_buffer_op_was_read = true;
#endif
} // if
 
flags.binary = binary ? 1 : 0;
 
error = ENOERR;
// in due course we would do an equivalent to fseek(...,0, SEEK_END);
// when appending. for now, there's nothing, except set eof
flags.at_eof = append ? 1 : 0;
 
position = 0;
 
#ifdef CYGSEM_LIBC_STDIO_WANT_BUFFERED_IO
 
switch (buffer_mode) {
case _IONBF:
CYG_ASSERT( (buffer_size == 0) && (buffer_addr == NULL),
"No buffering wanted but size/address specified!" );
flags.buffering = flags.line_buffering = false;
break;
case _IOLBF:
flags.buffering = true;
flags.line_buffering = true;
break;
case _IOFBF:
flags.buffering = true;
flags.line_buffering = false;
break;
default:
error = EINVAL;
return;
} // switch
 
// one way of checking the buffer was set up correctly
if (flags.buffering && io_buf.get_buffer_size()==-1) {
error = ENOMEM;
return;
}
 
#endif
 
#if 0 // FIXME - Need to set binary mode.
if (my_device->open) {
error = (*my_device->open)( my_device->cookie,
binary ? CYG_DEVICE_OPEN_MODE_RAW
: CYG_DEVICE_OPEN_MODE_TEXT );
if (error != ENOERR)
return; // keep error code the same
} // if
#endif
 
#ifdef CYGDBG_USE_ASSERTS
magic_validity_word = 0x7b4321ce;
#endif
} // Cyg_StdioStream constructor
 
 
Cyg_StdioStream::Cyg_StdioStream( OpenMode open_mode,
cyg_ucount32 buffer_size,
cyg_uint8 *buffer_addr )
#ifdef CYGSEM_LIBC_STDIO_WANT_BUFFERED_IO
: io_buf( buffer_size, buffer_addr )
#endif
{
initialize( CYG_STDIO_HANDLE_NULL, open_mode, false, false, _IOFBF,
buffer_size, buffer_addr );
 
if( error != ENOERR )
return;
switch( open_mode )
{
case CYG_STREAM_READ:
// Fix up the stream so it looks like the buffer contents has just
// been read in.
#ifdef CYGSEM_LIBC_STDIO_WANT_BUFFERED_IO
io_buf.set_bytes_written( buffer_size );
#endif
break;
case CYG_STREAM_WRITE:
// Fix up the stream so it looks like the buffer is ready to accept
// new data.
break;
 
default:
error = EINVAL;
return;
}
}
 
 
Cyg_ErrNo
Cyg_StdioStream::refill_read_buffer( void )
{
Cyg_ErrNo read_err;
cyg_uint8 *buffer;
cyg_uint32 len;
 
CYG_ASSERTCLASS( this, "Stream object is not a valid stream!" );
if (!lock_me())
return EBADF; // assume file is now invalid
 
// first just check that we _can_ read this device!
if (!flags.opened_for_read) {
unlock_me();
return EINVAL;
}
#ifdef CYGSEM_LIBC_STDIO_WANT_BUFFERED_IO
// If there is pending output to write, then this will check and
// write it
if (flags.buffering) {
read_err = flush_output_unlocked();
 
// we're now reading
flags.last_buffer_op_was_read = true;
 
// flush ALL streams
if (read_err == ENOERR)
read_err = cyg_libc_stdio_flush_all_but(this);
 
if (read_err != ENOERR) {
unlock_me();
return read_err;
} // if
 
len = io_buf.get_buffer_addr_to_write( (cyg_uint8**)&buffer );
if (!len) { // no buffer space available
unlock_me();
return ENOERR; // isn't an error, just needs user to read out data
} // if
}
else
#endif
 
if (!flags.readbuf_char_in_use) {
len = 1;
buffer = &readbuf_char;
}
else {
// no buffer space available
unlock_me();
return ENOERR; // isn't an error, just needs user to read out data
} // else
 
read_err = cyg_stdio_read(my_device, buffer, &len);
 
 
#ifdef CYGSEM_LIBC_STDIO_WANT_BUFFERED_IO
if (flags.buffering)
io_buf.set_bytes_written( len );
else
#endif
flags.readbuf_char_in_use = len ? 1 : 0;
 
unlock_me();
 
if (read_err == ENOERR) {
if (len == 0) {
read_err = EAGAIN;
flags.at_eof = true;
}
else
flags.at_eof = false;
} // if
return read_err;
} // refill_read_buffer()
 
 
Cyg_ErrNo
Cyg_StdioStream::read( cyg_uint8 *user_buffer, cyg_ucount32 buffer_length,
cyg_ucount32 *bytes_read )
{
CYG_ASSERTCLASS( this, "Stream object is not a valid stream!" );
*bytes_read = 0;
 
if (!lock_me())
return EBADF; // assume file is now invalid
 
if (!flags.opened_for_read) {
unlock_me();
return EINVAL;
}
 
#ifdef CYGFUN_LIBC_STDIO_ungetc
if (flags.unread_char_buf_in_use && buffer_length) {
*user_buffer++ = unread_char_buf;
++*bytes_read;
flags.unread_char_buf_in_use = false;
--buffer_length;
} // if
 
#endif // ifdef CYGFUN_LIBC_STDIO_ungetc
 
#ifdef CYGSEM_LIBC_STDIO_WANT_BUFFERED_IO
if (flags.buffering) {
 
// need to flush output if we were writing before
if (!flags.last_buffer_op_was_read) {
Cyg_ErrNo err = flush_output_unlocked();
 
if (ENOERR != err) {
unlock_me();
return err;
}
}
cyg_uint8 *buff_to_read_from;
cyg_ucount32 bytes_available;
bytes_available = io_buf.get_buffer_addr_to_read(
(cyg_uint8 **)&buff_to_read_from );
cyg_ucount32 count =
(bytes_available < buffer_length) ? bytes_available : buffer_length;
 
if (count) {
memcpy( user_buffer, buff_to_read_from, count );
io_buf.set_bytes_read( count );
*bytes_read += count;
} // if
 
} // if
else
#endif
 
if (flags.readbuf_char_in_use && buffer_length) {
*user_buffer = readbuf_char;
*bytes_read = 1;
flags.readbuf_char_in_use = false;
}
 
position += *bytes_read;
unlock_me();
 
return ENOERR;
} // read()
 
 
Cyg_ErrNo
Cyg_StdioStream::read_byte( cyg_uint8 *c )
{
Cyg_ErrNo err=ENOERR;
 
CYG_ASSERTCLASS( this, "Stream object is not a valid stream!" );
if (!lock_me())
return EBADF; // assume file is now invalid
 
if (!flags.opened_for_read) {
unlock_me();
return EINVAL;
}
 
# ifdef CYGFUN_LIBC_STDIO_ungetc
if (flags.unread_char_buf_in_use) {
*c = unread_char_buf;
flags.unread_char_buf_in_use = false;
position++;
unlock_me();
return ENOERR;
} // if
# endif // ifdef CYGFUN_LIBC_STDIO_ungetc
 
#ifdef CYGSEM_LIBC_STDIO_WANT_BUFFERED_IO
if (flags.buffering) {
// need to flush output if we were writing before
if (!flags.last_buffer_op_was_read)
err = flush_output_unlocked();
 
if (ENOERR != err) {
unlock_me();
return err;
}
cyg_uint8 *buff_to_read_from;
cyg_ucount32 bytes_available;
bytes_available=io_buf.get_buffer_addr_to_read(&buff_to_read_from);
 
if (bytes_available) {
*c = *buff_to_read_from;
io_buf.set_bytes_read(1);
position++;
}
else
err = EAGAIN;
} // if
else
#endif
 
 
if (flags.readbuf_char_in_use) {
*c = readbuf_char;
flags.readbuf_char_in_use = false;
position++;
}
else
err = EAGAIN;
 
unlock_me();
 
return err;
} // read_byte()
 
 
Cyg_ErrNo
Cyg_StdioStream::peek_byte( cyg_uint8 *c )
{
Cyg_ErrNo err=ENOERR;
 
CYG_ASSERTCLASS( this, "Stream object is not a valid stream!" );
if (!lock_me())
return EBADF; // assume file is now invalid
 
if (!flags.opened_for_read) {
unlock_me();
return EINVAL;
}
 
// this should really only be called after refill_read_buffer, but just
// in case
#ifdef CYGSEM_LIBC_STDIO_WANT_BUFFERED_IO
if (flags.buffering)
err = flush_output_unlocked();
 
if (err != ENOERR)
return err;
 
// we're now reading
flags.last_buffer_op_was_read = true;
#endif
 
# ifdef CYGFUN_LIBC_STDIO_ungetc
if (flags.unread_char_buf_in_use) {
*c = unread_char_buf;
unlock_me();
return ENOERR;
} // if
# endif // ifdef CYGFUN_LIBC_STDIO_ungetc
 
#ifdef CYGSEM_LIBC_STDIO_WANT_BUFFERED_IO
if (flags.buffering) {
cyg_uint8 *buff_to_read_from;
cyg_ucount32 bytes_available;
bytes_available=io_buf.get_buffer_addr_to_read(&buff_to_read_from);
 
if (bytes_available) {
*c = *buff_to_read_from;
}
else
err = EAGAIN;
} // if
else
#endif
 
 
if (flags.readbuf_char_in_use) {
*c = readbuf_char;
}
else
err = EAGAIN;
 
unlock_me();
 
return err;
} // peek_byte()
 
 
Cyg_ErrNo
Cyg_StdioStream::flush_output_unlocked( void )
{
#ifdef CYGSEM_LIBC_STDIO_WANT_BUFFERED_IO
Cyg_ErrNo write_err=ENOERR;
cyg_uint8 *buffer;
cyg_uint32 len;
 
CYG_ASSERTCLASS( this, "Stream object is not a valid stream!" );
if ( flags.last_buffer_op_was_read )
return ENOERR;
 
// first just check that we _can_ write to the device!
if ( !flags.opened_for_write )
return EINVAL;
 
// shortcut if nothing to do
if (io_buf.get_buffer_space_used() == 0)
return ENOERR;
len = io_buf.get_buffer_addr_to_read( (cyg_uint8 **)&buffer );
CYG_ASSERT( len > 0,
"There should be data to read but there isn't!");
 
write_err = cyg_stdio_write(my_device, buffer, &len);
 
// since we're doing a concerted flush, we tell the I/O layer to
// flush too, otherwise output may just sit there forever
if (!write_err)
cyg_stdio_flush( my_device );
// we've just read it all, so just wipe it out
io_buf.drain_buffer();
 
return write_err;
 
#else // ifdef CYGSEM_LIBC_STDIO_WANT_BUFFERED_IO
 
CYG_ASSERTCLASS( this, "Stream object is not a valid stream!" );
return ENOERR;
 
#endif // ifdef CYGSEM_LIBC_STDIO_WANT_BUFFERED_IO
} // flush_output_unlocked()
 
 
 
Cyg_ErrNo
Cyg_StdioStream::write( const cyg_uint8 *buffer,
cyg_ucount32 buffer_length,
cyg_ucount32 *bytes_written )
{
Cyg_ErrNo write_err = ENOERR;
 
CYG_ASSERTCLASS( this, "Stream object is not a valid stream!" );
*bytes_written = 0;
 
if (!lock_me())
return EBADF; // assume file is now invalid
 
// first just check that we _can_ write to the device!
if ( !flags.opened_for_write ) {
unlock_me();
return EINVAL;
}
 
#ifdef CYGSEM_LIBC_STDIO_WANT_BUFFERED_IO
if (flags.last_buffer_op_was_read == true)
io_buf.drain_buffer(); // nuke input bytes to prevent confusion
 
flags.last_buffer_op_was_read = false;
 
if (!flags.buffering) {
#endif
cyg_uint32 len = buffer_length;
 
write_err = cyg_stdio_write(my_device, buffer, &len);
 
*bytes_written = len;
 
#ifdef CYGSEM_LIBC_STDIO_WANT_BUFFERED_IO
} // if
else {
cyg_ucount32 bytes_available;
cyg_ucount32 bytes_to_write;
cyg_ucount32 newline_pos;
cyg_uint8 *write_addr;
cyg_bool must_flush = false;
while ( buffer_length > 0 ) {
bytes_available =
io_buf.get_buffer_addr_to_write( &write_addr );
// we need to flush if we've no room or the buffer has an up
// and coming newline
if ( !bytes_available || must_flush ) {
write_err = flush_output_unlocked();
// harmless even if there was an error
bytes_available =
io_buf.get_buffer_addr_to_write( &write_addr );
 
CYG_ASSERT( bytes_available > 0,
"Help! still no bytes available in "
"write buffer" );
} // if
if (write_err) {
unlock_me();
return write_err;
} // if
// choose the lower of the buffer available and the length
// to write
bytes_to_write=(bytes_available < buffer_length)
? bytes_available
: buffer_length;
// if we're line buffered, we may want want to flush if there's
// a newline character, so lets find out
if (flags.line_buffering) {
for (newline_pos=0;
newline_pos<bytes_to_write;
newline_pos++) {
if (buffer[newline_pos] == '\n') {
break;
} // if
} // for
// if we didn't reach the end
if (newline_pos != bytes_to_write) {
// shrink bytes_to_write down to the bit we need to
// flush including the newline itself
bytes_to_write = newline_pos + 1;
must_flush = true;
} // if
} // if
memcpy( write_addr, buffer, bytes_to_write );
*bytes_written += bytes_to_write;
buffer += bytes_to_write;
buffer_length -= bytes_to_write;
io_buf.set_bytes_written( bytes_to_write );
 
position += bytes_to_write;
} // while
if ( must_flush ) {
write_err = flush_output_unlocked();
} // if
} // else
#endif // ifdef CYGSEM_LIBC_STDIO_WANT_BUFFERED_IO
 
unlock_me();
 
return write_err;
} // write()
 
// EOF stream.cxx
/fseek.cxx
0,0 → 1,167
//===========================================================================
//
// fseek.cxx
//
// Implementation of C library file positioning functions as per ANSI 7.9.9
//
//===========================================================================
//####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-07-12
// Purpose: Implements ISO C file positioning functions
// Description:
// Usage:
//
//####DESCRIPTIONEND####
//
//===========================================================================
 
// CONFIGURATION
 
#include <pkgconf/libc_stdio.h> // Configuration header
 
#include <cyg/infra/cyg_type.h> // Common project-wide type definitions
#include <cyg/infra/cyg_ass.h> // Assertion support
#include <cyg/infra/cyg_trac.h> // Tracing support
#include <stddef.h> // NULL and size_t from compiler
#include <errno.h> // Error codes
#include <stdio.h> // header for fseek() etc.
#include <cyg/libc/stdio/stdiofiles.hxx> // C library files
#include <cyg/libc/stdio/stream.hxx> // C library streams
 
//========================================================================
 
// ISO C 7.9.9 File positioning functions
 
externC int
fgetpos( FILE * stream , fpos_t *pos )
{
Cyg_StdioStream *real_stream = (Cyg_StdioStream *)stream;
Cyg_ErrNo err;
int ret = 0;
CYG_REPORT_FUNCNAME( "fgetpos" );
 
err = real_stream->get_position( pos );
if( err != ENOERR )
{
errno = err;
ret = -1;
}
CYG_REPORT_RETVAL( ret );
return ret;
}
 
externC int
fseek( FILE * stream , long int offset , int whence )
{
Cyg_StdioStream *real_stream = (Cyg_StdioStream *)stream;
Cyg_ErrNo err;
int ret = 0;
CYG_REPORT_FUNCNAME( "fgetpos" );
 
err = real_stream->set_position( (fpos_t)offset, whence );
if( err != ENOERR )
{
errno = err;
ret = -1;
}
CYG_REPORT_RETVAL( ret );
return ret;
}
 
externC int
fsetpos( FILE * stream , const fpos_t * pos )
{
Cyg_StdioStream *real_stream = (Cyg_StdioStream *)stream;
Cyg_ErrNo err;
int ret = 0;
CYG_REPORT_FUNCNAME( "fgetpos" );
 
err = real_stream->set_position( *pos, SEEK_SET );
if( err != ENOERR )
{
errno = err;
ret = -1;
}
CYG_REPORT_RETVAL( ret );
return ret;
}
 
externC long int
ftell( FILE * stream )
{
Cyg_StdioStream *real_stream = (Cyg_StdioStream *)stream;
Cyg_ErrNo err;
long int ret = 0;
fpos_t pos;
CYG_REPORT_FUNCNAME( "ftell" );
 
err = real_stream->get_position( &pos );
if( err != ENOERR )
{
errno = err;
ret = -1;
}
else ret = pos;
CYG_REPORT_RETVAL( ret );
return ret;
}
 
externC void
rewind( FILE * stream )
{
Cyg_StdioStream *real_stream = (Cyg_StdioStream *)stream;
(void)fseek( stream, 0L, SEEK_SET );
 
real_stream->set_error( ENOERR );
}
 
 
// EOF fseek.cxx
/freopen.cxx
0,0 → 1,79
//========================================================================
//
// freopen.cxx
//
// Implementation of C library freopen() function
//
//========================================================================
//####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-20
// Purpose: Provides ISO C freopen() function
// Description: Implementation of C library freopen() function as per
// ISO C standard chap. 7.9.5.4
// Usage:
//
//####DESCRIPTIONEND####
//
//========================================================================
 
// CONFIGURATION
 
#include <pkgconf/libc_stdio.h> // Configuration header
 
// We only want freopen() if we have fopen()
#if defined(CYGPKG_LIBC_STDIO_OPEN)
 
// INCLUDES
 
#include <cyg/infra/cyg_type.h> // Common project-wide type definitions
#include <stddef.h> // NULL and size_t from compiler
#include <stdio.h> // header for freopen()
 
// FUNCTIONS
 
 
externC FILE *
freopen( const char *, const char *, FILE * )
{
return NULL; // Returning NULL is valid! FIXME
} // freopen()
 
#endif // defined(CYGPKG_LIBC_STDIO_OPEN)
 
// EOF freopen.cxx
/vsscanf.cxx
0,0 → 1,155
//===========================================================================
//
// vsscanf.cxx
//
// ANSI Stdio vsscanf() function
//
//===========================================================================
//####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-20
// Purpose:
// Description:
// Usage:
//
//####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 <stdio.h> // header for this file
#include <errno.h> // error codes
#include <cyg/io/devtab.h> // Device table
#include <cyg/libc/stdio/stream.hxx>// Cyg_StdioStream
 
#include <cyg/libc/stdio/io.inl> // I/O system inlines
 
#ifndef CYGPKG_LIBC_STDIO_FILEIO
 
// FUNCTIONS
 
static Cyg_ErrNo
str_read(cyg_stdio_handle_t handle, void *buf, cyg_uint32 *len)
{
cyg_devtab_entry_t *dev = (cyg_devtab_entry_t *)handle;
cyg_uint8 *str_p = (cyg_uint8 *)dev->priv;
cyg_ucount32 i;
 
// we set str_p to NULL further down when the string has finished being
// read
if (str_p == NULL)
{
*len = 0;
return ENOERR;
} // if
 
// I suspect most strings passed to sprintf will be relatively short,
// so we just take the simple approach rather than have the overhead
// of calling memcpy etc.
 
// copy string until run out of user space, or we reach its end
for (i = 0; i < *len ; ++i)
{
*((cyg_uint8 *)buf + i) = *str_p;
 
if (*str_p++ == '\0')
{
str_p = NULL;
++i;
break;
} // if
 
} // for
 
*len = i;
dev->priv = (void *)str_p;
 
return ENOERR;
} // str_read()
 
static DEVIO_TABLE(devio_table,
NULL, // write
str_read, // read
NULL, // select
NULL, // get_config
NULL); // set_config
 
 
externC int
vsscanf( const char *s, const char *format, va_list arg )
{
// construct a fake device with the address of the string we've
// been passed as its private data. This way we can use the data
// directly
DEVTAB_ENTRY_NO_INIT(strdev,
"strdev", // Name
NULL, // Dependent name (layered device)
&devio_table, // I/O function table
NULL, // Init
NULL, // Lookup
(void *)s); // private
Cyg_StdioStream my_stream( &strdev, Cyg_StdioStream::CYG_STREAM_READ,
false, false, _IONBF, 0, NULL );
return vfscanf( (FILE *)&my_stream, format, arg );
 
} // vsscanf()
 
#else
 
externC int
vsscanf( const char *s, const char *format, va_list arg )
{
Cyg_StdioStream my_stream( Cyg_StdioStream::CYG_STREAM_READ,
strlen(s), (cyg_uint8 *)s );
return vfscanf( (FILE *)&my_stream, format, arg );
 
} // vsscanf()
 
#endif
 
// EOF vsscanf.cxx
/snprintf.cxx
0,0 → 1,81
//===========================================================================
//
// snprintf.cxx
//
// ANSI Stdio snprintf() function
//
//===========================================================================
//####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-20
// Purpose:
// Description:
// Usage:
//
//####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 <stdio.h> // header for this file
 
// FUNCTIONS
 
externC int
snprintf( char *s, size_t size, const char *format, ... )
{
int rc; // return code
va_list ap; // for variable args
 
va_start(ap, format); // init specifying last non-var arg
 
rc = vsnprintf(s, size, format, ap);
 
va_end(ap); // end var args
 
return rc;
} // snprintf()
 
// EOF snprintf.cxx
/stderr.cxx
0,0 → 1,110
//========================================================================
//
// stderr.cxx
//
// Initialization of stderr stream for ISO C library
//
//========================================================================
//####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-20
// Purpose: Initialization of stderr stream for ISO C library
// Description: We put all this in a separate file in the hope that if
// no-one uses stderr, then it is not included in the image
// Usage:
//
//####DESCRIPTIONEND####
//
//========================================================================
 
// CONFIGURATION
 
#include <pkgconf/libc_stdio.h> // Configuration header
 
// Don't let us get the stream definitions of stdin/out/err from stdio.h
// since we are going to break the type safety :-(
#define CYGPRI_LIBC_STDIO_NO_DEFAULT_STREAMS
 
// And we don't need the stdio inlines, which will otherwise complain if
// stdin/out/err are not available
#ifdef CYGIMP_LIBC_STDIO_INLINES
# undef CYGIMP_LIBC_STDIO_INLINES
#endif
 
// INCLUDES
 
#include <cyg/infra/cyg_type.h> // Common type definitions and support
#include <cyg/libc/stdio/stream.hxx> // Cyg_StdioStream class
#include <cyg/libc/stdio/stdiofiles.hxx> // C library files
#include <cyg/libc/stdio/stdiosupp.hxx> // Cyg_libc_stdio_find_filename()
 
// CONSTANTS
 
// add 2 to the priority to allow it to be the fd 2 if necessary
#define PRIO (CYG_INIT_LIBC+2)
 
// STATICS
 
Cyg_StdioStream
cyg_libc_stdio_stderr CYGBLD_ATTRIB_INIT_PRI(PRIO) = Cyg_StdioStream(
Cyg_libc_stdio_find_filename(CYGDAT_LIBC_STDIO_DEFAULT_CONSOLE,
Cyg_StdioStream::CYG_STREAM_WRITE,
false, false),
Cyg_StdioStream::CYG_STREAM_WRITE, false, false, _IONBF, 0, NULL );
 
// CLASSES
 
// This is a dummy class just so we can execute arbitrary code when
// stderr is requested
 
class cyg_libc_dummy_stderr_init_class {
public:
cyg_libc_dummy_stderr_init_class(void) {
Cyg_libc_stdio_files::set_file_stream(2, &cyg_libc_stdio_stderr);
}
};
 
// And here's an instance of the class just to make the code run
static cyg_libc_dummy_stderr_init_class cyg_libc_dummy_stderr_init
CYGBLD_ATTRIB_INIT_PRI(PRIO);
 
// and finally stderr itself
__externC Cyg_StdioStream * const stderr;
Cyg_StdioStream * const stderr=&cyg_libc_stdio_stderr;
 
// EOF stderr.cxx
/stdioinlines.cxx
0,0 → 1,164
//===========================================================================
//
// stdioinlines.cxx
//
// ANSI standard I/O routines - real alternatives for 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-20
// Purpose:
// Description:
// Usage:
//
//####DESCRIPTIONEND####
//
//===========================================================================
 
// CONFIGURATION
 
#include <pkgconf/libc_stdio.h> // Configuration header
 
// INCLUDES
 
// We don't want the inline versions of stdio functions defined here
 
#ifdef CYGIMP_LIBC_STDIO_INLINES
#undef CYGIMP_LIBC_STDIO_INLINES
#endif
 
#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> // Header for this file
#include <errno.h> // Definition of error codes and errno
#include <string.h> // Definition of strerror() for perror()
#include <limits.h> // INT_MAX
 
 
// FUNCTIONS
 
//===========================================================================
 
// 7.9.5 File access functions
 
externC 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
 
 
externC int
vfprintf( FILE *stream, const char *format, va_list arg )
{
return vfnprintf(stream, INT_MAX, format, arg);
} // vfprintf()
 
 
externC int
vprintf( const char *format, va_list arg)
{
return vfnprintf( stdout, INT_MAX, format, arg );
} // vprintf()
 
 
externC 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
 
externC 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
 
externC 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
 
#ifdef CYGFUN_LIBC_STDIO_ungetc
externC int
vscanf( const char *format, va_list arg )
{
return vfscanf( stdin, format, arg );
} // vscanf()
#endif
 
// EOF stdioinlines.cxx
/stdiofiles.cxx
0,0 → 1,82
//========================================================================
//
// stdiofiles.cxx
//
// ISO C library stdio central file data
//
//========================================================================
//####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-20
// Purpose: Allocate storage for central file data object
// Description: This file allocates the actual objects used by the
// Cyg_libc_stdio_files class defined in
// <cyg/libc/stdio/stdiofiles.hxx>
// Usage:
//
//####DESCRIPTIONEND####
//
//=========================================================================
 
// CONFIGURATION
 
#include <pkgconf/libc_stdio.h> // C library configuration
 
// INCLUDES
 
#include <stddef.h> // NULL
#include <cyg/libc/stdio/stream.hxx> // Cyg_StdioStream
#include <cyg/libc/stdio/stdiofiles.hxx> // Class definition for
// Cyg_libc_stdio_files
 
#ifdef CYGSEM_LIBC_STDIO_THREAD_SAFE_STREAMS
# include <cyg/infra/cyg_type.h> // CYGBLD_ATTRIB_INIT_PRI
# include <cyg/kernel/mutex.hxx> // mutexes
#endif
 
 
// GLOBAL VARIABLES
 
Cyg_StdioStream *Cyg_libc_stdio_files::files[FOPEN_MAX] = { NULL };
 
# ifdef CYGSEM_LIBC_STDIO_THREAD_SAFE_STREAMS
Cyg_Mutex Cyg_libc_stdio_files::files_lock
CYGBLD_ATTRIB_INIT_PRI(CYG_INIT_LIBC);
# endif
 
// EOF stdiofiles.cxx
/fopen.cxx
0,0 → 1,267
//===========================================================================
//
// fopen.cxx
//
// Implementation of C library file open function as per ANSI 7.9.5.3
//
//===========================================================================
//####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-20
// Purpose: Implements ISO C fopen() function
// Description:
// Usage:
//
//####DESCRIPTIONEND####
//
//===========================================================================
 
// CONFIGURATION
 
#include <pkgconf/libc_stdio.h> // Configuration header
 
 
// Do we want fopen()?
#if defined(CYGPKG_LIBC_STDIO_OPEN)
 
// 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 <stdio.h> // header for fopen()
#include <stdlib.h> // malloc()
#include <string.h> // strncmp() and strcmp()
#include <cyg/libc/stdio/stdiofiles.hxx> // C library files
#include <cyg/libc/stdio/stream.hxx> // C library streams
 
#include <cyg/libc/stdio/io.inl> // I/O system inlines
 
// FUNCTIONS
 
// placement new
inline void *operator new(size_t size, void *ptr)
{
CYG_CHECK_DATA_PTR( ptr, "Bad pointer" );
return ptr;
}
 
// process the mode string. Return true on error
static cyg_bool
process_mode( const char *mode, Cyg_StdioStream::OpenMode *rw,
cyg_bool *binary, cyg_bool *append )
{
*binary = *append = false; // default
 
switch (mode[0]) {
case 'r':
*rw = Cyg_StdioStream::CYG_STREAM_READ;
break;
 
case 'a':
*append = true;
case 'w':
*rw = Cyg_StdioStream::CYG_STREAM_WRITE;
break;
default:
return true;
} // switch
 
// ANSI says additional characters may follow the sequences, that we
// don't necessarily recognise so we just ignore them, and pretend that
// its the end of the string
 
switch (mode[1]) {
case 'b':
*binary = true;
break;
case '+':
*rw = Cyg_StdioStream::CYG_STREAM_READWRITE;
break;
default:
return false;
} // switch
 
switch (mode[2]) {
case 'b':
*binary = true;
break;
case '+':
*rw = Cyg_StdioStream::CYG_STREAM_READWRITE;
break;
default:
return false;
} // switch
return false;
} // process_mode()
 
 
static FILE *fopen_inner( cyg_stdio_handle_t dev,
Cyg_StdioStream::OpenMode open_mode,
cyg_bool binary,
cyg_bool append)
{
Cyg_StdioStream *curr_stream;
int i;
Cyg_ErrNo err;
int bufmode = _IOFBF;
cyg_ucount32 bufsize = BUFSIZ;
Cyg_libc_stdio_files::lock();
 
// find an empty slot
for (i=0; i < FOPEN_MAX; i++) {
curr_stream = Cyg_libc_stdio_files::get_file_stream(i);
if (curr_stream == NULL)
break;
} // for
 
if (i == FOPEN_MAX) { // didn't find an empty slot
errno = EMFILE;
cyg_stdio_close( dev );
return NULL;
} // if
 
// Decide the buffering mode. The default is fully buffered, but if
// this is an interactive stream then set it to non buffered.
if( (dev != CYG_STDIO_HANDLE_NULL) &&
cyg_stdio_interactive( dev ) )
bufmode = _IONBF, bufsize = 0;
// Allocate it some memory and construct it.
curr_stream = (Cyg_StdioStream *)malloc(sizeof(*curr_stream));
if (curr_stream == NULL) {
cyg_stdio_close( dev );
errno = ENOMEM;
return NULL;
} // if
 
curr_stream = new ((void *)curr_stream) Cyg_StdioStream( dev, open_mode,
append, binary,
bufmode, bufsize );
// it puts any error in its own error flag
if (( err=curr_stream->get_error() )) {
 
Cyg_libc_stdio_files::unlock();
free( curr_stream );
 
cyg_stdio_close( dev );
errno = err;
 
return NULL;
 
} // if
 
Cyg_libc_stdio_files::set_file_stream(i, curr_stream);
Cyg_libc_stdio_files::unlock();
 
return (FILE *)(curr_stream);
 
} // fopen_inner()
 
externC FILE *
fopen( const char *filename, const char *mode )
{
cyg_stdio_handle_t dev;
Cyg_ErrNo err;
Cyg_StdioStream::OpenMode open_mode;
cyg_bool binary, append;
// process_mode returns true on error
if (process_mode( mode, &open_mode, &binary, &append )) {
errno = EINVAL;
return NULL;
} // if
 
err = cyg_stdio_open( filename, open_mode, binary, append, &dev );
 
// if not found
if (err != ENOERR) {
errno = ENOENT;
return NULL;
} // if
 
return fopen_inner( dev, open_mode, binary, append );
} // fopen()
 
 
#endif // defined(CYGPKG_LIBC_STDIO_OPEN)
 
#ifdef CYGPKG_LIBC_STDIO_FILEIO
 
externC int fileno( FILE *stream )
{
Cyg_StdioStream *real_stream = (Cyg_StdioStream *)stream;
 
return real_stream->get_dev();
}
 
externC FILE *fdopen( int fd, const char *mode )
{
Cyg_StdioStream::OpenMode open_mode;
cyg_bool binary, append;
FILE *f;
// process_mode returns true on error
if (process_mode( mode, &open_mode, &binary, &append )) {
errno = EINVAL;
return NULL;
} // if
 
f = fopen_inner( (cyg_stdio_handle_t)fd, open_mode, binary, append );
 
if( f == NULL )
return f;
 
// Do a null seek to initialize the file position.
Cyg_StdioStream *real_stream = (Cyg_StdioStream *)f;
fpos_t pos = 0;
real_stream->set_position( pos, SEEK_CUR );
return f;
}
 
#endif // def CYGPKG_LIBC_STDIO_FILEIO
 
 
// EOF fopen.cxx
/fclose.cxx
0,0 → 1,129
//===========================================================================
//
// fclose.cxx
//
// Implementation of C library file close function as per ANSI 7.9.5.1
//
//===========================================================================
//####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-20
// Purpose: Implements ISO C fclose() function
// Description:
// Usage:
//
//####DESCRIPTIONEND####
//
//===========================================================================
 
// CONFIGURATION
 
#include <pkgconf/libc_stdio.h> // Configuration header
#include <pkgconf/infra.h>
 
// We can't have fclose() without fopen()
#if defined(CYGPKG_LIBC_STDIO_OPEN)
 
// 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 <stdio.h> // header for fclose()
#include <stdlib.h> // free()
#include <cyg/libc/stdio/stdiofiles.hxx> // C library files
#include <cyg/libc/stdio/stream.hxx> // C library streams
 
#include <cyg/libc/stdio/io.inl> // I/O system inlines
 
// FUNCTIONS
 
 
externC int
fclose( FILE *stream )
{
Cyg_StdioStream *real_stream = (Cyg_StdioStream *)stream;
int i;
Cyg_ErrNo err;
Cyg_libc_stdio_files::lock();
 
// find the stream in the table
for (i=0; i < FOPEN_MAX; i++)
{
if (real_stream == Cyg_libc_stdio_files::get_file_stream(i))
break;
} // for
 
if (i == FOPEN_MAX) // didn't find it
{
errno = EBADF;
 
return EOF;
} // if
 
err = real_stream->close();
 
if( err != ENOERR )
{
errno = err;
return EOF;
}
#ifdef CYGFUN_INFRA_EMPTY_DELETE_FUNCTIONS
// Explicitly call destructor - this flushes the output too
real_stream->~Cyg_StdioStream();
 
// and free it
free(real_stream);
#else
delete real_stream;
#endif // CYGFUN_INFRA_EMPTY_DELETE_FUNCTIONS
 
// and mark the stream available for use
Cyg_libc_stdio_files::set_file_stream(i, NULL);
Cyg_libc_stdio_files::unlock();
 
return 0;
 
} // fclose()
#endif // if defined(CYGPKG_LIBC_STDIO_OPEN)
 
// EOF fclose.cxx
/sscanf.cxx
0,0 → 1,81
//===========================================================================
//
// sscanf.cxx
//
// ANSI Stdio sscanf() function
//
//===========================================================================
//####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-20
// Purpose:
// Description:
// Usage:
//
//####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 <stdio.h> // header for this file
 
// FUNCTIONS
 
externC int
sscanf( const char *s, const char *format, ... )
{
int rc; // return code
va_list ap; // for variable args
 
va_start(ap, format); // init specifying last non-var arg
 
rc = vsscanf(s, format, ap);
 
va_end(ap); // end var args
 
return rc;
} // sscanf()
 
// EOF sscanf.cxx

powered by: WebSVN 2.1.0

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