Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 6535 → Rev 6536

/contrib/sdk/sources/newlib/libc/stdio/clearerr_u.c
0,0 → 1,41
/*
* Copyright (c) 2014 Red Hat, Inc.
* 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.
*/
 
#include <_ansi.h>
#include <stdio.h>
#include "local.h"
 
/* A subroutine version of the macro clearerr_unlocked. */
 
#undef clearerr_unlocked
 
_VOID
_DEFUN(clearerr_unlocked, (fp),
FILE * fp)
{
CHECK_INIT(_REENT, fp);
__sclearerr (fp);
}
/contrib/sdk/sources/newlib/libc/stdio/fcloseall.c
0,0 → 1,81
/*
* 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
<<fcloseall>>---close all files
 
INDEX
fcloseall
INDEX
_fcloseall_r
 
ANSI_SYNOPSIS
#include <stdio.h>
int fcloseall(void);
int _fcloseall_r (struct _reent *<[ptr]>);
 
TRAD_SYNOPSIS
#include <stdio.h>
int fcloseall()
 
int _fcloseall_r (<[ptr]>)
struct _reent *<[ptr]>;
 
DESCRIPTION
<<fcloseall>> closes all files in the current reentrancy struct's domain.
The function <<_fcloseall_r>> is the same function, except the reentrancy
struct is passed in as the <[ptr]> argument.
 
This function is not recommended as it closes all streams, including
the std streams.
 
RETURNS
<<fclose>> returns <<0>> if all closes are successful. Otherwise,
EOF is returned.
 
PORTABILITY
<<fcloseall>> is a glibc extension.
 
Required OS subroutines: <<close>>, <<fstat>>, <<isatty>>, <<lseek>>,
<<read>>, <<sbrk>>, <<write>>.
*/
/* This file based upon fwalk.c. */
 
#include <_ansi.h>
#include <reent.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include "local.h"
 
int
_DEFUN(_fcloseall_r, (ptr),
struct _reent *ptr)
{
return _fwalk_reent (ptr, _fclose_r);
}
 
#ifndef _REENT_ONLY
 
int
_DEFUN_VOID(fcloseall)
{
return _fcloseall_r (_GLOBAL_REENT);
}
 
#endif
/contrib/sdk/sources/newlib/libc/stdio/feof_u.c
0,0 → 1,40
/*
* Copyright (c) 2014 Red Hat, Inc.
* 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.
*/
 
#include <stdio.h>
#include "local.h"
 
/* A subroutine version of the macro feof_unlocked. */
 
#undef feof_unlocked
 
int
_DEFUN(feof_unlocked, (fp),
FILE * fp)
{
CHECK_INIT(_REENT, fp);
return __sfeof (fp);
}
/contrib/sdk/sources/newlib/libc/stdio/ferror_u.c
0,0 → 1,41
/*
* Copyright (c) 2014 Red Hat, Inc.
* 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.
*/
 
#include <_ansi.h>
#include <stdio.h>
#include "local.h"
 
/* A subroutine version of the macro ferror_unlocked. */
 
#undef ferror_unlocked
 
int
_DEFUN(ferror_unlocked, (fp),
FILE * fp)
{
CHECK_INIT(_REENT, fp);
return __sferror (fp);
}
/contrib/sdk/sources/newlib/libc/stdio/fflush_u.c
0,0 → 1,28
/*
* Copyright (c) 2014 Red Hat, Inc.
* 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.
*/
 
#define __IMPL_UNLOCKED__
#include "fflush.c"
/contrib/sdk/sources/newlib/libc/stdio/fgetc_u.c
0,0 → 1,56
/*
* Copyright (c) 2014 Red Hat, Inc.
* 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.
*/
 
#include <_ansi.h>
#include <stdio.h>
#include "local.h"
 
int
_DEFUN(_fgetc_unlocked_r, (ptr, fp),
struct _reent * ptr _AND
FILE * fp)
{
CHECK_INIT(ptr, fp);
return __sgetc_r (ptr, fp);
}
 
#ifndef _REENT_ONLY
 
int
_DEFUN(fgetc_unlocked, (fp),
FILE * fp)
{
#if !defined(PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__)
struct _reent *reent = _REENT;
 
CHECK_INIT(reent, fp);
return __sgetc_r (reent, fp);
#else
return _fgetc_unlocked_r (_REENT, fp);
#endif
}
 
#endif /* !_REENT_ONLY */
/contrib/sdk/sources/newlib/libc/stdio/fgetpos.c
0,0 → 1,103
/*
* 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
<<fgetpos>>---record position in a stream or file
 
INDEX
fgetpos
INDEX
_fgetpos_r
 
ANSI_SYNOPSIS
#include <stdio.h>
int fgetpos(FILE *restrict <[fp]>, fpos_t *restrict <[pos]>);
int _fgetpos_r(struct _reent *<[ptr]>, FILE *restrict <[fp]>, fpos_t *restrict <[pos]>);
 
TRAD_SYNOPSIS
#include <stdio.h>
int fgetpos(<[fp]>, <[pos]>)
FILE *<[fp]>;
fpos_t *<[pos]>;
 
int _fgetpos_r(<[ptr]>, <[fp]>, <[pos]>)
struct _reent *<[ptr]>;
FILE *<[fp]>;
fpos_t *<[pos]>;
 
DESCRIPTION
Objects of type <<FILE>> can have a ``position'' that records how much
of the file your program has already read. Many of the <<stdio>> functions
depend on this position, and many change it as a side effect.
 
You can use <<fgetpos>> to report on the current position for a file
identified by <[fp]>; <<fgetpos>> will write a value
representing that position at <<*<[pos]>>>. Later, you can
use this value with <<fsetpos>> to return the file to this
position.
 
In the current implementation, <<fgetpos>> simply uses a character
count to represent the file position; this is the same number that
would be returned by <<ftell>>.
 
RETURNS
<<fgetpos>> returns <<0>> when successful. If <<fgetpos>> fails, the
result is <<1>>. Failure occurs on streams that do not support
positioning; the global <<errno>> indicates this condition with the
value <<ESPIPE>>.
 
PORTABILITY
<<fgetpos>> is required by the ANSI C standard, but the meaning of the
value it records is not specified beyond requiring that it be
acceptable as an argument to <<fsetpos>>. In particular, other
conforming C implementations may return a different result from
<<ftell>> than what <<fgetpos>> writes at <<*<[pos]>>>.
 
No supporting OS subroutines are required.
*/
 
#include <_ansi.h>
#include <reent.h>
#include <stdio.h>
 
int
_DEFUN(_fgetpos_r, (ptr, fp, pos),
struct _reent * ptr _AND
FILE *__restrict fp _AND
_fpos_t *__restrict pos)
{
*pos = _ftell_r (ptr, fp);
 
if (*pos != -1)
{
return 0;
}
return 1;
}
 
#ifndef _REENT_ONLY
 
int
_DEFUN(fgetpos, (fp, pos),
FILE *__restrict fp _AND
_fpos_t *__restrict pos)
{
return _fgetpos_r (_REENT, fp, pos);
}
 
#endif /* !_REENT_ONLY */
/contrib/sdk/sources/newlib/libc/stdio/fgets_u.c
0,0 → 1,28
/*
* Copyright (c) 2014 Red Hat, Inc.
* 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.
*/
 
#define __IMPL_UNLOCKED__
#include "fgets.c"
/contrib/sdk/sources/newlib/libc/stdio/fileno_u.c
0,0 → 1,46
/*
* Copyright (c) 2014 Red Hat, Inc.
* 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.
*/
 
#include <_ansi.h>
#include <stdio.h>
#include <errno.h>
#include "local.h"
 
int
_DEFUN(fileno_unlocked, (f),
FILE * f)
{
int result;
CHECK_INIT (_REENT, f);
if (f->_flags)
result = __sfileno (f);
else
{
result = -1;
_REENT->_errno = EBADF;
}
return result;
}
/contrib/sdk/sources/newlib/libc/stdio/findfp.c
267,25 → 267,25
_VOID
_DEFUN_VOID(__sfp_lock_acquire)
{
//__lock_acquire_recursive (__sfp_lock);
__lock_acquire_recursive (__sfp_lock);
}
 
_VOID
_DEFUN_VOID(__sfp_lock_release)
{
//__lock_release_recursive (__sfp_lock);
__lock_release_recursive (__sfp_lock);
}
 
_VOID
_DEFUN_VOID(__sinit_lock_acquire)
{
//__lock_acquire_recursive (__sinit_lock);
__lock_acquire_recursive (__sinit_lock);
}
 
_VOID
_DEFUN_VOID(__sinit_lock_release)
{
//__lock_release_recursive (__sinit_lock);
__lock_release_recursive (__sinit_lock);
}
 
/* Walkable file locking routine. */
/contrib/sdk/sources/newlib/libc/stdio/fmemopen.c
0,0 → 1,371
/* Copyright (C) 2007 Eric Blake
* Permission to use, copy, modify, and distribute this software
* is freely granted, provided that this notice is preserved.
*/
 
/*
FUNCTION
<<fmemopen>>---open a stream around a fixed-length string
 
INDEX
fmemopen
 
ANSI_SYNOPSIS
#include <stdio.h>
FILE *fmemopen(void *restrict <[buf]>, size_t <[size]>,
const char *restrict <[mode]>);
 
DESCRIPTION
<<fmemopen>> creates a seekable <<FILE>> stream that wraps a
fixed-length buffer of <[size]> bytes starting at <[buf]>. The stream
is opened with <[mode]> treated as in <<fopen>>, where append mode
starts writing at the first NUL byte. If <[buf]> is NULL, then
<[size]> bytes are automatically provided as if by <<malloc>>, with
the initial size of 0, and <[mode]> must contain <<+>> so that data
can be read after it is written.
 
The stream maintains a current position, which moves according to
bytes read or written, and which can be one past the end of the array.
The stream also maintains a current file size, which is never greater
than <[size]>. If <[mode]> starts with <<r>>, the position starts at
<<0>>, and file size starts at <[size]> if <[buf]> was provided. If
<[mode]> starts with <<w>>, the position and file size start at <<0>>,
and if <[buf]> was provided, the first byte is set to NUL. If
<[mode]> starts with <<a>>, the position and file size start at the
location of the first NUL byte, or else <[size]> if <[buf]> was
provided.
 
When reading, NUL bytes have no significance, and reads cannot exceed
the current file size. When writing, the file size can increase up to
<[size]> as needed, and NUL bytes may be embedded in the stream (see
<<open_memstream>> for an alternative that automatically enlarges the
buffer). When the stream is flushed or closed after a write that
changed the file size, a NUL byte is written at the current position
if there is still room; if the stream is not also open for reading, a
NUL byte is additionally written at the last byte of <[buf]> when the
stream has exceeded <[size]>, so that a write-only <[buf]> is always
NUL-terminated when the stream is flushed or closed (and the initial
<[size]> should take this into account). It is not possible to seek
outside the bounds of <[size]>. A NUL byte written during a flush is
restored to its previous value when seeking elsewhere in the string.
 
RETURNS
The return value is an open FILE pointer on success. On error,
<<NULL>> is returned, and <<errno>> will be set to EINVAL if <[size]>
is zero or <[mode]> is invalid, ENOMEM if <[buf]> was NULL and memory
could not be allocated, or EMFILE if too many streams are already
open.
 
PORTABILITY
This function is being added to POSIX 200x, but is not in POSIX 2001.
 
Supporting OS subroutines required: <<sbrk>>.
*/
 
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <sys/lock.h>
#include "local.h"
 
/* Describe details of an open memstream. */
typedef struct fmemcookie {
void *storage; /* storage to free on close */
char *buf; /* buffer start */
size_t pos; /* current position */
size_t eof; /* current file size */
size_t max; /* maximum file size */
char append; /* nonzero if appending */
char writeonly; /* 1 if write-only */
char saved; /* saved character that lived at pos before write-only NUL */
} fmemcookie;
 
/* Read up to non-zero N bytes into BUF from stream described by
COOKIE; return number of bytes read (0 on EOF). */
static _READ_WRITE_RETURN_TYPE
_DEFUN(fmemreader, (ptr, cookie, buf, n),
struct _reent *ptr _AND
void *cookie _AND
char *buf _AND
_READ_WRITE_BUFSIZE_TYPE n)
{
fmemcookie *c = (fmemcookie *) cookie;
/* Can't read beyond current size, but EOF condition is not an error. */
if (c->pos > c->eof)
return 0;
if (n >= c->eof - c->pos)
n = c->eof - c->pos;
memcpy (buf, c->buf + c->pos, n);
c->pos += n;
return n;
}
 
/* Write up to non-zero N bytes of BUF into the stream described by COOKIE,
returning the number of bytes written or EOF on failure. */
static _READ_WRITE_RETURN_TYPE
_DEFUN(fmemwriter, (ptr, cookie, buf, n),
struct _reent *ptr _AND
void *cookie _AND
const char *buf _AND
_READ_WRITE_BUFSIZE_TYPE n)
{
fmemcookie *c = (fmemcookie *) cookie;
int adjust = 0; /* true if at EOF, but still need to write NUL. */
 
/* Append always seeks to eof; otherwise, if we have previously done
a seek beyond eof, ensure all intermediate bytes are NUL. */
if (c->append)
c->pos = c->eof;
else if (c->pos > c->eof)
memset (c->buf + c->eof, '\0', c->pos - c->eof);
/* Do not write beyond EOF; saving room for NUL on write-only stream. */
if (c->pos + n > c->max - c->writeonly)
{
adjust = c->writeonly;
n = c->max - c->pos;
}
/* Now n is the number of bytes being modified, and adjust is 1 if
the last byte is NUL instead of from buf. Write a NUL if
write-only; or if read-write, eof changed, and there is still
room. When we are within the file contents, remember what we
overwrite so we can restore it if we seek elsewhere later. */
if (c->pos + n > c->eof)
{
c->eof = c->pos + n;
if (c->eof - adjust < c->max)
c->saved = c->buf[c->eof - adjust] = '\0';
}
else if (c->writeonly)
{
if (n)
{
c->saved = c->buf[c->pos + n - adjust];
c->buf[c->pos + n - adjust] = '\0';
}
else
adjust = 0;
}
c->pos += n;
if (n - adjust)
memcpy (c->buf + c->pos - n, buf, n - adjust);
else
{
ptr->_errno = ENOSPC;
return EOF;
}
return n;
}
 
