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
    from Rev 27 to Rev 174
    Reverse comparison

Rev 27 → Rev 174

/input/fscanf.cxx
0,0 → 1,82
//===========================================================================
//
// fscanf.cxx
//
// ANSI Stdio fscanf() 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
fscanf( FILE *stream, const char *format, ... )
{
int rc; // return code
va_list ap; // for variable args
 
va_start(ap, format); // init specifying last non-var arg
 
rc = vfscanf( stream, format, ap );
 
va_end(ap); // end var args
 
return rc;
} // fscanf()
 
// EOF fscanf.cxx
/input/fread.cxx
0,0 → 1,123
//========================================================================
//
// fread.cxx
//
// ANSI Stdio fread() 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 <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 <stdio.h> // header for this file
#include <errno.h> // error codes
#include <cyg/libc/stdio/stream.hxx>// Cyg_StdioStream
 
// FUNCTIONS
 
externC size_t
fread( void *ptr, size_t object_size, size_t num_objects, FILE *stream )
{
Cyg_StdioStream *real_stream = (Cyg_StdioStream *)stream;
cyg_ucount32 bytes_read;
cyg_ucount32 bytes_to_read;
cyg_ucount32 total_read;
Cyg_ErrNo err;
cyg_uint8 *ptrc = (cyg_uint8 *)ptr;
 
CYG_REPORT_FUNCNAMETYPE( "fread", "read %d objects" );
CYG_REPORT_FUNCARG4( "ptr=%08x, object_size=%d, num_objects=%d, "
"stream=%08x", ptr, object_size, num_objects,
stream );
 
bytes_to_read = object_size*num_objects;
total_read = 0;
 
if ( !bytes_to_read ) {
CYG_REPORT_RETVAL(0);
return 0;
} // if
 
err = real_stream->read( (cyg_uint8 *)ptr, bytes_to_read,
&bytes_read );
bytes_to_read -= bytes_read;
total_read += bytes_read;
ptrc += bytes_read;
 
while (!err && bytes_to_read) { // if no err, but not finished - get next
err = real_stream->refill_read_buffer();
if ( !err ) {
err = real_stream->read( (cyg_uint8 *)ptrc, bytes_to_read,
&bytes_read );
bytes_to_read -= bytes_read;
total_read += bytes_read;
ptrc += bytes_read;
} // if
} // while
 
if (err) {
real_stream->set_error( err );
errno = err;
} // if
// we return the number of _objects_ read. Simple division is
// sufficient as this returns the quotient rather than rounding
CYG_REPORT_RETVAL( bytes_read/object_size );
return total_read/object_size;
 
} // fread()
 
// EOF fread.cxx
/input/gets.cxx
0,0 → 1,124
//===========================================================================
//
// gets.cxx
//
// ISO C standard I/O gets() 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: 2001-03-15
// Purpose: Implementation of ISO C standard I/O gets() function
// Description:
// Usage:
//
//####DESCRIPTIONEND####
//
//===========================================================================
 
// CONFIGURATION
 
#include <pkgconf/libc_stdio.h> // Configuration header
 
// INCLUDES
 
#include <cyg/infra/cyg_type.h> // Common 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 <stdio.h> // header for this file
#include <errno.h> // error codes
#include <cyg/libc/stdio/stream.hxx>// Cyg_StdioStream
 
// FUNCTIONS
 
// FIXME: should be reworked to read buffer at a time, and scan that
// for newlines, rather than reading byte at a time.
 
externC char *
gets( char *s )
{
Cyg_StdioStream *real_stream = (Cyg_StdioStream *)stdin;
Cyg_ErrNo err=ENOERR;
cyg_uint8 c;
cyg_uint8 *str=(cyg_uint8 *)s;
int nch;
 
CYG_CHECK_DATA_PTRC( s );
CYG_CHECK_DATA_PTRC( real_stream );
 
CYG_REPORT_FUNCTYPE( "returning string %08x");
CYG_REPORT_FUNCARG1( "s=%08x", s );
for (nch=1;; nch++) {
err = real_stream->read_byte( &c );
// if nothing to read, try again ONCE after refilling buffer
if (EAGAIN == err) {
err = real_stream->refill_read_buffer();
if ( !err )
err = real_stream->read_byte( &c );
 
if (EAGAIN == err) {
if (1 == nch) { // indicates EOF at start
CYG_REPORT_RETVAL( NULL );
return NULL;
} else
break; // EOF
} // if
} // if
if ('\n' == c) // discard newlines
break;
*str++ = c;
} // while
*str = '\0'; // NULL terminate it
if (err && EAGAIN != err) {
real_stream->set_error( err );
errno = err;
CYG_REPORT_RETVAL( NULL );
return NULL;
} // if
 
CYG_REPORT_RETVAL( s );
return s;
} // gets()
 
// EOF gets.cxx
/input/vfscanf.cxx
0,0 → 1,1002
//========================================================================
//
// vfscanf.cxx
//
// I/O routines for vfscanf() for use with ANSI 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:
// Description:
// Usage:
//
//####DESCRIPTIONEND####
//
//========================================================================
//
// This code is based on original code with the following copyright:
//
/*
* Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
 
 
// CONFIGURATION
 
#include <pkgconf/libc_stdio.h> // Configuration header
#include <pkgconf/libc_i18n.h> // Configuration header for mb support
 
// We have to have ungetc for this to work
#if defined(CYGFUN_LIBC_STDIO_ungetc)
 
 
// INCLUDES
 
#include <cyg/infra/cyg_type.h> // Common type definitions and support
#include <stdarg.h> // Variable argument definitions
#include <stdio.h> // Standard header for all stdio files
#include <ctype.h> // isspace() and isupper()
#include <stdlib.h> // standard utility functions e.g. strtol
#include <cyg/libc/stdio/stream.hxx> // C library streams
 
#ifdef CYGSEM_LIBC_STDIO_SCANF_FLOATING_POINT
 
#include <float.h>
 
# define MAXFRACT DBL_DIG
# define MAXEXP DBL_MAX_10_EXP
 
# define BUF (MAXEXP+MAXFRACT+3) /* 3 = sign + decimal point + NUL */
 
#else // ifdef CYGSEM_LIBC_STDIO_PRINTF_FLOATING_POINT
 
# define BUF 40
 
#endif // ifdef CYGSEM_LIBC_STDIO_PRINTF_FLOATING_POINT
 
/*
* Flags used during conversion.
*/
 
#define LONG 0x01 /* l: long or double */
#define LONGDBL 0x02 /* L: long double; unimplemented */
#define SHORT 0x04 /* h: short */
#define SUPPRESS 0x08 /* suppress assignment */
#define POINTER 0x10 /* weird %p pointer (`fake hex') */
#define NOSKIP 0x20 /* do not skip blanks */
 
/*
* The following are used in numeric conversions only:
* SIGNOK, NDIGITS, DPTOK, and EXPOK are for floating point;
* SIGNOK, NDIGITS, PFXOK, and NZDIGITS are for integral.
*/
 
#define SIGNOK 0x40 /* +/- is (still) legal */
#define NDIGITS 0x80 /* no digits detected */
 
#define DPTOK 0x100 /* (float) decimal point is still legal */
#define EXPOK 0x200 /* (float) exponent (e+3, etc) still
legal */
 
#define PFXOK 0x100 /* 0x prefix is (still) legal */
#define NZDIGITS 0x200 /* no zero digits detected */
 
/*
* Conversion types.
*/
 
