Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 2828 → Rev 3065

/programs/develop/libraries/newlib/stdio/clearerr.c
0,0 → 1,71
/*
* 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.
*/
 
/*
FUNCTION
<<clearerr>>---clear file or stream error indicator
 
INDEX
clearerr
 
ANSI_SYNOPSIS
#include <stdio.h>
void clearerr(FILE *<[fp]>);
 
TRAD_SYNOPSIS
#include <stdio.h>
void clearerr(<[fp]>)
FILE *<[fp]>;
 
DESCRIPTION
The <<stdio>> functions maintain an error indicator with each file
pointer <[fp]>, to record whether any read or write errors have
occurred on the associated file or stream. Similarly, it maintains an
end-of-file indicator to record whether there is no more data in the
file.
 
Use <<clearerr>> to reset both of these indicators.
 
See <<ferror>> and <<feof>> to query the two indicators.
 
 
RETURNS
<<clearerr>> does not return a result.
 
PORTABILITY
ANSI C requires <<clearerr>>.
 
No supporting OS subroutines are required.
*/
 
#include <_ansi.h>
#include <stdio.h>
#include "local.h"
 
/* A subroutine version of the macro clearerr. */
 
#undef clearerr
 
_VOID
_DEFUN(clearerr, (fp),
FILE * fp)
{
CHECK_INIT(_REENT, fp);
_flockfile (fp);
__sclearerr (fp);
_funlockfile (fp);
}
/programs/develop/libraries/newlib/stdio/diprintf.c
0,0 → 1,82
/* Copyright (C) 2005, 2007 Shaun Jackman
* Permission to use, copy, modify, and distribute this software
* is freely granted, provided that this notice is preserved.
*/
 
/*
FUNCTION
<<diprintf>>, <<vdiprintf>>---print to a file descriptor (integer only)
 
INDEX
diprintf
INDEX
_diprintf_r
INDEX
vdiprintf
INDEX
_vdiprintf_r
 
ANSI_SYNOPSIS
#include <stdio.h>
#include <stdarg.h>
int diprintf(int <[fd]>, const char *<[format]>, ...);
int vdiprintf(int <[fd]>, const char *<[format]>, va_list <[ap]>);
int _diprintf_r(struct _reent *<[ptr]>, int <[fd]>,
const char *<[format]>, ...);
int _vdiprintf_r(struct _reent *<[ptr]>, int <[fd]>,
const char *<[format]>, va_list <[ap]>);
 
DESCRIPTION
<<diprintf>> and <<vdiprintf>> are similar to <<dprintf>> and <<vdprintf>>,
except that only integer format specifiers are processed.
 
The functions <<_diprintf_r>> and <<_vdiprintf_r>> are simply
reentrant versions of the functions above.
 
RETURNS
Similar to <<dprintf>> and <<vdprintf>>.
 
PORTABILITY
This set of functions is an integer-only extension, and is not portable.
 
Supporting OS subroutines required: <<sbrk>>, <<write>>.
*/
 
#include <_ansi.h>
#include <reent.h>
#include <stdio.h>
#include <unistd.h>
#include <stdarg.h>
 
int
_DEFUN(_diprintf_r, (ptr, fd, format),
struct _reent *ptr _AND
int fd _AND
const char *format _DOTS)
{
va_list ap;
int n;
 
va_start (ap, format);
n = _vdiprintf_r (ptr, fd, format, ap);
va_end (ap);
return n;
}
 
#ifndef _REENT_ONLY
 
int
_DEFUN(diprintf, (fd, format),
int fd _AND
const char *format _DOTS)
{
va_list ap;
int n;
 
va_start (ap, format);
n = _vdiprintf_r (_REENT, fd, format, ap);
va_end (ap);
return n;
}
 
#endif /* ! _REENT_ONLY */
/programs/develop/libraries/newlib/stdio/dprintf.c
0,0 → 1,87
/* Copyright 2005, 2007 Shaun Jackman
* Permission to use, copy, modify, and distribute this software
* is freely granted, provided that this notice is preserved.
*/
 