/* Seek to position POS relative to WHENCE within stream described by
COOKIE; return resulting position or fail with EOF. */
static _fpos_t
_DEFUN(fmemseeker, (ptr, cookie, pos, whence),
struct _reent *ptr _AND
void *cookie _AND
_fpos_t pos _AND
int whence)
{
fmemcookie *c = (fmemcookie *) cookie;
#ifndef __LARGE64_FILES
off_t offset = (off_t) pos;
#else /* __LARGE64_FILES */
_off64_t offset = (_off64_t) pos;
#endif /* __LARGE64_FILES */
 
if (whence == SEEK_CUR)
offset += c->pos;
else if (whence == SEEK_END)
offset += c->eof;
if (offset < 0)
{
ptr->_errno = EINVAL;
offset = -1;
}
else if (offset > c->max)
{
ptr->_errno = ENOSPC;
offset = -1;
}
#ifdef __LARGE64_FILES
else if ((_fpos_t) offset != offset)
{
ptr->_errno = EOVERFLOW;
offset = -1;
}
#endif /* __LARGE64_FILES */
else
{
if (c->writeonly && c->pos < c->eof)
{
c->buf[c->pos] = c->saved;
c->saved = '\0';
}
c->pos = offset;
if (c->writeonly && c->pos < c->eof)
{
c->saved = c->buf[c->pos];
c->buf[c->pos] = '\0';
}
}
return (_fpos_t) offset;
}
 
/* Seek to position POS relative to WHENCE within stream described by
COOKIE; return resulting position or fail with EOF. */
#ifdef __LARGE64_FILES
static _fpos64_t
_DEFUN(fmemseeker64, (ptr, cookie, pos, whence),
struct _reent *ptr _AND
void *cookie _AND
_fpos64_t pos _AND
int whence)
{
_off64_t offset = (_off64_t) pos;
fmemcookie *c = (fmemcookie *) cookie;
if (whence == SEEK_CUR)
offset += c->pos;
else if (whence == SEEK_END)
offset += c->eof;
if (offset < 0)
{
ptr->_errno = EINVAL;
offset = -1;
}
else if (offset > c->max)
{
ptr->_errno = ENOSPC;
offset = -1;
}
else
{
if (c->writeonly && c->pos < c->eof)
{
c->buf[c->pos] = c->saved;
c->saved = '\0';
}
c->pos = offset;
if (c->writeonly && c->pos < c->eof)
{
c->saved = c->buf[c->pos];
c->buf[c->pos] = '\0';
}
}
return (_fpos64_t) offset;
}
#endif /* __LARGE64_FILES */
 
/* Reclaim resources used by stream described by COOKIE. */
static int
_DEFUN(fmemcloser, (ptr, cookie),
struct _reent *ptr _AND
void *cookie)
{
fmemcookie *c = (fmemcookie *) cookie;
_free_r (ptr, c->storage);
return 0;
}
 
/* Open a memstream around buffer BUF of SIZE bytes, using MODE.
Return the new stream, or fail with NULL. */
FILE *
_DEFUN(_fmemopen_r, (ptr, buf, size, mode),
struct _reent *ptr _AND
void *__restrict buf _AND
size_t size _AND
const char *__restrict mode)
{
FILE *fp;
fmemcookie *c;
int flags;
int dummy;
 
if ((flags = __sflags (ptr, mode, &dummy)) == 0)
return NULL;
if (!size || !(buf || flags & __SRW))
{
ptr->_errno = EINVAL;
return NULL;
}
if ((fp = __sfp (ptr)) == NULL)
return NULL;
if ((c = (fmemcookie *) _malloc_r (ptr, sizeof *c + (buf ? 0 : size)))
== NULL)
{
_newlib_sfp_lock_start ();
fp->_flags = 0; /* release */
#ifndef __SINGLE_THREAD__
__lock_close_recursive (fp->_lock);
#endif
_newlib_sfp_lock_end ();
return NULL;
}
 
c->storage = c;
c->max = size;
/* 9 modes to worry about. */
/* w/a, buf or no buf: Guarantee a NUL after any file writes. */
c->writeonly = (flags & __SWR) != 0;
c->saved = '\0';
if (!buf)
{
/* r+/w+/a+, and no buf: file starts empty. */
c->buf = (char *) (c + 1);
c->buf[0] = '\0';
c->pos = c->eof = 0;
c->append = (flags & __SAPP) != 0;
}
else
{
c->buf = (char *) buf;
switch (*mode)
{
case 'a':
/* a/a+ and buf: position and size at first NUL. */
buf = memchr (c->buf, '\0', size);
c->eof = c->pos = buf ? (char *) buf - c->buf : size;
if (!buf && c->writeonly)
/* a: guarantee a NUL within size even if no writes. */
c->buf[size - 1] = '\0';
c->append = 1;
break;
case 'r':
/* r/r+ and buf: read at beginning, full size available. */
c->pos = c->append = 0;
c->eof = size;
break;
case 'w':
/* w/w+ and buf: write at beginning, truncate to empty. */
c->pos = c->append = c->eof = 0;
*c->buf = '\0';
break;
default:
abort ();
}
}
 
_newlib_flockfile_start (fp);
fp->_file = -1;
fp->_flags = flags;
fp->_cookie = c;
fp->_read = flags & (__SRD | __SRW) ? fmemreader : NULL;
fp->_write = flags & (__SWR | __SRW) ? fmemwriter : NULL;
fp->_seek = fmemseeker;
#ifdef __LARGE64_FILES
fp->_seek64 = fmemseeker64;
fp->_flags |= __SL64;
#endif
fp->_close = fmemcloser;
_newlib_flockfile_end (fp);
return fp;
}
 
#ifndef _REENT_ONLY
FILE *
_DEFUN(fmemopen, (buf, size, mode),
void *__restrict buf _AND
size_t size _AND
const char *__restrict mode)
{
return _fmemopen_r (_REENT, buf, size, mode);
}
#endif /* !_REENT_ONLY */
/contrib/sdk/sources/newlib/libc/stdio/fopencookie.c
0,0 → 1,263
/* Copyright (C) 2007 Eric Blake
* Permission to use, copy, modify, and distribute this software
* is freely granted, provided that this notice is preserved.
*/
 
/*
FUNCTION
<<fopencookie>>---open a stream with custom callbacks
 
INDEX
fopencookie
 
ANSI_SYNOPSIS
#include <stdio.h>
FILE *fopencookie(const void *<[cookie]>, const char *<[mode]>,
cookie_io_functions_t <[functions]>);
 
DESCRIPTION
<<fopencookie>> creates a <<FILE>> stream where I/O is performed using
custom callbacks. The callbacks are registered via the structure:
 
typedef ssize_t (*cookie_read_function_t)(void *_cookie, char *_buf,
size_t _n);
typedef ssize_t (*cookie_write_function_t)(void *_cookie,
const char *_buf, size_t _n);
typedef int (*cookie_seek_function_t)(void *_cookie, off_t *_off,
int _whence);
typedef int (*cookie_close_function_t)(void *_cookie);
 
. typedef struct
. {
. cookie_read_function_t *read;
. cookie_write_function_t *write;
. cookie_seek_function_t *seek;
. cookie_close_function_t *close;
. } cookie_io_functions_t;
 
The stream is opened with <[mode]> treated as in <<fopen>>. The
callbacks <[functions.read]> and <[functions.write]> may only be NULL
when <[mode]> does not require them.
 
<[functions.read]> should return -1 on failure, or else the number of
bytes read (0 on EOF). It is similar to <<read>>, except that
<[cookie]> will be passed as the first argument.
 
<[functions.write]> should return -1 on failure, or else the number of
bytes written. It is similar to <<write>>, except that <[cookie]>
will be passed as the first argument.
 
<[functions.seek]> should return -1 on failure, and 0 on success, with
*<[_off]> set to the current file position. It is a cross between
<<lseek>> and <<fseek>>, with the <[_whence]> argument interpreted in
the same manner. A NULL <[functions.seek]> makes the stream behave
similarly to a pipe in relation to stdio functions that require
positioning.
 
<[functions.close]> should return -1 on failure, or 0 on success. It
is similar to <<close>>, except that <[cookie]> will be passed as the
first argument. A NULL <[functions.close]> merely flushes all data
then lets <<fclose>> succeed. A failed close will still invalidate
the stream.
 
Read and write I/O functions are allowed to change the underlying
buffer on fully buffered or line buffered streams by calling
<<setvbuf>>. They are also not required to completely fill or empty
the buffer. They are not, however, allowed to change streams from
unbuffered to buffered or to change the state of the line buffering
flag. They must also be prepared to have read or write calls occur on
buffers other than the one most recently specified.
 
RETURNS
The return value is an open FILE pointer on success. On error,
<<NULL>> is returned, and <<errno>> will be set to EINVAL if a
function pointer is missing or <[mode]> is invalid, ENOMEM if the
stream cannot be created, or EMFILE if too many streams are already
open.
 
PORTABILITY
This function is a newlib extension, copying the prototype from Linux.
It is not portable. See also the <<funopen>> interface from BSD.
 
Supporting OS subroutines required: <<sbrk>>.
*/
 
#define _GNU_SOURCE
#include <stdio.h>
#include <errno.h>
#include <sys/lock.h>
#include "local.h"
 
typedef struct fccookie {
void *cookie;
FILE *fp;
cookie_read_function_t *readfn;
cookie_write_function_t *writefn;
cookie_seek_function_t *seekfn;
cookie_close_function_t *closefn;
} fccookie;
 
static _READ_WRITE_RETURN_TYPE
_DEFUN(fcreader, (ptr, cookie, buf, n),
struct _reent *ptr _AND
void *cookie _AND
char *buf _AND
_READ_WRITE_BUFSIZE_TYPE n)
{
int result;
fccookie *c = (fccookie *) cookie;
errno = 0;
if ((result = c->readfn (c->cookie, buf, n)) < 0 && errno)
ptr->_errno = errno;
return result;
}
 
static _READ_WRITE_RETURN_TYPE
_DEFUN(fcwriter, (ptr, cookie, buf, n),
struct _reent *ptr _AND
void *cookie _AND
const char *buf _AND
_READ_WRITE_BUFSIZE_TYPE n)
{
int result;
fccookie *c = (fccookie *) cookie;
if (c->fp->_flags & __SAPP && c->fp->_seek)
{
#ifdef __LARGE64_FILES
c->fp->_seek64 (ptr, cookie, 0, SEEK_END);
#else
c->fp->_seek (ptr, cookie, 0, SEEK_END);
#endif
}
errno = 0;
if ((result = c->writefn (c->cookie, buf, n)) < 0 && errno)
ptr->_errno = errno;
return result;
}
 
static _fpos_t
_DEFUN(fcseeker, (ptr, cookie, pos, whence),
struct _reent *ptr _AND
void *cookie _AND
_fpos_t pos _AND
int whence)
{
fccookie *c = (fccookie *) cookie;
#ifndef __LARGE64_FILES
off_t offset = (off_t) pos;
#else /* __LARGE64_FILES */
_off64_t offset = (_off64_t) pos;
#endif /* __LARGE64_FILES */
 
errno = 0;
if (c->seekfn (c->cookie, &offset, whence) < 0 && errno)
ptr->_errno = errno;
#ifdef __LARGE64_FILES
else if ((_fpos_t)offset != offset)
{
ptr->_errno = EOVERFLOW;
offset = -1;
}
#endif /* __LARGE64_FILES */
return (_fpos_t) offset;
}
 
#ifdef __LARGE64_FILES
static _fpos64_t
_DEFUN(fcseeker64, (ptr, cookie, pos, whence),
struct _reent *ptr _AND
void *cookie _AND
_fpos64_t pos _AND
int whence)
{
_off64_t offset;
fccookie *c = (fccookie *) cookie;
errno = 0;
if (c->seekfn (c->cookie, &offset, whence) < 0 && errno)
ptr->_errno = errno;
return (_fpos64_t) offset;
}
#endif /* __LARGE64_FILES */
 
static int
_DEFUN(fccloser, (ptr, cookie),
struct _reent *ptr _AND
void *cookie)
{
int result = 0;
fccookie *c = (fccookie *) cookie;
if (c->closefn)
{
errno = 0;
if ((result = c->closefn (c->cookie)) < 0 && errno)
ptr->_errno = errno;
}
_free_r (ptr, c);
return result;
}
 
FILE *
_DEFUN(_fopencookie_r, (ptr, cookie, mode, functions),
struct _reent *ptr _AND
void *cookie _AND
const char *mode _AND
cookie_io_functions_t functions)
{
FILE *fp;
fccookie *c;
int flags;
int dummy;
 
if ((flags = __sflags (ptr, mode, &dummy)) == 0)
return NULL;
if (((flags & (__SRD | __SRW)) && !functions.read)
|| ((flags & (__SWR | __SRW)) && !functions.write))
{
ptr->_errno = EINVAL;
return NULL;
}
if ((fp = __sfp (ptr)) == NULL)
return NULL;
if ((c = (fccookie *) _malloc_r (ptr, sizeof *c)) == NULL)
{
_newlib_sfp_lock_start ();
fp->_flags = 0; /* release */
#ifndef __SINGLE_THREAD__
__lock_close_recursive (fp->_lock);
#endif
_newlib_sfp_lock_end ();
return NULL;
}
 
_newlib_flockfile_start (fp);
fp->_file = -1;
fp->_flags = flags;
c->cookie = cookie;
c->fp = fp;
fp->_cookie = c;
c->readfn = functions.read;
fp->_read = fcreader;
c->writefn = functions.write;
fp->_write = fcwriter;
c->seekfn = functions.seek;
fp->_seek = functions.seek ? fcseeker : NULL;
#ifdef __LARGE64_FILES
fp->_seek64 = functions.seek ? fcseeker64 : NULL;
fp->_flags |= __SL64;
#endif
c->closefn = functions.close;
fp->_close = fccloser;
_newlib_flockfile_end (fp);
return fp;
}
 
#ifndef _REENT_ONLY
FILE *
_DEFUN(fopencookie, (cookie, mode, functions),
void *cookie _AND
const char *mode _AND
cookie_io_functions_t functions)
{
return _fopencookie_r (_REENT, cookie, mode, functions);
}
#endif /* !_REENT_ONLY */
/contrib/sdk/sources/newlib/libc/stdio/fpurge.c
0,0 → 1,113
/* Copyright (C) 2009 Eric Blake
* Permission to use, copy, modify, and distribute this software
* is freely granted, provided that this notice is preserved.
*/
 
/*
FUNCTION
<<fpurge>>---discard pending file I/O
 
INDEX
fpurge
INDEX
_fpurge_r
INDEX
__fpurge
 
ANSI_SYNOPSIS
#include <stdio.h>
int fpurge(FILE *<[fp]>);
 
int _fpurge_r(struct _reent *<[reent]>, FILE *<[fp]>);
 
#include <stdio.h>
#include <stdio_ext.h>
void __fpurge(FILE *<[fp]>);
 
 
DESCRIPTION
Use <<fpurge>> to clear all buffers of the given stream. For output
streams, this discards data not yet written to disk. For input streams,
this discards any data from <<ungetc>> and any data retrieved from disk
but not yet read via <<getc>>. This is more severe than <<fflush>>,
and generally is only needed when manually altering the underlying file
descriptor of a stream.
 
<<__fpurge>> behaves exactly like <<fpurge>> but does not return a value.
 
The alternate function <<_fpurge_r>> is a reentrant version, where the
extra argument <[reent]> is a pointer to a reentrancy structure, and
<[fp]> must not be NULL.
 
RETURNS
<<fpurge>> returns <<0>> unless <[fp]> is not valid, in which case it
returns <<EOF>> and sets <<errno>>.
 
PORTABILITY
These functions are not portable to any standard.
 
No supporting OS subroutines are required.
*/
 