#define CT_CHAR 0 /* %c conversion */
#define CT_CCL 1 /* %[...] conversion */
#define CT_STRING 2 /* %s conversion */
#define CT_INT 3 /* integer, i.e., strtol or strtoul */
#define CT_FLOAT 4 /* floating, i.e., strtod */
 
#if 0
#define u_char unsigned char
#endif
#define u_char char
#define u_long unsigned long
 
typedef unsigned long (*strtoul_t)(const char *, char **endptr, int base);
 
static u_char *
__sccl (char *tab, u_char *fmt);
 
 
/*
* vfscanf
*/
 
#define _CAST_VOID
 
#define CURR_POS (file->peek_byte( (cyg_uint8 *)&curr_byte),&curr_byte )
 
#define INC_CURR_POS ( file->read_byte( (cyg_uint8 *)&curr_byte ) )
 
#define MOVE_CURR_POS(x) (file->set_position( (x), SEEK_CUR ))
 
#define SPACE_LEFT (file->bytes_available_to_read())
 
#define REFILL (file->refill_read_buffer())
 
#define BufferEmpty ( !SPACE_LEFT && \
(REFILL, (!SPACE_LEFT)) )
 
#ifdef CYGINT_LIBC_I18N_MB_REQUIRED
typedef int (*mbtowc_fn_type)(wchar_t *, const char *, size_t, int *);
externC mbtowc_fn_type __get_current_locale_mbtowc_fn();
#endif
 
