jehanne: fix uio initializations; disable optimizations in print related functions

This commit is contained in:
Giacomo Tesio 2017-04-21 21:27:24 +02:00
parent 0f0315dbff
commit 595d23fca2
14 changed files with 6225 additions and 3 deletions

View File

@ -385,6 +385,7 @@ case "${host}" in
sys_dir=jehanne
syscall_dir=syscalls
newlib_cflags="${newlib_cflags} -DREENTRANT_SYSCALLS_PROVIDED -DMALLOC_PROVIDED"
newlib_cflags="${newlib_cflags} -fno-omit-frame-pointer"
have_crt0="no"
;;
*-*-netware*)

View File

@ -10,7 +10,9 @@ else
extra_objs =
endif
lib_a_SOURCES = getenv_r.c getenv.c malloc.c mallocr.c free.c freer.c calloc.c callocr.c realloc.c reallocr.c
lib_a_SOURCES = getenv_r.c getenv.c malloc.c mallocr.c free.c freer.c \
calloc.c callocr.c realloc.c reallocr.c \
fputs.c fputws.c fvwrite.c fwrite.c puts.c vfprintf.c vfwprintf.c wbuf.c
lib_a_LIBADD = $(extra_objs)
EXTRA_lib_a_SOURCES = libposix_conf.c syscalls.c
lib_a_DEPENDENCIES = $(extra_objs)

View File

@ -57,7 +57,11 @@ am_lib_a_OBJECTS = lib_a-getenv_r.$(OBJEXT) lib_a-getenv.$(OBJEXT) \
lib_a-malloc.$(OBJEXT) lib_a-mallocr.$(OBJEXT) \
lib_a-free.$(OBJEXT) lib_a-freer.$(OBJEXT) \
lib_a-calloc.$(OBJEXT) lib_a-callocr.$(OBJEXT) \
lib_a-realloc.$(OBJEXT) lib_a-reallocr.$(OBJEXT)
lib_a-realloc.$(OBJEXT) lib_a-reallocr.$(OBJEXT) \
lib_a-fputs.$(OBJEXT) lib_a-fputws.$(OBJEXT) \
lib_a-fvwrite.$(OBJEXT) lib_a-fwrite.$(OBJEXT) \
lib_a-puts.$(OBJEXT) lib_a-vfprintf.$(OBJEXT) \
lib_a-vfwprintf.$(OBJEXT) lib_a-wbuf.$(OBJEXT)
lib_a_OBJECTS = $(am_lib_a_OBJECTS)
DEFAULT_INCLUDES = -I.@am__isrc@
depcomp =
@ -178,7 +182,10 @@ AM_CCASFLAGS = $(INCLUDES)
noinst_LIBRARIES = lib.a
@MAY_SUPPLY_SYSCALLS_FALSE@extra_objs =
@MAY_SUPPLY_SYSCALLS_TRUE@extra_objs = syscalls.o libposix_conf.o
lib_a_SOURCES = getenv_r.c getenv.c malloc.c mallocr.c free.c freer.c calloc.c callocr.c realloc.c reallocr.c
lib_a_SOURCES = getenv_r.c getenv.c malloc.c mallocr.c free.c freer.c \
calloc.c callocr.c realloc.c reallocr.c \
fputs.c fputws.c fvwrite.c fwrite.c puts.c vfprintf.c vfwprintf.c wbuf.c
lib_a_LIBADD = $(extra_objs)
EXTRA_lib_a_SOURCES = libposix_conf.c syscalls.c
lib_a_DEPENDENCIES = $(extra_objs)
@ -308,6 +315,54 @@ lib_a-reallocr.o: reallocr.c
lib_a-reallocr.obj: reallocr.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-reallocr.obj `if test -f 'reallocr.c'; then $(CYGPATH_W) 'reallocr.c'; else $(CYGPATH_W) '$(srcdir)/reallocr.c'; fi`
lib_a-fputs.o: fputs.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-fputs.o `test -f 'fputs.c' || echo '$(srcdir)/'`fputs.c
lib_a-fputs.obj: fputs.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-fputs.obj `if test -f 'fputs.c'; then $(CYGPATH_W) 'fputs.c'; else $(CYGPATH_W) '$(srcdir)/fputs.c'; fi`
lib_a-fputws.o: fputws.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-fputws.o `test -f 'fputws.c' || echo '$(srcdir)/'`fputws.c
lib_a-fputws.obj: fputws.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-fputws.obj `if test -f 'fputws.c'; then $(CYGPATH_W) 'fputws.c'; else $(CYGPATH_W) '$(srcdir)/fputws.c'; fi`
lib_a-fvwrite.o: fvwrite.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-fvwrite.o `test -f 'fvwrite.c' || echo '$(srcdir)/'`fvwrite.c
lib_a-fvwrite.obj: fvwrite.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-fvwrite.obj `if test -f 'fvwrite.c'; then $(CYGPATH_W) 'fvwrite.c'; else $(CYGPATH_W) '$(srcdir)/fvwrite.c'; fi`
lib_a-fwrite.o: fwrite.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-fwrite.o `test -f 'fwrite.c' || echo '$(srcdir)/'`fwrite.c
lib_a-fwrite.obj: fwrite.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-fwrite.obj `if test -f 'fwrite.c'; then $(CYGPATH_W) 'fwrite.c'; else $(CYGPATH_W) '$(srcdir)/fwrite.c'; fi`
lib_a-puts.o: puts.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-puts.o `test -f 'puts.c' || echo '$(srcdir)/'`puts.c
lib_a-puts.obj: puts.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-puts.obj `if test -f 'puts.c'; then $(CYGPATH_W) 'puts.c'; else $(CYGPATH_W) '$(srcdir)/puts.c'; fi`
lib_a-vfprintf.o: vfprintf.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-vfprintf.o `test -f 'vfprintf.c' || echo '$(srcdir)/'`vfprintf.c
lib_a-vfprintf.obj: vfprintf.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-vfprintf.obj `if test -f 'vfprintf.c'; then $(CYGPATH_W) 'vfprintf.c'; else $(CYGPATH_W) '$(srcdir)/vfprintf.c'; fi`
lib_a-vfwprintf.o: vfwprintf.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-vfwprintf.o `test -f 'vfwprintf.c' || echo '$(srcdir)/'`vfwprintf.c
lib_a-vfwprintf.obj: vfwprintf.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-vfwprintf.obj `if test -f 'vfwprintf.c'; then $(CYGPATH_W) 'vfwprintf.c'; else $(CYGPATH_W) '$(srcdir)/vfwprintf.c'; fi`
lib_a-wbuf.o: wbuf.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-wbuf.o `test -f 'wbuf.c' || echo '$(srcdir)/'`wbuf.c
lib_a-wbuf.obj: wbuf.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-wbuf.obj `if test -f 'wbuf.c'; then $(CYGPATH_W) 'wbuf.c'; else $(CYGPATH_W) '$(srcdir)/wbuf.c'; fi`
lib_a-libposix_conf.o: libposix_conf.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-libposix_conf.o `test -f 'libposix_conf.c' || echo '$(srcdir)/'`libposix_conf.c

View File