#include <_ansi.h>
#include <stdio.h>
#ifndef __rtems__
#include <stdio_ext.h>
#endif
#include <errno.h>
#include "local.h"
 
/* Discard I/O from a single file. */
 
int
_DEFUN(_fpurge_r, (ptr, fp),
struct _reent *ptr _AND
register FILE * fp)
{
int t;
 
CHECK_INIT (ptr, fp);
 
_newlib_flockfile_start (fp);
 
t = fp->_flags;
if (!t)
{
ptr->_errno = EBADF;
_newlib_flockfile_exit (fp);
return EOF;
}
fp->_p = fp->_bf._base;
if ((t & __SWR) == 0)
{
fp->_r = 0;
if (HASUB (fp))
FREEUB (ptr, fp);
}
else
fp->_w = t & (__SLBF | __SNBF) ? 0 : fp->_bf._size;
_newlib_flockfile_end (fp);
return 0;
}
 
#ifndef _REENT_ONLY
 
int
_DEFUN(fpurge, (fp),
register FILE * fp)
{
return _fpurge_r (_REENT, fp);
}
 
#ifndef __rtems__
 
void
_DEFUN(__fpurge, (fp),
register FILE * fp)
{
_fpurge_r (_REENT, fp);
}
 
#endif
 
#endif /* _REENT_ONLY */
/contrib/sdk/sources/newlib/libc/stdio/fputc_u.c
0,0 → 1,56
/*
* Copyright (c) 2014 Red Hat, Inc.
* 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.
*/
 
#include <_ansi.h>
#include <stdio.h>
#include "local.h"
 
int
_DEFUN(_fputc_unlocked_r, (ptr, ch, file),
struct _reent *ptr _AND
int ch _AND
FILE * file)
{
CHECK_INIT(ptr, file);
return _putc_unlocked_r (ptr, ch, file);
}
 
#ifndef _REENT_ONLY
int
_DEFUN(fputc_unlocked, (ch, file),
int ch _AND
FILE * file)
{
#if !defined(__OPTIMIZE_SIZE__) && !defined(PREFER_SIZE_OVER_SPEED)
struct _reent *reent = _REENT;
 
CHECK_INIT(reent, file);
return _putc_unlocked_r (reent, ch, file);
#else
return _fputc_unlocked_r (_REENT, ch, file);
#endif
}
#endif /* !_REENT_ONLY */
/contrib/sdk/sources/newlib/libc/stdio/fputs_u.c
0,0 → 1,28
/*
* Copyright (c) 2014 Red Hat, Inc.
* 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.
*/
 
#define __IMPL_UNLOCKED__
#include "fputs.c"
/contrib/sdk/sources/newlib/libc/stdio/fread_u.c
0,0 → 1,28
/*
* Copyright (c) 2014 Red Hat, Inc.
* 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.
*/
 
#define __IMPL_UNLOCKED__
#include "fread.c"
/contrib/sdk/sources/newlib/libc/stdio/fsetlocking.c
0,0 → 1,90
/*
* Copyright (c) 2014 Red Hat, Inc.
* 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
<<__fsetlocking>>---set or query locking mode on FILE stream
 
INDEX
__fsetlocking
 
ANSI_SYNOPSIS
#include <stdio.h>
#include <stdio_ext.h>
int __fsetlocking(FILE *<[fp]>, int <[type]>);
 
DESCRIPTION
This function sets how the stdio functions handle locking of FILE <[fp]>.
The following values describe <[type]>:
 
<<FSETLOCKING_INTERNAL>> is the default state, where stdio functions
automatically lock and unlock the stream.
 
<<FSETLOCKING_BYCALLER>> means that automatic locking in stdio functions
is disabled. Applications which set this take all responsibility for file
locking themselves.
 
<<FSETLOCKING_QUERY>> returns the current locking mode without changing it.
 
RETURNS
<<__fsetlocking>> returns the current locking mode of <[fp]>.
 
PORTABILITY
This function originates from Solaris and is also provided by GNU libc.
 
No supporting OS subroutines are required.
*/
 
#ifndef __rtems__
 
#include <_ansi.h>
#include <stdio.h>
#include <stdio_ext.h>
#include "local.h"
 
int
_DEFUN(__fsetlocking, (fp, type),
FILE * fp _AND
int type)
{
int result;
CHECK_INIT(_REENT, fp);
result = (fp->_flags2 & __SNLK) ? FSETLOCKING_BYCALLER : FSETLOCKING_INTERNAL;
switch (type)
{
case FSETLOCKING_BYCALLER:
fp->_flags2 |= __SNLK;
break;
case FSETLOCKING_INTERNAL:
fp->_flags2 &= ~__SNLK;
break;
case FSETLOCKING_QUERY:
default:
break;
}
return result;
}
 
#endif /* __rtems__ */
/contrib/sdk/sources/newlib/libc/stdio/fsetpos.c
0,0 → 1,95
/*
* 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
<<fsetpos>>---restore position of a stream or file
 
INDEX
fsetpos
INDEX
_fsetpos_r
 
ANSI_SYNOPSIS
#include <stdio.h>
int fsetpos(FILE *<[fp]>, const fpos_t *<[pos]>);
int _fsetpos_r(struct _reent *<[ptr]>, FILE *<[fp]>,
const fpos_t *<[pos]>);
 
TRAD_SYNOPSIS
#include <stdio.h>
int fsetpos(<[fp]>, <[pos]>)
FILE *<[fp]>;
fpos_t *<[pos]>;
 
int _fsetpos_r(<[ptr]>, <[fp]>, <[pos]>)
struct _reent *<[ptr]>;
FILE *<[fp]>;
fpos_t *<[pos]>;
 
DESCRIPTION
Objects of type <<FILE>> can have a ``position'' that records how much
of the file your program has already read. Many of the <<stdio>> functions
depend on this position, and many change it as a side effect.
 
You can use <<fsetpos>> to return the file identified by <[fp]> to a previous
position <<*<[pos]>>> (after first recording it with <<fgetpos>>).
 
See <<fseek>> for a similar facility.
 
RETURNS
<<fgetpos>> returns <<0>> when successful. If <<fgetpos>> fails, the
result is <<1>>. The reason for failure is indicated in <<errno>>:
either <<ESPIPE>> (the stream identified by <[fp]> doesn't support
repositioning) or <<EINVAL>> (invalid file position).
 
PORTABILITY
ANSI C requires <<fsetpos>>, but does not specify the nature of
<<*<[pos]>>> beyond identifying it as written by <<fgetpos>>.
 
Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
<<lseek>>, <<read>>, <<sbrk>>, <<write>>.
*/
 
#include <_ansi.h>
#include <reent.h>
#include <stdio.h>
 
int
_DEFUN(_fsetpos_r, (ptr, iop, pos),
struct _reent * ptr _AND
FILE * iop _AND
_CONST _fpos_t * pos)
{
int x = _fseek_r (ptr, iop, *pos, SEEK_SET);
 
if (x != 0)
return 1;
return 0;
}
 
#ifndef _REENT_ONLY
 
int
_DEFUN(fsetpos, (iop, pos),
FILE * iop _AND
_CONST _fpos_t * pos)
{
return _fsetpos_r (_REENT, iop, pos);
}
 
#endif /* !_REENT_ONLY */
/contrib/sdk/sources/newlib/libc/stdio/funopen.c
0,0 → 1,279
/* Copyright (C) 2007 Eric Blake
* Permission to use, copy, modify, and distribute this software
* is freely granted, provided that this notice is preserved.
*/
 
/*
FUNCTION
<<funopen>>, <<fropen>>, <<fwopen>>---open a stream with custom callbacks
 
INDEX
funopen
INDEX
fropen
INDEX
fwopen
 
ANSI_SYNOPSIS
#include <stdio.h>
FILE *funopen(const void *<[cookie]>,
int (*<[readfn]>) (void *cookie, char *buf, int n),
int (*<[writefn]>) (void *cookie, const char *buf, int n),
fpos_t (*<[seekfn]>) (void *cookie, fpos_t off, int whence),
int (*<[closefn]>) (void *cookie));
FILE *fropen(const void *<[cookie]>,
int (*<[readfn]>) (void *cookie, char *buf, int n));
FILE *fwopen(const void *<[cookie]>,
int (*<[writefn]>) (void *cookie, const char *buf, int n));
 
DESCRIPTION
<<funopen>> creates a <<FILE>> stream where I/O is performed using
custom callbacks. At least one of <[readfn]> and <[writefn]> must be
provided, which determines whether the stream behaves with mode <"r">,
<"w">, or <"r+">.
 
<[readfn]> should return -1 on failure, or else the number of bytes
read (0 on EOF). It is similar to <<read>>, except that <int> rather
than <size_t> bounds a transaction size, and <[cookie]> will be passed
as the first argument. A NULL <[readfn]> makes attempts to read the
stream fail.
 
<[writefn]> should return -1 on failure, or else the number of bytes
written. It is similar to <<write>>, except that <int> rather than
<size_t> bounds a transaction size, and <[cookie]> will be passed as
the first argument. A NULL <[writefn]> makes attempts to write the
stream fail.
 
<[seekfn]> should return (fpos_t)-1 on failure, or else the current
file position. It is similar to <<lseek>>, except that <[cookie]>
will be passed as the first argument. A NULL <[seekfn]> makes the
stream behave similarly to a pipe in relation to stdio functions that
require positioning. This implementation assumes fpos_t and off_t are
the same type.
 
<[closefn]> should return -1 on failure, or 0 on success. It is
similar to <<close>>, except that <[cookie]> will be passed as the
first argument. A NULL <[closefn]> merely flushes all data then lets
<<fclose>> succeed. A failed close will still invalidate the stream.
 
Read and write I/O functions are allowed to change the underlying
buffer on fully buffered or line buffered streams by calling
<<setvbuf>>. They are also not required to completely fill or empty
the buffer. They are not, however, allowed to change streams from
unbuffered to buffered or to change the state of the line buffering
flag. They must also be prepared to have read or write calls occur on
buffers other than the one most recently specified.
 
The functions <<fropen>> and <<fwopen>> are convenience macros around
<<funopen>> that only use the specified callback.
 
RETURNS
The return value is an open FILE pointer on success. On error,
<<NULL>> is returned, and <<errno>> will be set to EINVAL if a
function pointer is missing, ENOMEM if the stream cannot be created,
or EMFILE if too many streams are already open.
 
PORTABILITY
This function is a newlib extension, copying the prototype from BSD.
It is not portable. See also the <<fopencookie>> interface from Linux.
 
Supporting OS subroutines required: <<sbrk>>.
*/
 
#include <stdio.h>
#include <errno.h>
#include <sys/lock.h>
#include "local.h"
 
typedef int (*funread)(void *_cookie, char *_buf, _READ_WRITE_BUFSIZE_TYPE _n);
typedef int (*funwrite)(void *_cookie, const char *_buf,
_READ_WRITE_BUFSIZE_TYPE _n);
#ifdef __LARGE64_FILES
typedef _fpos64_t (*funseek)(void *_cookie, _fpos64_t _off, int _whence);
#else
typedef fpos_t (*funseek)(void *_cookie, fpos_t _off, int _whence);
#endif
typedef int (*funclose)(void *_cookie);
 
typedef struct funcookie {
void *cookie;
funread readfn;
funwrite writefn;
funseek seekfn;
funclose closefn;
} funcookie;
 
static _READ_WRITE_RETURN_TYPE
_DEFUN(funreader, (ptr, cookie, buf, n),
struct _reent *ptr _AND
void *cookie _AND
char *buf _AND
_READ_WRITE_BUFSIZE_TYPE n)
{
int result;
funcookie *c = (funcookie *) cookie;
errno = 0;
if ((result = c->readfn (c->cookie, buf, n)) < 0 && errno)
ptr->_errno = errno;
return result;
}
 
static _READ_WRITE_RETURN_TYPE
_DEFUN(funwriter, (ptr, cookie, buf, n),
struct _reent *ptr _AND
void *cookie _AND
const char *buf _AND
_READ_WRITE_BUFSIZE_TYPE n)
{
int result;
funcookie *c = (funcookie *) cookie;
errno = 0;
if ((result = c->writefn (c->cookie, buf, n)) < 0 && errno)
ptr->_errno = errno;
return result;
}
 
static _fpos_t
_DEFUN(funseeker, (ptr, cookie, off, whence),
struct _reent *ptr _AND
void *cookie _AND
_fpos_t off _AND
int whence)
{
funcookie *c = (funcookie *) cookie;
#ifndef __LARGE64_FILES
fpos_t result;
errno = 0;
if ((result = c->seekfn (c->cookie, (fpos_t) off, whence)) < 0 && errno)
ptr->_errno = errno;
#else /* __LARGE64_FILES */
_fpos64_t result;
errno = 0;
if ((result = c->seekfn (c->cookie, (_fpos64_t) off, whence)) < 0 && errno)
ptr->_errno = errno;
else if ((_fpos_t)result != result)
{
ptr->_errno = EOVERFLOW;
result = -1;
}
#endif /* __LARGE64_FILES */
return result;
}
 
#ifdef __LARGE64_FILES
static _fpos64_t
_DEFUN(funseeker64, (ptr, cookie, off, whence),
struct _reent *ptr _AND
void *cookie _AND
_fpos64_t off _AND
int whence)
{
_fpos64_t result;
funcookie *c = (funcookie *) cookie;
errno = 0;
if ((result = c->seekfn (c->cookie, off, whence)) < 0 && errno)
ptr->_errno = errno;
return result;
}
#endif /* __LARGE64_FILES */
 
static int
_DEFUN(funcloser, (ptr, cookie),
struct _reent *ptr _AND
void *cookie)
{
int result = 0;
funcookie *c = (funcookie *) cookie;
if (c->closefn)
{
errno = 0;
if ((result = c->closefn (c->cookie)) < 0 && errno)
ptr->_errno = errno;
}
_free_r (ptr, c);
return result;
}
 