/*
FUNCTION
<<dprintf>>, <<vdprintf>>---print to a file descriptor
 
INDEX
dprintf
INDEX
_dprintf_r
INDEX
vdprintf
INDEX
_vdprintf_r
 
ANSI_SYNOPSIS
#include <stdio.h>
#include <stdarg.h>
int dprintf(int <[fd]>, const char *<[format]>, ...);
int vdprintf(int <[fd]>, const char *<[format]>, va_list <[ap]>);
int _dprintf_r(struct _reent *<[ptr]>, int <[fd]>,
const char *<[format]>, ...);
int _vdprintf_r(struct _reent *<[ptr]>, int <[fd]>,
const char *<[format]>, va_list <[ap]>);
 
DESCRIPTION
<<dprintf>> and <<vdprintf>> allow printing a format, similarly to
<<printf>>, but write to a file descriptor instead of to a <<FILE>>
stream.
 
The functions <<_dprintf_r>> and <<_vdprintf_r>> are simply
reentrant versions of the functions above.
 
RETURNS
The return value and errors are exactly as for <<write>>, except that
<<errno>> may also be set to <<ENOMEM>> if the heap is exhausted.
 
PORTABILITY
This function is originally a GNU extension in glibc and is not portable.
 
Supporting OS subroutines required: <<sbrk>>, <<write>>.
*/
 
#include <_ansi.h>
#include <reent.h>
#include <stdio.h>
#include <unistd.h>
#include <stdarg.h>
#include "local.h"
 
int
_DEFUN(_dprintf_r, (ptr, fd, format),
struct _reent *ptr _AND
int fd _AND
const char *format _DOTS)
{
va_list ap;
int n;
_REENT_SMALL_CHECK_INIT (ptr);
va_start (ap, format);
n = _vdprintf_r (ptr, fd, format, ap);
va_end (ap);
return n;
}
 
#ifndef _REENT_ONLY
 
int
_DEFUN(dprintf, (fd, format),
int fd _AND
const char *format _DOTS)
{
va_list ap;
int n;
struct _reent *ptr = _REENT;
 
_REENT_SMALL_CHECK_INIT (ptr);
va_start (ap, format);
n = _vdprintf_r (ptr, fd, format, ap);
va_end (ap);
return n;
}
 
#endif /* ! _REENT_ONLY */
/programs/develop/libraries/newlib/stdio/fclose.c
74,8 → 74,6
if (fp == NULL)
return (0); /* on NULL */
 
__sfp_lock_acquire ();
 
CHECK_INIT (rptr, fp);
 
_flockfile (fp);
83,7 → 81,6
if (fp->_flags == 0) /* not open! */
{
_funlockfile (fp);
__sfp_lock_release ();
return (0);
}
/* Unconditionally flush to allow special handling for seekable read
98,6 → 95,7
FREEUB (rptr, fp);
if (HASLB (fp))
FREELB (rptr, fp);
__sfp_lock_acquire ();
fp->_flags = 0; /* release this FILE for reuse */
_funlockfile (fp);
#ifndef __SINGLE_THREAD__
/programs/develop/libraries/newlib/stdio/fflush.c
67,8 → 67,10
 
/* Flush a single file, or (if fp is NULL) all files. */
 
/* Core function which does not lock file pointer. This gets called
directly from __srefill. */
int
_DEFUN(_fflush_r, (ptr, fp),
_DEFUN(__sflush_r, (ptr, fp),
struct _reent *ptr _AND
register FILE * fp)
{
75,29 → 77,6
register unsigned char *p;
register int n, t;
 
#ifdef _REENT_SMALL
/* For REENT_SMALL platforms, it is possible we are being
called for the first time on a std stream. This std
stream can belong to a reentrant struct that is not
_REENT. If CHECK_INIT gets called below based on _REENT,
we will end up changing said file pointers to the equivalent
std stream off of _REENT. This causes unexpected behavior if
there is any data to flush on the _REENT std stream. There
are two alternatives to fix this: 1) make a reentrant fflush
or 2) simply recognize that this file has nothing to flush
and return immediately before performing a CHECK_INIT. Choice
2 is implemented here due to its simplicity. */
if (fp->_bf._base == NULL)
return 0;
#endif /* _REENT_SMALL */
 
CHECK_INIT (ptr, fp);
 
if (!fp->_flags)
return 0;
 
_flockfile (fp);
 
t = fp->_flags;
if ((t & __SWR) == 0)
{
150,7 → 129,6
}
else
fp->_flags |= __SERR;
_funlockfile (fp);
return result;
}
}
186,17 → 164,14
else
{
fp->_flags |= __SERR;
_funlockfile (fp);
return EOF;
}
}
_funlockfile (fp);
return 0;
}
if ((p = fp->_bf._base) == NULL)
{
/* Nothing to flush. */
_funlockfile (fp);
return 0;
}
n = fp->_p - p; /* write this much */
215,16 → 190,48
if (t <= 0)
{
fp->_flags |= __SERR;
_funlockfile (fp);
return EOF;
}
p += t;
n -= t;
}
_funlockfile (fp);
return 0;
}
 