externC int
vfscanf (FILE *fp, const char *fmt0, va_list ap)
{
u_char *fmt = (u_char *) fmt0;
int c; /* character from format, or conversion */
wchar_t wc; /* wide character from format */
size_t width; /* field width, or 0 */
char *p; /* points into all kinds of strings */
int n; /* handy integer */
int flags; /* flags as defined above */
char *p0; /* saves original value of p when necessary */
char *lptr; /* literal pointer */
int nassigned; /* number of fields assigned */
int nread; /* number of characters consumed from fp */
int base = 0; /* base argument to strtol/strtoul */
int nbytes = 1; /* number of bytes processed */
 
#ifdef CYGINT_LIBC_I18N_MB_REQUIRED
mbtowc_fn_type mbtowc_fn;
int state = 0; /* used for mbtowc_fn */
#endif
strtoul_t ccfn = NULL; /* conversion function (strtol/strtoul) */
char ccltab[256]; /* character class table for %[...] */
char buf[BUF]; /* buffer for numeric conversions */
 
Cyg_StdioStream *file = (Cyg_StdioStream *)fp;
char curr_byte;
 
short *sp;
int *ip;
float *flp;
long double *ldp;
double *dp;
long *lp;
 
/* `basefix' is used to avoid `if' tests in the integer scanner */
static const short basefix[17] =
{10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
 
#ifdef CYGINT_LIBC_I18N_MB_REQUIRED
mbtowc_fn = __get_current_locale_mbtowc_fn();
#endif
 
nassigned = 0;
nread = 0;
for (;;)
{
#ifndef CYGINT_LIBC_I18N_MB_REQUIRED
wc = *fmt;
#else
nbytes = mbtowc_fn (&wc, fmt, MB_CUR_MAX, &state);
#endif
fmt += nbytes;
 
if (wc == 0)
return nassigned;
if (nbytes == 1 && isspace (wc))
{
for (;;)
{
if (BufferEmpty)
return nassigned;
if (!isspace (*CURR_POS))
break;
nread++, INC_CURR_POS;
}
continue;
}
if (wc != '%')
goto literal;
width = 0;
flags = 0;
 
/*
* switch on the format. continue if done; break once format
* type is derived.
*/
again:
c = *fmt++;
switch (c)
{
case '%':
literal:
lptr = fmt - nbytes;
for (n = 0; n < nbytes; ++n)
{
if (BufferEmpty)
goto input_failure;
if (*CURR_POS != *lptr)
goto match_failure;
INC_CURR_POS;
nread++;
++lptr;
}
continue;
 
case '*':
flags |= SUPPRESS;
goto again;
case 'l':
flags |= LONG;
goto again;
case 'L':
flags |= LONGDBL;
goto again;
case 'h':
flags |= SHORT;
goto again;
 
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
width = width * 10 + c - '0';
goto again;
 
/*
* Conversions. Those marked `compat' are for
* 4.[123]BSD compatibility.
*
* (According to ANSI, E and X formats are supposed to
* the same as e and x. Sorry about that.)
*/
 
case 'D': /* compat */
flags |= LONG;
/* FALLTHROUGH */
case 'd':
c = CT_INT;
ccfn = (strtoul_t)strtol;
base = 10;
break;
 
case 'i':
c = CT_INT;
ccfn = (strtoul_t)strtol;
base = 0;
break;
 
case 'O': /* compat */
flags |= LONG;
/* FALLTHROUGH */
case 'o':
c = CT_INT;
ccfn = strtoul;
base = 8;
break;
 
case 'u':
c = CT_INT;
ccfn = strtoul;
base = 10;
break;
 
case 'X': /* compat XXX */
case 'x':
flags |= PFXOK; /* enable 0x prefixing */
c = CT_INT;
ccfn = strtoul;
base = 16;
break;
 
case 'E': /* compat XXX */
case 'G': /* compat XXX */
/* ANSI says that E,G and X behave the same way as e,g,x */
/* FALLTHROUGH */
case 'e':
case 'f':
case 'g':
c = CT_FLOAT;
break;
 
case 's':
c = CT_STRING;
break;
 
case '[':
fmt = __sccl (ccltab, fmt);
flags |= NOSKIP;
c = CT_CCL;
break;
 
case 'c':
flags |= NOSKIP;
c = CT_CHAR;
break;
 
case 'p': /* pointer format is like hex */
flags |= POINTER | PFXOK;
c = CT_INT;
ccfn = strtoul;
base = 16;
break;
 
case 'n':
if (flags & SUPPRESS) /* ??? */
continue;
if (flags & SHORT)
{
sp = va_arg (ap, short *);
*sp = nread;
}
else if (flags & LONG)
{
lp = va_arg (ap, long *);
*lp = nread;
}
else
{
ip = va_arg (ap, int *);
*ip = nread;
}
continue;
 
/*
* Disgusting backwards compatibility hacks. XXX
*/
case '\0': /* compat */
return EOF;
 
default: /* compat */
if (isupper (c))
flags |= LONG;
c = CT_INT;
ccfn = (strtoul_t)strtol;
base = 10;
break;
}
 
/*
* We have a conversion that requires input.
*/
if (BufferEmpty)
goto input_failure;
 
/*
* Consume leading white space, except for formats that
* suppress this.
*/
if ((flags & NOSKIP) == 0)
{
while (isspace (*CURR_POS))
{
nread++;
INC_CURR_POS;
if (SPACE_LEFT == 0)
#ifndef REDHAT_NEC
if (REFILL)
#endif
goto input_failure;
}
/*
* Note that there is at least one character in the
* buffer, so conversions that do not set NOSKIP ca
* no longer result in an input failure.
*/
}
 
/*
* Do the conversion.
*/
switch (c)
{
 
case CT_CHAR:
/* scan arbitrary characters (sets NOSKIP) */
if (width == 0)
width = 1;
if (flags & SUPPRESS)
{
size_t sum = 0;
 
for (;;)
{
if ((n = SPACE_LEFT) < (signed)width)
{
sum += n;
width -= n;
MOVE_CURR_POS(n-1);
INC_CURR_POS;
#ifndef REDHAT_NEC
if (REFILL)
{
#endif
if (sum == 0)
goto input_failure;
break;
#ifndef REDHAT_NEC
}
#endif
}
else
{
sum += width;
MOVE_CURR_POS(width - 1);
INC_CURR_POS;
break;
}
}
nread += sum;
}
else
{
/* Kludge city for the moment */
char *dest = va_arg (ap, char *);
int n = width;
if (SPACE_LEFT == 0)
#ifndef REDHAT_NEC
if (REFILL)
#endif
goto input_failure;
 
while (n && !BufferEmpty)
{
*dest++ = *CURR_POS;
INC_CURR_POS;
n--;
nread++;
}
nassigned++;
}
break;
 
case CT_CCL:
/* scan a (nonempty) character class (sets NOSKIP) */
if (width == 0)
width = ~0; /* `infinity' */
/* take only those things in the class */
if (flags & SUPPRESS)
{
n = 0;
while (ccltab[*CURR_POS])
{
n++, INC_CURR_POS;
if (--width == 0)
break;
if (BufferEmpty)
{
if (n == 0)
goto input_failure;
break;
}
}
if (n == 0)
goto match_failure;
}
else
{
p0 = p = va_arg (ap, char *);
while (ccltab[*CURR_POS])
{
*p++ = *CURR_POS;
INC_CURR_POS;
if (--width == 0)
break;
if (BufferEmpty)
{
if (p == p0)
goto input_failure;
break;
}
}
n = p - p0;
if (n == 0)
goto match_failure;
*p = 0;
nassigned++;
}
nread += n;
break;
 
case CT_STRING:
/* like CCL, but zero-length string OK, & no NOSKIP */
if (width == 0)
width = ~0;
if (flags & SUPPRESS)
{
n = 0;
while (!isspace (*CURR_POS))
{
n++, INC_CURR_POS;
if (--width == 0)
break;
if (BufferEmpty)
break;
}
nread += n;
}
else
{
p0 = p = va_arg (ap, char *);
while (!isspace (*CURR_POS))
{
*p++ = *CURR_POS;
INC_CURR_POS;
if (--width == 0)
break;
if (BufferEmpty)
break;
}
*p = 0;
nread += p - p0;
nassigned++;
}
continue;
 
case CT_INT:
/* scan an integer as if by strtol/strtoul */
#ifdef hardway
if (width == 0 || width > sizeof (buf) - 1)
width = sizeof (buf) - 1;
#else
/* size_t is unsigned, hence this optimisation */
if (--width > sizeof (buf) - 2)
width = sizeof (buf) - 2;
width++;
#endif
flags |= SIGNOK | NDIGITS | NZDIGITS;
for (p = buf; width; width--)
{
c = *CURR_POS;
/*
* Switch on the character; `goto ok' if we
* accept it as a part of number.
*/
switch (c)
{
/*
* The digit 0 is always legal, but is special.
* For %i conversions, if no digits (zero or nonzero)
* have been scanned (only signs), we will have base==0
* In that case, we should set it to 8 and enable 0x
* prefixing. Also, if we have not scanned zero digits
* before this, do not turn off prefixing (someone else
* will turn it off if we have scanned any nonzero
* digits).
*/
case '0':
if (base == 0)
{
base = 8;
flags |= PFXOK;
}
if (flags & NZDIGITS)
flags &= ~(SIGNOK | NZDIGITS | NDIGITS);
else
flags &= ~(SIGNOK | PFXOK | NDIGITS);
goto ok;
 
/* 1 through 7 always legal */
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
base = basefix[base];
flags &= ~(SIGNOK | PFXOK | NDIGITS);
goto ok;
 
/* digits 8 and 9 ok iff decimal or hex */
case '8':
case '9':
base = basefix[base];
if (base <= 8)
break; /* not legal here */
flags &= ~(SIGNOK | PFXOK | NDIGITS);
goto ok;
 
/* letters ok iff hex */
case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':
case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'f':
/* no need to fix base here */
if (base <= 10)
break; /* not legal here */
flags &= ~(SIGNOK | PFXOK | NDIGITS);
goto ok;
 
/* sign ok only as first character */
case '+':
case '-':
if (flags & SIGNOK)
{
flags &= ~SIGNOK;
goto ok;
}
break;
 
/* x ok iff flag still set & 2nd char */
case 'x':
case 'X':
if (flags & PFXOK && p == buf + 1)
{
base = 16;/* if %i */
flags &= ~PFXOK;
goto ok;
}
break;
}
 
/*
* If we got here, c is not a legal character
* for a number. Stop accumulating digits.
*/
break;
ok:
/*
* c is legal: store it and look at the next.
*/
*p++ = c;
INC_CURR_POS;
if (SPACE_LEFT == 0)
#ifndef REDHAT_NEC
if (REFILL)
#endif
break; /* EOF */
}
/*
* If we had only a sign, it is no good; push back the sign.
* If the number ends in `x', it was [sign] '0' 'x', so push
* back the x and treat it as [sign] '0'.
*/
if (flags & NDIGITS)
{
if (p > buf)
_CAST_VOID ungetc (*(u_char *)-- p, fp);
goto match_failure;
}
c = ((u_char *) p)[-1];
if (c == 'x' || c == 'X')
{
--p;
/*(void)*/ ungetc (c, fp);
}
if ((flags & SUPPRESS) == 0)
{
u_long res;
 
*p = 0;
res = (*ccfn) (buf, (char **) NULL, base);
if (flags & POINTER)
*(va_arg (ap, char **)) = (char *) (CYG_ADDRESS) res;
else if (flags & SHORT)
{
sp = va_arg (ap, short *);
*sp = res;
}
else if (flags & LONG)
{
lp = va_arg (ap, long *);
*lp = res;
}
else
{
ip = va_arg (ap, int *);
*ip = res;
}
nassigned++;
}
nread += p - buf;
break;
 
case CT_FLOAT:
/* scan a floating point number as if by strtod */
 
#ifdef hardway
if (width == 0 || width > sizeof (buf) - 1)
width = sizeof (buf) - 1;
#else
/* size_t is unsigned, hence this optimisation */
if (--width > sizeof (buf) - 2)
width = sizeof (buf) - 2;
width++;
#endif // ifdef hardway
 
flags |= SIGNOK | NDIGITS | DPTOK | EXPOK;
for (p = buf; width; width--)
{
c = *CURR_POS;
/*
* This code mimicks the integer conversion
* code, but is much simpler.
*/
switch (c)
{
 
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
flags &= ~(SIGNOK | NDIGITS);
goto fok;
 
case '+':
case '-':
if (flags & SIGNOK)
{
flags &= ~SIGNOK;
goto fok;
}
break;
case '.':
if (flags & DPTOK)
{
flags &= ~(SIGNOK | DPTOK);
goto fok;
}
break;
case 'e':
case 'E':
/* no exponent without some digits */
if ((flags & (NDIGITS | EXPOK)) == EXPOK)
{
flags =
(flags & ~(EXPOK | DPTOK)) |
SIGNOK | NDIGITS;
goto fok;
}
break;
}
break;
fok:
*p++ = c;
INC_CURR_POS;
if (SPACE_LEFT == 0)
#ifndef REDHAT_NEC
if (REFILL)
#endif
break; /* EOF */
}
/*
* If no digits, might be missing exponent digits
* (just give back the exponent) or might be missing
* regular digits, but had sign and/or decimal point.
*/
if (flags & NDIGITS)
{
if (flags & EXPOK)
{
/* no digits at all */
while (p > buf)
ungetc (*(u_char *)-- p, fp);
goto match_failure;
}
/* just a bad exponent (e and maybe sign) */
c = *(u_char *)-- p;
if (c != 'e' && c != 'E')
{
_CAST_VOID ungetc (c, fp); /* sign */
c = *(u_char *)-- p;
}
_CAST_VOID ungetc (c, fp);
}
if ((flags & SUPPRESS) == 0)
{
double res;
 
*p = 0;
#ifdef CYGSEM_LIBC_STDIO_SCANF_FLOATING_POINT
res = atof (buf);
#else
res = 0.0;
#endif
if (flags & LONG)
{
dp = va_arg (ap, double *);
*dp = res;
}
else if (flags & LONGDBL)
{
ldp = va_arg (ap, long double *);
*ldp = res;
}
else
{
flp = va_arg (ap, float *);
*flp = res;
}
nassigned++;
}
nread += p - buf;
break;
}
}
 
input_failure:
return nassigned ? nassigned : -1;
match_failure:
return nassigned;
} // vfscanf()
 
/*
* Fill in the given table from the scanset at the given format
* (just after `['). Return a pointer to the character past the
* closing `]'. The table has a 1 wherever characters should be
* considered part of the scanset.
*/
 
/*static*/
u_char *
__sccl (char *tab, u_char *fmt)
{
int c, n, v;
 
/* first `clear' the whole table */
c = *fmt++; /* first char hat => negated scanset */
if (c == '^')
{
v = 1; /* default => accept */
c = *fmt++; /* get new first char */
}
else
v = 0; /* default => reject */
/* should probably use memset here */
for (n = 0; n < 256; n++)
tab[n] = v;
if (c == 0)
return fmt - 1; /* format ended before closing ] */
 
/*
* Now set the entries corresponding to the actual scanset to the
* opposite of the above.
*
* The first character may be ']' (or '-') without being special; the
* last character may be '-'.
*/
 
v = 1 - v;
for (;;)
{
tab[c] = v; /* take character c */
doswitch:
n = *fmt++; /* and examine the next */
switch (n)
{
 
case 0: /* format ended too soon */
return fmt - 1;
 
case '-':
/*
* A scanset of the form [01+-] is defined as `the digit 0, the
* digit 1, the character +, the character -', but the effect
* of a scanset such as [a-zA-Z0-9] is implementation defined.
* The V7 Unix scanf treats `a-z' as `the letters a through z',
* but treats `a-a' as `the letter a, the character -, and the
* letter a'.
*
* For compatibility, the `-' is not considerd to define a
* range if the character following it is either a close
* bracket (required by ANSI) or is not numerically greater
* than the character we just stored in the table (c).
*/
n = *fmt;
if (n == ']' || n < c)
{
c = '-';
break; /* resume the for(;;) */
}
fmt++;
do
{ /* fill in the range */
tab[++c] = v;
}
while (c < n);
#if 1 /* XXX another disgusting compatibility hack */
/*
* Alas, the V7 Unix scanf also treats formats such
* as [a-c-e] as `the letters a through e'. This too
* is permitted by the standard....
*/
goto doswitch;
#else
c = *fmt++;
if (c == 0)
return fmt - 1;
if (c == ']')
return fmt;
#endif
 
break;
 
 
case ']': /* end of scanset */
return fmt;
 
default: /* just another character */
c = n;
break;
}
}
/* NOTREACHED */
} // __sccl()
 
#endif // if defined(CYGFUN_LIBC_STDIO_ungetc)
 
// EOF vfscanf.cxx
/input/fgetc.cxx
0,0 → 1,131
//===========================================================================
//
// fgetc.cxx
//
// ISO C standard I/O get character 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: Provide the fgetc() function. Also provides the function
// version of getc() and getchar()
// 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> // Standard eCos assertion support
#include <cyg/infra/cyg_trac.h> // Standard eCos tracing support
#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
fgetc( FILE *stream )
{
Cyg_StdioStream *real_stream = (Cyg_StdioStream *)stream;
cyg_ucount32 bytes_read;
Cyg_ErrNo err;
cyg_uint8 c;
 
CYG_REPORT_FUNCNAMETYPE("fgetc", "returning char %d");
CYG_REPORT_FUNCARG1XV( stream );
CYG_CHECK_DATA_PTR( stream, "stream is not a valid pointer" );
 
err = real_stream->read( &c, 1, &bytes_read );
 
// Why do we need this? Because the buffer might be empty.
if (!err && !bytes_read) { // if no err, but nothing to read, try again
err = real_stream->refill_read_buffer();
if ( !err )
err = real_stream->read( &c, 1, &bytes_read );
} // if
 
CYG_ASSERT( (ENOERR != err) || (1 == bytes_read), "Didn't read 1 byte!" );
 
if (err)
{
if ( EAGAIN != err ) {
real_stream->set_error( err );
errno = err;
}
CYG_REPORT_RETVAL(EOF);
return EOF;
} // if
CYG_REPORT_RETVAL((int)c);
return (int)c;
 
} // fgetc()
 
 
// Also define getc() even though it can be a macro.
// Undefine it first though
#undef getchar
 
externC int
getchar( void )
{
return fgetc( stdin );
} // getchar()
 
 
// EXPORTED SYMBOLS
 
// Also define getc() even though it can be a macro.
// Undefine it first though
#undef getc
 
externC int
getc( FILE * ) CYGBLD_ATTRIB_WEAK_ALIAS(fgetc);
 
// EOF fgetc.cxx
/input/fgets.cxx
0,0 → 1,126
//========================================================================
//
// fgets.cxx
//
// ISO C standard I/O fgets() 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: 2001-03-14
// Purpose: Implementation of ISO C standard I/O fgets() function
// Description:
// Usage:
//
//####DESCRIPTIONEND####
//
//=======================================================================
 
// CONFIGURATION
 
#include <pkgconf/libc_stdio.h> // Configuration header
 
// INCLUDES
 
#include <cyg/infra/cyg_type.h> // Common 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 <stdio.h> // header for this file
#include <errno.h> // error codes
#include <cyg/libc/stdio/stream.hxx>// Cyg_StdioStream
 
// FUNCTIONS
 
// FIXME: should be reworked to read buffer at a time, and scan that
// for newlines, rather than reading byte at a time.
 
externC char *
fgets( char *s, int n, FILE *stream )
{
Cyg_StdioStream *real_stream = (Cyg_StdioStream *)stream;
Cyg_ErrNo err=ENOERR;
cyg_uint8 c;
cyg_uint8 *str=(cyg_uint8 *)s;
int nch;
 
CYG_CHECK_DATA_PTRC( s );
CYG_CHECK_DATA_PTRC( stream );
CYG_PRECONDITION( n > 0, "requested 0 or negative chars");
 
CYG_REPORT_FUNCTYPE( "returning string %08x");
CYG_REPORT_FUNCARG3( "s=%08x, n=%d, stream=%08x", s, n, stream );
for (nch=1; nch < n; nch++) {
err = real_stream->read_byte( &c );
// if nothing to read, try again ONCE after refilling buffer
if (EAGAIN == err) {
err = real_stream->refill_read_buffer();
if ( !err )
err = real_stream->read_byte( &c );
 
if (EAGAIN == err) {
if (1 == nch) { // indicates EOF at start
CYG_REPORT_RETVAL( NULL );
return NULL;
} else
break; // EOF
} // if
} // if
*str++ = c;
if ('\n' == c)
break;
} // while
*str = '\0'; // NULL terminate it
if (err && EAGAIN != err) {
real_stream->set_error( err );
errno = err;
CYG_REPORT_RETVAL( NULL );
return NULL;
} // if
 
CYG_REPORT_RETVAL( s );
return s;
 
} // fgets()
 
// EOF fgets.cxx
/input/scanf.cxx
0,0 → 1,82
//===========================================================================
//
// scanf.cxx
//
// ANSI Stdio scanf() 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
scanf( const char *format, ... )
{
int rc; // return code
va_list ap; // for variable args
 
va_start(ap, format); // init specifying last non-var arg
 
rc = vfscanf( stdin, format, ap );
 
va_end(ap); // end var args
 
return rc;
} // scanf()
 
// EOF scanf.cxx
/output/fwrite.cxx
0,0 → 1,103
//========================================================================
//
// fwrite.cxx
//
// ANSI Stdio fwrite() 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 <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 <stdio.h> // header for this file
#include <errno.h> // error codes
#include <cyg/libc/stdio/stream.hxx>// Cyg_StdioStream
 
// FUNCTIONS
 
externC size_t
fwrite( const void *ptr, size_t object_size, size_t num_objects,
FILE *stream )
{
Cyg_StdioStream *real_stream = (Cyg_StdioStream *)stream;
cyg_ucount32 written;
Cyg_ErrNo err;
CYG_REPORT_FUNCNAMETYPE( "fwrite", "wrote %d objects" );
CYG_REPORT_FUNCARG4( "ptr=%08x, object_size=%d, num_objects=%d, "
"stream=%08x", ptr, object_size, num_objects,
stream );
 
if ( (object_size==0) || (num_objects==0) ) {
CYG_REPORT_RETVAL(0);
return 0;
} // if
 
err = real_stream->write( (cyg_uint8 *)ptr, num_objects*object_size,
&written );
 
if (err) {
real_stream->set_error( err );
errno = err;
} // if
// we return the number of _objects_ written. Simple division is
// sufficient as this returns the quotient rather than rounding
 
CYG_REPORT_RETVAL( written/object_size );
return written/object_size;
} // fwrite()
 
// EOF fwrite.cxx
/output/fputc.cxx
0,0 → 1,116
//===========================================================================
//
// fputc.cxx
//
// ISO Standard I/O character output 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: Provide the fputc() function. Also provides the function
// versions of putc() and putchar()
// 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> // Standard eCos assertion support
#include <cyg/infra/cyg_trac.h> // Standard eCos tracing support
#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
fputc( int c, FILE *stream )
{
Cyg_StdioStream *real_stream = (Cyg_StdioStream *)stream;
Cyg_ErrNo err;
cyg_uint8 real_c = (cyg_uint8) c;
CYG_REPORT_FUNCNAMETYPE("fputc", "wrote char %d");
CYG_REPORT_FUNCARG2( "c = %d, stream=%08x", c, stream );
CYG_CHECK_DATA_PTR( stream, "stream is not a valid pointer" );
 
err = real_stream->write_byte( real_c );
 
if (err)
{
real_stream->set_error( err );
errno = err;
CYG_REPORT_RETVAL(EOF);
return EOF;
} // if
CYG_REPORT_RETVAL((int)real_c);
return (int)real_c;
 
} // fputc()
 
 
// Also define putchar() even though it can be a macro.
// Undefine the macro first though
#undef putchar
 
externC int
putchar( int c )
{
return fputc( c, stdout );
} // putchar()
 
// Also define putc() even though it can be a macro.
// Undefine the macro first though
#undef putc
 
externC int
putc( int, FILE * ) CYGBLD_ATTRIB_WEAK_ALIAS(fputc);
 
// EOF fputc.cxx
/output/fputs.cxx
0,0 → 1,90
//========================================================================
//
// fputs.cxx
//
// ANSI Stdio fputs() 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
#include <string.h> // strlen()
 
// FUNCTIONS
 
externC int
fputs( const char *s, FILE *stream )
{
Cyg_StdioStream *real_stream = (Cyg_StdioStream *)stream;
cyg_ucount32 size = strlen(s);
cyg_ucount32 written;
Cyg_ErrNo err;
err = real_stream->write( (cyg_uint8 *)s, size, &written );
 
if (err) {
real_stream->set_error( err );
errno = err;
return EOF;
} // if
return written;
 
} // fputs()
 
// EOF fputs.cxx
/output/printf.cxx
0,0 → 1,82
//===========================================================================
//
// printf.cxx
//
// ANSI Stdio printf() 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
printf( const char *format, ... )
{
int rc; // return code
va_list ap; // for variable args
 
va_start(ap, format); // init specifying last non-var arg
 
rc = vfnprintf(stdout, INT_MAX, format, ap);
 
va_end(ap); // end var args
 
return rc;
} // printf()
 
// EOF printf.cxx
/output/fnprintf.cxx
0,0 → 1,81
//===========================================================================
//
// fnprintf.cxx
//
// ANSI Stdio fnprintf() 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
fnprintf( FILE *stream, 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 = vfnprintf(stream, size, format, ap);
 
va_end(ap); // end var args
 
return rc;
} // fnprintf()
 
// EOF fnprintf.cxx
/output/fprintf.cxx
0,0 → 1,82
//===========================================================================
//
// fprintf.cxx
//
// ANSI Stdio fprintf() 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
fprintf( FILE *stream, const char *format, ... )
{
int rc; // return code
va_list ap; // for variable args
 
va_start(ap, format); // init specifying last non-var arg
 
rc = vfnprintf(stream, INT_MAX, format, ap);
 
va_end(ap); // end var args
 
return rc;
} // fprintf()
 
// EOF fprintf.cxx
/output/vfnprintf.cxx
0,0 → 1,966
//===========================================================================
//
// vfnprintf.c
//
// I/O routines for vfnprintf() for use with ANSI 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:
// Description:
// Usage:
//
//####DESCRIPTIONEND####
//
//===========================================================================
//
// This code is based on original code with the following copyright:
//
/*-
* Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Chris Torek.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
 
 
// CONFIGURATION
 
#include <pkgconf/libc_stdio.h> // Configuration header
#include <pkgconf/libc_i18n.h> // Configuration header for mb support
 
// INCLUDES
 
#include <cyg/infra/cyg_type.h> // Common type definitions and support
#include <stdarg.h> // Variable argument definitions
#include <stdio.h> // Standard header for all stdio files
#include <string.h> // memchr() and strlen() functions
#include <cyg/libc/stdio/stream.hxx> // C library streams
 
#ifdef CYGSEM_LIBC_STDIO_PRINTF_FLOATING_POINT
 
# include <float.h> // for DBL_DIG etc. below
# include <math.h> // for modf()
# include <sys/ieeefp.h> // Cyg_libm_ieee_double_shape_type
 
# define MAXFRACT DBL_DIG
# define MAXEXP DBL_MAX_10_EXP
 
# define BUF (MAXEXP+MAXFRACT+1) /* + decimal point */
# define DEFPREC 6
 
static int
cvt( double, int, int, char *, int, char *, char * );
 
#else // ifdef CYGSEM_LIBC_STDIO_PRINTF_FLOATING_POINT
 
# define BUF 40
 
#endif // ifdef CYGSEM_LIBC_STDIO_PRINTF_FLOATING_POINT
 
/*
* Actual printf innards.
*
* This code is large and complicated...
*/
 
#ifdef CYGINT_LIBC_I18N_MB_REQUIRED
typedef int (*mbtowc_fn_type)(wchar_t *, const char *, size_t, int *);
externC mbtowc_fn_type __get_current_locale_mbtowc_fn();
#endif
 
/*
* Macros for converting digits to letters and vice versa
*/
#define to_digit(c) ((c) - '0')
#define is_digit(c) ((unsigned)to_digit(c) <= 9)
#define to_char(n) ((n) + '0')
 
/*
* Flags used during conversion.
*/
#define ALT 0x001 /* alternate form */
#define HEXPREFIX 0x002 /* add 0x or 0X prefix */
#define LADJUST 0x004 /* left adjustment */
#define LONGDBL 0x008 /* long double; unimplemented */
#define LONGINT 0x010 /* long integer */
#define QUADINT 0x020 /* quad integer */
#define SHORTINT 0x040 /* short integer */
#define ZEROPAD 0x080 /* zero (as opposed to blank) pad */
#define FPT 0x100 /* Floating point number */
#define SIZET 0x200 /* size_t */
 
externC int
vfnprintf ( FILE *stream, size_t n, const char *format, va_list arg)
{
char *fmt; /* format string */
int ch; /* character from fmt */
int x, y; /* handy integers (short term usage) */
char *cp; /* handy char pointer (short term usage) */
int flags; /* flags as above */
 
#ifdef CYGINT_LIBC_I18N_MB_REQUIRED
int state = 0; /* state for mbtowc conversion */
mbtowc_fn_type mbtowc_fn;
#endif
 
int ret; /* return value accumulator */
int width; /* width from format (%8d), or 0 */
int prec; /* precision from format (%.3d), or -1 */
char sign; /* sign prefix (' ', '+', '-', or \0) */
wchar_t wc;
 
#define quad_t long long
#define u_quad_t unsigned long long
 
u_quad_t _uquad; /* integer arguments %[diouxX] */
enum { OCT, DEC, HEX } base;/* base for [diouxX] conversion */
int dprec; /* a copy of prec if [diouxX], 0 otherwise */
int fieldsz; /* field size expanded by sign, etc */
int realsz; /* field size expanded by dprec */
int size; /* size of converted field or string */
char *xdigs; /* digits for [xX] conversion */
#define NIOV 8
char buf[BUF]; /* space for %c, %[diouxX], %[eEfgG] */
char ox[2]; /* space for 0x hex-prefix */
#ifdef CYGSEM_LIBC_STDIO_PRINTF_FLOATING_POINT
char softsign; /* temporary negative sign for floats */
double _double; /* double precision arguments %[eEfgG] */
int fpprec; /* `extra' floating precision in [eEfgG] */
#endif
 
/*
* Choose PADSIZE to trade efficiency vs. size. If larger printf
* fields occur frequently, increase PADSIZE and make the initialisers
* below longer.
*/
#define PADSIZE 16 /* pad chunk size */
static char blanks[PADSIZE] =
{' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '};
static char zeroes[PADSIZE] =
{'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'};
 
#define MIN(a, b) ((a) < (b) ? (a) : (b))
 
/*
* BEWARE, these `goto error' on error, and PAD uses `n'.
*/
#define PRINT(ptr, len) \
CYG_MACRO_START \
cyg_ucount32 length = MIN( (cyg_ucount32) len, n - ret - 1); \
if (((Cyg_StdioStream *)stream)->write( (const cyg_uint8 *)ptr, \
length, &length )) \
goto error; \
if (length < (cyg_ucount32)len) { \
ret += length; \
goto done; \
} \
CYG_MACRO_END
 
 
#define PAD(howmany, with) \
CYG_MACRO_START \
if ((x = (howmany)) > 0) { \
while (x > PADSIZE) { \
PRINT(with, PADSIZE); \
x -= PADSIZE; \
} \
PRINT(with, x); \
} \
CYG_MACRO_END
 
/*
* To extend shorts properly, we need both signed and unsigned
* argument extraction methods.
*/
 
#define SARG() \
(flags&QUADINT ? va_arg(arg, cyg_int64) : \
flags&LONGINT ? va_arg(arg, long) : \
flags&SHORTINT ? (long)(short)va_arg(arg, int) : \
flags&SIZET ? va_arg(arg, size_t) : \
(long)va_arg(arg, int))
#define UARG() \
(flags&QUADINT ? va_arg(arg, cyg_uint64) : \
flags&LONGINT ? va_arg(arg, unsigned long) : \
flags&SHORTINT ? (unsigned long)(unsigned short)va_arg(arg, int) : \
flags&SIZET ? va_arg(arg, size_t) : \
(unsigned long)va_arg(arg, unsigned int))
 
 
xdigs = NULL; // stop compiler whinging
fmt = (char *)format;
ret = 0;
#ifdef CYGINT_LIBC_I18N_MB_REQUIRED
mbtowc_fn = __get_current_locale_mbtowc_fn();
#endif
 
/*
* Scan the format for conversions (`%' character).
*/
for (;;) {
cp = (char *)fmt;
#ifndef CYGINT_LIBC_I18N_MB_REQUIRED
while ((x = ((wc = *fmt) != 0))) {
#else
while ((x = mbtowc_fn (&wc, fmt, MB_CUR_MAX, &state)) > 0) {
#endif
fmt += x;
if (wc == '%') {
fmt--;
break;
}
}
if ((y = fmt - cp) != 0) {
PRINT(cp, y);
ret += y;
}
if ((x <= 0) || (ret >= (int)n)) // @@@ this check with n isn't good enough
goto done;
fmt++; /* skip over '%' */
 
flags = 0;
dprec = 0;
#ifdef CYGSEM_LIBC_STDIO_PRINTF_FLOATING_POINT
fpprec = 0;
#endif
width = 0;
prec = -1;
sign = '\0';
 
rflag: ch = *fmt++;
reswitch: switch (ch) {
case ' ':
/*
* ``If the space and + flags both appear, the space
* flag will be ignored.''
* -- ANSI X3J11
*/
if (!sign)
sign = ' ';
goto rflag;
case '#':
flags |= ALT;
goto rflag;
case '*':
/*
* ``A negative field width argument is taken as a
* - flag followed by a positive field width.''
* -- ANSI X3J11
* They don't exclude field widths read from args.
*/
if ((width = va_arg(arg, int)) >= 0)
goto rflag;
width = -width;
/* FALLTHROUGH */
case '-':
flags |= LADJUST;
goto rflag;
case '+':
sign = '+';
goto rflag;
case '.':
if ((ch = *fmt++) == '*') {
x = va_arg(arg, int);
prec = x < 0 ? -1 : x;
goto rflag;
}
x = 0;
while (is_digit(ch)) {
x = 10 * x + to_digit(ch);
ch = *fmt++;
}
prec = x < 0 ? -1 : x;
goto reswitch;
case '0':
/*
* ``Note that 0 is taken as a flag, not as the
* beginning of a field width.''
* -- ANSI X3J11
*/
flags |= ZEROPAD;
goto rflag;
case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
x = 0;
do {
x = 10 * x + to_digit(ch);
ch = *fmt++;
} while (is_digit(ch));
width = x;
goto reswitch;
#ifdef CYGSEM_LIBC_STDIO_PRINTF_FLOATING_POINT
case 'L':
flags |= LONGDBL;
goto rflag;
#endif
case 'h':
flags |= SHORTINT;
goto rflag;
case 'l':
if (*fmt == 'l') {
fmt++;
flags |= QUADINT;
} else {
flags |= LONGINT;
}
goto rflag;
case 'q':
flags |= QUADINT;
goto rflag;
case 'c':
*(cp = buf) = va_arg(arg, int);
size = 1;
sign = '\0';
break;
case 'D':
flags |= LONGINT;
/*FALLTHROUGH*/
case 'd':
case 'i':
_uquad = SARG();
#ifndef _NO_LONGLONG
if ((quad_t)_uquad < 0)
#else
if ((long) _uquad < 0)
#endif
{
 
_uquad = -_uquad;
sign = '-';
}
base = DEC;
goto number;
 
#ifdef CYGSEM_LIBC_STDIO_PRINTF_FLOATING_POINT
case 'e':
case 'E':
case 'f':
case 'g':
case 'G':
_double = va_arg(arg, double);
/*
* don't do unrealistic precision; just pad it with
* zeroes later, so buffer size stays rational.
*/
if (prec > MAXFRACT) {
if ((ch != 'g' && ch != 'G') || (flags&ALT))
fpprec = prec - MAXFRACT;
prec = MAXFRACT;
} else if (prec == -1)
prec = DEFPREC;
/*
* cvt may have to round up before the "start" of
* its buffer, i.e. ``intf("%.2f", (double)9.999);'';
* if the first character is still NUL, it did.
* softsign avoids negative 0 if _double < 0 but
* no significant digits will be shown.
*/
cp = buf;
*cp = '\0';
size = cvt(_double, prec, flags, &softsign, ch,
cp, buf + sizeof(buf));
if (softsign)
sign = '-';
if (*cp == '\0')
cp++;
break;
#else
case 'e':
case 'E':
case 'f':
case 'g':
case 'G':
// Output nothing at all
(void) va_arg(arg, double); // take off arg anyway
cp = "";
size = 0;
sign = '\0';
break;
#endif // ifdef CYGSEM_LIBC_STDIO_PRINTF_FLOATING_POINT
 
case 'n':
#ifndef _NO_LONGLONG
if (flags & QUADINT)
*va_arg(arg, quad_t *) = ret;
else
#endif
if (flags & LONGINT)
*va_arg(arg, long *) = ret;
else if (flags & SHORTINT)
*va_arg(arg, short *) = ret;
else if (flags & SIZET)
*va_arg(arg, size_t *) = ret;
else
*va_arg(arg, int *) = ret;
continue; /* no output */
case 'O':
flags |= LONGINT;
/*FALLTHROUGH*/
case 'o':
_uquad = UARG();
base = OCT;
goto nosign;
case 'p':
/*
* ``The argument shall be a pointer to void. The
* value of the pointer is converted to a sequence
* of printable characters, in an implementation-
* defined manner.''
* -- ANSI X3J11
*/
/* NOSTRICT */
_uquad = (unsigned long)va_arg(arg, void *);
base = HEX;
xdigs = "0123456789abcdef";
flags |= HEXPREFIX;
ch = 'x';
goto nosign;
case 's':
if ((cp = va_arg(arg, char *)) == NULL)
cp = "(null)";
if (prec >= 0) {
/*
* can't use strlen; can only look for the
* NUL in the first `prec' characters, and
* strlen() will go further.
*/
char *p = (char *)memchr(cp, 0, prec);
 
if (p != NULL) {
size = p - cp;
if (size > prec)
size = prec;
} else
size = prec;
} else
size = strlen(cp);
sign = '\0';
break;
case 'U':
flags |= LONGINT;
/*FALLTHROUGH*/
case 'u':
_uquad = UARG();
base = DEC;
goto nosign;
case 'X':
xdigs = "0123456789ABCDEF";
goto hex;
case 'x':
xdigs = "0123456789abcdef";
hex: _uquad = UARG();
base = HEX;
/* leading 0x/X only if non-zero */
if (flags & ALT && _uquad != 0)
flags |= HEXPREFIX;
 
/* unsigned conversions */
nosign: sign = '\0';
/*
* ``... diouXx conversions ... if a precision is
* specified, the 0 flag will be ignored.''
* -- ANSI X3J11
*/
number: if ((dprec = prec) >= 0)
flags &= ~ZEROPAD;
 
/*
* ``The result of converting a zero value with an
* explicit precision of zero is no characters.''
* -- ANSI X3J11
*/
cp = buf + BUF;
if (_uquad != 0 || prec != 0) {
/*
* Unsigned mod is hard, and unsigned mod
* by a constant is easier than that by
* a variable; hence this switch.
*/
switch (base) {
case OCT:
do {
*--cp = to_char(_uquad & 7);
_uquad >>= 3;
} while (_uquad);
/* handle octal leading 0 */
if (flags & ALT && *cp != '0')
*--cp = '0';
break;
 
case DEC:
/* many numbers are 1 digit */
while (_uquad >= 10) {
*--cp = to_char(_uquad % 10);
_uquad /= 10;
}
*--cp = to_char(_uquad);
break;
 
case HEX:
do {
*--cp = xdigs[_uquad & 15];
_uquad >>= 4;
} while (_uquad);
break;
 
default:
cp = "bug in vfprintf: bad base";
size = strlen(cp);
goto skipsize;
}
}
size = buf + BUF - cp;
skipsize:
break;
case 'z':
flags |= SIZET;
goto rflag;
default: /* "%?" prints ?, unless ? is NUL */
if (ch == '\0')
goto done;
/* pretend it was %c with argument ch */
cp = buf;
*cp = ch;
size = 1;
sign = '\0';
break;
}
 
/*
* All reasonable formats wind up here. At this point, `cp'
* points to a string which (if not flags&LADJUST) should be
* padded out to `width' places. If flags&ZEROPAD, it should
* first be prefixed by any sign or other prefix; otherwise,
* it should be blank padded before the prefix is emitted.
* After any left-hand padding and prefixing, emit zeroes
* required by a decimal [diouxX] precision, then print the
* string proper, then emit zeroes required by any leftover
* floating precision; finally, if LADJUST, pad with blanks.
*
* Compute actual size, so we know how much to pad.
* fieldsz excludes decimal prec; realsz includes it.
*/
#ifdef CYGSEM_LIBC_STDIO_PRINTF_FLOATING_POINT
fieldsz = size + fpprec;
#else
fieldsz = size;
#endif
if (sign)
fieldsz++;
else if (flags & HEXPREFIX)
fieldsz+= 2;
realsz = dprec > fieldsz ? dprec : fieldsz;
 
/* right-adjusting blank padding */
if ((flags & (LADJUST|ZEROPAD)) == 0) {
if (width - realsz > 0) {
PAD(width - realsz, blanks);
ret += width - realsz;
}
}
 
/* prefix */
if (sign) {
PRINT(&sign, 1);
ret++;
} else if (flags & HEXPREFIX) {
ox[0] = '0';
ox[1] = ch;
PRINT(ox, 2);
ret += 2;
}
 
/* right-adjusting zero padding */
if ((flags & (LADJUST|ZEROPAD)) == ZEROPAD) {
if (width - realsz > 0) {
PAD(width - realsz, zeroes);
ret += width - realsz;
}
}
 
if (dprec - fieldsz > 0) {
/* leading zeroes from decimal precision */
PAD(dprec - fieldsz, zeroes);
ret += dprec - fieldsz;
}
 
/* the string or number proper */
PRINT(cp, size);
ret += size;
 
#ifdef CYGSEM_LIBC_STDIO_PRINTF_FLOATING_POINT
/* trailing f.p. zeroes */
PAD(fpprec, zeroes);
ret += fpprec;
#endif
 
/* left-adjusting padding (always blank) */
if (flags & LADJUST) {
if (width - realsz > 0) {
PAD(width - realsz, blanks);
ret += width - realsz;
}
}
 
}
done:
error:
return (((Cyg_StdioStream *) stream)->get_error() ? EOF : ret);
/* NOTREACHED */
}
 
 
#ifdef CYGSEM_LIBC_STDIO_PRINTF_FLOATING_POINT
 
static char *
round(double fract, int *exp, char *start, char *end, char ch, char *signp)
{
double tmp;
 
if (fract)
(void)modf(fract * 10, &tmp);
else
tmp = to_digit(ch);
if (tmp > 4)
for (;; --end) {
if (*end == '.')
--end;
if (++*end <= '9')
break;
*end = '0';
if (end == start) {
if (exp) { /* e/E; increment exponent */
*end = '1';
++*exp;
}
else { /* f; add extra digit */
*--end = '1';
--start;
}
break;
}
}
/* ``"%.3f", (double)-0.0004'' gives you a negative 0. */
else if (*signp == '-')
for (;; --end) {
if (*end == '.')
--end;
if (*end != '0')
break;
if (end == start)
*signp = 0;
}
return (start);
} // round()
 
 
static char *
exponent(char *p, int exp, int fmtch)
{
char *t;
char expbuf[MAXEXP];
 
*p++ = fmtch;
if (exp < 0) {
exp = -exp;
*p++ = '-';
}
else
*p++ = '+';
t = expbuf + MAXEXP;
if (exp > 9) {
do {
*--t = to_char(exp % 10);
} while ((exp /= 10) > 9);
*--t = to_char(exp);
for (; t < expbuf + MAXEXP; *p++ = *t++);
}
else {
*p++ = '0';
*p++ = to_char(exp);
}
return (p);
} // exponent()
 
 
static int
cvt(double number, int prec, int flags, char *signp, int fmtch, char *startp,
char *endp)
{
Cyg_libm_ieee_double_shape_type ieeefp;
char *t = startp;
 
ieeefp.value = number;
*signp = 0;
if ( ieeefp.number.sign ){ // this checks for <0.0 and -0.0
number = -number;
*signp = '-';
}
 
if (finite(number)) {
char *p;
double fract;
int dotrim, expcnt, gformat;
double integer, tmp;
 
dotrim = expcnt = gformat = 0;
fract = modf(number, &integer);
 
/* get an extra slot for rounding. */
t = ++startp;
 
/*
* get integer portion of number; put into the end of the buffer; the
* .01 is added for modf(356.0 / 10, &integer) returning .59999999...
*/
for (p = endp - 1; integer; ++expcnt) {
tmp = modf(integer / 10, &integer);
*p-- = to_char((int)((tmp + .01) * 10));
}
switch (fmtch) {
case 'f':
/* reverse integer into beginning of buffer */
if (expcnt)
for (; ++p < endp; *t++ = *p);
else
*t++ = '0';
/*
* if precision required or alternate flag set, add in a
* decimal point.
*/
if (prec || flags&ALT)
*t++ = '.';
/* if requires more precision and some fraction left */
if (fract) {
if (prec)
do {
fract = modf(fract * 10, &tmp);
*t++ = to_char((int)tmp);
} while (--prec && fract);
if (fract)
startp = round(fract, (int *)NULL, startp,
t - 1, (char)0, signp);
}
for (; prec--; *t++ = '0');
break;
case 'e':
case 'E':
eformat: if (expcnt) {
*t++ = *++p;
if (prec || flags&ALT)
*t++ = '.';
/* if requires more precision and some integer left */
for (; prec && ++p < endp; --prec)
*t++ = *p;
/*
* if done precision and more of the integer component,
* round using it; adjust fract so we don't re-round
* later.
*/
if (!prec && ++p < endp) {
fract = 0;
startp = round((double)0, &expcnt, startp,
t - 1, *p, signp);
}
/* adjust expcnt for digit in front of decimal */
--expcnt;
}
/* until first fractional digit, decrement exponent */
else if (fract) {
/* adjust expcnt for digit in front of decimal */
for (expcnt = -1;; --expcnt) {
fract = modf(fract * 10, &tmp);
if (tmp)
break;
}
*t++ = to_char((int)tmp);
if (prec || flags&ALT)
*t++ = '.';
}
else {
*t++ = '0';
if (prec || flags&ALT)
*t++ = '.';
}
/* if requires more precision and some fraction left */
if (fract) {
if (prec)
do {
fract = modf(fract * 10, &tmp);
*t++ = to_char((int)tmp);
} while (--prec && fract);
if (fract)
startp = round(fract, &expcnt, startp,
t - 1, (char)0, signp);
}
/* if requires more precision */
for (; prec--; *t++ = '0');
 
/* unless alternate flag, trim any g/G format trailing 0's */
if (gformat && !(flags&ALT)) {
while (t > startp && *--t == '0');
if (*t == '.')
--t;
++t;
}
t = exponent(t, expcnt, fmtch);
break;
case 'g':
case 'G':
/* a precision of 0 is treated as a precision of 1. */
if (!prec)
++prec;
/*
* ``The style used depends on the value converted; style e
* will be used only if the exponent resulting from the
* conversion is less than -4 or greater than the precision.''
* -- ANSI X3J11
*/
if (expcnt > prec || (!expcnt && fract && fract < .0001)) {
/*
* g/G format counts "significant digits, not digits of
* precision; for the e/E format, this just causes an
* off-by-one problem, i.e. g/G considers the digit
* before the decimal point significant and e/E doesn't
* count it as precision.
*/
--prec;
fmtch -= 2; /* G->E, g->e */
gformat = 1;
goto eformat;
}
/*
* reverse integer into beginning of buffer,
* note, decrement precision
*/
if (expcnt)
for (; ++p < endp; *t++ = *p, --prec);
else
*t++ = '0';
/*
* if precision required or alternate flag set, add in a
* decimal point. If no digits yet, add in leading 0.
*/
if (prec || flags&ALT) {
dotrim = 1;
*t++ = '.';
}
else
dotrim = 0;
/* if requires more precision and some fraction left */
if (fract) {
if (prec) {
do {
fract = modf(fract * 10, &tmp);
*t++ = to_char((int)tmp);
} while(!tmp);
while (--prec && fract) {
fract = modf(fract * 10, &tmp);
*t++ = to_char((int)tmp);
}
}
if (fract)
startp = round(fract, (int *)NULL, startp,
t - 1, (char)0, signp);
}
/* alternate format, adds 0's for precision, else trim 0's */
if (flags&ALT)
for (; prec--; *t++ = '0');
else if (dotrim) {
while (t > startp && *--t == '0');
if (*t != '.')
++t;
}
}
} else {
unsigned case_adj;
switch (fmtch) {
case 'f':
case 'g':
case 'e':
case_adj = 'a' - 'A';
break;
default:
case_adj = 0;
}
if (isnan(number)) {
*t++ = 'N' + case_adj;
*t++ = 'A' + case_adj;
*t++ = 'N' + case_adj;
} else { // infinite
*t++ = 'I' + case_adj;
*t++ = 'N' + case_adj;
*t++ = 'F' + case_adj;
}
}
return (t - startp);
} // cvt()
 
#endif // ifdef CYGSEM_LIBC_STDIO_PRINTF_FLOATING_POINT
 
// EOF vfnprintf.cxx
/common/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
/common/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
/common/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
/common/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
/common/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
/common/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
/common/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
/common/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
/common/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
/common/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
/common/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
/common/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
/common/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
/common/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
/common/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
/common/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
/common/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
/common/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
/common/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
/common/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
/common/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.