FILE *
_DEFUN(_funopen_r, (ptr, cookie, readfn, writefn, seekfn, closefn),
struct _reent *ptr _AND
const void *cookie _AND
funread readfn _AND
funwrite writefn _AND
funseek seekfn _AND
funclose closefn)
{
FILE *fp;
funcookie *c;
 
if (!readfn && !writefn)
{
ptr->_errno = EINVAL;
return NULL;
}
if ((fp = __sfp (ptr)) == NULL)
return NULL;
if ((c = (funcookie *) _malloc_r (ptr, sizeof *c)) == NULL)
{
_newlib_sfp_lock_start ();
fp->_flags = 0; /* release */
#ifndef __SINGLE_THREAD__
__lock_close_recursive (fp->_lock);
#endif
_newlib_sfp_lock_end ();
return NULL;
}
 
_newlib_flockfile_start (fp);
fp->_file = -1;
c->cookie = (void *) cookie; /* cast away const */
fp->_cookie = c;
if (readfn)
{
c->readfn = readfn;
fp->_read = funreader;
if (writefn)
{
fp->_flags = __SRW;
c->writefn = writefn;
fp->_write = funwriter;
}
else
{
fp->_flags = __SRD;
c->writefn = NULL;
fp->_write = NULL;
}
}
else
{
fp->_flags = __SWR;
c->writefn = writefn;
fp->_write = funwriter;
c->readfn = NULL;
fp->_read = NULL;
}
c->seekfn = seekfn;
fp->_seek = seekfn ? funseeker : NULL;
#ifdef __LARGE64_FILES
fp->_seek64 = seekfn ? funseeker64 : NULL;
fp->_flags |= __SL64;
#endif
c->closefn = closefn;
fp->_close = funcloser;
_newlib_flockfile_end (fp);
return fp;
}
 
#ifndef _REENT_ONLY
FILE *
_DEFUN(funopen, (cookie, readfn, writefn, seekfn, closefn),
const void *cookie _AND
funread readfn _AND
funwrite writefn _AND
funseek seekfn _AND
funclose closefn)
{
return _funopen_r (_REENT, cookie, readfn, writefn, seekfn, closefn);
}
#endif /* !_REENT_ONLY */
/contrib/sdk/sources/newlib/libc/stdio/fwide.c
0,0 → 1,89
/*
FUNCTION
<<fwide>>---set and determine the orientation of a FILE stream
 
INDEX
fwide
INDEX
_fwide_r
 
ANSI_SYNOPSIS
#include <wchar.h>
int fwide(FILE *<[fp]>, int <[mode]>);
 
int _fwide_r(struct _reent *<[ptr]>, FILE *<[fp]>, int <[mode]>);
 
TRAD_SYNOPSIS
#include <wchar.h>
int fwide(<[fp]>, <[mode]>);
FILE *<[fp]>;
int <[mode]>;
 
int _fwide_r(<[ptr]>, <[fp]>, <[mode]>);
struct _reent *<[ptr]>;
FILE *<[fp]>;
int <[mode]>;
 
DESCRIPTION
When <[mode]> is zero, the <<fwide>> function determines the current
orientation of <[fp]>. It returns a value > 0 if <[fp]> is
wide-character oriented, i.e. if wide character I/O is permitted but
char I/O is disallowed. It returns a value < 0 if <[fp]> is byte
oriented, i.e. if char I/O is permitted but wide character I/O is
disallowed. It returns zero if <[fp]> has no orientation yet; in
this case the next I/O operation might change the orientation (to byte
oriented if it is a char I/O operation, or to wide-character oriented
if it is a wide character I/O operation).
 
Once a stream has an orientation, it cannot be changed and persists
until the stream is closed, unless the stream is re-opened with freopen,
which removes the orientation of the stream.
 
When <[mode]> is non-zero, the <<fwide>> function first attempts to set
<[fp]>'s orientation (to wide-character oriented if <[mode]> > 0, or to
byte oriented if <[mode]> < 0). It then returns a value denoting the
current orientation, as above.
 
RETURNS
The <<fwide>> function returns <[fp]>'s orientation, after possibly
changing it. A return value > 0 means wide-character oriented. A return
value < 0 means byte oriented. A return value of zero means undecided.
 
PORTABILITY
C99, POSIX.1-2001.
 
*/
 
#include <_ansi.h>
#include <wchar.h>
#include "local.h"
 
int
_DEFUN(_fwide_r, (ptr, fp, mode),
struct _reent *ptr _AND
FILE *fp _AND
int mode)
{
int ret;
 
CHECK_INIT(ptr, fp);
 
_newlib_flockfile_start (fp);
if (mode != 0) {
ORIENT (fp, mode);
}
if (!(fp->_flags & __SORD))
ret = 0;
else
ret = (fp->_flags2 & __SWID) ? 1 : -1;
_newlib_flockfile_end (fp);
return ret;
}
 
int
_DEFUN(fwide, (fp, mode),
FILE *fp _AND
int mode)
{
return _fwide_r (_REENT, fp, mode);
}
/contrib/sdk/sources/newlib/libc/stdio/fwrite_u.c
0,0 → 1,28
/*
* Copyright (c) 2014 Red Hat, Inc.
* 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.
*/
 
#define __IMPL_UNLOCKED__
#include "fwrite.c"
/contrib/sdk/sources/newlib/libc/stdio/getc.c
0,0 → 1,117
/*
* 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
<<getc>>---read a character (macro)
 
INDEX
getc
INDEX
_getc_r
 
ANSI_SYNOPSIS
#include <stdio.h>
int getc(FILE *<[fp]>);
 
#include <stdio.h>
int _getc_r(struct _reent *<[ptr]>, FILE *<[fp]>);
 
TRAD_SYNOPSIS
#include <stdio.h>
int getc(<[fp]>)
FILE *<[fp]>;
 
#include <stdio.h>
int _getc_r(<[ptr]>, <[fp]>)
struct _reent *<[ptr]>;
FILE *<[fp]>;
 
DESCRIPTION
<<getc>> is a macro, defined in <<stdio.h>>. You can use <<getc>>
to get the next single character from the file or stream
identified by <[fp]>. As a side effect, <<getc>> advances the file's
current position indicator.
 
For a subroutine version of this macro, see <<fgetc>>.
 
The <<_getc_r>> function is simply the reentrant version of <<getc>>
which passes an additional reentrancy 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, <<getc>> returns <<EOF>>.
 
You can distinguish the two situations that cause an <<EOF>> result by
using the <<ferror>> and <<feof>> functions.
 
PORTABILITY
ANSI C requires <<getc>>; it suggests, but does not require, that
<<getc>> be implemented as a macro. The standard explicitly permits
macro implementations of <<getc>> to use the argument more than once;
therefore, in a portable program, you should not use an expression
with side effects as the <<getc>> argument.
 
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 "local.h"
 
/*
* A subroutine version of the macro getc.
*/
 
#undef getc
 
int
_DEFUN(_getc_r, (ptr, fp),
struct _reent *ptr _AND
register FILE *fp)
{
int result;
CHECK_INIT (ptr, fp);
_newlib_flockfile_start (fp);
result = __sgetc_r (ptr, fp);
_newlib_flockfile_end (fp);
return result;
}
 
#ifndef _REENT_ONLY
 
int
_DEFUN(getc, (fp),
register FILE *fp)
{
int result;
struct _reent *reent = _REENT;
 
CHECK_INIT (reent, fp);
_newlib_flockfile_start (fp);
result = __sgetc_r (reent, fp);
_newlib_flockfile_end (fp);
return result;
}
 
#endif /* !_REENT_ONLY */
/contrib/sdk/sources/newlib/libc/stdio/getc_u.c
0,0 → 1,90
/*
* 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
<<getc_unlocked>>---non-thread-safe version of getc (macro)
 
INDEX
getc_unlocked
INDEX
_getc_unlocked_r
 
SYNOPSIS
#include <stdio.h>
int getc_unlocked(FILE *<[fp]>);
 
#include <stdio.h>
int _getc_unlocked_r(FILE *<[fp]>);
 
DESCRIPTION
<<getc_unlocked>> is a non-thread-safe version of <<getc>> declared in
<<stdio.h>>. <<getc_unlocked>> may only safely be used within a scope
protected by flockfile() (or ftrylockfile()) and funlockfile(). These
functions 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
<<getc_unlocked>> is equivalent to <<getc>>.
 
The <<_getc_unlocked_r>> function is simply the reentrant version of
<<get_unlocked>> which passes an additional reentrancy structure pointer
argument: <[ptr]>.
 
RETURNS
See <<getc>>.
 
PORTABILITY
POSIX 1003.1 requires <<getc_unlocked>>. <<getc_unlocked>> may be
implemented as a macro, so arguments should not have side-effects.
 
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>
 
/*
* A subroutine version of the macro getc_unlocked.
*/
 
#undef getc_unlocked
 
int
_DEFUN(_getc_unlocked_r, (ptr, fp),
struct _reent *ptr _AND
register FILE *fp)
{
/* CHECK_INIT is called (eventually) by __srefill_r. */
 
return __sgetc_r (ptr, fp);
}
 
#ifndef _REENT_ONLY
 
int
_DEFUN(getc_unlocked, (fp),
register FILE *fp)
{
return __sgetc_r (_REENT, fp);
}
 
#endif /* !_REENT_ONLY */
/contrib/sdk/sources/newlib/libc/stdio/getchar.c
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.
*/
 
/*
FUNCTION
<<getchar>>---read a character (macro)
 
INDEX
getchar
INDEX
_getchar_r
 
ANSI_SYNOPSIS
#include <stdio.h>
int getchar(void);
 
int _getchar_r(struct _reent *<[reent]>);
 
TRAD_SYNOPSIS
#include <stdio.h>
int getchar();
 
int _getchar_r(<[reent]>)
char * <[reent]>;
 
DESCRIPTION
<<getchar>> is a macro, defined in <<stdio.h>>. You can use <<getchar>>
to get the next single character from the standard input stream.
As a side effect, <<getchar>> advances the standard input's
current position indicator.
 
The alternate function <<_getchar_r>> is a reentrant version. The
extra argument <[reent]> is a pointer to a reentrancy structure.
 
 
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, <<getchar>> returns <<EOF>>.
 
You can distinguish the two situations that cause an <<EOF>> result by
using `<<ferror(stdin)>>' and `<<feof(stdin)>>'.
 
PORTABILITY
ANSI C requires <<getchar>>; it suggests, but does not require, that
<<getchar>> be implemented as a macro.
 
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 */
 
/*
* A subroutine version of the macro getchar.
*/
 
#include <_ansi.h>
#include <reent.h>
#include <stdio.h>
#include "local.h"
 
#undef getchar
 
int
_DEFUN(_getchar_r, (reent),
struct _reent *reent)
{
_REENT_SMALL_CHECK_INIT (reent);
return _getc_r (reent, _stdin_r (reent));
}
 
#ifndef _REENT_ONLY
 
int
_DEFUN_VOID(getchar)
{
struct _reent *reent = _REENT;
 
/* CHECK_INIT is called (eventually) by __srefill_r. */
_REENT_SMALL_CHECK_INIT (reent);
return _getc_r (reent, _stdin_r (reent));
}
 
#endif
/contrib/sdk/sources/newlib/libc/stdio/getchar_u.c
0,0 → 1,89
/*
* 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
<<getchar_unlocked>>---non-thread-safe version of getchar (macro)
 
INDEX
getchar_unlocked
INDEX
_getchar_unlocked_r
 
SYNOPSIS
#include <stdio.h>
int getchar_unlocked(void);
 
#include <stdio.h>
int _getchar_unlocked_r(struct _reent *<[ptr]>);
 
DESCRIPTION
<<getchar_unlocked>> is a non-thread-safe version of <<getchar>>
declared in <<stdio.h>>. <<getchar_unlocked>> may only safely be used
within a scope protected by flockfile() (or ftrylockfile()) and
funlockfile(). These functions 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 <<getchar_unlocked>> is equivalent to <<getchar>>.
 
The <<_getchar_unlocked_r>> function is simply the reentrant version of
<<getchar_unlocked>> which passes an addtional reentrancy structure pointer
argument: <[ptr]>.
 
RETURNS
See <<getchar>>.
 
PORTABILITY
POSIX 1003.1 requires <<getchar_unlocked>>. <<getchar_unlocked>> may
be implemented as a macro.
 
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 */
 
/*
* A subroutine version of the macro getchar_unlocked.
*/
 
#include <_ansi.h>
#include <reent.h>
#include <stdio.h>
 
#undef getchar_unlocked
 
int
_DEFUN(_getchar_unlocked_r, (ptr),
struct _reent *ptr)
{
return _getc_unlocked_r (ptr, _stdin_r (ptr));
}
 
#ifndef _REENT_ONLY
 
int
_DEFUN_VOID(getchar_unlocked)
{
/* CHECK_INIT is called (eventually) by __srefill_r. */
 
return _getc_unlocked_r (_REENT, _stdin_r (_REENT));
}
 
#endif
/contrib/sdk/sources/newlib/libc/stdio/getdelim.c
0,0 → 1,142
/* Copyright 2002, Red Hat Inc. - all rights reserved */
/*
FUNCTION
<<getdelim>>---read a line up to a specified line delimiter
 
INDEX
getdelim
 
ANSI_SYNOPSIS
#include <stdio.h>
int getdelim(char **<[bufptr]>, size_t *<[n]>,
int <[delim]>, FILE *<[fp]>);
 
TRAD_SYNOPSIS
#include <stdio.h>
int getdelim(<[bufptr]>, <[n]>, <[delim]>, <[fp]>)
char **<[bufptr]>;
size_t *<[n]>;
int <[delim]>;
FILE *<[fp]>;
 
DESCRIPTION
<<getdelim>> reads a file <[fp]> up to and possibly including a specified
delimiter <[delim]>. The line is read into a buffer pointed to
by <[bufptr]> and designated with size *<[n]>. If the buffer is
not large enough, it will be dynamically grown by <<getdelim>>.
As the buffer is grown, the pointer to the size <[n]> will be
updated.
 
RETURNS
<<getdelim>> returns <<-1>> if no characters were successfully read;
otherwise, it returns the number of bytes successfully read.
At end of file, the result is nonzero.
 
PORTABILITY
<<getdelim>> is a glibc extension.
 
No supporting OS subroutines are directly required.
*/
 
#include <_ansi.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include "local.h"
 
#define MIN_LINE_SIZE 4
#define DEFAULT_LINE_SIZE 128
 
ssize_t
_DEFUN(__getdelim, (bufptr, n, delim, fp),
char **bufptr _AND
size_t *n _AND
int delim _AND
FILE *fp)
{
char *buf;
char *ptr;
size_t newsize, numbytes;
int pos;
int ch;
int cont;
 
if (fp == NULL || bufptr == NULL || n == NULL)
{
errno = EINVAL;
return -1;
}
 
buf = *bufptr;
if (buf == NULL || *n < MIN_LINE_SIZE)
{
buf = (char *)realloc (*bufptr, DEFAULT_LINE_SIZE);
if (buf == NULL)
{
return -1;
}
*bufptr = buf;
*n = DEFAULT_LINE_SIZE;
}
 
CHECK_INIT (_REENT, fp);
 
_newlib_flockfile_start (fp);
 
numbytes = *n;
ptr = buf;
 
cont = 1;
 
while (cont)
{
/* fill buffer - leaving room for nul-terminator */
while (--numbytes > 0)
{
if ((ch = getc_unlocked (fp)) == EOF)
{
cont = 0;
break;
}
else
{
*ptr++ = ch;
if (ch == delim)
{
cont = 0;
break;
}
}
}
 
if (cont)
{
/* Buffer is too small so reallocate a larger buffer. */
pos = ptr - buf;
newsize = (*n << 1);
buf = realloc (buf, newsize);
if (buf == NULL)
{
cont = 0;
break;
}
 
/* After reallocating, continue in new buffer */
*bufptr = buf;
*n = newsize;
ptr = buf + pos;
numbytes = newsize - pos;
}
}
 
_newlib_flockfile_end (fp);
 
/* if no input data, return failure */
if (ptr == buf)
return -1;
 
/* otherwise, nul-terminate and return number of bytes read */
*ptr = '\0';
return (ssize_t)(ptr - buf);
}
 
