jehanne: use upstream print functions with -O0 and --disable-newlib-fvwrite-in-streamio

This commit is contained in:
Giacomo Tesio 2017-04-27 23:48:43 +02:00
parent 34fe847918
commit 6ba8da3d11
11 changed files with 5 additions and 5549 deletions

View File

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

View File

@ -11,8 +11,8 @@ 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 \
fputs.c fputws.c fvwrite.c fwrite.c puts.c vfprintf.c vfwprintf.c wbuf.c
calloc.c callocr.c realloc.c reallocr.c
lib_a_LIBADD = $(extra_objs)
EXTRA_lib_a_SOURCES = libposix_conf.c syscalls.c
lib_a_DEPENDENCIES = $(extra_objs)

View File

@ -57,11 +57,7 @@ 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-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-realloc.$(OBJEXT) lib_a-reallocr.$(OBJEXT)
lib_a_OBJECTS = $(am_lib_a_OBJECTS)
DEFAULT_INCLUDES = -I.@am__isrc@
depcomp =
@ -183,8 +179,7 @@ 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 \
fputs.c fputws.c fvwrite.c fwrite.c puts.c vfprintf.c vfwprintf.c wbuf.c
calloc.c callocr.c realloc.c reallocr.c
lib_a_LIBADD = $(extra_objs)
EXTRA_lib_a_SOURCES = libposix_conf.c syscalls.c
@ -315,54 +310,6 @@ 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

@ -1,173 +0,0 @@
/*
* 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

@ -1,198 +0,0 @@
/*-
* 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

@ -1,271 +0,0 @@
/*
* 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

@ -1,218 +0,0 @@
/*
* 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

@ -1,148 +0,0 @@
/*
* 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

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,101 +0,0 @@
/*
* 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);
}