int
_DEFUN(_fflush_r, (ptr, fp),
struct _reent *ptr _AND
register FILE * fp)
{
int ret;
 
#ifdef _REENT_SMALL
/* For REENT_SMALL platforms, it is possible we are being
called for the first time on a std stream. This std
stream can belong to a reentrant struct that is not
_REENT. If CHECK_INIT gets called below based on _REENT,
we will end up changing said file pointers to the equivalent
std stream off of _REENT. This causes unexpected behavior if
there is any data to flush on the _REENT std stream. There
are two alternatives to fix this: 1) make a reentrant fflush
or 2) simply recognize that this file has nothing to flush
and return immediately before performing a CHECK_INIT. Choice
2 is implemented here due to its simplicity. */
if (fp->_bf._base == NULL)
return 0;
#endif /* _REENT_SMALL */
 
CHECK_INIT (ptr, fp);
 
if (!fp->_flags)
return 0;
 
_flockfile (fp);
ret = __sflush_r (ptr, fp);
_funlockfile (fp);
return ret;
}
 
#ifndef _REENT_ONLY
 
int
/programs/develop/libraries/newlib/stdio/fgetc.c
0,0 → 1,106
/*
* 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.
*/
 
/*
FUNCTION
<<fgetc>>---get a character from a file or stream
 
INDEX
fgetc
INDEX
_fgetc_r
 
ANSI_SYNOPSIS
#include <stdio.h>
int fgetc(FILE *<[fp]>);
 
#include <stdio.h>
int _fgetc_r(struct _reent *<[ptr]>, FILE *<[fp]>);
 
TRAD_SYNOPSIS
#include <stdio.h>
int fgetc(<[fp]>)
FILE *<[fp]>;
 
#include <stdio.h>
int _fgetc_r(<[ptr]>, <[fp]>)
struct _reent *<[ptr]>;
FILE *<[fp]>;
 
DESCRIPTION
Use <<fgetc>> to get the next single character from the file or stream
identified by <[fp]>. As a side effect, <<fgetc>> advances the file's
current position indicator.
 
For a macro version of this function, see <<getc>>.
 
The function <<_fgetc_r>> is simply a reentrant version of
<<fgetc>> that is passed the additional reentrant structure
pointer argument: <[ptr]>.
 
RETURNS
The next character (read as an <<unsigned char>>, and cast to
<<int>>), unless there is no more data, or the host system reports a
read error; in either of these situations, <<fgetc>> returns <<EOF>>.
 
You can distinguish the two situations that cause an <<EOF>> result by
using the <<ferror>> and <<feof>> functions.
 
PORTABILITY
ANSI C requires <<fgetc>>.
 
Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
<<lseek>>, <<read>>, <<sbrk>>, <<write>>.
*/
 
#include <_ansi.h>
#include <stdio.h>
#include "local.h"
 
int
_DEFUN(_fgetc_r, (ptr, fp),
struct _reent * ptr _AND
FILE * fp)
{
int result;
CHECK_INIT(ptr, fp);
_flockfile (fp);
result = __sgetc_r (ptr, fp);
_funlockfile (fp);
return result;
}
 
#ifndef _REENT_ONLY
 