/contrib/sdk/sources/newlib/libc/stdio/getline.c
0,0 → 1,54
/* Copyright 2002, Red Hat Inc. - all rights reserved */
/*
FUNCTION
<<getline>>---read a line from a file
 
INDEX
getline
 
ANSI_SYNOPSIS
#include <stdio.h>
ssize_t getline(char **<[bufptr]>, size_t *<[n]>, FILE *<[fp]>);
 
TRAD_SYNOPSIS
#include <stdio.h>
ssize_t getline(<[bufptr]>, <[n]>, <[fp]>)
char **<[bufptr]>;
size_t *<[n]>;
FILE *<[fp]>;
 
DESCRIPTION
<<getline>> reads a file <[fp]> up to and possibly including the
newline character. The line is read into a buffer pointed to
by <[bufptr]> and designated with size *<[n]>. If the buffer is
not large enough, it will be dynamically grown by <<getdelim>>.
As the buffer is grown, the pointer to the size <[n]> will be
updated.
 
<<getline>> is equivalent to getdelim(bufptr, n, '\n', fp);
 
RETURNS
<<getline>> returns <<-1>> if no characters were successfully read,
otherwise, it returns the number of bytes successfully read.
at end of file, the result is nonzero.
 
PORTABILITY
<<getline>> is a glibc extension.
 
No supporting OS subroutines are directly required.
*/
 
#include <_ansi.h>
#include <stdio.h>
 
extern ssize_t _EXFUN(__getdelim, (char **, size_t *, int, FILE *));
 
ssize_t
_DEFUN(__getline, (lptr, n, fp),
char **lptr _AND
size_t *n _AND
FILE *fp)
{
return __getdelim (lptr, n, '\n', fp);
}
 
/contrib/sdk/sources/newlib/libc/stdio/gets.c
0,0 → 1,113
/*
* 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
<<gets>>---get character string (obsolete, use <<fgets>> instead)
 
INDEX
gets
INDEX
_gets_r
 
ANSI_SYNOPSIS
#include <stdio.h>
 
char *gets(char *<[buf]>);
 
char *_gets_r(struct _reent *<[reent]>, char *<[buf]>);
 
TRAD_SYNOPSIS
#include <stdio.h>
 
char *gets(<[buf]>)
char *<[buf]>;
 
char *_gets_r(<[reent]>, <[buf]>)
struct _reent *<[reent]>;
char *<[buf]>;
 
DESCRIPTION
Reads characters from standard input until a newline is found.
The characters up to the newline are stored in <[buf]>. The
newline is discarded, and the buffer is terminated with a 0.
 
This is a @emph{dangerous} function, as it has no way of checking
the amount of space available in <[buf]>. One of the attacks
used by the Internet Worm of 1988 used this to overrun a
buffer allocated on the stack of the finger daemon and
overwrite the return address, causing the daemon to execute
code downloaded into it over the connection.
 
The alternate function <<_gets_r>> is a reentrant version. The extra
argument <[reent]> is a pointer to a reentrancy structure.
 
 
RETURNS
<<gets>> returns the buffer passed to it, with the data filled
in. If end of file occurs with some data already accumulated,
the data is returned with no other indication. If end of file
occurs with no data in the buffer, NULL is returned.
 
Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
<<lseek>>, <<read>>, <<sbrk>>, <<write>>.
*/
 
#include <_ansi.h>
#include <reent.h>
#include <stdio.h>
#include "local.h"
 
char *
_DEFUN(_gets_r, (ptr, buf),
struct _reent *ptr _AND
char *buf)
{
register int c;
register char *s = buf;
FILE *fp;
 
_REENT_SMALL_CHECK_INIT (ptr);
fp = _stdin_r (ptr);
CHECK_INIT (ptr, fp);
_newlib_flockfile_start (fp);
while ((c = __sgetc_r (ptr, fp)) != '\n')
if (c == EOF)
if (s == buf)
{
_newlib_flockfile_exit (fp);
return NULL;
}
else
break;
else
*s++ = c;
*s = 0;
_newlib_flockfile_end (fp);
return buf;
}
 
#ifndef _REENT_ONLY
 
char *
_DEFUN(gets, (buf),
char *buf)
{
return _gets_r (_REENT, buf);
}
 
#endif
/contrib/sdk/sources/newlib/libc/stdio/iprintf.c
0,0 → 1,57
/*
* 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.
*/
/* doc in siprintf.c */
 
#include <_ansi.h>
#include <reent.h>
#include <stdio.h>
#include <stdarg.h>
#include "local.h"
 
#ifndef _REENT_ONLY
 
int
_DEFUN(iprintf, (fmt),
const char *fmt _DOTS)
{
int ret;
va_list ap;
struct _reent *ptr = _REENT;
 
_REENT_SMALL_CHECK_INIT (ptr);
va_start (ap, fmt);
ret = _vfiprintf_r (ptr, _stdout_r (ptr), fmt, ap);
va_end (ap);
return ret;
}
 
#endif /* ! _REENT_ONLY */
 
int
_DEFUN(_iprintf_r, (ptr, fmt),
struct _reent *ptr _AND
const char *fmt _DOTS)
{
int ret;
va_list ap;
 
_REENT_SMALL_CHECK_INIT (ptr);
va_start (ap, fmt);
ret = _vfiprintf_r (ptr, _stdout_r (ptr), fmt, ap);
va_end (ap);
return ret;
}
/contrib/sdk/sources/newlib/libc/stdio/iscanf.c
0,0 → 1,78
/*
* 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.
*/
 
#include <_ansi.h>
#include <reent.h>
#include <stdio.h>
#ifdef _HAVE_STDC
#include <stdarg.h>
#else
#include <varargs.h>
#endif
#include "local.h"
 
#ifndef _REENT_ONLY
 
int
#ifdef _HAVE_STDC
iscanf(_CONST char *fmt, ...)
#else
iscanf(fmt, va_alist)
char *fmt;
va_dcl
#endif
{
int ret;
va_list ap;
 
_REENT_SMALL_CHECK_INIT (_REENT);
#ifdef _HAVE_STDC
va_start (ap, fmt);
#else
va_start (ap);
#endif
ret = __svfiscanf_r (_REENT, _stdin_r (_REENT), fmt, ap);
va_end (ap);
return ret;
}
 
#endif /* !_REENT_ONLY */
 
int
#ifdef _HAVE_STDC
_iscanf_r(struct _reent *ptr, _CONST char *fmt, ...)
#else
_iscanf_r(ptr, fmt, va_alist)
struct _reent *ptr;
char *fmt;
va_dcl
#endif
{
int ret;
va_list ap;
 
_REENT_SMALL_CHECK_INIT (ptr);
#ifdef _HAVE_STDC
va_start (ap, fmt);
#else
va_start (ap);
#endif
ret = __svfiscanf_r (ptr, _stdin_r (ptr), fmt, ap);
va_end (ap);
return (ret);
}
 
/contrib/sdk/sources/newlib/libc/stdio/local.h
182,6 → 182,7
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));
/contrib/sdk/sources/newlib/libc/stdio/makebuf.c
39,13 → 39,10
struct _reent *ptr _AND
register FILE *fp)
{
register size_t size, couldbetty;
register _PTR p;
#ifdef __USE_INTERNAL_STAT64
struct stat64 st;
#else
struct stat st;
#endif
int flags;
size_t size;
int couldbetty;
 
if (fp->_flags & __SNBF)
{
53,49 → 50,7
fp->_bf._size = 1;
return;
}
#ifdef __USE_INTERNAL_STAT64
if (fp->_file < 0 || _fstat64_r (ptr, fp->_file, &st) < 0)
#else
if (fp->_file < 0 || _fstat_r (ptr, fp->_file, &st) < 0)
#endif
{
couldbetty = 0;
/* Check if we are be called by asprintf family for initial buffer. */
if (fp->_flags & __SMBF)
size = _DEFAULT_ASPRINTF_BUFSIZE;
else
size = BUFSIZ;
#ifdef _FSEEK_OPTIMIZATION
/* do not try to optimise fseek() */
fp->_flags |= __SNPT;
#endif
}
else
{
couldbetty = (st.st_mode & S_IFMT) == S_IFCHR;
#ifdef HAVE_BLKSIZE
size = st.st_blksize <= 0 ? BUFSIZ : st.st_blksize;
#else
size = BUFSIZ;
#endif
#ifdef _FSEEK_OPTIMIZATION
/*
* Optimize fseek() only if it is a regular file.
* (The test for __sseek is mainly paranoia.)
*/
if ((st.st_mode & S_IFMT) == S_IFREG && fp->_seek == __sseek)
{
fp->_flags |= __SOPT;
#ifdef HAVE_BLKSIZE
fp->_blksize = st.st_blksize;
#else
fp->_blksize = 1024;
#endif
}
else
fp->_flags |= __SNPT;
#endif
}
flags = __swhatbuf_r (ptr, fp, &size, &couldbetty);
if ((p = _malloc_r (ptr, size)) == NULL)
{
if (!(fp->_flags & __SSTR))
113,5 → 68,60
fp->_bf._size = size;
if (couldbetty && _isatty_r (ptr, fp->_file))
fp->_flags |= __SLBF;
fp->_flags |= flags;
}
}
 
/*
* Internal routine to determine `proper' buffering for a file.
*/
int
_DEFUN(__swhatbuf_r, (ptr, fp, bufsize, couldbetty),
struct _reent *ptr _AND
FILE *fp _AND
size_t *bufsize _AND
int *couldbetty)
{
#ifdef _FSEEK_OPTIMIZATION
const int snpt = __SNPT;
#else
const int snpt = 0;
#endif
 
#ifdef __USE_INTERNAL_STAT64
struct stat64 st;
 
if (fp->_file < 0 || _fstat64_r (ptr, fp->_file, &st) < 0)
#else
struct stat st;
 
if (fp->_file < 0 || _fstat_r (ptr, fp->_file, &st) < 0)
#endif
{
*couldbetty = 0;
/* Check if we are be called by asprintf family for initial buffer. */
if (fp->_flags & __SMBF)
*bufsize = _DEFAULT_ASPRINTF_BUFSIZE;
else
*bufsize = BUFSIZ;
return (0);
}
 
/* could be a tty iff it is a character device */
*couldbetty = S_ISCHR(st.st_mode);
#ifdef HAVE_BLKSIZE
if (st.st_blksize > 0)
{
/*
* Optimise fseek() only if it is a regular file. (The test for
* __sseek is mainly paranoia.) It is safe to set _blksize
* unconditionally; it will only be used if __SOPT is also set.
*/
*bufsize = st.st_blksize;
fp->_blksize = st.st_blksize;
return ((st.st_mode & S_IFMT) == S_IFREG ? __SOPT : snpt);
}
#endif
*bufsize = BUFSIZ;
return (snpt);
}
/contrib/sdk/sources/newlib/libc/stdio/open_memstream.c
0,0 → 1,414
/* Copyright (C) 2007 Eric Blake
* Permission to use, copy, modify, and distribute this software
* is freely granted, provided that this notice is preserved.
*/
 
/*
FUNCTION
<<open_memstream>>, <<open_wmemstream>>---open a write stream around an arbitrary-length string
 
INDEX
open_memstream
INDEX
open_wmemstream
 
ANSI_SYNOPSIS
#include <stdio.h>
FILE *open_memstream(char **restrict <[buf]>,
size_t *restrict <[size]>);
 
#include <wchar.h>
FILE *open_wmemstream(wchar_t **restrict <[buf]>,
size_t *restrict <[size]>);
 
DESCRIPTION
<<open_memstream>> creates a seekable, byte-oriented <<FILE>> stream that
wraps an arbitrary-length buffer, created as if by <<malloc>>. The current
contents of *<[buf]> are ignored; this implementation uses *<[size]>
as a hint of the maximum size expected, but does not fail if the hint
was wrong. The parameters <[buf]> and <[size]> are later stored
through following any call to <<fflush>> or <<fclose>>, set to the
current address and usable size of the allocated string; although
after fflush, the pointer is only valid until another stream operation
that results in a write. Behavior is undefined if the user alters
either *<[buf]> or *<[size]> prior to <<fclose>>.
 
<<open_wmemstream>> is like <<open_memstream>> just with the associated
stream being wide-oriented. The size set in <[size]> in subsequent
operations is the number of wide characters.
 
The stream is write-only, since the user can directly read *<[buf]>
after a flush; see <<fmemopen>> for a way to wrap a string with a
readable stream. The user is responsible for calling <<free>> on
the final *<[buf]> after <<fclose>>.
 
Any time the stream is flushed, a NUL byte is written at the current
position (but is not counted in the buffer length), so that the string
is always NUL-terminated after at most *<[size]> bytes (or wide characters
in case of <<open_wmemstream>>). However, data previously written beyond
the current stream offset is not lost, and the NUL value written during a
flush is restored to its previous value when seeking elsewhere in the string.
 
RETURNS
The return value is an open FILE pointer on success. On error,
<<NULL>> is returned, and <<errno>> will be set to EINVAL if <[buf]>
or <[size]> is NULL, ENOMEM if memory could not be allocated, or
EMFILE if too many streams are already open.
 
PORTABILITY
POSIX.1-2008
 
Supporting OS subroutines required: <<sbrk>>.
*/
 
#include <stdio.h>
#include <wchar.h>
#include <errno.h>
#include <string.h>
#include <sys/lock.h>
#include <stdint.h>
#include "local.h"
 
#ifndef __LARGE64_FILES
# define OFF_T off_t
#else
# define OFF_T _off64_t
#endif
 
/* Describe details of an open memstream. */
typedef struct memstream {
void *storage; /* storage to free on close */
char **pbuf; /* pointer to the current buffer */
size_t *psize; /* pointer to the current size, smaller of pos or eof */
size_t pos; /* current position */
size_t eof; /* current file size */
size_t max; /* current malloc buffer size, always > eof */
union {
char c;
wchar_t w;
} saved; /* saved character that lived at *psize before NUL */
int8_t wide; /* wide-oriented (>0) or byte-oriented (<0) */
} memstream;
 