@ -0,0 +1,173 @@
/*
* 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
<<fputs>>, <<fputs_unlocked>>---write a character string in a file or stream
INDEX
fputs
INDEX
fputs_unlocked
INDEX
_fputs_r
INDEX
_fputs_unlocked_r
ANSI_SYNOPSIS
#include <stdio.h>
int fputs(const char *restrict <[s]>, FILE *restrict <[fp]>);
#define _GNU_SOURCE
#include <stdio.h>
int fputs_unlocked(const char *restrict <[s]>, FILE *restrict <[fp]>);
#include <stdio.h>
int _fputs_r(struct _reent *<[ptr]>, const char *restrict <[s]>, FILE *restrict <[fp]>);
#include <stdio.h>
int _fputs_unlocked_r(struct _reent *<[ptr]>, const char *restrict <[s]>, FILE *restrict <[fp]>);
TRAD_SYNOPSIS
#include <stdio.h>
int fputs(<[s]>, <[fp]>)
char *<[s]>;
FILE *<[fp]>;
#define _GNU_SOURCE
#include <stdio.h>
int fputs_unlocked(<[s]>, <[fp]>)
char *<[s]>;
FILE *<[fp]>;
#include <stdio.h>
int _fputs_r(<[ptr]>, <[s]>, <[fp]>)
struct _reent *<[ptr]>;
char *<[s]>;
FILE *<[fp]>;
#include <stdio.h>
int _fputs_unlocked_r(<[ptr]>, <[s]>, <[fp]>)
struct _reent *<[ptr]>;
char *<[s]>;
FILE *<[fp]>;
DESCRIPTION
<<fputs>> writes the string at <[s]> (but without the trailing null)
to the file or stream identified by <[fp]>.
<<fputs_unlocked>> is a non-thread-safe version of <<fputs>>.
<<fputs_unlocked>> may only safely be used within a scope
protected by flockfile() (or ftrylockfile()) and funlockfile(). This
function may safely be used in a multi-threaded program if and only
if they are called while the invoking thread owns the (FILE *)
object, as is the case after a successful call to the flockfile() or
ftrylockfile() functions. If threads are disabled, then
<<fputs_unlocked>> is equivalent to <<fputs>>.
<<_fputs_r>> and <<_fputs_unlocked_r>> are simply reentrant versions of the
above that take an additional reentrant struct pointer argument: <[ptr]>.
RETURNS
If successful, the result is <<0>>; otherwise, the result is <<EOF>>.
PORTABILITY
ANSI C requires <<fputs>>, but does not specify that the result on
success must be <<0>>; any non-negative value is permitted.
<<fputs_unlocked>> is a GNU extension.
Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
<<lseek>>, <<read>>, <<sbrk>>, <<write>>.
*/
#include <_ansi.h>
#include <stdio.h>
#include <string.h>
#include "fvwrite.h"
#include "local.h"
#ifdef __IMPL_UNLOCKED__
#define _fputs_r _fputs_unlocked_r
#define fputs fputs_unlocked
#endif
/*
* Write the given string to the given file.
*/
#pragma GCC push_option
#pragma GCC optimize("O0")
int
_DEFUN(_fputs_r, (ptr, s, fp),
struct _reent * ptr _AND
char _CONST *__restrict s _AND
FILE *__restrict fp)
{
#ifdef _FVWRITE_IN_STREAMIO
int result;
struct __suio uio = {0, 0, 0};
struct __siov iov;
iov.iov_base = s;
iov.iov_len = uio.uio_resid = strlen (s);
uio.uio_iov = &iov;
uio.uio_iovcnt = 1;
CHECK_INIT(ptr, fp);
_newlib_flockfile_start (fp);
ORIENT (fp, -1);
result = __sfvwrite_r (ptr, fp, &uio);
_newlib_flockfile_end (fp);
return result;
#else
_CONST char *p = s;
CHECK_INIT(ptr, fp);
_newlib_flockfile_start (fp);
ORIENT (fp, -1);
/* Make sure we can write. */
if (cantwrite (ptr, fp))
goto error;
while (*p)
{
if (__sputc_r (ptr, *p++, fp) == EOF)
goto error;
}
_newlib_flockfile_exit (fp);
return 0;
error:
_newlib_flockfile_end (fp);
return EOF;
#endif
}
#pragma GCC pop_option
#ifndef _REENT_ONLY
int
_DEFUN(fputs, (s, fp),
char _CONST *__restrict s _AND
FILE *__restrict fp)
{
return _fputs_r (_REENT, s, fp);
}
#endif /* !_REENT_ONLY */

View File

@ -0,0 +1,198 @@
/*-
* Copyright (c) 2002-2004 Tim J. Robbins.
* All rights reserved.
*
* 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.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
*/
/*
FUNCTION
<<fputws>>, <<fputws_unlocked>>---write a wide character string in a file or stream
INDEX
fputws
INDEX
fputws_unlocked
INDEX
_fputws_r
INDEX
_fputws_unlocked_r
ANSI_SYNOPSIS
#include <wchar.h>
int fputws(const wchar_t *__restrict <[ws]>, FILE *__restrict <[fp]>);
#define _GNU_SOURCE
#include <wchar.h>
int fputws_unlocked(const wchar_t *__restrict <[ws]>, FILE *__restrict <[fp]>);
#include <wchar.h>
int _fputws_r(struct _reent *<[ptr]>, const wchar_t *<[ws]>,
FILE *<[fp]>);
#include <wchar.h>
int _fputws_unlocked_r(struct _reent *<[ptr]>, const wchar_t *<[ws]>,
FILE *<[fp]>);
TRAD_SYNOPSIS
#include <wchar.h>
int fputws(<[ws]>, <[fp]>)
wchar_t *__restrict <[ws]>;
FILE *__restrict <[fp]>;
#define _GNU_SOURCE
#include <wchar.h>
int fputws_unlocked(<[ws]>, <[fp]>)
wchar_t *__restrict <[ws]>;
FILE *__restrict <[fp]>;
#include <wchar.h>
int _fputws_r(<[ptr]>, <[ws]>, <[fp]>)
struct _reent *<[ptr]>;
wchar_t *<[ws]>;
FILE *<[fp]>;
#include <wchar.h>
int _fputws_unlocked_r(<[ptr]>, <[ws]>, <[fp]>)
struct _reent *<[ptr]>;
wchar_t *<[ws]>;
FILE *<[fp]>;
DESCRIPTION
<<fputws>> writes the wide character string at <[ws]> (but without the
trailing null) to the file or stream identified by <[fp]>.
<<fputws_unlocked>> is a non-thread-safe version of <<fputws>>.
<<fputws_unlocked>> may only safely be used within a scope
protected by flockfile() (or ftrylockfile()) and funlockfile(). This
function may safely be used in a multi-threaded program if and only
if they are called while the invoking thread owns the (FILE *)
object, as is the case after a successful call to the flockfile() or
ftrylockfile() functions. If threads are disabled, then
<<fputws_unlocked>> is equivalent to <<fputws>>.
<<_fputws_r>> and <<_fputws_unlocked_r>> are simply reentrant versions of the
above that take an additional reentrant struct pointer argument: <[ptr]>.
RETURNS
If successful, the result is a non-negative integer; otherwise, the result
is <<-1>> to indicate an error.
PORTABILITY
<<fputws>> is required by C99 and POSIX.1-2001.
<<fputws_unlocked>> is a GNU extension.
*/
#include <_ansi.h>
#include <reent.h>
#include <errno.h>
#include <limits.h>
#include <stdio.h>
#include <wchar.h>
#include "fvwrite.h"
#include "local.h"
#ifdef __IMPL_UNLOCKED__
#define _fputws_r _fputws_unlocked_r
#define fputws fputws_unlocked
#endif
#pragma GCC push_option
#pragma GCC optimize("O0")
int
_DEFUN(_fputws_r, (ptr, ws, fp),
struct _reent *ptr _AND
const wchar_t *ws _AND
FILE *fp)
{
size_t nbytes;
char buf[BUFSIZ];
#ifdef _FVWRITE_IN_STREAMIO
struct __suio uio = {0, 0, 0};
struct __siov iov;
_newlib_flockfile_start (fp);
ORIENT (fp, 1);
if (cantwrite (ptr, fp) != 0)
goto error;
uio.uio_iov = &iov;
uio.uio_iovcnt = 1;
iov.iov_base = buf;
do
{
nbytes = _wcsrtombs_r(ptr, buf, &ws, sizeof (buf), &fp->_mbstate);
if (nbytes == (size_t) -1)
goto error;
iov.iov_len = uio.uio_resid = nbytes;
if (__sfvwrite_r(ptr, fp, &uio) != 0)
goto error;
}
while (ws != NULL);
_newlib_flockfile_exit (fp);
return (0);
error:
_newlib_flockfile_end (fp);
return (-1);
#else
_newlib_flockfile_start (fp);
ORIENT (fp, 1);
if (cantwrite (ptr, fp) != 0)
goto error;
do
{
size_t i = 0;
nbytes = _wcsrtombs_r (ptr, buf, &ws, sizeof (buf), &fp->_mbstate);
if (nbytes == (size_t) -1)
goto error;
while (i < nbytes)
{
if (__sputc_r (ptr, buf[i], fp) == EOF)
goto error;
i++;
}
}
while (ws != NULL);
_newlib_flockfile_exit (fp);
return (0);
error:
_newlib_flockfile_end (fp);
return (-1);
#endif
}
#pragma GCC pop_option
int
_DEFUN(fputws, (ws, fp),
const wchar_t *__restrict ws _AND
FILE *__restrict fp)
{
struct _reent *reent = _REENT;
CHECK_INIT (reent, fp);
return _fputws_r (reent, ws, fp);
}