int
_DEFUN(fgetc, (fp),
FILE * fp)
{
#if !defined(PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__)
int result;
CHECK_INIT(_REENT, fp);
_flockfile (fp);
result = __sgetc_r (_REENT, fp);
_funlockfile (fp);
return result;
#else
return _fgetc_r (_REENT, fp);
#endif
}
 
#endif /* !_REENT_ONLY */
 
/programs/develop/libraries/newlib/stdio/fgets.c
98,7 → 98,6
 
CHECK_INIT(ptr, fp);
 
__sfp_lock_acquire ();
_flockfile (fp);
#ifdef __SCLE
if (fp->_flags & __SCLE)
114,12 → 113,10
if (c == EOF && s == buf)
{
_funlockfile (fp);
__sfp_lock_release ();
return NULL;
}
*s = 0;
_funlockfile (fp);
__sfp_lock_release ();
return buf;
}
#endif
138,7 → 135,6
if (s == buf)
{
_funlockfile (fp);
__sfp_lock_release ();
return 0;
}
break;
164,7 → 160,6
_CAST_VOID memcpy ((_PTR) s, (_PTR) p, len);
s[len] = 0;
_funlockfile (fp);
__sfp_lock_release ();
return (buf);
}
fp->_r -= len;
175,7 → 170,6
while ((n -= len) != 0);
*s = 0;
_funlockfile (fp);
__sfp_lock_release ();
return buf;
}
 
/programs/develop/libraries/newlib/stdio/fread.c
146,7 → 146,6
 
CHECK_INIT(ptr, fp);
 
__sfp_lock_acquire ();
_flockfile (fp);
ORIENT (fp, -1);
if (fp->_r < 0)
197,12 → 196,10
if (fp->_flags & __SCLE)
{
_funlockfile (fp);
__sfp_lock_release ();
return crlf_r (ptr, fp, buf, total-resid, 1) / size;
}
#endif
_funlockfile (fp);
__sfp_lock_release ();
return (total - resid) / size;
}
}
224,12 → 221,10
if (fp->_flags & __SCLE)
{
_funlockfile (fp);
__sfp_lock_release ();
return crlf_r (ptr, fp, buf, total-resid, 1) / size;
}
#endif
_funlockfile (fp);
__sfp_lock_release ();
return (total - resid) / size;
}
}
243,12 → 238,10
if (fp->_flags & __SCLE)
{
_funlockfile (fp);
__sfp_lock_release ();
return crlf_r(ptr, fp, buf, total, 0) / size;
}
#endif
_funlockfile (fp);
__sfp_lock_release ();
return count;
}
 
/programs/develop/libraries/newlib/stdio/freopen.c
98,8 → 98,6
int flags, oflags;
int e = 0;
 
__sfp_lock_acquire ();
 
CHECK_INIT (ptr, fp);
 
_flockfile (fp);
108,7 → 106,6
{
_funlockfile (fp);
_fclose_r (ptr, fp);
__sfp_lock_release ();
return NULL;
}
 
208,6 → 205,7
 
if (f < 0)
{ /* did not get it after all */
__sfp_lock_acquire ();
fp->_flags = 0; /* set it free */
ptr->_errno = e; /* restore in case _close clobbered */
_funlockfile (fp);
232,7 → 230,6
#endif
 
_funlockfile (fp);
__sfp_lock_release ();
return fp;
}
 
/programs/develop/libraries/newlib/stdio/fscanf.c
45,7 → 45,7
#else
va_start (ap);
#endif
ret = __svfscanf_r (_REENT, fp, fmt, ap);
ret = _vfscanf_r (_REENT, fp, fmt, ap);
va_end (ap);
return ret;
}
71,7 → 71,7
#else
va_start (ap);
#endif
ret = __svfscanf_r (ptr, fp, fmt, ap);
ret = _vfscanf_r (ptr, fp, fmt, ap);
va_end (ap);
return (ret);
}
/programs/develop/libraries/newlib/stdio/fseek.c
138,7 → 138,6
 
CHECK_INIT (ptr, fp);
 
__sfp_lock_acquire ();
_flockfile (fp);
 
/* If we've been doing some writing, and we're in append mode
156,7 → 155,6
{
ptr->_errno = ESPIPE; /* ??? */
_funlockfile (fp);
__sfp_lock_release ();
return EOF;
}
 