/* Write up to non-zero N bytes of BUF into the stream described by COOKIE,
returning the number of bytes written or EOF on failure. */
static _READ_WRITE_RETURN_TYPE
_DEFUN(memwriter, (ptr, cookie, buf, n),
struct _reent *ptr _AND
void *cookie _AND
const char *buf _AND
_READ_WRITE_BUFSIZE_TYPE n)
{
memstream *c = (memstream *) cookie;
char *cbuf = *c->pbuf;
 
/* size_t is unsigned, but off_t is signed. Don't let stream get so
big that user cannot do ftello. */
if (sizeof (OFF_T) == sizeof (size_t) && (ssize_t) (c->pos + n) < 0)
{
ptr->_errno = EFBIG;
return EOF;
}
/* Grow the buffer, if necessary. Choose a geometric growth factor
to avoid quadratic realloc behavior, but use a rate less than
(1+sqrt(5))/2 to accomodate malloc overhead. Overallocate, so
that we can add a trailing \0 without reallocating. The new
allocation should thus be max(prev_size*1.5, c->pos+n+1). */
if (c->pos + n >= c->max)
{
size_t newsize = c->max * 3 / 2;
if (newsize < c->pos + n + 1)
newsize = c->pos + n + 1;
cbuf = _realloc_r (ptr, cbuf, newsize);
if (! cbuf)
return EOF; /* errno already set to ENOMEM */
*c->pbuf = cbuf;
c->max = newsize;
}
/* If we have previously done a seek beyond eof, ensure all
intermediate bytes are NUL. */
if (c->pos > c->eof)
memset (cbuf + c->eof, '\0', c->pos - c->eof);
memcpy (cbuf + c->pos, buf, n);
c->pos += n;
/* If the user has previously written further, remember what the
trailing NUL is overwriting. Otherwise, extend the stream. */
if (c->pos > c->eof)
c->eof = c->pos;
else if (c->wide > 0)
c->saved.w = *(wchar_t *)(cbuf + c->pos);
else
c->saved.c = cbuf[c->pos];
cbuf[c->pos] = '\0';
*c->psize = (c->wide > 0) ? c->pos / sizeof (wchar_t) : c->pos;
return n;
}
 
/* Seek to position POS relative to WHENCE within stream described by
COOKIE; return resulting position or fail with EOF. */
static _fpos_t
_DEFUN(memseeker, (ptr, cookie, pos, whence),
struct _reent *ptr _AND
void *cookie _AND
_fpos_t pos _AND
int whence)
{
memstream *c = (memstream *) cookie;
OFF_T offset = (OFF_T) pos;
 
if (whence == SEEK_CUR)
offset += c->pos;
else if (whence == SEEK_END)
offset += c->eof;
if (offset < 0)
{
ptr->_errno = EINVAL;
offset = -1;
}
else if ((size_t) offset != offset)
{
ptr->_errno = ENOSPC;
offset = -1;
}
#ifdef __LARGE64_FILES
else if ((_fpos_t) offset != offset)
{
ptr->_errno = EOVERFLOW;
offset = -1;
}
#endif /* __LARGE64_FILES */
else
{
if (c->pos < c->eof)
{
if (c->wide > 0)
*(wchar_t *)((*c->pbuf) + c->pos) = c->saved.w;
else
(*c->pbuf)[c->pos] = c->saved.c;
c->saved.w = L'\0';
}
c->pos = offset;
if (c->pos < c->eof)
{
if (c->wide > 0)
{
c->saved.w = *(wchar_t *)((*c->pbuf) + c->pos);
*(wchar_t *)((*c->pbuf) + c->pos) = L'\0';
*c->psize = c->pos / sizeof (wchar_t);
}
else
{
c->saved.c = (*c->pbuf)[c->pos];
(*c->pbuf)[c->pos] = '\0';
*c->psize = c->pos;
}
}
else if (c->wide > 0)
*c->psize = c->eof / sizeof (wchar_t);
else
*c->psize = c->eof;
}
return (_fpos_t) offset;
}
 
/* Seek to position POS relative to WHENCE within stream described by
COOKIE; return resulting position or fail with EOF. */
#ifdef __LARGE64_FILES
static _fpos64_t
_DEFUN(memseeker64, (ptr, cookie, pos, whence),
struct _reent *ptr _AND
void *cookie _AND
_fpos64_t pos _AND
int whence)
{
_off64_t offset = (_off64_t) pos;
memstream *c = (memstream *) cookie;
 
if (whence == SEEK_CUR)
offset += c->pos;
else if (whence == SEEK_END)
offset += c->eof;
if (offset < 0)
{
ptr->_errno = EINVAL;
offset = -1;
}
else if ((size_t) offset != offset)
{
ptr->_errno = ENOSPC;
offset = -1;
}
else
{
if (c->pos < c->eof)
{
if (c->wide > 0)
*(wchar_t *)((*c->pbuf) + c->pos) = c->saved.w;
else
(*c->pbuf)[c->pos] = c->saved.c;
c->saved.w = L'\0';
}
c->pos = offset;
if (c->pos < c->eof)
{
if (c->wide > 0)
{
c->saved.w = *(wchar_t *)((*c->pbuf) + c->pos);
*(wchar_t *)((*c->pbuf) + c->pos) = L'\0';
*c->psize = c->pos / sizeof (wchar_t);
}
else
{
c->saved.c = (*c->pbuf)[c->pos];
(*c->pbuf)[c->pos] = '\0';
*c->psize = c->pos;
}
}
else if (c->wide > 0)
*c->psize = c->eof / sizeof (wchar_t);
else
*c->psize = c->eof;
}
return (_fpos64_t) offset;
}
#endif /* __LARGE64_FILES */
 
/* Reclaim resources used by stream described by COOKIE. */
static int
_DEFUN(memcloser, (ptr, cookie),
struct _reent *ptr _AND
void *cookie)
{
memstream *c = (memstream *) cookie;
char *buf;
 
/* Be nice and try to reduce any unused memory. */
buf = _realloc_r (ptr, *c->pbuf,
c->wide > 0 ? (*c->psize + 1) * sizeof (wchar_t)
: *c->psize + 1);
if (buf)
*c->pbuf = buf;
_free_r (ptr, c->storage);
return 0;
}
 
/* Open a memstream that tracks a dynamic buffer in BUF and SIZE.
Return the new stream, or fail with NULL. */
static FILE *
_DEFUN(internal_open_memstream_r, (ptr, buf, size, wide),
struct _reent *ptr _AND
char **buf _AND
size_t *size _AND
int wide)
{
FILE *fp;
memstream *c;
 
if (!buf || !size)
{
ptr->_errno = EINVAL;
return NULL;
}
if ((fp = __sfp (ptr)) == NULL)
return NULL;
if ((c = (memstream *) _malloc_r (ptr, sizeof *c)) == NULL)
{
_newlib_sfp_lock_start ();
fp->_flags = 0; /* release */
#ifndef __SINGLE_THREAD__
__lock_close_recursive (fp->_lock);
#endif
_newlib_sfp_lock_end ();
return NULL;
}
/* Use *size as a hint for initial sizing, but bound the initial
malloc between 64 bytes (same as asprintf, to avoid frequent
mallocs on small strings) and 64k bytes (to avoid overusing the
heap if *size was garbage). */
c->max = *size;
if (wide == 1)
c->max *= sizeof(wchar_t);
if (c->max < 64)
c->max = 64;
#if (SIZE_MAX >= 64 * 1024)
else if (c->max > 64 * 1024)
c->max = 64 * 1024;
#endif
*size = 0;
*buf = _malloc_r (ptr, c->max);
if (!*buf)
{
_newlib_sfp_lock_start ();
fp->_flags = 0; /* release */
#ifndef __SINGLE_THREAD__
__lock_close_recursive (fp->_lock);
#endif
_newlib_sfp_lock_end ();
_free_r (ptr, c);
return NULL;
}
if (wide == 1)
**((wchar_t **)buf) = L'\0';
else
**buf = '\0';
 
c->storage = c;
c->pbuf = buf;
c->psize = size;
c->pos = 0;
c->eof = 0;
c->saved.w = L'\0';
c->wide = (int8_t) wide;
 
_newlib_flockfile_start (fp);
fp->_file = -1;
fp->_flags = __SWR;
fp->_cookie = c;
fp->_read = NULL;
fp->_write = memwriter;
fp->_seek = memseeker;
#ifdef __LARGE64_FILES
fp->_seek64 = memseeker64;
fp->_flags |= __SL64;
#endif
fp->_close = memcloser;
ORIENT (fp, wide);
_newlib_flockfile_end (fp);
return fp;
}
 
FILE *
_DEFUN(_open_memstream_r, (ptr, buf, size),
struct _reent *ptr _AND
char **buf _AND
size_t *size)
{
return internal_open_memstream_r (ptr, buf, size, -1);
}
 
FILE *
_DEFUN(_open_wmemstream_r, (ptr, buf, size),
struct _reent *ptr _AND
wchar_t **buf _AND
size_t *size)
{
return internal_open_memstream_r (ptr, (char **)buf, size, 1);
}
 
#ifndef _REENT_ONLY
FILE *
_DEFUN(open_memstream, (buf, size),
char **buf _AND
size_t *size)
{
return _open_memstream_r (_REENT, buf, size);
}
 
FILE *
_DEFUN(open_wmemstream, (buf, size),
wchar_t **buf _AND
size_t *size)
{
return _open_wmemstream_r (_REENT, buf, size);
}
#endif /* !_REENT_ONLY */
/contrib/sdk/sources/newlib/libc/stdio/putc_u.c
0,0 → 1,93
/*
* 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
<<putc_unlocked>>---non-thread-safe version of putc (macro)
 
INDEX
putc_unlocked
INDEX
_putc_unlocked_r
 
SYNOPSIS
#include <stdio.h>
int putc_unlocked(int <[ch]>, FILE *<[fp]>);
 
#include <stdio.h>
int _putc_unlocked_r(struct _reent *<[ptr]>, int <[ch]>, FILE *<[fp]>);
 
DESCRIPTION
<<putc_unlocked>> is a non-thread-safe version of <<putc>> declared in
<<stdio.h>>. <<putc_unlocked>> may only safely be used within a scope
protected by flockfile() (or ftrylockfile()) and funlockfile(). These
functions 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
<<putc_unlocked>> is equivalent to <<putc>>.
 
The function <<_putc_unlocked_r>> is simply the reentrant version of
<<putc_unlocked>> that takes an additional reentrant structure pointer
argument: <[ptr]>.
 
RETURNS
See <<putc>>.
 
PORTABILITY
POSIX 1003.1 requires <<putc_unlocked>>. <<putc_unlocked>> may be
implemented as a macro, so arguments should not have side-effects.
 
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>
 
/*
* A subroutine version of the macro putc_unlocked.
*/
 
#undef putc_unlocked
 
int
_DEFUN(_putc_unlocked_r, (ptr, c, fp),
struct _reent *ptr _AND
int c _AND
register FILE *fp)
{
/* CHECK_INIT is (eventually) called by __swbuf. */
 
return __sputc_r (ptr, c, fp);
}
 
#ifndef _REENT_ONLY
int
_DEFUN(putc_unlocked, (c, fp),
int c _AND
register FILE *fp)
{
/* CHECK_INIT is (eventually) called by __swbuf. */
 
return __sputc_r (_REENT, c, fp);
}
#endif /* !_REENT_ONLY */
/contrib/sdk/sources/newlib/libc/stdio/putchar_u.c
0,0 → 1,82
/*
* 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
<<putchar_unlocked>>---non-thread-safe version of putchar (macro)
 
INDEX
putchar_unlocked
 
SYNOPSIS
#include <stdio.h>
int putchar_unlocked(int <[ch]>);
 
DESCRIPTION
<<putchar_unlocked>> is a non-thread-safe version of <<putchar>>
declared in <<stdio.h>>. <<putchar_unlocked>> may only safely be used
within a scope protected by flockfile() (or ftrylockfile()) and
funlockfile(). These functions 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 <<putchar_unlocked>> is equivalent to <<putchar>>.
 
RETURNS
See <<putchar>>.
 
PORTABILITY
POSIX 1003.1 requires <<putchar_unlocked>>. <<putchar_unlocked>> may
be implemented as a macro.
 
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 */
 
/*
* A subroutine version of the macro putchar_unlocked.
*/
 
#include <_ansi.h>
#include <reent.h>
#include <stdio.h>
 
#undef putchar_unlocked
 
int
_DEFUN(_putchar_unlocked_r, (ptr, c),
struct _reent *ptr _AND
int c)
{
return putc_unlocked (c, _stdout_r (ptr));
}
 
#ifndef _REENT_ONLY
 
int
_DEFUN(putchar_unlocked, (c),
int c)
{
/* CHECK_INIT is (eventually) called by __swbuf. */
 
return _putchar_unlocked_r (_REENT, c);
}
 
#endif
/contrib/sdk/sources/newlib/libc/stdio/scanf.c
0,0 → 1,90
/*
* 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.
*/
 
#include <_ansi.h>
#include <reent.h>
#include <stdio.h>
#ifdef _HAVE_STDC
#include <stdarg.h>
#else
#include <varargs.h>
#endif
#include "local.h"
 
#ifndef _REENT_ONLY
 
int
#ifdef _HAVE_STDC
scanf(_CONST char *__restrict fmt, ...)
#else
scanf(fmt, va_alist)
char *fmt;
va_dcl
#endif
{
int ret;
va_list ap;
struct _reent *reent = _REENT;
 
_REENT_SMALL_CHECK_INIT (reent);
#ifdef _HAVE_STDC
va_start (ap, fmt);
#else
va_start (ap);
#endif
ret = _vfscanf_r (reent, _stdin_r (reent), fmt, ap);
va_end (ap);
return ret;
}
 
#ifdef _NANO_FORMATTED_IO
int
_EXFUN(iscanf, (const char *, ...)
_ATTRIBUTE ((__alias__("scanf"))));
#endif
 
#endif /* !_REENT_ONLY */
 
int
#ifdef _HAVE_STDC
_scanf_r(struct _reent *ptr, _CONST char *__restrict fmt, ...)
#else
_scanf_r(ptr, fmt, va_alist)
struct _reent *ptr;
char *fmt;
va_dcl
#endif
{
int ret;
va_list ap;
 
_REENT_SMALL_CHECK_INIT (ptr);
#ifdef _HAVE_STDC
va_start (ap, fmt);
#else
va_start (ap);
#endif
ret = _vfscanf_r (ptr, _stdin_r (ptr), fmt, ap);
va_end (ap);
return (ret);
}
 