View File

@ -0,0 +1,271 @@
/*
* 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.
*/
/* No user fns here. Pesch 15apr92. */
#include <_ansi.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <limits.h>
#include "local.h"
#include "fvwrite.h"
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define COPY(n) _CAST_VOID memmove ((_PTR) fp->_p, (_PTR) p, (size_t) (n))
#define GETIOV(extra_work) \
while (len == 0) \
{ \
extra_work; \
p = iov->iov_base; \
len = iov->iov_len; \
iov++; \
}
/*
* Write some memory regions. Return zero on success, EOF on error.
*
* This routine is large and unsightly, but most of the ugliness due
* to the three different kinds of output buffering is handled here.
*/
#pragma GCC push_option
#pragma GCC optimize("O0")
int
_DEFUN(__sfvwrite_r, (ptr, fp, uio),
struct _reent *ptr _AND
register FILE *fp _AND
register struct __suio *uio)
{
register size_t len;
register _CONST char *p = NULL;
register struct __siov *iov;
register _READ_WRITE_RETURN_TYPE w, s;
char *nl;
int nlknown, nldist;
if ((len = uio->uio_resid) == 0)
return 0;
/* make sure we can write */
if (cantwrite (ptr, fp))
return EOF;
iov = uio->uio_iov;
len = 0;
#ifdef __SCLE
if (fp->_flags & __SCLE) /* text mode */
{
do
{
GETIOV (;);
while (len > 0)
{
if (putc (*p, fp) == EOF)
return EOF;
p++;
len--;
uio->uio_resid--;
}
}
while (uio->uio_resid > 0);
return 0;
}
#endif
if (fp->_flags & __SNBF)
{
/*
* Unbuffered: Split buffer in the largest multiple of BUFSIZ < INT_MAX
* as some legacy code may expect int instead of size_t.
*/
do
{
GETIOV (;);
w = fp->_write (ptr, fp->_cookie, p,
MIN (len, INT_MAX - INT_MAX % BUFSIZ));
if (w <= 0)
goto err;
p += w;
len -= w;
}
while ((uio->uio_resid -= w) != 0);
}
else if ((fp->_flags & __SLBF) == 0)
{
/*
* Fully buffered: fill partially full buffer, if any,
* and then flush. If there is no partial buffer, write
* one _bf._size byte chunk directly (without copying).
*
* String output is a special case: write as many bytes
* as fit, but pretend we wrote everything. This makes
* snprintf() return the number of bytes needed, rather
* than the number used, and avoids its write function
* (so that the write function can be invalid). If
* we are dealing with the asprintf routines, we will
* dynamically increase the buffer size as needed.
*/
do
{
GETIOV (;);
w = fp->_w;
if (fp->_flags & __SSTR)
{
if (len >= w && fp->_flags & (__SMBF | __SOPT))
{ /* must be asprintf family */
unsigned char *str;
int curpos = (fp->_p - fp->_bf._base);
/* Choose a geometric growth factor to avoid
quadratic realloc behavior, but use a rate less
than (1+sqrt(5))/2 to accomodate malloc
overhead. asprintf EXPECTS us to overallocate, so
that it can add a trailing \0 without
reallocating. The new allocation should thus be
max(prev_size*1.5, curpos+len+1). */
int newsize = fp->_bf._size * 3 / 2;
if (newsize < curpos + len + 1)
newsize = curpos + len + 1;
if (fp->_flags & __SOPT)
{
/* asnprintf leaves original buffer alone. */
str = (unsigned char *)_malloc_r (ptr, newsize);
if (!str)
{
ptr->_errno = ENOMEM;
goto err;
}
memcpy (str, fp->_bf._base, curpos);
fp->_flags = (fp->_flags & ~__SOPT) | __SMBF;
}
else
{
str = (unsigned char *)_realloc_r (ptr, fp->_bf._base,
newsize);
if (!str)
{
/* Free buffer which is no longer used and clear
__SMBF flag to avoid double free in fclose. */
_free_r (ptr, fp->_bf._base);
fp->_flags &= ~__SMBF;
/* Ensure correct errno, even if free changed it. */
ptr->_errno = ENOMEM;
goto err;
}
}
fp->_bf._base = str;
fp->_p = str + curpos;
fp->_bf._size = newsize;
w = len;
fp->_w = newsize - curpos;
}
if (len < w)
w = len;
COPY (w); /* copy MIN(fp->_w,len), */
fp->_w -= w;
fp->_p += w;
w = len; /* but pretend copied all */
}
else if (fp->_p > fp->_bf._base || len < fp->_bf._size)
{
/* pass through the buffer */
w = MIN (len, w);
COPY (w);
fp->_w -= w;
fp->_p += w;
if (fp->_w == 0 && _fflush_r (ptr, fp))
goto err;
}
else
{
/* write directly */
w = ((int)MIN (len, INT_MAX)) / fp->_bf._size * fp->_bf._size;
w = fp->_write (ptr, fp->_cookie, p, w);
if (w <= 0)
goto err;
}
p += w;
len -= w;
}
while ((uio->uio_resid -= w) != 0);
}
else
{
/*
* Line buffered: like fully buffered, but we
* must check for newlines. Compute the distance
* to the first newline (including the newline),
* or `infinity' if there is none, then pretend
* that the amount to write is MIN(len,nldist).
*/
nlknown = 0;
nldist = 0;
do
{
GETIOV (nlknown = 0);
if (!nlknown)
{
nl = memchr ((_PTR) p, '\n', len);
nldist = nl ? nl + 1 - p : len + 1;
nlknown = 1;
}
s = MIN (len, nldist);
w = fp->_w + fp->_bf._size;
if (fp->_p > fp->_bf._base && s > w)
{
COPY (w);
/* fp->_w -= w; */
fp->_p += w;
if (_fflush_r (ptr, fp))
goto err;
}
else if (s >= (w = fp->_bf._size))
{
w = fp->_write (ptr, fp->_cookie, p, w);
if (w <= 0)
goto err;
}
else
{
w = s;
COPY (w);
fp->_w -= w;
fp->_p += w;
}
if ((nldist -= w) == 0)
{
/* copied the newline: flush and forget */
if (_fflush_r (ptr, fp))
goto err;
nlknown = 0;
}
p += w;
len -= w;
}
while ((uio->uio_resid -= w) != 0);
}
return 0;
err:
fp->_flags |= __SERR;
return EOF;
}
#pragma GCC pop_option

