newlib: update

git-svn-id: svn://kolibrios.org@3065 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Sergey Semyonov (Serge)
2012-11-26 10:18:42 +00:00
parent 16ef653fe4
commit a1006b9202
51 changed files with 1196 additions and 542 deletions
@@ -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);
}
@@ -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 */
@@ -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 */
@@ -74,8 +74,6 @@ _DEFUN(_fclose_r, (rptr, fp),
if (fp == NULL)
return (0); /* on NULL */
__sfp_lock_acquire ();
CHECK_INIT (rptr, fp);
_flockfile (fp);
@@ -83,7 +81,6 @@ _DEFUN(_fclose_r, (rptr, fp),
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 @@ _DEFUN(_fclose_r, (rptr, fp),
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__
@@ -67,37 +67,16 @@ No supporting OS subroutines are required.
/* 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)
{
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 @@ _DEFUN(_fflush_r, (ptr, fp),
}
else
fp->_flags |= __SERR;
_funlockfile (fp);
return result;
}
}
@@ -186,17 +164,14 @@ _DEFUN(_fflush_r, (ptr, fp),
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 @@ _DEFUN(_fflush_r, (ptr, fp),
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
@@ -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 */
@@ -98,7 +98,6 @@ _DEFUN(_fgets_r, (ptr, buf, n, fp),
CHECK_INIT(ptr, fp);
__sfp_lock_acquire ();
_flockfile (fp);
#ifdef __SCLE
if (fp->_flags & __SCLE)
@@ -114,12 +113,10 @@ _DEFUN(_fgets_r, (ptr, buf, n, fp),
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 @@ _DEFUN(_fgets_r, (ptr, buf, n, fp),
if (s == buf)
{
_funlockfile (fp);
__sfp_lock_release ();
return 0;
}
break;
@@ -164,7 +160,6 @@ _DEFUN(_fgets_r, (ptr, buf, n, fp),
_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 @@ _DEFUN(_fgets_r, (ptr, buf, n, fp),
while ((n -= len) != 0);
*s = 0;
_funlockfile (fp);
__sfp_lock_release ();
return buf;
}
@@ -146,7 +146,6 @@ _DEFUN(_fread_r, (ptr, buf, size, count, fp),
CHECK_INIT(ptr, fp);
__sfp_lock_acquire ();
_flockfile (fp);
ORIENT (fp, -1);
if (fp->_r < 0)
@@ -197,12 +196,10 @@ _DEFUN(_fread_r, (ptr, buf, size, count, fp),
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 @@ _DEFUN(_fread_r, (ptr, buf, size, count, fp),
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 @@ _DEFUN(_fread_r, (ptr, buf, size, count, fp),
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;
}
@@ -98,8 +98,6 @@ _DEFUN(_freopen_r, (ptr, file, mode, fp),
int flags, oflags;
int e = 0;
__sfp_lock_acquire ();
CHECK_INIT (ptr, fp);
_flockfile (fp);
@@ -108,7 +106,6 @@ _DEFUN(_freopen_r, (ptr, file, mode, fp),
{
_funlockfile (fp);
_fclose_r (ptr, fp);
__sfp_lock_release ();
return NULL;
}
@@ -208,6 +205,7 @@ _DEFUN(_freopen_r, (ptr, file, mode, fp),
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 @@ _DEFUN(_freopen_r, (ptr, file, mode, fp),
#endif
_funlockfile (fp);
__sfp_lock_release ();
return fp;
}
@@ -45,7 +45,7 @@ fscanf(FILE *fp, fmt, va_alist)
#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 @@ _fscanf_r(ptr, FILE *fp, fmt, va_alist)
#else
va_start (ap);
#endif
ret = __svfscanf_r (ptr, fp, fmt, ap);
ret = _vfscanf_r (ptr, fp, fmt, ap);
va_end (ap);
return (ret);
}
@@ -138,7 +138,6 @@ _DEFUN(_fseek_r, (ptr, fp, offset, whence),
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 @@ _DEFUN(_fseek_r, (ptr, fp, offset, whence),
{
ptr->_errno = ESPIPE; /* ??? */
_funlockfile (fp);
__sfp_lock_release ();
return EOF;
}
@@ -182,7 +180,6 @@ _DEFUN(_fseek_r, (ptr, fp, offset, whence),
if (curoff == -1L)
{
_funlockfile (fp);
__sfp_lock_release ();
return EOF;
}
}
@@ -208,7 +205,6 @@ _DEFUN(_fseek_r, (ptr, fp, offset, whence),
default:
ptr->_errno = EINVAL;
_funlockfile (fp);
__sfp_lock_release ();
return (EOF);
}
@@ -268,7 +264,6 @@ _DEFUN(_fseek_r, (ptr, fp, offset, whence),
{
ptr->_errno = EOVERFLOW;
_funlockfile (fp);
__sfp_lock_release ();
return EOF;
}
@@ -325,7 +320,6 @@ _DEFUN(_fseek_r, (ptr, fp, offset, whence),
fp->_flags &= ~__SEOF;
memset (&fp->_mbstate, 0, sizeof (_mbstate_t));
_funlockfile (fp);
__sfp_lock_release ();
return 0;
}
@@ -356,7 +350,6 @@ _DEFUN(_fseek_r, (ptr, fp, offset, whence),
}
memset (&fp->_mbstate, 0, sizeof (_mbstate_t));
_funlockfile (fp);
__sfp_lock_release ();
return 0;
/*
@@ -369,7 +362,6 @@ dumb:
|| 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 @@ dumb:
fp->_flags &= ~__SNPT;
memset (&fp->_mbstate, 0, sizeof (_mbstate_t));
_funlockfile (fp);
__sfp_lock_release ();
return 0;
}
@@ -61,11 +61,7 @@ _DEFUN(__sfvwrite_r, (ptr, fp, uio),
/* make sure we can write */
if (cantwrite (ptr, fp))
{
fp->_flags |= __SERR;
ptr->_errno = EBADF;
return EOF;
}
iov = uio->uio_iov;
len = 0;
+22 -44
View File
@@ -27,8 +27,8 @@ static char sccsid[] = "%W% (Berkeley) %G%";
#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 @@ _DEFUN(__fwalk, (ptr, function),
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 @@ _DEFUN(__fwalk, (ptr, function),
/* 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 @@ _DEFUN(__fwalk_reent, (ptr, reent_function),
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;
}
@@ -54,6 +54,7 @@ int _EXFUN(_svfiwprintf_r,(struct _reent *, FILE *, const wchar_t *,
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 @@ extern _READ_WRITE_RETURN_TYPE _EXFUN(__swrite64,(struct _reent *, void *,
} \
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) && \
@@ -102,9 +102,19 @@ _DEFUN(__srefill_r, (ptr, fp),
* 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__
@@ -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
@@ -453,7 +453,9 @@ _DEFUN(__SVFSCANF_R, (rptr, fp, fmt0, ap),
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 @@ _DEFUN(__SVFSCANF_R, (rptr, fp, fmt0, ap),
# define GET_ARG(n, ap, type) (va_arg (ap, type))
#endif
__sfp_lock_acquire ();
_flockfile (fp);
ORIENT (fp, -1);
@@ -795,7 +796,6 @@ _DEFUN(__SVFSCANF_R, (rptr, fp, fmt0, ap),
*/
case '\0': /* compat */
_funlockfile (fp);
__sfp_lock_release ();
return EOF;
default: /* compat */
@@ -1596,13 +1596,11 @@ input_failure:
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;
}
@@ -27,6 +27,8 @@ static char sccsid[] = "%W% (Berkeley) %G%";
#include <stdarg.h>
#include <errno.h>
#include "local.h"
#ifndef _REENT_ONLY
int
@@ -26,6 +26,8 @@ static char sccsid[] = "%W% (Berkeley) %G%";
#include <limits.h>
#include <stdarg.h>
#include "local.h"
#ifndef _REENT_ONLY
int
@@ -54,11 +54,7 @@ _DEFUN(__swbuf_r, (ptr, c, fp),
fp->_w = fp->_lbfsize;
if (cantwrite (ptr, fp))
{
fp->_flags |= __SERR;
ptr->_errno = EBADF;
return EOF;
}
c = (unsigned char) c;
ORIENT (fp, -1);
@@ -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 @@ _DEFUN(__swsetup_r, (ptr, fp),
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 @@ _DEFUN(__swsetup_r, (ptr, fp),
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;
}