#ifdef _NANO_FORMATTED_IO
int
_EXFUN(_iscanf_r, (struct _reent *, const char *, ...)
_ATTRIBUTE ((__alias__("_scanf_r"))));
#endif
/contrib/sdk/sources/newlib/libc/stdio/setbuf.c
0,0 → 1,79
/*
* 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
<<setbuf>>---specify full buffering for a file or stream
 
INDEX
setbuf
 
ANSI_SYNOPSIS
#include <stdio.h>
void setbuf(FILE *<[fp]>, char *<[buf]>);
 
TRAD_SYNOPSIS
#include <stdio.h>
void setbuf(<[fp]>, <[buf]>)
FILE *<[fp]>;
char *<[buf]>;
 
DESCRIPTION
<<setbuf>> specifies that output to the file or stream identified by <[fp]>
should be fully buffered. All output for this file will go to a
buffer (of size <<BUFSIZ>>, specified in `<<stdio.h>>'). Output will
be passed on to the host system only when the buffer is full, or when
an input operation intervenes.
 
You may, if you wish, supply your own buffer by passing a pointer to
it as the argument <[buf]>. It must have size <<BUFSIZ>>. You can
also use <<NULL>> as the value of <[buf]>, to signal that the
<<setbuf>> function is to allocate the buffer.
 
WARNINGS
You may only use <<setbuf>> before performing any file operation other
than opening the file.
 
If you supply a non-null <[buf]>, you must ensure that the associated
storage continues to be available until you close the stream
identified by <[fp]>.
 
RETURNS
<<setbuf>> does not return a result.
 
PORTABILITY
Both ANSI C and the System V Interface Definition (Issue 2) require
<<setbuf>>. However, they differ on the meaning of a <<NULL>> buffer
pointer: the SVID issue 2 specification says that a <<NULL>> buffer
pointer requests unbuffered output. For maximum portability, avoid
<<NULL>> buffer pointers.
 
Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
<<lseek>>, <<read>>, <<sbrk>>, <<write>>.
*/
 
#include <_ansi.h>
#include <stdio.h>
#include "local.h"
 
_VOID
_DEFUN(setbuf, (fp, buf),
FILE *__restrict fp _AND
char *__restrict buf)
{
_CAST_VOID setvbuf (fp, buf, buf ? _IOFBF : _IONBF, BUFSIZ);
}
/contrib/sdk/sources/newlib/libc/stdio/setbuffer.c
0,0 → 1,81
/*
* 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.
*/
/*
Modified copy of setbuf.c to support the setbuffer function
defined as part of BSD.
Modifications by Gareth Pearce, 2001.
*/
 
/*
FUNCTION
<<setbuffer>>---specify full buffering for a file or stream with size
 
INDEX
setbuffer
 
ANSI_SYNOPSIS
#include <stdio.h>
void setbuffer(FILE *<[fp]>, char *<[buf]>, int <[size]>);
 
TRAD_SYNOPSIS
#include <stdio.h>
void setbuffer(<[fp]>, <[buf]>, <[size]>)
FILE *<[fp]>;
char *<[buf]>;
int <[size]>;
 
DESCRIPTION
<<setbuffer>> specifies that output to the file or stream identified by
<[fp]> should be fully buffered. All output for this file will go to a
buffer (of size <[size]>). Output will be passed on to the host system
only when the buffer is full, or when an input operation intervenes.
 
You may, if you wish, supply your own buffer by passing a pointer to
it as the argument <[buf]>. It must have size <[size]>. You can
also use <<NULL>> as the value of <[buf]>, to signal that the
<<setbuffer>> function is to allocate the buffer.
 
WARNINGS
You may only use <<setbuffer>> before performing any file operation
other than opening the file.
 
If you supply a non-null <[buf]>, you must ensure that the associated
storage continues to be available until you close the stream
identified by <[fp]>.
 
RETURNS
<<setbuffer>> does not return a result.
 
PORTABILITY
This function comes from BSD not ANSI or POSIX.
 
Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
<<lseek>>, <<read>>, <<sbrk>>, <<write>>.
*/
 
#include <_ansi.h>
#include <stdio.h>
#include "local.h"
 
_VOID
_DEFUN(setbuffer, (fp, buf, size),
FILE * fp _AND
char *buf _AND
int size)
{
_CAST_VOID setvbuf (fp, buf, buf ? _IOFBF : _IONBF, (size_t) size);
}
/contrib/sdk/sources/newlib/libc/stdio/setlinebuf.c
0,0 → 1,68
/*
* 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.
*/
/*
Modified copy of setbuf.c to support setlinebuf function
defined as part of BSD.
Modifications by Gareth Pearce, 2001.
*/
 
/*
FUNCTION
<<setlinebuf>>---specify line buffering for a file or stream
 
INDEX
setlinebuf
 
ANSI_SYNOPSIS
#include <stdio.h>
void setlinebuf(FILE *<[fp]>);
 
TRAD_SYNOPSIS
#include <stdio.h>
void setlinebuf(<[fp]>)
FILE *<[fp]>;
 
DESCRIPTION
<<setlinebuf>> specifies that output to the file or stream identified by
<[fp]> should be line buffered. This causes the file or stream to pass
on output to the host system at every newline, as well as when the
buffer is full, or when an input operation intervenes.
 
WARNINGS
You may only use <<setlinebuf>> before performing any file operation
other than opening the file.
 
RETURNS
<<setlinebuf>> returns as per setvbuf.
 
PORTABILITY
This function comes from BSD not ANSI or POSIX.
 
Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
<<lseek>>, <<read>>, <<sbrk>>, <<write>>.
*/
 
#include <_ansi.h>
#include <stdio.h>
#include "local.h"
 