View File

@ -0,0 +1,36 @@
/*
* 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.
*/
/* %W% (Berkeley) %G% */
#include <_ansi.h>
/*
* I/O descriptors for __sfvwrite_r().
*/
struct __siov {
_CONST _PTR iov_base;
size_t iov_len;
};
struct __suio {
struct __siov *uio_iov;
int uio_iovcnt;
size_t uio_resid;
};
extern int _EXFUN(__sfvwrite_r,(struct _reent *, FILE *, struct __suio *));
extern int _EXFUN(__swsetup_r,(struct _reent *, FILE *));

View File

@ -0,0 +1,218 @@
/*
* 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
<<fwrite>>, <<fwrite_unlocked>>---write array elements
INDEX
fwrite
INDEX
fwrite_unlocked
INDEX
_fwrite_r
INDEX
_fwrite_unlocked_r
ANSI_SYNOPSIS
#include <stdio.h>
size_t fwrite(const void *restrict <[buf]>, size_t <[size]>,
size_t <[count]>, FILE *restrict <[fp]>);
#define _BSD_SOURCE
#include <stdio.h>
size_t fwrite_unlocked(const void *restrict <[buf]>, size_t <[size]>,
size_t <[count]>, FILE *restrict <[fp]>);
#include <stdio.h>
size_t _fwrite_r(struct _reent *<[ptr]>, const void *restrict <[buf]>, size_t <[size]>,
size_t <[count]>, FILE *restrict <[fp]>);
#include <stdio.h>
size_t _fwrite_unlocked_r(struct _reent *<[ptr]>, const void *restrict <[buf]>, size_t <[size]>,
size_t <[count]>, FILE *restrict <[fp]>);
TRAD_SYNOPSIS
#include <stdio.h>
size_t fwrite(<[buf]>, <[size]>, <[count]>, <[fp]>)
char *<[buf]>;
size_t <[size]>;
size_t <[count]>;
FILE *<[fp]>;
#define _BSD_SOURCE
#include <stdio.h>
size_t fwrite_unlocked(<[buf]>, <[size]>, <[count]>, <[fp]>)
char *<[buf]>;
size_t <[size]>;
size_t <[count]>;
FILE *<[fp]>;
#include <stdio.h>
size_t _fwrite_r(<[ptr]>, <[buf]>, <[size]>, <[count]>, <[fp]>)
struct _reent *<[ptr]>;
char *<[buf]>;
size_t <[size]>;
size_t <[count]>;
FILE *<[fp]>;
#include <stdio.h>
size_t _fwrite_unlocked_r(<[ptr]>, <[buf]>, <[size]>, <[count]>, <[fp]>)
struct _reent *<[ptr]>;
char *<[buf]>;
size_t <[size]>;
size_t <[count]>;
FILE *<[fp]>;
DESCRIPTION
<<fwrite>> attempts to copy, starting from the memory location
<[buf]>, <[count]> elements (each of size <[size]>) into the file or
stream identified by <[fp]>. <<fwrite>> may copy fewer elements than
<[count]> if an error intervenes.
<<fwrite>> also advances the file position indicator (if any) for
<[fp]> by the number of @emph{characters} actually written.
<<fwrite_unlocked>> is a non-thread-safe version of <<fwrite>>.
<<fwrite_unlocked>> may only safely be used within a scope
protected by flockfile() (or ftrylockfile()) and funlockfile(). This
function may safely be used in a multi-threaded program if and only
if they are called while the invoking thread owns the (FILE *)
object, as is the case after a successful call to the flockfile() or
ftrylockfile() functions. If threads are disabled, then
<<fwrite_unlocked>> is equivalent to <<fwrite>>.
<<_fwrite_r>> and <<_fwrite_unlocked_r>> are simply reentrant versions of the
above that take an additional reentrant structure argument: <[ptr]>.
RETURNS
If <<fwrite>> succeeds in writing all the elements you specify, the
result is the same as the argument <[count]>. In any event, the
result is the number of complete elements that <<fwrite>> copied to
the file.
PORTABILITY
ANSI C requires <<fwrite>>.
<<fwrite_unlocked>> is a BSD extension also provided by GNU libc.
Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
<<lseek>>, <<read>>, <<sbrk>>, <<write>>.
*/
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "%W% (Berkeley) %G%";
#endif /* LIBC_SCCS and not lint */
#include <_ansi.h>
#include <stdio.h>
#include <string.h>
#if 0
#include <sys/stdc.h>
#endif
#include "local.h"
#if 1
#include "fvwrite.h"
#endif
#ifdef __IMPL_UNLOCKED__
#define _fwrite_r _fwrite_unlocked_r
#define fwrite fwrite_unlocked
#endif
/*
* Write `count' objects (each size `size') from memory to the given file.
* Return the number of whole objects written.
*/
#pragma GCC push_option
#pragma GCC optimize("O0")
size_t
_DEFUN(_fwrite_r, (ptr, buf, size, count, fp),
struct _reent * ptr _AND
_CONST _PTR __restrict buf _AND
size_t size _AND
size_t count _AND
FILE * __restrict fp)
{
size_t n;
#ifdef _FVWRITE_IN_STREAMIO
struct __suio uio = {0, 0, 0};
struct __siov iov;
iov.iov_base = buf;
uio.uio_resid = iov.iov_len = n = count * size;
uio.uio_iov = &iov;
uio.uio_iovcnt = 1;
/*
* The usual case is success (__sfvwrite_r returns 0);
* skip the divide if this happens, since divides are
* generally slow and since this occurs whenever size==0.
*/
CHECK_INIT(ptr, fp);
_newlib_flockfile_start (fp);
ORIENT (fp, -1);
if (__sfvwrite_r (ptr, fp, &uio) == 0)
{
_newlib_flockfile_exit (fp);
return count;
}
_newlib_flockfile_end (fp);
return (n - uio.uio_resid) / size;
#else
size_t i = 0;
_CONST char *p = buf;
n = count * size;
CHECK_INIT (ptr, fp);
_newlib_flockfile_start (fp);
ORIENT (fp, -1);
/* Make sure we can write. */
if (cantwrite (ptr, fp))
goto ret;
while (i < n)
{
if (__sputc_r (ptr, p[i], fp) == EOF)
break;
i++;
}
ret:
_newlib_flockfile_end (fp);
return i / size;
#endif
}
#pragma GCC pop_option
#ifndef _REENT_ONLY
size_t
_DEFUN(fwrite, (buf, size, count, fp),
_CONST _PTR __restrict buf _AND
size_t size _AND
size_t count _AND
FILE * fp)
{
return _fwrite_r (_REENT, buf, size, count, fp);
}
#endif