182,7 → 180,6
if (curoff == -1L)
{
_funlockfile (fp);
__sfp_lock_release ();
return EOF;
}
}
208,7 → 205,6
default:
ptr->_errno = EINVAL;
_funlockfile (fp);
__sfp_lock_release ();
return (EOF);
}
 
268,7 → 264,6
{
ptr->_errno = EOVERFLOW;
_funlockfile (fp);
__sfp_lock_release ();
return EOF;
}
 
325,7 → 320,6
fp->_flags &= ~__SEOF;
memset (&fp->_mbstate, 0, sizeof (_mbstate_t));
_funlockfile (fp);
__sfp_lock_release ();
return 0;
}
 
356,7 → 350,6
}
memset (&fp->_mbstate, 0, sizeof (_mbstate_t));
_funlockfile (fp);
__sfp_lock_release ();
return 0;
 
/*
369,7 → 362,6
|| seekfn (ptr, fp->_cookie, offset, whence) == POS_ERR)
{
_funlockfile (fp);
__sfp_lock_release ();
return EOF;
}
/* success: clear EOF indicator and discard ungetc() data */
388,7 → 380,6
fp->_flags &= ~__SNPT;
memset (&fp->_mbstate, 0, sizeof (_mbstate_t));
_funlockfile (fp);
__sfp_lock_release ();
return 0;
}
 
/programs/develop/libraries/newlib/stdio/fvwrite.c
61,11 → 61,7
 
/* make sure we can write */
if (cantwrite (ptr, fp))
{
fp->_flags |= __SERR;
ptr->_errno = EBADF;
return EOF;
}
 
iov = uio->uio_iov;
len = 0;
/programs/develop/libraries/newlib/stdio/fwalk.c
27,8 → 27,8
#include <errno.h>
#include "local.h"
 
static int
_DEFUN(__fwalk, (ptr, function),
int
_DEFUN(_fwalk, (ptr, function),
struct _reent *ptr _AND
register int (*function) (FILE *))
{
36,11 → 36,19
register int n, ret = 0;
register struct _glue *g;
 
/*
* It should be safe to walk the list without locking it;
* new nodes are only added to the end and none are ever
* removed.
*
* Avoid locking this list while walking it or else you will
* introduce a potential deadlock in [at least] refill.c.
*/
for (g = &ptr->__sglue; g != NULL; g = g->_next)
for (fp = g->_iobs, n = g->_niobs; --n >= 0; fp++)
if (fp->_flags != 0)
{
if (fp->_flags != 0 && fp->_file != -1)
if (fp->_flags != 0 && fp->_flags != 1 && fp->_file != -1)
ret |= (*function) (fp);
}
 
49,8 → 57,8
 
/* Special version of __fwalk where the function pointer is a reentrant
I/O function (e.g. _fclose_r). */
static int
_DEFUN(__fwalk_reent, (ptr, reent_function),
int
_DEFUN(_fwalk_reent, (ptr, reent_function),
struct _reent *ptr _AND
register int (*reent_function) (struct _reent *, FILE *))
{
58,51 → 66,21
register int n, ret = 0;
register struct _glue *g;
 
/*
* It should be safe to walk the list without locking it;
* new nodes are only added to the end and none are ever
* removed.
*
* Avoid locking this list while walking it or else you will
* introduce a potential deadlock in [at least] refill.c.
*/
for (g = &ptr->__sglue; g != NULL; g = g->_next)
for (fp = g->_iobs, n = g->_niobs; --n >= 0; fp++)
if (fp->_flags != 0)
{
if (fp->_flags != 0 && fp->_file != -1)
if (fp->_flags != 0 && fp->_flags != 1 && fp->_file != -1)
ret |= (*reent_function) (ptr, fp);
}
 
return ret;
}
 
int
_DEFUN(_fwalk, (ptr, function),
struct _reent *ptr _AND
register int (*function)(FILE *))
{
register int ret = 0;
 
__sfp_lock_acquire ();
 
/* Must traverse given list for streams. Note that _GLOBAL_REENT
only walked once in exit(). */
ret |= __fwalk (ptr, function);
 
__sfp_lock_release ();
 
return ret;
}
 
/* Special version of _fwalk which handles a function pointer to a
reentrant I/O function (e.g. _fclose_r). */
int
_DEFUN(_fwalk_reent, (ptr, reent_function),
struct _reent *ptr _AND
register int (*reent_function) (struct _reent *, FILE *))
{
register int ret = 0;
 
__sfp_lock_acquire ();
 
/* Must traverse given list for streams. Note that _GLOBAL_REENT
only walked once in exit(). */
ret |= __fwalk_reent (ptr, reent_function);
 
__sfp_lock_release ();
 
return ret;
}
/programs/develop/libraries/newlib/stdio/local.h
54,6 → 54,7
va_list));
extern FILE *_EXFUN(__sfp,(struct _reent *));
extern int _EXFUN(__sflags,(struct _reent *,_CONST char*, int*));
extern int _EXFUN(__sflush_r,(struct _reent *,FILE *));
extern int _EXFUN(__srefill_r,(struct _reent *,FILE *));
extern _READ_WRITE_RETURN_TYPE _EXFUN(__sread,(struct _reent *, void *, char *,
int));
112,7 → 113,8
} \
while (0)
 