int
_DEFUN(setlinebuf, (fp),
FILE * fp)
{
return (setvbuf (fp, (char *) NULL, _IOLBF, (size_t) 0));
}
/contrib/sdk/sources/newlib/libc/stdio/setvbuf.c
104,22 → 104,21
{
int ret = 0;
struct _reent *reent = _REENT;
size_t iosize;
int ttyflag;
 
CHECK_INIT (reent, fp);
 
_newlib_flockfile_start (fp);
 
/*
* Verify arguments. The `int' limit on `size' is due to this
* particular implementation.
* particular implementation. Note, buf and size are ignored
* when setting _IONBF.
*/
 
if ((mode != _IOFBF && mode != _IOLBF && mode != _IONBF) || (int)(_POINTER_INT) size < 0)
{
_newlib_flockfile_exit (fp);
if (mode != _IONBF)
if ((mode != _IOFBF && mode != _IOLBF) || (int)(_POINTER_INT) size < 0)
return (EOF);
}
 
 
/*
* Write current buffer, if any; drop read count, if any.
* Make sure putc() will not think fp is line buffered.
126,34 → 125,49
* Free old buffer if it was from malloc(). Clear line and
* non buffer flags, and clear malloc flag.
*/
 
_newlib_flockfile_start (fp);
_fflush_r (reent, fp);
fp->_r = 0;
fp->_lbfsize = 0;
if (HASUB(fp))
FREEUB(reent, fp);
fp->_r = fp->_lbfsize = 0;
if (fp->_flags & __SMBF)
_free_r (reent, (_PTR) fp->_bf._base);
fp->_flags &= ~(__SLBF | __SNBF | __SMBF);
fp->_flags &= ~(__SLBF | __SNBF | __SMBF | __SOPT | __SNPT | __SEOF);
 
if (mode == _IONBF)
goto nbf;
 
/*
* Allocate buffer if needed. */
* Find optimal I/O size for seek optimization. This also returns
* a `tty flag' to suggest that we check isatty(fd), but we do not
* care since our caller told us how to buffer.
*/
fp->_flags |= __swhatbuf_r (reent, fp, &iosize, &ttyflag);
if (size == 0)
{
buf = NULL;
size = iosize;
}
 
/* Allocate buffer if needed. */
if (buf == NULL)
{
/* we need this here because malloc() may return a pointer
even if size == 0 */
if (!size) size = BUFSIZ;
if ((buf = malloc (size)) == NULL)
{
/*
* Unable to honor user's request. We will return
* failure, but try again with file system size.
*/
ret = EOF;
/* Try another size... */
buf = malloc (BUFSIZ);
size = BUFSIZ;
if (size != iosize)
{
size = iosize;
buf = malloc (size);
}
}
if (buf == NULL)
{
/* Can't allocate it, let's try another approach */
/* No luck; switch to unbuffered I/O. */
nbf:
fp->_flags |= __SNBF;
fp->_w = 0;
164,36 → 178,54
}
fp->_flags |= __SMBF;
}
 
/*
* Now put back whichever flag is needed, and fix _lbfsize
* if line buffered. Ensure output flush on exit if the
* stream will be buffered at all.
* If buf is NULL then make _lbfsize 0 to force the buffer
* to be flushed and hence malloced on first use
* We're committed to buffering from here, so make sure we've
* registered to flush buffers on exit.
*/
if (!reent->__sdidinit)
__sinit(reent);
 
switch (mode)
{
case _IOLBF:
#ifdef _FSEEK_OPTIMIZATION
/*
* Kill any seek optimization if the buffer is not the
* right size.
*
* SHOULD WE ALLOW MULTIPLES HERE (i.e., ok iff (size % iosize) == 0)?
*/
if (size != iosize)
fp->_flags |= __SNPT;
#endif
 
/*
* Fix up the FILE fields, and set __cleanup for output flush on
* exit (since we are buffered in some way).
*/
if (mode == _IOLBF)
fp->_flags |= __SLBF;
fp->_lbfsize = buf ? -size : 0;
/* FALLTHROUGH */
 
case _IOFBF:
/* no flag */
reent->__cleanup = _cleanup_r;
fp->_bf._base = fp->_p = (unsigned char *) buf;
fp->_bf._size = size;
break;
}
 
/* fp->_lbfsize is still 0 */
if (fp->_flags & __SWR)
{
/*
* Patch up write count if necessary.
* Begin or continue writing: see __swsetup(). Note
* that __SNBF is impossible (it was handled earlier).
*/
if (fp->_flags & __SLBF)
{
fp->_w = 0;
fp->_lbfsize = -fp->_bf._size;
}
else
fp->_w = size;
}
else
{
/* begin/continue reading, or stay in intermediate state */
fp->_w = 0;
}
 
if (fp->_flags & __SWR)
fp->_w = fp->_flags & (__SLBF | __SNBF) ? 0 : size;
 
_newlib_flockfile_end (fp);
return 0;
}
/contrib/sdk/sources/newlib/libc/stdio/stdio_ext.c
0,0 → 1,113
/*
FUNCTION
<<stdio_ext>>,<<__fbufsize>>,<<__fpending>>,<<__flbf>>,<<__freadable>>,<<__fwritable>>,<<__freading>>,<<__fwriting>>---access internals of FILE structure
 
INDEX
__fbufsize
INDEX
__fpending
INDEX
__flbf
INDEX
__freadable
INDEX
__fwritable
INDEX
__freading
INDEX
__fwriting
 
ANSI_SYNOPSIS
#include <stdio.h>
#include <stdio_ext.h>
size_t __fbufsize(FILE *<[fp]>);
size_t __fpending(FILE *<[fp]>);
int __flbf(FILE *<[fp]>);
int __freadable(FILE *<[fp]>);
int __fwritable(FILE *<[fp]>);
int __freading(FILE *<[fp]>);
int __fwriting(FILE *<[fp]>);
 
DESCRIPTION
These functions provides access to the internals of the FILE structure <[fp]>.
 
RETURNS
<<__fbufsize>> returns the number of bytes in the buffer of stream <[fp]>.
 
<<__fpending>> returns the number of bytes in the output buffer of stream <[fp]>.
 
<<__flbf>> returns nonzero if stream <[fp]> is line-buffered, and <<0>> if not.
 
<<__freadable>> returns nonzero if stream <[fp]> may be read, and <<0>> if not.
 
<<__fwritable>> returns nonzero if stream <[fp]> may be written, and <<0>> if not.
 
<<__freading>> returns nonzero if stream <[fp]> if the last operation on
it was a read, or if it read-only, and <<0>> if not.
 
<<__fwriting>> returns nonzero if stream <[fp]> if the last operation on
it was a write, or if it write-only, and <<0>> if not.
 
PORTABILITY
These functions originate from Solaris and are also provided by GNU libc.
 
No supporting OS subroutines are required.
*/
 
#ifndef __rtems__
 
#include <_ansi.h>
#include <stdio.h>
 
/* Subroutine versions of the inline or macro functions. */
 
size_t
_DEFUN(__fbufsize, (fp),
FILE * fp)
{
return (size_t) fp->_bf._size;
}
 
size_t
_DEFUN(__fpending, (fp),
FILE * fp)
{
return fp->_p - fp->_bf._base;
}
 
int
_DEFUN(__flbf, (fp),
FILE * fp)
{
return (fp->_flags & __SLBF) != 0;
}
 
int
_DEFUN(__freadable, (fp),
FILE * fp)
{
return (fp->_flags & (__SRD | __SRW)) != 0;
}
 
int
_DEFUN(__fwritable, (fp),
FILE * fp)
{
return (fp->_flags & (__SWR | __SRW)) != 0;
}
 
int
_DEFUN(__freading, (fp),
FILE * fp)
{
return (fp->_flags & __SRD) != 0;
}
 
int
_DEFUN(__fwriting, (fp),
FILE * fp)
{
return (fp->_flags & __SWR) != 0;
}
 
#endif /* __rtems__ */
/contrib/sdk/sources/newlib/libc/stdio/vasiprintf.c
0,0 → 1,65
/*
* 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 was based on vsiprintf.c */
/* doc in vfprintf.c */
 
#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 <limits.h>
#include <stdarg.h>
 
#include "local.h"
 
#ifndef _REENT_ONLY
 
int
_DEFUN(vasiprintf, (strp, fmt, ap),
char **strp _AND
const char *fmt _AND
va_list ap)
{
return _vasiprintf_r (_REENT, strp, fmt, ap);
}
 
#endif /* !_REENT_ONLY */
 
int
_DEFUN(_vasiprintf_r, (ptr, strp, fmt, ap),
struct _reent *ptr _AND
char **strp _AND
const char *fmt _AND
va_list ap)
{
int ret;
FILE f;
 
f._flags = __SWR | __SSTR | __SMBF ;
f._bf._base = f._p = NULL;
f._bf._size = f._w = 0;
f._file = -1; /* No file. */
ret = _svfiprintf_r (ptr, &f, fmt, ap);
if (ret >= 0)
{
*f._p = 0;
*strp = (char *) f._bf._base;
}
return ret;
}
/contrib/sdk/sources/newlib/libc/stdio/vasprintf.c
0,0 → 1,77
/*
* 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 was based on vsprintf.c */
/* doc in vfprintf.c */
 
#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 <limits.h>
#include <stdarg.h>
 
#include "local.h"
 
#ifndef _REENT_ONLY
 
int
_DEFUN(vasprintf, (strp, fmt, ap),
char **strp _AND
const char *fmt _AND
va_list ap)
{
return _vasprintf_r (_REENT, strp, fmt, ap);
}
 
#ifdef _NANO_FORMATTED_IO
int
_EXFUN(vasiprintf, (char **, const char *, __VALIST)
_ATTRIBUTE ((__alias__("vasprintf"))));
#endif
 
#endif /* !_REENT_ONLY */
 
int
_DEFUN(_vasprintf_r, (ptr, strp, fmt, ap),
struct _reent *ptr _AND
char **strp _AND
const char *fmt _AND
va_list ap)
{
int ret;
FILE f;
 
f._flags = __SWR | __SSTR | __SMBF ;
f._bf._base = f._p = NULL;
f._bf._size = f._w = 0;
f._file = -1; /* No file. */
ret = _svfprintf_r (ptr, &f, fmt, ap);
if (ret >= 0)
{
*f._p = 0;
*strp = (char *) f._bf._base;
}
return ret;
}
 
#ifdef _NANO_FORMATTED_IO
int
_EXFUN(_vasiprintf_r, (struct _reent *, char **, const char *, __VALIST)
_ATTRIBUTE ((__alias__("_vasprintf_r"))));
#endif
/contrib/sdk/sources/newlib/libc/stdio/vfprintf.c
1332,7 → 1332,7
expsize = exponent (expstr, expt, ch);
size = expsize + ndig;
if (ndig > 1 || flags & ALT)
++size;
size += decp_len;
# ifdef _WANT_IO_C99_FORMATS
flags &= ~GROUPING;
# endif
1341,18 → 1341,20
if (expt > 0) {
size = expt;
if (prec || flags & ALT)
size += prec + 1;
size += prec + decp_len;
} else /* "0.X" */
size = (prec || flags & ALT)
? prec + 2
? prec + 1 + decp_len
: 1;
} else if (expt >= ndig) { /* fixed g fmt */
size = expt;
if (flags & ALT)
++size;
} else
size = ndig + (expt > 0 ?
1 : 2 - expt);
size += decp_len;
} else {
size = ndig + decp_len;
if (expt <= 0)
size += 1 - expt;
}
# ifdef _WANT_IO_C99_FORMATS
if ((flags & GROUPING) && expt > 0) {
/* space for thousands' grouping */
/contrib/sdk/sources/newlib/libc/stdio/viprintf.c
0,0 → 1,128
/*
* 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
<<viprintf>>, <<vfiprintf>>, <<vsiprintf>>, <<vsniprintf>>, <<vasiprintf>>, <<vasniprintf>>---format argument list (integer only)
 
INDEX
viprintf
INDEX
_viprintf_r
INDEX
vfiprintf
INDEX
_vfiprintf_r
INDEX
vsiprintf
INDEX
_vsiprintf_r
INDEX
vsniprintf
INDEX
_vsniprintf_r
INDEX
vasiprintf
INDEX
_vasiprintf_r
INDEX
vasniprintf
INDEX
_vasniprintf_r
 
ANSI_SYNOPSIS
#include <stdio.h>
#include <stdarg.h>
int viprintf(const char *<[fmt]>, va_list <[list]>);
int vfiprintf(FILE *<[fp]>, const char *<[fmt]>, va_list <[list]>);
int vsiprintf(char *<[str]>, const char *<[fmt]>, va_list <[list]>);
int vsniprintf(char *<[str]>, size_t <[size]>, const char *<[fmt]>,
va_list <[list]>);
int vasiprintf(char **<[strp]>, const char *<[fmt]>, va_list <[list]>);
char *vasniprintf(char *<[str]>, size_t *<[size]>, const char *<[fmt]>,
va_list <[list]>);
 
int _viprintf_r(struct _reent *<[reent]>, const char *<[fmt]>,
va_list <[list]>);
int _vfiprintf_r(struct _reent *<[reent]>, FILE *<[fp]>,
const char *<[fmt]>, va_list <[list]>);
int _vsiprintf_r(struct _reent *<[reent]>, char *<[str]>,
const char *<[fmt]>, va_list <[list]>);
int _vsniprintf_r(struct _reent *<[reent]>, char *<[str]>,
size_t <[size]>, const char *<[fmt]>, va_list <[list]>);
int _vasiprintf_r(struct _reent *<[reent]>, char **<[str]>,
const char *<[fmt]>, va_list <[list]>);
char *_vasniprintf_r(struct _reent *<[reent]>, char *<[str]>,
size_t *<[size]>, const char *<[fmt]>, va_list <[list]>);
 
DESCRIPTION
<<viprintf>>, <<vfiprintf>>, <<vasiprintf>>, <<vsiprintf>>,
<<vsniprintf>>, and <<vasniprintf>> are (respectively) variants of
<<iprintf>>, <<fiprintf>>, <<asiprintf>>, <<siprintf>>, <<sniprintf>>,
and <<asniprintf>>. They differ only in allowing their caller to pass
the variable argument list as a <<va_list>> object (initialized by
<<va_start>>) rather than directly accepting a variable number of
arguments. The caller is responsible for calling <<va_end>>.
 
<<_viprintf_r>>, <<_vfiprintf_r>>, <<_vasiprintf_r>>,
<<_vsiprintf_r>>, <<_vsniprintf_r>>, and <<_vasniprintf_r>> are
reentrant versions of the above.
 
RETURNS
The return values are consistent with the corresponding functions:
 
PORTABILITY
All of these functions are newlib extensions.
 
Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
<<lseek>>, <<read>>, <<sbrk>>, <<write>>.
*/
 
#include <_ansi.h>
#include <reent.h>
#include <stdio.h>
#ifdef _HAVE_STDC
#include <stdarg.h>
#else
#include <varargs.h>
#endif
#include "local.h"
 
#ifndef _REENT_ONLY
 
int
_DEFUN(viprintf, (fmt, ap),
_CONST char *fmt _AND
va_list ap)
{
struct _reent *reent = _REENT;
 
_REENT_SMALL_CHECK_INIT (reent);
return _vfiprintf_r (reent, _stdout_r (reent), fmt, ap);
}
 
#endif /* !_REENT_ONLY */
 
int
_DEFUN(_viprintf_r, (ptr, fmt, ap),
struct _reent *ptr _AND
_CONST char *fmt _AND
va_list ap)
{
_REENT_SMALL_CHECK_INIT (ptr);
return _vfiprintf_r (ptr, _stdout_r (ptr), fmt, ap);
}
/contrib/sdk/sources/newlib/libc/stdio/viscanf.c
0,0 → 1,147
/*-
* Code created by modifying iscanf.c which has following copyright.
*
* Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
 
/*
FUNCTION
<<viscanf>>, <<vfiscanf>>, <<vsiscanf>>---format argument list
 
INDEX
viscanf
INDEX
_viscanf_r
INDEX
vfiscanf
INDEX
_vfiscanf_r
INDEX
vsiscanf
INDEX
_vsiscanf_r
 
ANSI_SYNOPSIS
#include <stdio.h>
#include <stdarg.h>
int viscanf(const char *<[fmt]>, va_list <[list]>);
int vfiscanf(FILE *<[fp]>, const char *<[fmt]>, va_list <[list]>);
int vsiscanf(const char *<[str]>, const char *<[fmt]>, va_list <[list]>);
 
int _viscanf_r(struct _reent *<[reent]>, const char *<[fmt]>,
va_list <[list]>);
int _vfiscanf_r(struct _reent *<[reent]>, FILE *<[fp]>, const char *<[fmt]>,
va_list <[list]>);
int _vsiscanf_r(struct _reent *<[reent]>, const char *<[str]>,
const char *<[fmt]>, va_list <[list]>);
 
TRAD_SYNOPSIS
#include <stdio.h>
#include <varargs.h>
int viscanf( <[fmt]>, <[ist]>)
char *<[fmt]>;
va_list <[list]>;
 
int vfiscanf( <[fp]>, <[fmt]>, <[list]>)
FILE *<[fp]>;
char *<[fmt]>;
va_list <[list]>;
int vsiscanf( <[str]>, <[fmt]>, <[list]>)
char *<[str]>;
char *<[fmt]>;
va_list <[list]>;
 
int _viscanf_r( <[reent]>, <[fmt]>, <[ist]>)
struct _reent *<[reent]>;
char *<[fmt]>;
va_list <[list]>;
 
int _vfiscanf_r( <[reent]>, <[fp]>, <[fmt]>, <[list]>)
struct _reent *<[reent]>;
FILE *<[fp]>;
char *<[fmt]>;
va_list <[list]>;
int _vsiscanf_r( <[reent]>, <[str]>, <[fmt]>, <[list]>)
struct _reent *<[reent]>;
char *<[str]>;
char *<[fmt]>;
va_list <[list]>;
 
DESCRIPTION
<<viscanf>>, <<vfiscanf>>, and <<vsiscanf>> are (respectively) variants
of <<iscanf>>, <<fiscanf>>, and <<siscanf>>. They differ only in
allowing their caller to pass the variable argument list as a
<<va_list>> object (initialized by <<va_start>>) rather than
directly accepting a variable number of arguments.
 
RETURNS
The return values are consistent with the corresponding functions:
<<viscanf>> returns the number of input fields successfully scanned,
converted, and stored; the return value does not include scanned
fields which were not stored.
 
If <<viscanf>> attempts to read at end-of-file, the return value
is <<EOF>>.
 
If no fields were stored, the return value is <<0>>.
 
The routines <<_viscanf_r>>, <<_vfiscanf_f>>, and <<_vsiscanf_r>> are
reentrant versions which take an additional first parameter which points to the
reentrancy structure.
 
PORTABILITY
These are newlib extensions.
 
Supporting OS subroutines required:
*/
 
#include <_ansi.h>
#include <reent.h>
#include <stdio.h>
#ifdef _HAVE_STDC
#include <stdarg.h>
#else
#include <varargs.h>
#endif
#include "local.h"
 
#ifndef _REENT_ONLY
 
int
_DEFUN(viscanf, (fmt, ap),
_CONST char *fmt _AND
va_list ap)
{
struct _reent *reent = _REENT;
 
_REENT_SMALL_CHECK_INIT (reent);
return __svfiscanf_r (reent, _stdin_r (reent), fmt, ap);
}
 
#endif /* !_REENT_ONLY */
 
int
_DEFUN(_viscanf_r, (ptr, fmt, ap),
struct _reent *ptr _AND
_CONST char *fmt _AND
va_list ap)
{
_REENT_SMALL_CHECK_INIT (ptr);
return __svfiscanf_r (ptr, _stdin_r (ptr), fmt, ap);
}
 
/contrib/sdk/sources/newlib/libc/stdio/vprintf.c
0,0 → 1,63
/*
* 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.
*/
/* doc in vfprintf.c */
 
#include <_ansi.h>
#include <reent.h>
#include <stdio.h>
#ifdef _HAVE_STDC
#include <stdarg.h>
#else
#include <varargs.h>
#endif
#include "local.h"
 
#ifndef _REENT_ONLY
 
int
_DEFUN(vprintf, (fmt, ap),
_CONST char *fmt _AND
va_list ap)
{
struct _reent *reent = _REENT;
 
_REENT_SMALL_CHECK_INIT (reent);
return _vfprintf_r (reent, _stdout_r (reent), fmt, ap);
}
 
#ifdef _NANO_FORMATTED_IO
int
_EXFUN(viprintf, (const char *, __VALIST) _ATTRIBUTE ((__alias__("vprintf"))));
#endif
 
#endif /* !_REENT_ONLY */
 
int
_DEFUN(_vprintf_r, (ptr, fmt, ap),
struct _reent *ptr _AND
_CONST char *__restrict fmt _AND
va_list ap)
{
_REENT_SMALL_CHECK_INIT (ptr);
return _vfprintf_r (ptr, _stdout_r (ptr), fmt, ap);
}
 
#ifdef _NANO_FORMATTED_IO
int
_EXFUN(_viprintf_r, (struct _reent *, const char *, __VALIST)
_ATTRIBUTE ((__alias__("_vprintf_r"))));
#endif
/contrib/sdk/sources/newlib/libc/stdio/vsiprintf.c
0,0 → 1,61
/*
* 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.
*/
/* doc in viprintf.c */
 
#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 <limits.h>
#include <stdarg.h>
 
#include "local.h"
 
#ifndef _REENT_ONLY
 
int
_DEFUN(vsiprintf, (str, fmt, ap),
char *str _AND
const char *fmt _AND
va_list ap)
{
return _vsiprintf_r (_REENT, str, fmt, ap);
}
 
#endif /* !_REENT_ONLY */
 
int
_DEFUN(_vsiprintf_r, (ptr, str, fmt, ap),
struct _reent *ptr _AND
char *str _AND
const char *fmt _AND
va_list ap)
{
int ret;
FILE f;
 
f._flags = __SWR | __SSTR;
f._bf._base = f._p = (unsigned char *) str;
f._bf._size = f._w = INT_MAX;
f._file = -1; /* No file. */
ret = _svfiprintf_r (ptr, &f, fmt, ap);
*f._p = 0;
return ret;
}
/contrib/sdk/sources/newlib/libc/stdio/vsiscanf.c
0,0 → 1,65
/*
* Code created by modifying iscanf.c which has following copyright.
*
* Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
 
#include <_ansi.h>
#include <reent.h>
#include <stdio.h>
#include <string.h>
#ifdef _HAVE_STDC
#include <stdarg.h>
#else
#include <varargs.h>
#endif
#include "local.h"
 
/*
* vsiscanf
*/
 
#ifndef _REENT_ONLY
 
int
_DEFUN(vsiscanf, (str, fmt, ap),
_CONST char *str _AND
_CONST char *fmt _AND
va_list ap)
{
return _vsiscanf_r (_REENT, str, fmt, ap);
}
 
#endif /* !_REENT_ONLY */
 
int
_DEFUN(_vsiscanf_r, (ptr, str, fmt, ap),
struct _reent *ptr _AND
_CONST char *str _AND
_CONST char *fmt _AND
va_list ap)
{
FILE f;
 
f._flags = __SRD | __SSTR;
f._bf._base = f._p = (unsigned char *) str;
f._bf._size = f._r = strlen (str);
f._read = __seofread;
f._ub._base = NULL;
f._lb._base = NULL;
f._file = -1; /* No file. */
return __ssvfiscanf_r (ptr, &f, fmt, ap);
}
/contrib/sdk/sources/newlib/libc/stdio/vsniprintf.c
0,0 → 1,72
/*
* 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.
*/
/* doc in viprintf.c */
 
#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 <limits.h>
#include <stdarg.h>
#include <errno.h>
 
#include "local.h"
 
#ifndef _REENT_ONLY
 
int
_DEFUN(vsniprintf, (str, size, fmt, ap),
char *str _AND
size_t size _AND
const char *fmt _AND
va_list ap)
{
return _vsniprintf_r (_REENT, str, size, fmt, ap);
}
 
#endif /* !_REENT_ONLY */
 
int
_DEFUN(_vsniprintf_r, (ptr, str, size, fmt, ap),
struct _reent *ptr _AND
char *str _AND
size_t size _AND
const char *fmt _AND
va_list ap)
{
int ret;
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. */
ret = _svfiprintf_r (ptr, &f, fmt, ap);
if (ret < EOF)
ptr->_errno = EOVERFLOW;
if (size > 0)
*f._p = 0;
return ret;
}