View File

@ -0,0 +1,352 @@
/*
* 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.
*
* %W% (UofMD/Berkeley) %G%
*/
/*
* Information local to this implementation of stdio,
* in particular, macros and private variables.
*/
#include <_ansi.h>
#include <reent.h>
#include <stdarg.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#ifdef __SCLE
# include <io.h>
#endif
/* The following define determines if the per-reent stdin, stdout and stderr
streams are closed during _reclaim_reent(). The stdin, stdout and stderr
streams are initialized to use file descriptors 0, 1 and 2 respectively. In
case _STDIO_CLOSE_PER_REENT_STD_STREAMS is defined these file descriptors
will be closed via close() provided the owner of the reent structure
triggerd the on demand reent initilization, see CHECK_INIT(). */
#if !defined(__rtems__) && !defined(__tirtos__)
#define _STDIO_CLOSE_PER_REENT_STD_STREAMS
#endif
/* The following macros are supposed to replace calls to _flockfile/_funlockfile
and __sfp_lock_acquire/__sfp_lock_release. In case of multi-threaded
environments using pthreads, it's not sufficient to lock the stdio functions
against concurrent threads accessing the same data, the locking must also be
secured against thread cancellation.
The below macros have to be used in pairs. The _newlib_XXX_start macro
starts with a opening curly brace, the _newlib_XXX_end macro ends with a
closing curly brace, so the start macro and the end macro mark the code
start and end of a critical section. In case the code leaves the critical
section before reaching the end of the critical section's code end, use
the appropriate _newlib_XXX_exit macro. */
#if !defined (__SINGLE_THREAD__) && defined (_POSIX_THREADS) \
&& !defined (__rtems__)
#define _STDIO_WITH_THREAD_CANCELLATION_SUPPORT
#endif
#if defined(__SINGLE_THREAD__) || defined(__IMPL_UNLOCKED__)
# define _newlib_flockfile_start(_fp)
# define _newlib_flockfile_exit(_fp)
# define _newlib_flockfile_end(_fp)
# define _newlib_sfp_lock_start()
# define _newlib_sfp_lock_exit()
# define _newlib_sfp_lock_end()
#elif defined(_STDIO_WITH_THREAD_CANCELLATION_SUPPORT)
#include <pthread.h>
/* Start a stream oriented critical section: */
# define _newlib_flockfile_start(_fp) \
{ \
int __oldfpcancel; \
pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, &__oldfpcancel); \
if (!(_fp->_flags2 & __SNLK)) \
_flockfile (_fp)
/* Exit from a stream oriented critical section prematurely: */
# define _newlib_flockfile_exit(_fp) \
if (!(_fp->_flags2 & __SNLK)) \
_funlockfile (_fp); \
pthread_setcancelstate (__oldfpcancel, &__oldfpcancel);
/* End a stream oriented critical section: */
# define _newlib_flockfile_end(_fp) \
if (!(_fp->_flags2 & __SNLK)) \
_funlockfile (_fp); \
pthread_setcancelstate (__oldfpcancel, &__oldfpcancel); \
}
/* Start a stream list oriented critical section: */
# define _newlib_sfp_lock_start() \
{ \
int __oldsfpcancel; \
pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, &__oldsfpcancel); \
__sfp_lock_acquire ()
/* Exit from a stream list oriented critical section prematurely: */
# define _newlib_sfp_lock_exit() \
__sfp_lock_release (); \
pthread_setcancelstate (__oldsfpcancel, &__oldsfpcancel);
/* End a stream list oriented critical section: */
# define _newlib_sfp_lock_end() \
__sfp_lock_release (); \
pthread_setcancelstate (__oldsfpcancel, &__oldsfpcancel); \
}
#else /* !__SINGLE_THREAD__ && !__IMPL_UNLOCKED__ && !_STDIO_WITH_THREAD_CANCELLATION_SUPPORT */
# define _newlib_flockfile_start(_fp) \
{ \
if (!(_fp->_flags2 & __SNLK)) \
_flockfile (_fp)
# define _newlib_flockfile_exit(_fp) \
if (!(_fp->_flags2 & __SNLK)) \
_funlockfile(_fp); \
# define _newlib_flockfile_end(_fp) \
if (!(_fp->_flags2 & __SNLK)) \
_funlockfile(_fp); \
}
# define _newlib_sfp_lock_start() \
{ \
__sfp_lock_acquire ()
# define _newlib_sfp_lock_exit() \
__sfp_lock_release ();
# define _newlib_sfp_lock_end() \
__sfp_lock_release (); \
}
#endif /* __SINGLE_THREAD__ || __IMPL_UNLOCKED__ */
extern wint_t _EXFUN(__fgetwc, (struct _reent *, FILE *));
extern wint_t _EXFUN(__fputwc, (struct _reent *, wchar_t, FILE *));
extern u_char *_EXFUN(__sccl, (char *, u_char *fmt));
extern int _EXFUN(__svfscanf_r,(struct _reent *,FILE *, _CONST char *,va_list));
extern int _EXFUN(__ssvfscanf_r,(struct _reent *,FILE *, _CONST char *,va_list));
extern int _EXFUN(__svfiscanf_r,(struct _reent *,FILE *, _CONST char *,va_list));
extern int _EXFUN(__ssvfiscanf_r,(struct _reent *,FILE *, _CONST char *,va_list));
extern int _EXFUN(__svfwscanf_r,(struct _reent *,FILE *, _CONST wchar_t *,va_list));
extern int _EXFUN(__ssvfwscanf_r,(struct _reent *,FILE *, _CONST wchar_t *,va_list));
extern int _EXFUN(__svfiwscanf_r,(struct _reent *,FILE *, _CONST wchar_t *,va_list));
extern int _EXFUN(__ssvfiwscanf_r,(struct _reent *,FILE *, _CONST wchar_t *,va_list));
int _EXFUN(_svfprintf_r,(struct _reent *, FILE *, const char *,
va_list)
_ATTRIBUTE ((__format__ (__printf__, 3, 0))));
int _EXFUN(_svfiprintf_r,(struct _reent *, FILE *, const char *,
va_list)
_ATTRIBUTE ((__format__ (__printf__, 3, 0))));
int _EXFUN(_svfwprintf_r,(struct _reent *, FILE *, const wchar_t *,
va_list));
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 *));
#ifdef _STDIO_BSD_SEMANTICS
extern int _EXFUN(__sflushw_r,(struct _reent *,FILE *));
#endif
extern int _EXFUN(__srefill_r,(struct _reent *,FILE *));
extern _READ_WRITE_RETURN_TYPE _EXFUN(__sread,(struct _reent *, void *, char *,
_READ_WRITE_BUFSIZE_TYPE));
extern _READ_WRITE_RETURN_TYPE _EXFUN(__seofread,(struct _reent *, void *,
char *,
_READ_WRITE_BUFSIZE_TYPE));
extern _READ_WRITE_RETURN_TYPE _EXFUN(__swrite,(struct _reent *, void *,
const char *,
_READ_WRITE_BUFSIZE_TYPE));
extern _fpos_t _EXFUN(__sseek,(struct _reent *, void *, _fpos_t, int));
extern int _EXFUN(__sclose,(struct _reent *, void *));
extern int _EXFUN(__stextmode,(int));
extern _VOID _EXFUN(__sinit,(struct _reent *));
extern _VOID _EXFUN(_cleanup_r,(struct _reent *));
extern _VOID _EXFUN(__smakebuf_r,(struct _reent *, FILE *));
extern int _EXFUN(__swhatbuf_r,(struct _reent *, FILE *, size_t *, int *));
extern int _EXFUN(_fwalk,(struct _reent *, int (*)(FILE *)));
extern int _EXFUN(_fwalk_reent,(struct _reent *, int (*)(struct _reent *, FILE *)));
struct _glue * _EXFUN(__sfmoreglue,(struct _reent *,int n));
extern int _EXFUN(__submore, (struct _reent *, FILE *));
#ifdef __LARGE64_FILES
extern _fpos64_t _EXFUN(__sseek64,(struct _reent *, void *, _fpos64_t, int));
extern _READ_WRITE_RETURN_TYPE _EXFUN(__swrite64,(struct _reent *, void *,
const char *,
_READ_WRITE_BUFSIZE_TYPE));
#endif
/* Called by the main entry point fns to ensure stdio has been initialized. */
#ifdef _REENT_SMALL
#define CHECK_INIT(ptr, fp) \
do \
{ \
struct _reent *_check_init_ptr = (ptr); \
if ((_check_init_ptr) && !(_check_init_ptr)->__sdidinit) \
__sinit (_check_init_ptr); \
if ((fp) == (FILE *)&__sf_fake_stdin) \
(fp) = _stdin_r(_check_init_ptr); \
else if ((fp) == (FILE *)&__sf_fake_stdout) \
(fp) = _stdout_r(_check_init_ptr); \
else if ((fp) == (FILE *)&__sf_fake_stderr) \
(fp) = _stderr_r(_check_init_ptr); \
} \
while (0)
#else /* !_REENT_SMALL */
#define CHECK_INIT(ptr, fp) \
do \
{ \
struct _reent *_check_init_ptr = (ptr); \
if ((_check_init_ptr) && !(_check_init_ptr)->__sdidinit) \
__sinit (_check_init_ptr); \
} \
while (0)
#endif /* !_REENT_SMALL */
#define CHECK_STD_INIT(ptr) \
do \
{ \
struct _reent *_check_init_ptr = (ptr); \
if ((_check_init_ptr) && !(_check_init_ptr)->__sdidinit) \
__sinit (_check_init_ptr); \
} \
while (0)
/* 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) && \
__swsetup_r(ptr, fp))
/* Test whether the given stdio file has an active ungetc buffer;
release such a buffer, without restoring ordinary unread data. */
#define HASUB(fp) ((fp)->_ub._base != NULL)
#define FREEUB(ptr, fp) { \
if ((fp)->_ub._base != (fp)->_ubuf) \
_free_r(ptr, (char *)(fp)->_ub._base); \
(fp)->_ub._base = NULL; \
}
/* Test for an fgetline() buffer. */
#define HASLB(fp) ((fp)->_lb._base != NULL)
#define FREELB(ptr, fp) { _free_r(ptr,(char *)(fp)->_lb._base); \
(fp)->_lb._base = NULL; }
#ifdef _WIDE_ORIENT
/*
* Set the orientation for a stream. If o > 0, the stream has wide-
* orientation. If o < 0, the stream has byte-orientation.
*/
#define ORIENT(fp,ori) \
do \
{ \
if (!((fp)->_flags & __SORD)) \
{ \
(fp)->_flags |= __SORD; \
if (ori > 0) \
(fp)->_flags2 |= __SWID; \
else \
(fp)->_flags2 &= ~__SWID; \
} \
} \
while (0)
#else
#define ORIENT(fp,ori)
#endif
/* WARNING: _dcvt is defined in the stdlib directory, not here! */
char *_EXFUN(_dcvt,(struct _reent *, char *, double, int, int, char, int));
char *_EXFUN(_sicvt,(char *, short, char));
char *_EXFUN(_icvt,(char *, int, char));
char *_EXFUN(_licvt,(char *, long, char));
#ifdef __GNUC__
char *_EXFUN(_llicvt,(char *, long long, char));
#endif
#define CVT_BUF_SIZE 128
#define NDYNAMIC 4 /* add four more whenever necessary */
#ifdef __SINGLE_THREAD__
#define __sfp_lock_acquire()
#define __sfp_lock_release()
#define __sinit_lock_acquire()
#define __sinit_lock_release()
#else
_VOID _EXFUN(__sfp_lock_acquire,(_VOID));
_VOID _EXFUN(__sfp_lock_release,(_VOID));
_VOID _EXFUN(__sinit_lock_acquire,(_VOID));
_VOID _EXFUN(__sinit_lock_release,(_VOID));
#endif
/* Types used in positional argument support in vfprinf/vfwprintf.
The implementation is char/wchar_t dependent but the class and state
tables are only defined once in vfprintf.c. */
typedef enum __packed {
ZERO, /* '0' */
DIGIT, /* '1-9' */
DOLLAR, /* '$' */
MODFR, /* spec modifier */
SPEC, /* format specifier */
DOT, /* '.' */
STAR, /* '*' */
FLAG, /* format flag */
OTHER, /* all other chars */
MAX_CH_CLASS /* place-holder */
} __CH_CLASS;
typedef enum __packed {
START, /* start */
SFLAG, /* seen a flag */
WDIG, /* seen digits in width area */
WIDTH, /* processed width */
SMOD, /* seen spec modifier */
SDOT, /* seen dot */
VARW, /* have variable width specifier */
VARP, /* have variable precision specifier */
PREC, /* processed precision */
VWDIG, /* have digits in variable width specification */
VPDIG, /* have digits in variable precision specification */
DONE, /* done */
MAX_STATE, /* place-holder */
} __STATE;
typedef enum __packed {
NOOP, /* do nothing */
NUMBER, /* build a number from digits */
SKIPNUM, /* skip over digits */
GETMOD, /* get and process format modifier */
GETARG, /* get and process argument */
GETPW, /* get variable precision or width */
GETPWB, /* get variable precision or width and pushback fmt char */
GETPOS, /* get positional parameter value */
PWPOS, /* get positional parameter value for variable width or precision */
} __ACTION;
extern _CONST __CH_CLASS __chclass[256];
extern _CONST __STATE __state_table[MAX_STATE][MAX_CH_CLASS];
extern _CONST __ACTION __action_table[MAX_STATE][MAX_CH_CLASS];