/* Return true iff the given FILE cannot be written now. */
/* Return true and set errno and stream error flag iff the given FILE
cannot be written now. */
 
#define cantwrite(ptr, fp) \
((((fp)->_flags & __SWR) == 0 || (fp)->_bf._base == NULL) && \
/programs/develop/libraries/newlib/stdio/refill.c
102,9 → 102,19
* flush all line buffered output files, per the ANSI C
* standard.
*/
 
if (fp->_flags & (__SLBF | __SNBF))
{
/* Ignore this file in _fwalk to avoid potential deadlock. */
short orig_flags = fp->_flags;
fp->_flags = 1;
_CAST_VOID _fwalk (_GLOBAL_REENT, lflush);
fp->_flags = orig_flags;
 
/* Now flush this file without locking it. */
if ((fp->_flags & (__SLBF|__SWR)) == (__SLBF|__SWR))
__sflush_r (ptr, fp);
}
 
fp->_p = fp->_bf._base;
fp->_r = fp->_read (ptr, fp->_cookie, (char *) fp->_p, fp->_bf._size);
#ifndef __CYGWIN__
/programs/develop/libraries/newlib/stdio/sniprintf.c
0,0 → 1,120
/*
* Copyright (c) 1990, 2007 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.
*/
 
/* This code created by modifying snprintf.c so copyright inherited. */
/* doc in siprintf.c */
 
#include <_ansi.h>
#include <reent.h>
#include <stdio.h>
#ifdef _HAVE_STDC
#include <stdarg.h>
#else
#include <varargs.h>
#endif
#include <limits.h>
#include <errno.h>
#include "local.h"
 
int
#ifdef _HAVE_STDC
_DEFUN (_sniprintf_r, (ptr, str, size, fmt),
struct _reent *ptr _AND
char *str _AND
size_t size _AND
_CONST char *fmt _DOTS)
#else
_sniprintf_r (ptr, str, size, fmt, va_alist)
struct _reent *ptr;
char *str;
size_t size;
_CONST char *fmt;
va_dcl
#endif
{
int ret;
va_list ap;
FILE f;
 
if (size > INT_MAX)
{
ptr->_errno = EOVERFLOW;
return EOF;
}
f._flags = __SWR | __SSTR;
f._bf._base = f._p = (unsigned char *) str;
f._bf._size = f._w = (size > 0 ? size - 1 : 0);
f._file = -1; /* No file. */
#ifdef _HAVE_STDC
va_start (ap, fmt);
#else
va_start (ap);
#endif
ret = _svfiprintf_r (ptr, &f, fmt, ap);
va_end (ap);
if (ret < EOF)
ptr->_errno = EOVERFLOW;
if (size > 0)
*f._p = 0;
return (ret);
}
 
#ifndef _REENT_ONLY
 
int
#ifdef _HAVE_STDC
_DEFUN (sniprintf, (str, size, fmt),
char *str _AND
size_t size _AND
_CONST char *fmt _DOTS)
#else
sniprintf (str, size, fmt, va_alist)
char *str;
size_t size;
_CONST char *fmt;
va_dcl
#endif
{
int ret;
va_list ap;
FILE f;
struct _reent *ptr = _REENT;
 
if (size > INT_MAX)
{
ptr->_errno = EOVERFLOW;
return EOF;
}
f._flags = __SWR | __SSTR;
f._bf._base = f._p = (unsigned char *) str;
f._bf._size = f._w = (size > 0 ? size - 1 : 0);
f._file = -1; /* No file. */
#ifdef _HAVE_STDC
va_start (ap, fmt);
#else
va_start (ap);
#endif
ret = _svfiprintf_r (ptr, &f, fmt, ap);
va_end (ap);
if (ret < EOF)
ptr->_errno = EOVERFLOW;
if (size > 0)
*f._p = 0;
return (ret);
}
 
#endif
/programs/develop/libraries/newlib/stdio/vfscanf.c
453,7 → 453,9
wchar_t wc; /* wchar to use to read format string */
wchar_t *wcp; /* handy wide character pointer */
size_t mbslen; /* length of converted multibyte sequence */
#ifdef _MB_CAPABLE
mbstate_t state; /* value to keep track of multibyte state */
#endif
 
#define CCFN_PARAMS _PARAMS((struct _reent *, const char *, char **, int))
u_long (*ccfn)CCFN_PARAMS=0; /* conversion function (strtol/strtoul) */
494,7 → 496,6
# define GET_ARG(n, ap, type) (va_arg (ap, type))
#endif
 
__sfp_lock_acquire ();
_flockfile (fp);
 
ORIENT (fp, -1);
795,7 → 796,6
*/
case '\0': /* compat */
_funlockfile (fp);
__sfp_lock_release ();
return EOF;
 
default: /* compat */
1596,13 → 1596,11
invalid format string), return EOF if no matches yet, else number
of matches made prior to failure. */
_funlockfile (fp);
__sfp_lock_release ();
return nassigned && !(fp->_flags & __SERR) ? nassigned : EOF;
match_failure:
all_done:
/* Return number of matches, which can be 0 on match failure. */
_funlockfile (fp);
__sfp_lock_release ();
return nassigned;
}
 