View File

@ -0,0 +1,148 @@
/*
* 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
<<puts>>---write a character string
INDEX
puts
INDEX
_puts_r
ANSI_SYNOPSIS
#include <stdio.h>
int puts(const char *<[s]>);
int _puts_r(struct _reent *<[reent]>, const char *<[s]>);
TRAD_SYNOPSIS
#include <stdio.h>
int puts(<[s]>)
char *<[s]>;
int _puts_r(<[reent]>, <[s]>)
struct _reent *<[reent]>;
char *<[s]>;
DESCRIPTION
<<puts>> writes the string at <[s]> (followed by a newline, instead of
the trailing null) to the standard output stream.
The alternate function <<_puts_r>> is a reentrant version. The extra
argument <[reent]> is a pointer to a reentrancy structure.
RETURNS
If successful, the result is a nonnegative integer; otherwise, the
result is <<EOF>>.
PORTABILITY
ANSI C requires <<puts>>, but does not specify that the result on
success must be <<0>>; any non-negative value is permitted.
Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
<<lseek>>, <<read>>, <<sbrk>>, <<write>>.
*/
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "%W% (Berkeley) %G%";
#endif /* LIBC_SCCS and not lint */
#include <_ansi.h>
#include <reent.h>
#include <stdio.h>
#include <string.h>
#include "fvwrite.h"
#include "local.h"
/*
* Write the given string to stdout, appending a newline.
*/
#pragma GCC push_option
#pragma GCC optimize("O0")
int
_DEFUN(_puts_r, (ptr, s),
struct _reent *ptr _AND
_CONST char * s)
{
#ifdef _FVWRITE_IN_STREAMIO
int result;
size_t c = strlen (s);
struct __suio uio = {0, 0, 0};
struct __siov iov[2];
FILE *fp;
iov[0].iov_base = s;
iov[0].iov_len = c;
iov[1].iov_base = "\n";
iov[1].iov_len = 1;
uio.uio_resid = c + 1;
uio.uio_iov = &iov[0];
uio.uio_iovcnt = 2;
_REENT_SMALL_CHECK_INIT (ptr);
fp = _stdout_r (ptr);
CHECK_INIT (ptr, fp);
_newlib_flockfile_start (fp);
ORIENT (fp, -1);
result = (__sfvwrite_r (ptr, fp, &uio) ? EOF : '\n');
_newlib_flockfile_end (fp);
return result;
#else
int result = EOF;
const char *p = s;
FILE *fp;
_REENT_SMALL_CHECK_INIT (ptr);
fp = _stdout_r (ptr);
CHECK_INIT (ptr, fp);
_newlib_flockfile_start (fp);
ORIENT (fp, -1);
/* Make sure we can write. */
if (cantwrite (ptr, fp))
goto err;
while (*p)
{
if (__sputc_r (ptr, *p++, fp) == EOF)
goto err;
}
if (__sputc_r (ptr, '\n', fp) == EOF)
goto err;
result = '\n';
err:
_newlib_flockfile_end (fp);
return result;
#endif
}
#pragma GCC pop_option
#ifndef _REENT_ONLY
int
_DEFUN(puts, (s),
char _CONST * s)
{
return _puts_r (_REENT, s);
}
#endif