/programs/develop/libraries/newlib/stdio/vsnprintf.c
27,6 → 27,8
#include <stdarg.h>
#include <errno.h>
 
#include "local.h"
 
#ifndef _REENT_ONLY
 
int
/programs/develop/libraries/newlib/stdio/vsprintf.c
26,6 → 26,8
#include <limits.h>
#include <stdarg.h>
 
#include "local.h"
 
#ifndef _REENT_ONLY
 
int
/programs/develop/libraries/newlib/stdio/wbuf.c
54,11 → 54,7
 
fp->_w = fp->_lbfsize;
if (cantwrite (ptr, fp))
{
fp->_flags |= __SERR;
ptr->_errno = EBADF;
return EOF;
}
c = (unsigned char) c;
 
ORIENT (fp, -1);
/programs/develop/libraries/newlib/stdio/wsetup.c
20,12 → 20,13
#include <_ansi.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include "local.h"
 
/*
* Various output routines call wsetup to be sure it is safe to write,
* because either _flags does not include __SWR, or _buf is NULL.
* _wsetup returns 0 if OK to write, nonzero otherwise.
* _wsetup returns 0 if OK to write, nonzero and set errno otherwise.
*/
 
int
44,7 → 45,11
if ((fp->_flags & __SWR) == 0)
{
if ((fp->_flags & __SRW) == 0)
{
ptr->_errno = EBADF;
fp->_flags |= __SERR;
return EOF;
}
if (fp->_flags & __SRD)
{
/* clobber any ungetc data */
79,5 → 84,11
else
fp->_w = fp->_flags & __SNBF ? 0 : fp->_bf._size;
 
return (!fp->_bf._base && (fp->_flags & __SMBF)) ? EOF : 0;
if (!fp->_bf._base && (fp->_flags & __SMBF))
{
/* __smakebuf_r set errno, but not flag */
fp->_flags |= __SERR;
return EOF;
}
return 0;
}