View File

@ -0,0 +1,284 @@
/****************************************************************
*
* The author of this software is David M. Gay.
*
* Copyright (c) 1991 by AT&T.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose without fee is hereby granted, provided that this entire notice
* is included in all copies of any software which is or includes a copy
* or modification of this software and in all copies of the supporting
* documentation for such software.
*
* THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTY. IN PARTICULAR, NEITHER THE AUTHOR NOR AT&T MAKES ANY
* REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY
* OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
*
***************************************************************/
/* Please send bug reports to
David M. Gay
AT&T Bell Laboratories, Room 2C-463
600 Mountain Avenue
Murray Hill, NJ 07974-2070
U.S.A.
dmg@research.att.com or research!dmg
*/
/* This header file is a modification of mprec.h that only contains floating
point union code. */
#include <newlib.h>
#include <ieeefp.h>
#include <math.h>
#include <float.h>
#include <errno.h>
#include <sys/config.h>
#include <sys/cdefs.h>
#ifdef __IEEE_LITTLE_ENDIAN
#define IEEE_8087
#endif
#ifdef __IEEE_BIG_ENDIAN
#define IEEE_MC68k
#endif
#ifdef __Z8000__
#define Just_16
#endif
#ifdef Unsigned_Shifts
#define Sign_Extend(a,b) if (b < 0) a |= (__uint32_t)0xffff0000;
#else
#define Sign_Extend(a,b) /*no-op*/
#endif
#if defined(IEEE_8087) + defined(IEEE_MC68k) + defined(VAX) + defined(IBM) != 1
Exactly one of IEEE_8087, IEEE_MC68k, VAX, or IBM should be defined.
#endif
#ifdef _WANT_IO_LONG_DOUBLE
/* If we are going to examine or modify specific bits in a long double using
the lword0 or lwordx macros, then we must wrap the long double inside
a union. This is necessary to avoid undefined behavior according to
the ANSI C spec. */
#ifdef IEEE_8087
#if LDBL_MANT_DIG == 24
struct ldieee
{
unsigned manh:23;
unsigned exp:8;
unsigned sign:1;
} __packed;
#elif LDBL_MANT_DIG == 53
struct ldieee
{
unsigned manl:20;
unsigned manh:32;
unsigned exp:11;
unsigned sign:1;
} __packed;
#elif LDBL_MANT_DIG == 64
struct ldieee
{
unsigned manl:32;
unsigned manh:32;
unsigned exp:15;
unsigned sign:1;
} __packed;
#elif LDBL_MANT_DIG > 64
struct ldieee
{
unsigned manl3:16;
unsigned manl2:32;
unsigned manl:32;
unsigned manh:32;
unsigned exp:15;
unsigned sign:1;
} __packed;
#endif /* LDBL_MANT_DIG */
#else /* !IEEE_8087 */
#if LDBL_MANT_DIG == 24
struct ldieee
{
unsigned sign:1;
unsigned exp:8;
unsigned manh:23;
} __packed;
#elif LDBL_MANT_DIG == 53
struct ldieee
{
unsigned sign:1;
unsigned exp:11;
unsigned manh:32;
unsigned manl:20;
} __packed;
#elif LDBL_MANT_DIG == 64
struct ldieee
{
unsigned sign:1;
unsigned exp:15;
unsigned manh:32;
unsigned manl:32;
} __packed;
#elif LDBL_MANT_DIG > 64
struct ldieee
{
unsigned sign:1;
unsigned exp:15;
unsigned manh:32;
unsigned manl:32;
unsigned manl2:32;
unsigned manl3:16;
} __packed;
#endif /* LDBL_MANT_DIG */
#endif /* !IEEE_8087 */
#endif /* _WANT_IO_LONG_DOUBLE */
/* If we are going to examine or modify specific bits in a double using
the word0 and/or word1 macros, then we must wrap the double inside
a union. This is necessary to avoid undefined behavior according to
the ANSI C spec. */
union double_union
{
double d;
__uint32_t i[2];
};
#ifdef IEEE_8087
#define word0(x) (x.i[1])
#define word1(x) (x.i[0])
#else
#define word0(x) (x.i[0])
#define word1(x) (x.i[1])
#endif
/* #define P DBL_MANT_DIG */
/* Ten_pmax = floor(P*log(2)/log(5)) */
/* Bletch = (highest power of 2 < DBL_MAX_10_EXP) / 16 */
/* Quick_max = floor((P-1)*log(FLT_RADIX)/log(10) - 1) */
/* Int_max = floor(P*log(FLT_RADIX)/log(10) - 1) */
#if defined(IEEE_8087) + defined(IEEE_MC68k)
#if defined (_DOUBLE_IS_32BITS)
#define Exp_shift 23
#define Exp_shift1 23
#define Exp_msk1 ((__uint32_t)0x00800000L)
#define Exp_msk11 ((__uint32_t)0x00800000L)
#define Exp_mask ((__uint32_t)0x7f800000L)
#define P 24
#define Bias 127
#define IEEE_Arith
#define Emin (-126)
#define Exp_1 ((__uint32_t)0x3f800000L)
#define Exp_11 ((__uint32_t)0x3f800000L)
#define Ebits 8
#define Frac_mask ((__uint32_t)0x007fffffL)
#define Frac_mask1 ((__uint32_t)0x007fffffL)
#define Ten_pmax 10
#define Sign_bit ((__uint32_t)0x80000000L)
#define Ten_pmax 10
#define Bletch 2
#define Bndry_mask ((__uint32_t)0x007fffffL)
#define Bndry_mask1 ((__uint32_t)0x007fffffL)
#define LSB 1
#define Sign_bit ((__uint32_t)0x80000000L)
#define Log2P 1
#define Tiny0 0
#define Tiny1 1
#define Quick_max 5
#define Int_max 6
#define Infinite(x) (word0(x) == ((__uint32_t)0x7f800000L))
#undef word0
#undef word1
#define word0(x) (x.i[0])
#define word1(x) 0
#else
#define Exp_shift 20
#define Exp_shift1 20
#define Exp_msk1 ((__uint32_t)0x100000L)
#define Exp_msk11 ((__uint32_t)0x100000L)
#define Exp_mask ((__uint32_t)0x7ff00000L)
#define P 53
#define Bias 1023
#define IEEE_Arith
#define Emin (-1022)
#define Exp_1 ((__uint32_t)0x3ff00000L)
#define Exp_11 ((__uint32_t)0x3ff00000L)
#define Ebits 11
#define Frac_mask ((__uint32_t)0xfffffL)
#define Frac_mask1 ((__uint32_t)0xfffffL)
#define Ten_pmax 22
#define Bletch 0x10
#define Bndry_mask ((__uint32_t)0xfffffL)
#define Bndry_mask1 ((__uint32_t)0xfffffL)
#define LSB 1
#define Sign_bit ((__uint32_t)0x80000000L)
#define Log2P 1
#define Tiny0 0
#define Tiny1 1
#define Quick_max 14
#define Int_max 14
#define Infinite(x) (word0(x) == ((__uint32_t)0x7ff00000L)) /* sufficient test for here */
#endif
#else
#undef Sudden_Underflow
#define Sudden_Underflow
#ifdef IBM
#define Exp_shift 24
#define Exp_shift1 24
#define Exp_msk1 ((__uint32_t)0x1000000L)
#define Exp_msk11 ((__uint32_t)0x1000000L)
#define Exp_mask ((__uint32_t)0x7f000000L)
#define P 14
#define Bias 65
#define Exp_1 ((__uint32_t)0x41000000L)
#define Exp_11 ((__uint32_t)0x41000000L)
#define Ebits 8 /* exponent has 7 bits, but 8 is the right value in b2d */
#define Frac_mask ((__uint32_t)0xffffffL)
#define Frac_mask1 ((__uint32_t)0xffffffL)
#define Bletch 4
#define Ten_pmax 22
#define Bndry_mask ((__uint32_t)0xefffffL)
#define Bndry_mask1 ((__uint32_t)0xffffffL)
#define LSB 1
#define Sign_bit ((__uint32_t)0x80000000L)
#define Log2P 4
#define Tiny0 ((__uint32_t)0x100000L)
#define Tiny1 0
#define Quick_max 14
#define Int_max 15
#else /* VAX */
#define Exp_shift 23
#define Exp_shift1 7
#define Exp_msk1 0x80
#define Exp_msk11 ((__uint32_t)0x800000L)
#define Exp_mask ((__uint32_t)0x7f80L)
#define P 56
#define Bias 129
#define Exp_1 ((__uint32_t)0x40800000L)
#define Exp_11 ((__uint32_t)0x4080L)
#define Ebits 8
#define Frac_mask ((__uint32_t)0x7fffffL)
#define Frac_mask1 ((__uint32_t)0xffff007fL)
#define Ten_pmax 24
#define Bletch 2
#define Bndry_mask ((__uint32_t)0xffff007fL)
#define Bndry_mask1 ((__uint32_t)0xffff007fL)
#define LSB ((__uint32_t)0x10000L)
#define Sign_bit ((__uint32_t)0x8000L)
#define Log2P 1
#define Tiny0 0x80
#define Tiny1 0
#define Quick_max 15
#define Int_max 15
#endif
#endif

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,101 @@
/*
* 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.
*/
/* No user fns here. Pesch 15apr92. */
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "%W% (Berkeley) %G%";
#endif /* LIBC_SCCS and not lint */
#include <_ansi.h>
#include <stdio.h>
#include <errno.h>
#include "local.h"
#include "fvwrite.h"
/*
* Write the given character into the (probably full) buffer for
* the given file. Flush the buffer out if it is or becomes full,
* or if c=='\n' and the file is line buffered.
*/
#pragma GCC push_option
#pragma GCC optimize("O0")
int
_DEFUN(__swbuf_r, (ptr, c, fp),
struct _reent *ptr _AND
register int c _AND
register FILE *fp)
{
register int n;
/* Ensure stdio has been initialized. */
CHECK_INIT (ptr, fp);
/*
* In case we cannot write, or longjmp takes us out early,
* make sure _w is 0 (if fully- or un-buffered) or -_bf._size
* (if line buffered) so that we will get called again.
* If we did not do this, a sufficient number of putc()
* calls might wrap _w from negative to positive.
*/
fp->_w = fp->_lbfsize;
if (cantwrite (ptr, fp))
return EOF;
c = (unsigned char) c;
ORIENT (fp, -1);
/*
* If it is completely full, flush it out. Then, in any case,
* stuff c into the buffer. If this causes the buffer to fill
* completely, or if c is '\n' and the file is line buffered,
* flush it (perhaps a second time). The second flush will always
* happen on unbuffered streams, where _bf._size==1; fflush()
* guarantees that putc() will always call wbuf() by setting _w
* to 0, so we need not do anything else.
*/
n = fp->_p - fp->_bf._base;
if (n >= fp->_bf._size)
{
if (_fflush_r (ptr, fp))
return EOF;
n = 0;
}
fp->_w--;
*fp->_p++ = c;
if (++n == fp->_bf._size || (fp->_flags & __SLBF && c == '\n'))
if (_fflush_r (ptr, fp))
return EOF;
return c;
}
#pragma GCC pop_option
/* This function isn't any longer declared in stdio.h, but it's
required for backward compatibility with applications built against
earlier dynamically built newlib libraries. */
int
_DEFUN(__swbuf, (c, fp),
register int c _AND
register FILE *fp)
{
return __swbuf_r (_REENT, c, fp);
}