* 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 <reent.h>
#include <stdio.h>
#include <wchar.h>
#include "local.h"
#undef putwc
wint_t
_DEFUN(_putwc_r, (ptr, wc, fp),
struct _reent *ptr _AND
wchar_t wc _AND
FILE *fp)
{
return _fputwc_r (ptr, wc, fp);
}
/*
* Synonym for fputwc(). The only difference is that putwc(), if it is a
* macro, may evaluate `fp' more than once.
*/
wint_t
_DEFUN(putwc, (wc, fp),
wchar_t wc _AND
FILE *fp)
{
return fputwc (wc, fp);
}
putwc.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: printf.c
===================================================================
--- printf.c (nonexistent)
+++ printf.c (revision 520)
@@ -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 sprintf.c */
+
+#include <_ansi.h>
+#include
+#include
+#include
+#include "local.h"
+
+int
+_DEFUN(_printf_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 = _vfprintf_r (ptr, _stdout_r (ptr), fmt, ap);
+ va_end (ap);
+ return ret;
+}
+
+#ifndef _REENT_ONLY
+
+int
+_DEFUN(printf, (fmt),
+ const char *fmt _DOTS)
+{
+ int ret;
+ va_list ap;
+ struct _reent *ptr = _REENT;
+
+ _REENT_SMALL_CHECK_INIT (ptr);
+ va_start (ap, fmt);
+ ret = _vfprintf_r (ptr, _stdout_r (ptr), fmt, ap);
+ va_end (ap);
+ return ret;
+}
+
+#endif /* ! _REENT_ONLY */
printf.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: vasniprintf.c
===================================================================
--- vasniprintf.c (nonexistent)
+++ vasniprintf.c (revision 520)
@@ -0,0 +1,71 @@
+/* Copyright (C) 2007, 2008 Eric Blake
+ * Permission to use, copy, modify, and distribute this software
+ * is freely granted, provided that this notice is preserved.
+ */
+/* This code was derived from asprintf.c */
+/* doc in viprintf.c */
+
+#include <_ansi.h>
+#include
+#include
+#include
+#include
+#include
+#include "local.h"
+
+char *
+_DEFUN(_vasniprintf_r, (ptr, buf, lenp, fmt, ap),
+ struct _reent *ptr _AND
+ char *buf _AND
+ size_t *lenp _AND
+ const char *fmt _AND
+ va_list ap)
+{
+ int ret;
+ FILE f;
+ size_t len = *lenp;
+
+ if (buf && len)
+ {
+ /* mark an existing buffer, but allow allocation of larger string */
+ f._flags = __SWR | __SSTR | __SOPT;
+ }
+ else
+ {
+ /* mark a zero-length reallocatable buffer */
+ f._flags = __SWR | __SSTR | __SMBF;
+ len = 0;
+ buf = NULL;
+ }
+ f._bf._base = f._p = (unsigned char *) buf;
+ /* For now, inherit the 32-bit signed limit of FILE._bf._size.
+ FIXME - it would be nice to rewrite sys/reent.h to support size_t
+ for _size. */
+ if (len > INT_MAX)
+ {
+ ptr->_errno = EOVERFLOW;
+ return NULL;
+ }
+ f._bf._size = f._w = len;
+ f._file = -1; /* No file. */
+ ret = _svfiprintf_r (ptr, &f, fmt, ap);
+ if (ret < 0)
+ return NULL;
+ *lenp = ret;
+ *f._p = '\0';
+ return (char *) f._bf._base;
+}
+
+#ifndef _REENT_ONLY
+
+char *
+_DEFUN(vasniprintf, (buf, lenp, fmt, ap),
+ char *buf _AND
+ size_t *lenp _AND
+ const char *fmt _AND
+ va_list ap)
+{
+ return _vasniprintf_r (_REENT, buf, lenp, fmt, ap);
+}
+
+#endif /* ! _REENT_ONLY */
vasniprintf.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: iscanf.c
===================================================================
--- iscanf.c (nonexistent)
+++ iscanf.c (revision 520)
@@ -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
+#include
+#ifdef _HAVE_STDC
+#include
+#else
+#include
+#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);
+}
+
iscanf.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: fwalk.c
===================================================================
--- fwalk.c (nonexistent)
+++ fwalk.c (revision 520)
@@ -0,0 +1,108 @@
+/*
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by the University of California, Berkeley. The name of the
+ * University may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ */
+/* No user fns here. Pesch 15apr92. */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "%W% (Berkeley) %G%";
+#endif /* LIBC_SCCS and not lint */
+
+#include <_ansi.h>
+#include
+#include
+#include
+#include
+#include "local.h"
+
+static int
+_DEFUN(__fwalk, (ptr, function),
+ struct _reent *ptr _AND
+ register int (*function) (FILE *))
+{
+ register FILE *fp;
+ register int n, ret = 0;
+ register struct _glue *g;
+
+ for (g = &ptr->__sglue; g != NULL; g = g->_next)
+ for (fp = g->_iobs, n = g->_niobs; --n >= 0; fp++)
+ if (fp->_flags != 0)
+ {
+ if (fp->_flags != 0 && fp->_file != -1)
+ ret |= (*function) (fp);
+ }
+
+ return ret;
+}
+
+/* Special version of __fwalk where the function pointer is a reentrant
+ I/O function (e.g. _fclose_r). */
+static int
+_DEFUN(__fwalk_reent, (ptr, reent_function),
+ struct _reent *ptr _AND
+ register int (*reent_function) (struct _reent *, FILE *))
+{
+ register FILE *fp;
+ register int n, ret = 0;
+ register struct _glue *g;
+
+ for (g = &ptr->__sglue; g != NULL; g = g->_next)
+ for (fp = g->_iobs, n = g->_niobs; --n >= 0; fp++)
+ if (fp->_flags != 0)
+ {
+ if (fp->_flags != 0 && fp->_file != -1)
+ ret |= (*reent_function) (ptr, fp);
+ }
+
+ return ret;
+}
+
+int
+_DEFUN(_fwalk, (ptr, function),
+ struct _reent *ptr _AND
+ register int (*function)(FILE *))
+{
+ register int ret = 0;
+
+ __sfp_lock_acquire ();
+
+ /* Must traverse given list for streams. Note that _GLOBAL_REENT
+ only walked once in exit(). */
+ ret |= __fwalk (ptr, function);
+
+ __sfp_lock_release ();
+
+ return ret;
+}
+
+/* Special version of _fwalk which handles a function pointer to a
+ reentrant I/O function (e.g. _fclose_r). */
+int
+_DEFUN(_fwalk_reent, (ptr, reent_function),
+ struct _reent *ptr _AND
+ register int (*reent_function) (struct _reent *, FILE *))
+{
+ register int ret = 0;
+
+ __sfp_lock_acquire ();
+
+ /* Must traverse given list for streams. Note that _GLOBAL_REENT
+ only walked once in exit(). */
+ ret |= __fwalk_reent (ptr, reent_function);
+
+ __sfp_lock_release ();
+
+ return ret;
+}
fwalk.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: getwchar.c
===================================================================
--- getwchar.c (nonexistent)
+++ getwchar.c (revision 520)
@@ -0,0 +1,93 @@
+/*-
+ * Copyright (c) 2002 Tim J. Robbins.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+FUNCTION
+<>---read a wide character from standard input
+
+INDEX
+ getwchar
+INDEX
+ _getwchar_r
+
+ANSI_SYNOPSIS
+ #include
+ wint_t getwchar(void);
+
+ wint_t _getwchar_r(struct _reent *<[reent]>);
+
+TRAD_SYNOPSIS
+ #include
+ wint_t getwchar();
+
+ wint_t _getwchar_r(<[reent]>)
+ char * <[reent]>;
+
+DESCRIPTION
+<> function or macro is the wide character equivalent of
+the <> function. You can use <> to get the next
+wide character from the standard input stream. As a side effect,
+<> advances the standard input's current position indicator.
+
+The alternate function <<_getwchar_r>> is a reentrant version. The
+extra argument <[reent]> is a pointer to a reentrancy structure.
+
+RETURNS
+The next wide character cast to <>, unless there is no more
+data, or the host system reports a read error; in either of these
+situations, <> returns <>.
+
+You can distinguish the two situations that cause an <> result by
+using `<>' and `<>'.
+
+PORTABILITY
+C99
+*/
+
+#include <_ansi.h>
+#include
+#include
+#include
+#include "local.h"
+
+#undef getwchar
+
+wint_t
+_DEFUN (_getwchar_r, (ptr),
+ struct _reent *ptr)
+{
+ return _fgetwc_r (ptr, stdin);
+}
+
+/*
+ * Synonym for fgetwc(stdin).
+ */
+wint_t
+_DEFUN_VOID (getwchar)
+{
+ _REENT_SMALL_CHECK_INIT (_REENT);
+ return fgetwc (stdin);
+}
getwchar.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: fgetpos.c
===================================================================
--- fgetpos.c (nonexistent)
+++ fgetpos.c (revision 520)
@@ -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
+<>---record position in a stream or file
+
+INDEX
+ fgetpos
+INDEX
+ _fgetpos_r
+
+ANSI_SYNOPSIS
+ #include
+ int fgetpos(FILE *<[fp]>, fpos_t *<[pos]>);
+ int _fgetpos_r(struct _reent *<[ptr]>, FILE *<[fp]>, fpos_t *<[pos]>);
+
+TRAD_SYNOPSIS
+ #include
+ 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 <> can have a ``position'' that records how much
+of the file your program has already read. Many of the <> functions
+depend on this position, and many change it as a side effect.
+
+You can use <> to report on the current position for a file
+identified by <[fp]>; <> will write a value
+representing that position at <<*<[pos]>>>. Later, you can
+use this value with <> to return the file to this
+position.
+
+In the current implementation, <> simply uses a character
+count to represent the file position; this is the same number that
+would be returned by <>.
+
+RETURNS
+<> returns <<0>> when successful. If <> fails, the
+result is <<1>>. Failure occurs on streams that do not support
+positioning; the global <> indicates this condition with the
+value <>.
+
+PORTABILITY
+<> 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 <>. In particular, other
+conforming C implementations may return a different result from
+<> than what <> writes at <<*<[pos]>>>.
+
+No supporting OS subroutines are required.
+*/
+
+#include <_ansi.h>
+#include
+#include
+
+int
+_DEFUN(_fgetpos_r, (ptr, fp, pos),
+ struct _reent * ptr _AND
+ FILE * fp _AND
+ _fpos_t * pos)
+{
+ *pos = _ftell_r (ptr, fp);
+
+ if (*pos != -1)
+ {
+ return 0;
+ }
+ return 1;
+}
+
+#ifndef _REENT_ONLY
+
+int
+_DEFUN(fgetpos, (fp, pos),
+ FILE * fp _AND
+ _fpos_t * pos)
+{
+ return _fgetpos_r (_REENT, fp, pos);
+}
+
+#endif /* !_REENT_ONLY */
fgetpos.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: fgets.c
===================================================================
--- fgets.c (nonexistent)
+++ fgets.c (revision 520)
@@ -0,0 +1,193 @@
+/*
+ * 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
+<>---get character string from a file or stream
+
+INDEX
+ fgets
+INDEX
+ _fgets_r
+
+ANSI_SYNOPSIS
+ #include
+ char *fgets(char *<[buf]>, int <[n]>, FILE *<[fp]>);
+
+ #include
+ char *_fgets_r(struct _reent *<[ptr]>, char *<[buf]>, int <[n]>, FILE *<[fp]>);
+
+TRAD_SYNOPSIS
+ #include
+ char *fgets(<[buf]>,<[n]>,<[fp]>)
+ char *<[buf]>;
+ int <[n]>;
+ FILE *<[fp]>;
+
+ #include
+ char *_fgets_r(<[ptr]>, <[buf]>,<[n]>,<[fp]>)
+ struct _reent *<[ptr]>;
+ char *<[buf]>;
+ int <[n]>;
+ FILE *<[fp]>;
+
+DESCRIPTION
+ Reads at most <[n-1]> characters from <[fp]> until a newline
+ is found. The characters including to the newline are stored
+ in <[buf]>. The buffer is terminated with a 0.
+
+ The <<_fgets_r>> function is simply the reentrant version of
+ <> and is passed an additional reentrancy structure
+ pointer: <[ptr]>.
+
+RETURNS
+ <> 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
+ no data are read, NULL is returned instead.
+
+PORTABILITY
+ <> should replace all uses of <>. Note however
+ that <> returns all of the data, while <> removes
+ the trailing newline (with no indication that it has done so.)
+
+Supporting OS subroutines required: <>, <>, <>,
+<>, <>, <>, <>.
+*/
+
+#include <_ansi.h>
+#include
+#include
+#include "local.h"
+
+/*
+ * Read at most n-1 characters from the given file.
+ * Stop when a newline has been read, or the count runs out.
+ * Return first argument, or NULL if no characters were read.
+ */
+
+char *
+_DEFUN(_fgets_r, (ptr, buf, n, fp),
+ struct _reent * ptr _AND
+ char *buf _AND
+ int n _AND
+ FILE * fp)
+{
+ size_t len;
+ char *s;
+ unsigned char *p, *t;
+
+ if (n < 2) /* sanity check */
+ return 0;
+
+ s = buf;
+
+ CHECK_INIT(ptr, fp);
+
+ __sfp_lock_acquire ();
+ _flockfile (fp);
+#ifdef __SCLE
+ if (fp->_flags & __SCLE)
+ {
+ int c;
+ /* Sorry, have to do it the slow way */
+ while (--n > 0 && (c = __sgetc_r (ptr, fp)) != EOF)
+ {
+ *s++ = c;
+ if (c == '\n')
+ break;
+ }
+ if (c == EOF && s == buf)
+ {
+ _funlockfile (fp);
+ __sfp_lock_release ();
+ return NULL;
+ }
+ *s = 0;
+ _funlockfile (fp);
+ __sfp_lock_release ();
+ return buf;
+ }
+#endif
+
+ n--; /* leave space for NUL */
+ do
+ {
+ /*
+ * If the buffer is empty, refill it.
+ */
+ if ((len = fp->_r) <= 0)
+ {
+ if (__srefill_r (ptr, fp))
+ {
+ /* EOF: stop with partial or no line */
+ if (s == buf)
+ {
+ _funlockfile (fp);
+ __sfp_lock_release ();
+ return 0;
+ }
+ break;
+ }
+ len = fp->_r;
+ }
+ p = fp->_p;
+
+ /*
+ * Scan through at most n bytes of the current buffer,
+ * looking for '\n'. If found, copy up to and including
+ * newline, and stop. Otherwise, copy entire chunk
+ * and loop.
+ */
+ if (len > n)
+ len = n;
+ t = (unsigned char *) memchr ((_PTR) p, '\n', len);
+ if (t != 0)
+ {
+ len = ++t - p;
+ fp->_r -= len;
+ fp->_p = t;
+ _CAST_VOID memcpy ((_PTR) s, (_PTR) p, len);
+ s[len] = 0;
+ _funlockfile (fp);
+ __sfp_lock_release ();
+ return (buf);
+ }
+ fp->_r -= len;
+ fp->_p += len;
+ _CAST_VOID memcpy ((_PTR) s, (_PTR) p, len);
+ s += len;
+ }
+ while ((n -= len) != 0);
+ *s = 0;
+ _funlockfile (fp);
+ __sfp_lock_release ();
+ return buf;
+}
+
+#ifndef _REENT_ONLY
+
+char *
+_DEFUN(fgets, (buf, n, fp),
+ char *buf _AND
+ int n _AND
+ FILE * fp)
+{
+ return _fgets_r (_REENT, buf, n, fp);
+}
+
+#endif /* !_REENT_ONLY */
fgets.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: perror.c
===================================================================
--- perror.c (nonexistent)
+++ perror.c (revision 520)
@@ -0,0 +1,99 @@
+/*
+ * 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
+<>---print an error message on standard error
+
+INDEX
+ perror
+INDEX
+ _perror_r
+
+ANSI_SYNOPSIS
+ #include
+ void perror(char *<[prefix]>);
+
+ void _perror_r(struct _reent *<[reent]>, char *<[prefix]>);
+
+TRAD_SYNOPSIS
+ #include
+ void perror(<[prefix]>)
+ char *<[prefix]>;
+
+ void _perror_r(<[reent]>, <[prefix]>)
+ struct _reent *<[reent]>;
+ char *<[prefix]>;
+
+DESCRIPTION
+Use <> to print (on standard error) an error message
+corresponding to the current value of the global variable <>.
+Unless you use <> as the value of the argument <[prefix]>, the
+error message will begin with the string at <[prefix]>, followed by a
+colon and a space (<<: >>). The remainder of the error message is one
+of the strings described for <>.
+
+The alternate function <<_perror_r>> is a reentrant version. The
+extra argument <[reent]> is a pointer to a reentrancy structure.
+
+RETURNS
+<> returns no result.
+
+PORTABILITY
+ANSI C requires <>, but the strings issued vary from one
+implementation to another.
+
+Supporting OS subroutines required: <>, <>, <>,
+<>, <>, <>, <>.
+*/
+
+#include <_ansi.h>
+#include
+#include
+#include
+#include "local.h"
+
+_VOID
+_DEFUN(_perror_r, (ptr, s),
+ struct _reent *ptr _AND
+ _CONST char *s)
+{
+ char *error;
+
+ _REENT_SMALL_CHECK_INIT (ptr);
+ if (s != NULL && *s != '\0')
+ {
+ fputs (s, _stderr_r (ptr));
+ fputs (": ", _stderr_r (ptr));
+ }
+
+ if ((error = strerror (ptr->_errno)) != NULL)
+ fputs (error, _stderr_r (ptr));
+
+ fputc ('\n', _stderr_r (ptr));
+}
+
+#ifndef _REENT_ONLY
+
+_VOID
+_DEFUN(perror, (s),
+ _CONST char *s)
+{
+ _perror_r (_REENT, s);
+}
+
+#endif
perror.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: refill.c
===================================================================
--- refill.c (nonexistent)
+++ refill.c (revision 520)
@@ -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.
+ */
+/* No user fns here. Pesch 15apr92. */
+
+#include <_ansi.h>
+#include
+#include
+#include
+#include "local.h"
+
+static int
+_DEFUN(lflush, (fp),
+ FILE *fp)
+{
+ if ((fp->_flags & (__SLBF | __SWR)) == (__SLBF | __SWR))
+ return fflush (fp);
+ return 0;
+}
+
+/*
+ * Refill a stdio buffer.
+ * Return EOF on eof or error, 0 otherwise.
+ */
+
+int
+_DEFUN(__srefill_r, (ptr, fp),
+ struct _reent * ptr _AND
+ register FILE * fp)
+{
+ /* make sure stdio is set up */
+
+ CHECK_INIT (ptr, fp);
+
+ ORIENT (fp, -1);
+
+ fp->_r = 0; /* largely a convenience for callers */
+
+#ifndef __CYGWIN__
+ /* SysV does not make this test; take it out for compatibility */
+ if (fp->_flags & __SEOF)
+ return EOF;
+#endif
+
+ /* if not already reading, have to be reading and writing */
+ if ((fp->_flags & __SRD) == 0)
+ {
+ if ((fp->_flags & __SRW) == 0)
+ {
+ ptr->_errno = EBADF;
+ fp->_flags |= __SERR;
+ return EOF;
+ }
+ /* switch to reading */
+ if (fp->_flags & __SWR)
+ {
+ if (_fflush_r (ptr, fp))
+ return EOF;
+ fp->_flags &= ~__SWR;
+ fp->_w = 0;
+ fp->_lbfsize = 0;
+ }
+ fp->_flags |= __SRD;
+ }
+ else
+ {
+ /*
+ * We were reading. If there is an ungetc buffer,
+ * we must have been reading from that. Drop it,
+ * restoring the previous buffer (if any). If there
+ * is anything in that buffer, return.
+ */
+ if (HASUB (fp))
+ {
+ FREEUB (ptr, fp);
+ if ((fp->_r = fp->_ur) != 0)
+ {
+ fp->_p = fp->_up;
+ return 0;
+ }
+ }
+ }
+
+ if (fp->_bf._base == NULL)
+ __smakebuf_r (ptr, fp);
+
+ /*
+ * Before reading from a line buffered or unbuffered file,
+ * flush all line buffered output files, per the ANSI C
+ * standard.
+ */
+
+ if (fp->_flags & (__SLBF | __SNBF))
+ _CAST_VOID _fwalk (_GLOBAL_REENT, lflush);
+ fp->_p = fp->_bf._base;
+ fp->_r = fp->_read (ptr, fp->_cookie, (char *) fp->_p, fp->_bf._size);
+#ifndef __CYGWIN__
+ if (fp->_r <= 0)
+#else
+ if (fp->_r > 0)
+ fp->_flags &= ~__SEOF;
+ else
+#endif
+ {
+ if (fp->_r == 0)
+ fp->_flags |= __SEOF;
+ else
+ {
+ fp->_r = 0;
+ fp->_flags |= __SERR;
+ }
+ return EOF;
+ }
+ return 0;
+}
refill.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: getc.c
===================================================================
--- getc.c (nonexistent)
+++ getc.c (revision 520)
@@ -0,0 +1,119 @@
+/*
+ * 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
+<>---read a character (macro)
+
+INDEX
+ getc
+INDEX
+ _getc_r
+
+ANSI_SYNOPSIS
+ #include
+ int getc(FILE *<[fp]>);
+
+ #include
+ int _getc_r(struct _reent *<[ptr]>, FILE *<[fp]>);
+
+TRAD_SYNOPSIS
+ #include
+ int getc(<[fp]>)
+ FILE *<[fp]>;
+
+ #include
+ int _getc_r(<[ptr]>, <[fp]>)
+ struct _reent *<[ptr]>;
+ FILE *<[fp]>;
+
+DESCRIPTION
+<> is a macro, defined in <>. You can use <>
+to get the next single character from the file or stream
+identified by <[fp]>. As a side effect, <> advances the file's
+current position indicator.
+
+For a subroutine version of this macro, see <>.
+
+The <<_getc_r>> function is simply the reentrant version of <>
+which passes an additional reentrancy structure pointer argument: <[ptr]>.
+
+RETURNS
+The next character (read as an <>, and cast to
+<>), unless there is no more data, or the host system reports a
+read error; in either of these situations, <> returns <>.
+
+You can distinguish the two situations that cause an <> result by
+using the <> and <> functions.
+
+PORTABILITY
+ANSI C requires <>; it suggests, but does not require, that
+<> be implemented as a macro. The standard explicitly permits
+macro implementations of <> to use the argument more than once;
+therefore, in a portable program, you should not use an expression
+with side effects as the <> argument.
+
+Supporting OS subroutines required: <>, <>, <>,
+<>, <>, <>, <>.
+*/
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "%W% (Berkeley) %G%";
+#endif /* LIBC_SCCS and not lint */
+
+#include <_ansi.h>
+#include
+#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);
+ __sfp_lock_acquire ();
+ _flockfile (fp);
+ result = __sgetc_r (ptr, fp);
+ _funlockfile (fp);
+ __sfp_lock_release ();
+ return result;
+}
+
+#ifndef _REENT_ONLY
+
+int
+_DEFUN(getc, (fp),
+ register FILE *fp)
+{
+ int result;
+ CHECK_INIT (_REENT, fp);
+ __sfp_lock_acquire ();
+ _flockfile (fp);
+ result = __sgetc_r (_REENT, fp);
+ _funlockfile (fp);
+ __sfp_lock_release ();
+ return result;
+}
+
+#endif /* !_REENT_ONLY */
getc.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: setbuffer.c
===================================================================
--- setbuffer.c (nonexistent)
+++ setbuffer.c (revision 520)
@@ -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
+<>---specify full buffering for a file or stream with size
+
+INDEX
+ setbuffer
+
+ANSI_SYNOPSIS
+ #include
+ void setbuffer(FILE *<[fp]>, char *<[buf]>, int <[size]>);
+
+TRAD_SYNOPSIS
+ #include
+ void setbuffer(<[fp]>, <[buf]>, <[size]>)
+ FILE *<[fp]>;
+ char *<[buf]>;
+ int <[size]>;
+
+DESCRIPTION
+<> 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 <> as the value of <[buf]>, to signal that the
+<> function is to allocate the buffer.
+
+WARNINGS
+You may only use <> 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
+<> does not return a result.
+
+PORTABILITY
+This function comes from BSD not ANSI or POSIX.
+
+Supporting OS subroutines required: <>, <>, <>,
+<>, <>, <>, <>.
+*/
+
+#include <_ansi.h>
+#include
+#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);
+}
setbuffer.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: getline.c
===================================================================
--- getline.c (nonexistent)
+++ getline.c (revision 520)
@@ -0,0 +1,54 @@
+/* Copyright 2002, Red Hat Inc. - all rights reserved */
+/*
+FUNCTION
+<>---read a line from a file
+
+INDEX
+ getline
+
+ANSI_SYNOPSIS
+ #include
+ ssize_t getline(char **<[bufptr]>, size_t *<[n]>, FILE *<[fp]>);
+
+TRAD_SYNOPSIS
+ #include
+ ssize_t getline(<[bufptr]>, <[n]>, <[fp]>)
+ char **<[bufptr]>;
+ size_t *<[n]>;
+ FILE *<[fp]>;
+
+DESCRIPTION
+<> 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 <>.
+As the buffer is grown, the pointer to the size <[n]> will be
+updated.
+
+<> is equivalent to getdelim(bufptr, n, '\n', fp);
+
+RETURNS
+<> 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
+<> is a glibc extension.
+
+No supporting OS subroutines are directly required.
+*/
+
+#include <_ansi.h>
+#include
+
+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);
+}
+
getline.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: setbuf.c
===================================================================
--- setbuf.c (nonexistent)
+++ setbuf.c (revision 520)
@@ -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
+<>---specify full buffering for a file or stream
+
+INDEX
+ setbuf
+
+ANSI_SYNOPSIS
+ #include
+ void setbuf(FILE *<[fp]>, char *<[buf]>);
+
+TRAD_SYNOPSIS
+ #include
+ void setbuf(<[fp]>, <[buf]>)
+ FILE *<[fp]>;
+ char *<[buf]>;
+
+DESCRIPTION
+<> 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 <>, specified in `<>'). 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 <>. You can
+also use <> as the value of <[buf]>, to signal that the
+<> function is to allocate the buffer.
+
+WARNINGS
+You may only use <> 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
+<> does not return a result.
+
+PORTABILITY
+Both ANSI C and the System V Interface Definition (Issue 2) require
+<>. However, they differ on the meaning of a <> buffer
+pointer: the SVID issue 2 specification says that a <> buffer
+pointer requests unbuffered output. For maximum portability, avoid
+<> buffer pointers.
+
+Supporting OS subroutines required: <>, <>, <>,
+<>, <>, <>, <>.
+*/
+
+#include <_ansi.h>
+#include
+#include "local.h"
+
+_VOID
+_DEFUN(setbuf, (fp, buf),
+ FILE * fp _AND
+ char *buf)
+{
+ _CAST_VOID setvbuf (fp, buf, buf ? _IOFBF : _IONBF, BUFSIZ);
+}
setbuf.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: fpurge.c
===================================================================
--- fpurge.c (nonexistent)
+++ fpurge.c (revision 520)
@@ -0,0 +1,90 @@
+/* Copyright (C) 2009 Eric Blake
+ * Permission to use, copy, modify, and distribute this software
+ * is freely granted, provided that this notice is preserved.
+ */
+
+/*
+FUNCTION
+<>---discard pending file I/O
+
+INDEX
+ fpurge
+INDEX
+ _fpurge_r
+
+ANSI_SYNOPSIS
+ #include
+ int fpurge(FILE *<[fp]>);
+
+ int _fpurge_r(struct _reent *<[reent]>, FILE *<[fp]>);
+
+DESCRIPTION
+Use <> 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 <> and any data retrieved from disk
+but not yet read via <>. This is more severe than <>,
+and generally is only needed when manually altering the underlying file
+descriptor of a stream.
+
+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
+<> returns <<0>> unless <[fp]> is not valid, in which case it
+returns <> and sets <>.
+
+PORTABILITY
+These functions are not portable to any standard.
+
+No supporting OS subroutines are required.
+*/
+
+#include <_ansi.h>
+#include
+#include
+#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);
+
+ _flockfile (fp);
+
+ t = fp->_flags;
+ if (!t)
+ {
+ ptr->_errno = EBADF;
+ _funlockfile (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;
+ _funlockfile (fp);
+ return 0;
+}
+
+#ifndef _REENT_ONLY
+
+int
+_DEFUN(fpurge, (fp),
+ register FILE * fp)
+{
+ return _fpurge_r (_REENT, fp);
+}
+
+#endif /* _REENT_ONLY */
fpurge.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: clearerr.c
===================================================================
--- clearerr.c (nonexistent)
+++ clearerr.c (revision 520)
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by the University of California, Berkeley. The name of the
+ * University may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
+/*
+FUNCTION
+<>---clear file or stream error indicator
+
+INDEX
+ clearerr
+
+ANSI_SYNOPSIS
+ #include
+ void clearerr(FILE *<[fp]>);
+
+TRAD_SYNOPSIS
+ #include
+ void clearerr(<[fp]>)
+ FILE *<[fp]>;
+
+DESCRIPTION
+The <> functions maintain an error indicator with each file
+pointer <[fp]>, to record whether any read or write errors have
+occurred on the associated file or stream. Similarly, it maintains an
+end-of-file indicator to record whether there is no more data in the
+file.
+
+Use <> to reset both of these indicators.
+
+See <> and <> to query the two indicators.
+
+
+RETURNS
+<> does not return a result.
+
+PORTABILITY
+ANSI C requires <>.
+
+No supporting OS subroutines are required.
+*/
+
+#include <_ansi.h>
+#include
+#include "local.h"
+
+/* A subroutine version of the macro clearerr. */
+
+#undef clearerr
+
+_VOID
+_DEFUN(clearerr, (fp),
+ FILE * fp)
+{
+ CHECK_INIT(_REENT, fp);
+ _flockfile (fp);
+ __sclearerr (fp);
+ _funlockfile (fp);
+}
clearerr.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: stdio.tex
===================================================================
--- stdio.tex (nonexistent)
+++ stdio.tex (revision 520)
@@ -0,0 +1,319 @@
+@node Stdio
+@chapter Input and Output (@file{stdio.h})
+
+This chapter comprises functions to manage files
+or other input/output streams. Among these functions are subroutines
+to generate or scan strings according to specifications from a format string.
+
+The underlying facilities for input and output depend on the host
+system, but these functions provide a uniform interface.
+
+The corresponding declarations are in @file{stdio.h}.
+
+The reentrant versions of these functions use macros
+
+@example
+_stdin_r(@var{reent})
+_stdout_r(@var{reent})
+_stderr_r(@var{reent})
+@end example
+
+@noindent
+instead of the globals @code{stdin}, @code{stdout}, and
+@code{stderr}. The argument <[reent]> is a pointer to a reentrancy
+structure.
+
+@menu
+* clearerr:: Clear file or stream error indicator
+* diprintf:: Print to a file descriptor (integer only)
+* dprintf:: Print to a file descriptor
+* fclose:: Close a file
+* fcloseall:: Close all files
+* fdopen:: Turn an open file into a stream
+* feof:: Test for end of file
+* ferror:: Test whether read/write error has occurred
+* fflush:: Flush buffered file output
+* fgetc:: Get a character from a file or stream
+* fgetpos:: Record position in a stream or file
+* fgets:: Get character string from a file or stream
+* fgetwc:: Get a wide character from a file or stream
+* fgetws:: Get a wide character string from a file or stream
+* fileno:: Get file descriptor associated with stream
+* fmemopen:: Open a stream around a fixed-length buffer
+* fopen:: Open a file
+* fopencookie:: Open a stream with custom callbacks
+* fpurge:: Discard all pending I/O on a stream
+* fputc:: Write a character on a stream or file
+* fputs:: Write a character string in a file or stream
+* fputwc:: Write a wide character to a file or stream
+* fputws:: Write a wide character string to a file or stream
+* fread:: Read array elements from a file
+* freopen:: Open a file using an existing file descriptor
+* fseek:: Set file position
+* fsetpos:: Restore position of a stream or file
+* ftell:: Return position in a stream or file
+* funopen:: Open a stream with custom callbacks
+* fwide:: Set and determine the orientation of a FILE stream
+* fwrite:: Write array elements from memory to a file or stream
+* getc:: Get a character from a file or stream (macro)
+* getc_unlocked:: Get a character from a file or stream (macro)
+* getchar:: Get a character from standard input (macro)
+* getchar_unlocked:: Get a character from standard input (macro)
+* getdelim:: Get character string from a file or stream
+* getline:: Get character string from a file or stream
+* gets:: Get character string from standard input (obsolete)
+* getw:: Get a word (int) from a file or stream
+* getwchar:: Get a wide character from standard input
+* mktemp:: Generate unused file name
+* open_memstream:: Open a write stream around an arbitrary-length buffer
+* perror:: Print an error message on standard error
+* putc:: Write a character on a stream or file (macro)
+* putc_unlocked:: Write a character on a stream or file (macro)
+* putchar:: Write a character on standard output (macro)
+* putchar_unlocked:: Write a character on standard output (macro)
+* puts:: Write a character string on standard output
+* putw:: Write a word (int) to a file or stream
+* putwchar:: Write a wide character to standard output
+* remove:: Delete a file's name
+* rename:: Rename a file
+* rewind:: Reinitialize a file or stream
+* setbuf:: Specify full buffering for a file or stream
+* setbuffer:: Specify full buffering for a file or stream with size
+* setlinebuf:: Specify line buffering for a file or stream
+* setvbuf:: Specify buffering for a file or stream
+* siprintf:: Write formatted output (integer only)
+* siscanf:: Scan and format input (integer only)
+* sprintf:: Write formatted output
+* sscanf:: Scan and format input
+* swprintf:: Write formatted wide character output
+* swscanf:: Scan and format wide character input
+* tmpfile:: Create a temporary file
+* tmpnam:: Generate name for a temporary file
+* ungetc:: Push data back into a stream
+* ungetwc:: Push wide character data back into a stream
+* vfprintf:: Format variable argument list
+* vfscanf:: Scan variable argument list
+* vfwprintf:: Format variable wide character argument list
+* vfwscanf:: Scan and format argument list from wide character input
+* viprintf:: Format variable argument list (integer only)
+* viscanf:: Scan variable format list (integer only)
+@end menu
+
+@page
+@include stdio/clearerr.def
+
+@page
+@include stdio/diprintf.def
+
+@page
+@include stdio/dprintf.def
+
+@page
+@include stdio/fclose.def
+
+@page
+@include stdio/fcloseall.def
+
+@page
+@include stdio/fdopen.def
+
+@page
+@include stdio/feof.def
+
+@page
+@include stdio/ferror.def
+
+@page
+@include stdio/fflush.def
+
+@page
+@include stdio/fgetc.def
+
+@page
+@include stdio/fgetpos.def
+
+@page
+@include stdio/fgets.def
+
+@page
+@include stdio/fgetwc.def
+
+@page
+@include stdio/fgetws.def
+
+@page
+@include stdio/fileno.def
+
+@page
+@include stdio/fmemopen.def
+
+@page
+@include stdio/fopen.def
+
+@page
+@include stdio/fopencookie.def
+
+@page
+@include stdio/fpurge.def
+
+@page
+@include stdio/fputc.def
+
+@page
+@include stdio/fputs.def
+
+@page
+@include stdio/fputwc.def
+
+@page
+@include stdio/fputws.def
+
+@page
+@include stdio/fread.def
+
+@page
+@include stdio/freopen.def
+
+@page
+@include stdio/fseek.def
+
+@page
+@include stdio/fsetpos.def
+
+@page
+@include stdio/ftell.def
+
+@page
+@include stdio/funopen.def
+
+@page
+@include stdio/fwide.def
+
+@page
+@include stdio/fwrite.def
+
+@page
+@include stdio/getc.def
+
+@page
+@include stdio/getc_u.def
+
+@page
+@include stdio/getchar.def
+
+@page
+@include stdio/getchar_u.def
+
+@page
+@include stdio/getdelim.def
+
+@page
+@include stdio/getline.def
+
+@page
+@include stdio/gets.def
+
+@page
+@include stdio/getw.def
+
+@page
+@include stdio/getwchar.def
+
+@page
+@include stdio/mktemp.def
+
+@page
+@include stdio/open_memstream.def
+
+@page
+@include stdio/perror.def
+
+@page
+@include stdio/putc.def
+
+@page
+@include stdio/putc_u.def
+
+@page
+@include stdio/putchar.def
+
+@page
+@include stdio/putchar_u.def
+
+@page
+@include stdio/puts.def
+
+@page
+@include stdio/putw.def
+
+@page
+@include stdio/putwchar.def
+
+@page
+@include stdio/remove.def
+
+@page
+@include stdio/rename.def
+
+@page
+@include stdio/rewind.def
+
+@page
+@include stdio/setbuf.def
+
+@page
+@include stdio/setbuffer.def
+
+@page
+@include stdio/setlinebuf.def
+
+@page
+@include stdio/setvbuf.def
+
+@page
+@include stdio/siprintf.def
+
+@page
+@include stdio/siscanf.def
+
+@page
+@include stdio/sprintf.def
+
+@page
+@include stdio/sscanf.def
+
+@page
+@include stdio/swprintf.def
+
+@page
+@include stdio/swscanf.def
+
+@page
+@include stdio/tmpfile.def
+
+@page
+@include stdio/tmpnam.def
+
+@page
+@include stdio/ungetc.def
+
+@page
+@include stdio/ungetwc.def
+
+@page
+@include stdio/vfprintf.def
+
+@page
+@include stdio/vfscanf.def
+
+@page
+@include stdio/vfwprintf.def
+
+@page
+@include stdio/vfwscanf.def
+
+@page
+@include stdio/viprintf.def
+
+@page
+@include stdio/viscanf.def
Index: gets.c
===================================================================
--- gets.c (nonexistent)
+++ gets.c (revision 520)
@@ -0,0 +1,111 @@
+/*
+ * 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
+<>---get character string (obsolete, use <> instead)
+
+INDEX
+ gets
+INDEX
+ _gets_r
+
+ANSI_SYNOPSIS
+ #include
+
+ char *gets(char *<[buf]>);
+
+ char *_gets_r(struct _reent *<[reent]>, char *<[buf]>);
+
+TRAD_SYNOPSIS
+ #include
+
+ 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
+ <> 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: <>, <>, <>,
+<>, <>, <>, <>.
+*/
+
+#include <_ansi.h>
+#include
+#include
+
+char *
+_DEFUN(_gets_r, (ptr, buf),
+ struct _reent *ptr _AND
+ char *buf)
+{
+ register int c;
+ register char *s = buf;
+
+ __sfp_lock_acquire ();
+ _flockfile (stdin);
+ while ((c = __sgetc_r (ptr, stdin)) != '\n')
+ if (c == EOF)
+ if (s == buf)
+ {
+ _funlockfile (stdin);
+ __sfp_lock_release ();
+ return NULL;
+ }
+ else
+ break;
+ else
+ *s++ = c;
+ *s = 0;
+ _funlockfile (stdin);
+ __sfp_lock_release ();
+ return buf;
+}
+
+#ifndef _REENT_ONLY
+
+char *
+_DEFUN(gets, (buf),
+ char *buf)
+{
+ return _gets_r (_REENT, buf);
+}
+
+#endif
gets.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: getw.c
===================================================================
--- getw.c (nonexistent)
+++ getw.c (revision 520)
@@ -0,0 +1,69 @@
+/*
+ * 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
+<>---read a word (int)
+
+INDEX
+ getw
+
+ANSI_SYNOPSIS
+ #include
+ int getw(FILE *<[fp]>);
+
+TRAD_SYNOPSIS
+ #include
+ int getw(<[fp]>)
+ FILE *<[fp]>;
+
+DESCRIPTION
+<> is a function, defined in <>. You can use <>
+to get the next word from the file or stream identified by <[fp]>. As
+a side effect, <> advances the file's current position
+indicator.
+
+RETURNS
+The next word (read as an <>), unless there is no more
+data or the host system reports a read error; in either of these
+situations, <> returns <>. Since <> is a valid
+<>, you must use <> or <> to distinguish these
+situations.
+
+PORTABILITY
+<> is a remnant of K&R C; it is not part of any ISO C Standard.
+<> should be used instead. In fact, this implementation of
+<> is based upon <>.
+
+Supporting OS subroutines required: <>. */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "%W% (Berkeley) %G%";
+#endif /* LIBC_SCCS and not lint */
+
+#include <_ansi.h>
+#include
+
+int
+_DEFUN(getw, (fp),
+ register FILE *fp)
+{
+ int result;
+ if (fread ((char*)&result, sizeof (result), 1, fp) != 1)
+ return EOF;
+ return result;
+}
getw.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: getwc.c
===================================================================
--- getwc.c (nonexistent)
+++ getwc.c (revision 520)
@@ -0,0 +1,52 @@
+/*-
+ * Copyright (c) 2002 Tim J. Robbins.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <_ansi.h>
+#include
+#include
+#include
+#include "local.h"
+
+#undef getwc
+
+wint_t
+_DEFUN(_getwc_r, (ptr, fp),
+ struct _reent *ptr _AND
+ FILE *fp)
+{
+ return _fgetwc_r (ptr, fp);
+}
+
+/*
+ * Synonym for fgetwc(). The only difference is that getwc(), if it is a
+ * macro, may evaluate `fp' more than once.
+ */
+wint_t
+_DEFUN(getwc, (fp),
+ FILE *fp)
+{
+ return fgetwc(fp);
+}
getwc.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: vsiprintf.c
===================================================================
--- vsiprintf.c (nonexistent)
+++ vsiprintf.c (revision 520)
@@ -0,0 +1,59 @@
+/*
+ * 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
+#include
+#include
+#include
+
+#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;
+}
vsiprintf.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: vsnprintf.c
===================================================================
--- vsnprintf.c (nonexistent)
+++ vsnprintf.c (revision 520)
@@ -0,0 +1,70 @@
+/*
+ * 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 */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "%W% (Berkeley) %G%";
+#endif /* LIBC_SCCS and not lint */
+
+#include <_ansi.h>
+#include
+#include
+#include
+#include
+#include
+
+#ifndef _REENT_ONLY
+
+int
+_DEFUN(vsnprintf, (str, size, fmt, ap),
+ char *str _AND
+ size_t size _AND
+ const char *fmt _AND
+ va_list ap)
+{
+ return _vsnprintf_r (_REENT, str, size, fmt, ap);
+}
+
+#endif /* !_REENT_ONLY */
+
+int
+_DEFUN(_vsnprintf_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 = _svfprintf_r (ptr, &f, fmt, ap);
+ if (ret < EOF)
+ ptr->_errno = EOVERFLOW;
+ if (size > 0)
+ *f._p = 0;
+ return ret;
+}
vsnprintf.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: flags.c
===================================================================
--- flags.c (nonexistent)
+++ flags.c (revision 520)
@@ -0,0 +1,86 @@
+/*
+ * Copyright (c) 1990 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 MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ */
+/* No user fns here. Pesch 15apr92 */
+
+#include <_ansi.h>
+#include
+#include
+#include
+#include
+#include
+
+/*
+ * Return the (stdio) flags for a given mode. Store the flags
+ * to be passed to an open() syscall through *optr.
+ * Return 0 on error.
+ */
+
+int
+_DEFUN(__sflags, (ptr, mode, optr),
+ struct _reent *ptr _AND
+ register char *mode _AND
+ int *optr)
+{
+ register int ret, m, o;
+
+ switch (mode[0])
+ {
+ case 'r': /* open for reading */
+ ret = __SRD;
+ m = O_RDONLY;
+ o = 0;
+ break;
+
+ case 'w': /* open for writing */
+ ret = __SWR;
+ m = O_WRONLY;
+ o = O_CREAT | O_TRUNC;
+ break;
+
+ case 'a': /* open for appending */
+ ret = __SWR | __SAPP;
+ m = O_WRONLY;
+ o = O_CREAT | O_APPEND;
+ break;
+ default: /* illegal mode */
+ ptr->_errno = EINVAL;
+ return (0);
+ }
+ if (mode[1] && (mode[1] == '+' || mode[2] == '+'))
+ {
+ ret = (ret & ~(__SRD | __SWR)) | __SRW;
+ m = O_RDWR;
+ }
+ if (mode[1] && (mode[1] == 'b' || mode[2] == 'b'))
+ {
+#ifdef O_BINARY
+ m |= O_BINARY;
+#endif
+ }
+#ifdef __CYGWIN__
+ else if (mode[1] && (mode[1] == 't' || mode[2] == 't'))
+#else
+ else
+#endif
+ {
+#ifdef O_TEXT
+ m |= O_TEXT;
+#endif
+ }
+ *optr = m | o;
+ return ret;
+}
flags.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: putwchar.c
===================================================================
--- putwchar.c (nonexistent)
+++ putwchar.c (revision 520)
@@ -0,0 +1,92 @@
+/*-
+ * Copyright (c) 2002 Tim J. Robbins.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+FUNCTION
+<>---write a wide character to standard output
+
+INDEX
+ putwchar
+INDEX
+ _putwchar_r
+
+ANSI_SYNOPSIS
+ #include
+ wint_t putwchar(wchar_t <[wc]>);
+
+ wint_t _putwchar_r(struct _reent *<[reent]>, wchar_t <[wc]>);
+
+TRAD_SYNOPSIS
+ #include
+ wint_t putwchar(<[wc]>)
+ wchar_t <[wc]>;
+
+ wint_t _putwchar_r(<[reent]>, <[wc]>)
+ struct _reent *<[reent]>;
+ wchar_t <[wc]>;
+
+DESCRIPTION
+The <> function or macro is the wide-character equivalent of
+the <> function. It writes the wide character wc to stdout.
+
+The alternate function <<_putwchar_r>> is a reentrant version. The
+extra argument <[reent]> is a pointer to a reentrancy structure.
+
+RETURNS
+If successful, <> returns its argument <[wc]>. If an error
+intervenes, the result is <>. You can use `<>' to
+query for errors.
+
+PORTABILITY
+C99
+*/
+
+#include <_ansi.h>
+#include
+#include
+#include
+#include "local.h"
+
+#undef putwchar
+
+wint_t
+_DEFUN(_putwchar_r, (ptr, wc),
+ struct _reent *ptr _AND
+ wchar_t wc)
+{
+ return _fputwc_r (ptr, wc, stdout);
+}
+
+/*
+ * Synonym for fputwc(wc, stdout).
+ */
+wint_t
+_DEFUN(putwchar, (wc),
+ wchar_t wc)
+{
+ _REENT_SMALL_CHECK_INIT (_REENT);
+ return fputwc (wc, stdout);
+}
putwchar.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: siprintf.c
===================================================================
--- siprintf.c (nonexistent)
+++ siprintf.c (revision 520)
@@ -0,0 +1,171 @@
+/*
+ * 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
+<>, <>, <>, <>, <>, <>---format output (integer only)
+
+INDEX
+ fiprintf
+INDEX
+ _fiprintf_r
+INDEX
+ iprintf
+INDEX
+ _iprintf_r
+INDEX
+ siprintf
+INDEX
+ _siprintf_r
+INDEX
+ sniprintf
+INDEX
+ _sniprintf_r
+INDEX
+ asiprintf
+INDEX
+ _asiprintf_r
+INDEX
+ asniprintf
+INDEX
+ _asniprintf_r
+
+ANSI_SYNOPSIS
+ #include
+
+ int iprintf(const char *<[format]>, ...);
+ int fiprintf(FILE *<[fd]>, const char *<[format]> , ...);
+ int siprintf(char *<[str]>, const char *<[format]>, ...);
+ int sniprintf(char *<[str]>, size_t <[size]>, const char *<[format]>,
+ ...);
+ int asiprintf(char **<[strp]>, const char *<[format]>, ...);
+ char *asniprintf(char *<[str]>, size_t *<[size]>,
+ const char *<[format]>, ...);
+
+ int _iprintf_r(struct _reent *<[ptr]>, const char *<[format]>, ...);
+ int _fiprintf_r(struct _reent *<[ptr]>, FILE *<[fd]>,
+ const char *<[format]>, ...);
+ int _siprintf_r(struct _reent *<[ptr]>, char *<[str]>,
+ const char *<[format]>, ...);
+ int _sniprintf_r(struct _reent *<[ptr]>, char *<[str]>, size_t <[size]>,
+ const char *<[format]>, ...);
+ int _asiprintf_r(struct _reent *<[ptr]>, char **<[strp]>,
+ const char *<[format]>, ...);
+ char *_asniprintf_r(struct _reent *<[ptr]>, char *<[str]>,
+ size_t *<[size]>, const char *<[format]>, ...);
+
+DESCRIPTION
+ <>, <>, <>, <>,
+ <>, and <> are the same as <>,
+ <>, <>, <>, <>, and
+ <>, respectively, except that they restrict usage
+ to non-floating-point format specifiers.
+
+ <<_iprintf_r>>, <<_fiprintf_r>>, <<_asiprintf_r>>,
+ <<_siprintf_r>>, <<_sniprintf_r>>, <<_asniprintf_r>> are
+ simply reentrant versions of the functions above.
+
+RETURNS
+Similar to <>, <>, <>, <>, <>,
+and <>.
+
+PORTABILITY
+<>, <>, <>, <>, <>,
+and <> are newlib extensions.
+
+Supporting OS subroutines required: <>, <>, <>,
+<>, <>, <>, <>.
+*/
+
+#include <_ansi.h>
+#include
+#include
+#ifdef _HAVE_STDC
+#include
+#else
+#include
+#endif
+#include
+#include "local.h"
+
+int
+#ifdef _HAVE_STDC
+_DEFUN(_siprintf_r, (ptr, str, fmt),
+ struct _reent *ptr _AND
+ char *str _AND
+ _CONST char *fmt _DOTS)
+#else
+_siprintf_r(ptr, str, fmt, va_alist)
+ struct _reent *ptr;
+ char *str;
+ _CONST char *fmt;
+ va_dcl
+#endif
+{
+ int ret;
+ va_list ap;
+ 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. */
+#ifdef _HAVE_STDC
+ va_start (ap, fmt);
+#else
+ va_start (ap);
+#endif
+ ret = _svfiprintf_r (ptr, &f, fmt, ap);
+ va_end (ap);
+ *f._p = 0;
+ return (ret);
+}
+
+#ifndef _REENT_ONLY
+
+int
+#ifdef _HAVE_STDC
+_DEFUN(siprintf, (str, fmt),
+ char *str _AND
+ _CONST char *fmt _DOTS)
+#else
+siprintf(str, fmt, va_alist)
+ char *str;
+ _CONST char *fmt;
+ va_dcl
+#endif
+{
+ int ret;
+ va_list ap;
+ 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. */
+#ifdef _HAVE_STDC
+ va_start (ap, fmt);
+#else
+ va_start (ap);
+#endif
+ ret = _svfiprintf_r (_REENT, &f, fmt, ap);
+ va_end (ap);
+ *f._p = 0;
+ return (ret);
+}
+
+#endif
siprintf.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: ferror.c
===================================================================
--- ferror.c (nonexistent)
+++ ferror.c (revision 520)
@@ -0,0 +1,74 @@
+/*
+ * 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
+<>---test whether read/write error has occurred
+
+INDEX
+ ferror
+
+ANSI_SYNOPSIS
+ #include
+ int ferror(FILE *<[fp]>);
+
+TRAD_SYNOPSIS
+ #include
+ int ferror(<[fp]>)
+ FILE *<[fp]>;
+
+DESCRIPTION
+The <> functions maintain an error indicator with each file
+pointer <[fp]>, to record whether any read or write errors have
+occurred on the associated file or stream.
+Use <> to query this indicator.
+
+See <> to reset the error indicator.
+
+RETURNS
+<> returns <<0>> if no errors have occurred; it returns a
+nonzero value otherwise.
+
+PORTABILITY
+ANSI C requires <>.
+
+No supporting OS subroutines are required.
+*/
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "%W% (Berkeley) %G%";
+#endif /* LIBC_SCCS and not lint */
+
+#include <_ansi.h>
+#include
+#include "local.h"
+
+/* A subroutine version of the macro ferror. */
+
+#undef ferror
+
+int
+_DEFUN(ferror, (fp),
+ FILE * fp)
+{
+ int result;
+ CHECK_INIT(_REENT, fp);
+ _flockfile (fp);
+ result = __sferror (fp);
+ _funlockfile (fp);
+ return result;
+}
ferror.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: setlinebuf.c
===================================================================
--- setlinebuf.c (nonexistent)
+++ setlinebuf.c (revision 520)
@@ -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
+<>---specify line buffering for a file or stream
+
+INDEX
+ setlinebuf
+
+ANSI_SYNOPSIS
+ #include
+ void setlinebuf(FILE *<[fp]>);
+
+TRAD_SYNOPSIS
+ #include
+ void setlinebuf(<[fp]>)
+ FILE *<[fp]>;
+
+DESCRIPTION
+<> 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 <> before performing any file operation
+other than opening the file.
+
+RETURNS
+<> returns as per setvbuf.
+
+PORTABILITY
+This function comes from BSD not ANSI or POSIX.
+
+Supporting OS subroutines required: <>, <>, <>,
+<>, <>, <>, <>.
+*/
+
+#include <_ansi.h>
+#include
+#include "local.h"
+
+int
+_DEFUN(setlinebuf, (fp),
+ FILE * fp)
+{
+ return (setvbuf (fp, (char *) NULL, _IOLBF, (size_t) 0));
+}
setlinebuf.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: vswprintf.c
===================================================================
--- vswprintf.c (nonexistent)
+++ vswprintf.c (revision 520)
@@ -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.
+ */
+/* doc in vfwprintf.c */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "%W% (Berkeley) %G%";
+#endif /* LIBC_SCCS and not lint */
+
+#include <_ansi.h>
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include "local.h"
+
+int
+_DEFUN(_vswprintf_r, (ptr, str, size, fmt, ap),
+ struct _reent *ptr _AND
+ wchar_t *str _AND
+ size_t size _AND
+ const wchar_t *fmt _AND
+ va_list ap)
+{
+ int ret;
+ FILE f;
+
+ if (size > INT_MAX / sizeof (wchar_t))
+ {
+ ptr->_errno = EOVERFLOW; /* POSIX extension */
+ return EOF;
+ }
+ f._flags = __SWR | __SSTR;
+ f._bf._base = f._p = (unsigned char *) str;
+ f._bf._size = f._w = (size > 0 ? (size - 1) * sizeof (wchar_t) : 0);
+ f._file = -1; /* No file. */
+ ret = _svfwprintf_r (ptr, &f, fmt, ap);
+ /* _svfwprintf_r() does not put in a terminating NUL, so add one if
+ * appropriate, which is whenever size is > 0. _svfwprintf_r() stops
+ * after n-1, so always just put at the end. */
+ if (size > 0) {
+ *(wchar_t *)f._p = L'\0'; /* terminate the string */
+ }
+ if(ret >= size) {
+ /* _svfwprintf_r() returns how many wide characters it would have printed
+ * if there were enough space. Return an error if too big to fit in str,
+ * unlike snprintf, which returns the size needed. */
+ ptr->_errno = EOVERFLOW; /* POSIX extension */
+ ret = -1;
+ }
+ return ret;
+}
+
+#ifndef _REENT_ONLY
+
+int
+_DEFUN(vswprintf, (str, size, fmt, ap),
+ wchar_t *str _AND
+ size_t size _AND
+ const wchar_t *fmt _AND
+ va_list ap)
+{
+ return _vswprintf_r (_REENT, str, size, fmt, ap);
+}
+
+#endif /* !_REENT_ONLY */
vswprintf.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: snprintf.c
===================================================================
--- snprintf.c (nonexistent)
+++ snprintf.c (revision 520)
@@ -0,0 +1,119 @@
+/*
+ * 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 sprintf.c */
+/* This code created by modifying sprintf.c so copyright inherited. */
+
+#include <_ansi.h>
+#include
+#include
+#ifdef _HAVE_STDC
+#include
+#else
+#include
+#endif
+#include
+#include
+#include "local.h"
+
+int
+#ifdef _HAVE_STDC
+_DEFUN(_snprintf_r, (ptr, str, size, fmt),
+ struct _reent *ptr _AND
+ char *str _AND
+ size_t size _AND
+ _CONST char *fmt _DOTS)
+#else
+_snprintf_r(ptr, str, size, fmt, va_alist)
+ struct _reent *ptr;
+ char *str;
+ size_t size;
+ _CONST char *fmt;
+ va_dcl
+#endif
+{
+ int ret;
+ va_list ap;
+ FILE f;
+
+ if (size > INT_MAX)
+ {
+ ptr->_errno = EOVERFLOW;
+ return EOF;
+ }
+ f._flags = __SWR | __SSTR;
+ f._bf._base = f._p = (unsigned char *) str;
+ f._bf._size = f._w = (size > 0 ? size - 1 : 0);
+ f._file = -1; /* No file. */
+#ifdef _HAVE_STDC
+ va_start (ap, fmt);
+#else
+ va_start (ap);
+#endif
+ ret = _svfprintf_r (ptr, &f, fmt, ap);
+ va_end (ap);
+ if (ret < EOF)
+ ptr->_errno = EOVERFLOW;
+ if (size > 0)
+ *f._p = 0;
+ return (ret);
+}
+
+#ifndef _REENT_ONLY
+
+int
+#ifdef _HAVE_STDC
+_DEFUN(snprintf, (str, size, fmt),
+ char *str _AND
+ size_t size _AND
+ _CONST char *fmt _DOTS)
+#else
+snprintf(str, size, fmt, va_alist)
+ char *str;
+ size_t size;
+ _CONST char *fmt;
+ va_dcl
+#endif
+{
+ int ret;
+ va_list ap;
+ FILE f;
+ struct _reent *ptr = _REENT;
+
+ if (size > INT_MAX)
+ {
+ ptr->_errno = EOVERFLOW;
+ return EOF;
+ }
+ f._flags = __SWR | __SSTR;
+ f._bf._base = f._p = (unsigned char *) str;
+ f._bf._size = f._w = (size > 0 ? size - 1 : 0);
+ f._file = -1; /* No file. */
+#ifdef _HAVE_STDC
+ va_start (ap, fmt);
+#else
+ va_start (ap);
+#endif
+ ret = _svfprintf_r (ptr, &f, fmt, ap);
+ va_end (ap);
+ if (ret < EOF)
+ ptr->_errno = EOVERFLOW;
+ if (size > 0)
+ *f._p = 0;
+ return (ret);
+}
+
+#endif
snprintf.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: vsscanf.c
===================================================================
--- vsscanf.c (nonexistent)
+++ vsscanf.c (revision 520)
@@ -0,0 +1,65 @@
+/*
+ * Code created by modifying scanf.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
+#include
+#include
+#ifdef _HAVE_STDC
+#include
+#else
+#include
+#endif
+#include "local.h"
+
+/*
+ * vsscanf
+ */
+
+#ifndef _REENT_ONLY
+
+int
+_DEFUN(vsscanf, (str, fmt, ap),
+ _CONST char *str _AND
+ _CONST char *fmt _AND
+ va_list ap)
+{
+ return _vsscanf_r (_REENT, str, fmt, ap);
+}
+
+#endif /* !_REENT_ONLY */
+
+int
+_DEFUN(_vsscanf_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 __ssvfscanf_r (ptr, &f, fmt, ap);
+}
vsscanf.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: vdiprintf.c
===================================================================
--- vdiprintf.c (nonexistent)
+++ vdiprintf.c (revision 520)
@@ -0,0 +1,47 @@
+/* Copyright 2005, 2007 Shaun Jackman
+ * Permission to use, copy, modify, and distribute this software
+ * is freely granted, provided that this notice is preserved.
+ */
+/* doc in diprintf.c */
+
+#include <_ansi.h>
+#include
+#include
+#include
+#include
+#include
+#include "local.h"
+
+int
+_DEFUN(_vdiprintf_r, (ptr, fd, format, ap),
+ struct _reent *ptr _AND
+ int fd _AND
+ const char *format _AND
+ va_list ap)
+{
+ char *p;
+ char buf[512];
+ size_t n = sizeof buf;
+
+ _REENT_SMALL_CHECK_INIT (ptr);
+ p = _vasniprintf_r (ptr, buf, &n, format, ap);
+ if (!p)
+ return -1;
+ n = _write_r (ptr, fd, p, n);
+ if (p != buf)
+ _free_r (ptr, p);
+ return n;
+}
+
+#ifndef _REENT_ONLY
+
+int
+_DEFUN(vdiprintf, (fd, format, ap),
+ int fd _AND
+ const char *format _AND
+ va_list ap)
+{
+ return _vdiprintf_r (_REENT, fd, format, ap);
+}
+
+#endif /* ! _REENT_ONLY */
fmemopen.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: ungetwc.c
===================================================================
--- ungetwc.c (nonexistent)
+++ ungetwc.c (revision 520)
@@ -0,0 +1,115 @@
+/*-
+ * Copyright (c) 2002-2004 Tim J. Robbins.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+FUNCTION
+<>---push wide character data back into a stream
+
+INDEX
+ ungetwc
+INDEX
+ _ungetwc_r
+
+ANSI_SYNOPSIS
+ #include
+ #include
+ wint_t ungetwc(wint_t <[wc]>, FILE *<[stream]>);
+
+ wint_t _ungetwc_r(struct _reent *<[reent]>, wint_t <[wc]>, FILE *<[stream]>);
+
+DESCRIPTION
+<> is used to return wide characters back to <[stream]> to be
+read again. If <[wc]> is WEOF, the stream is unchanged. Otherwise, the
+wide character <[wc]> is put back on the stream, and subsequent reads will see
+the wide chars pushed back in reverse order. Pushed wide chars are lost if the
+stream is repositioned, such as by <>, <>, or
+<>.
+
+The underlying file is not changed, but it is possible to push back
+something different than what was originally read. Ungetting a
+character will clear the end-of-stream marker, and decrement the file
+position indicator. Pushing back beyond the beginning of a file gives
+unspecified behavior.
+
+The alternate function <<_ungetwc_r>> is a reentrant version. The
+extra argument <[reent]> is a pointer to a reentrancy structure.
+
+RETURNS
+The wide character pushed back, or <> on error.
+
+PORTABILITY
+C99
+*/
+
+#include <_ansi.h>
+#include
+#include
+#include
+#include
+#include
+#include
+#include "local.h"
+
+wint_t
+_DEFUN(_ungetwc_r, (ptr, wc, fp),
+ struct _reent *ptr _AND
+ wint_t wc _AND
+ register FILE *fp)
+{
+ char buf[MB_LEN_MAX];
+ size_t len;
+
+ _flockfile (fp);
+ ORIENT (fp, 1);
+ if (wc == WEOF)
+ wc = WEOF;
+ else if ((len = _wcrtomb_r(ptr, buf, wc, &fp->_mbstate)) == (size_t)-1)
+ {
+ fp->_flags |= __SERR;
+ wc = WEOF;
+ }
+ else
+ while (len-- != 0)
+ if (_ungetc_r(ptr, (unsigned char)buf[len], fp) == EOF)
+ {
+ wc = WEOF;
+ break;
+ }
+ _funlockfile (fp);
+ return wc;
+}
+
+/*
+ * MT-safe version.
+ */
+wint_t
+_DEFUN(ungetwc, (wint_t wc, FILE *fp),
+ wint_t wc _AND
+ FILE *fp)
+{
+ CHECK_INIT (_REENT, fp);
+ return _ungetwc_r (_REENT, wc, fp);
+}
swprintf.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: getchar.c
===================================================================
--- getchar.c (nonexistent)
+++ getchar.c (revision 520)
@@ -0,0 +1,99 @@
+/*
+ * 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
+<>---read a character (macro)
+
+INDEX
+ getchar
+INDEX
+ _getchar_r
+
+ANSI_SYNOPSIS
+ #include
+ int getchar(void);
+
+ int _getchar_r(struct _reent *<[reent]>);
+
+TRAD_SYNOPSIS
+ #include
+ int getchar();
+
+ int _getchar_r(<[reent]>)
+ char * <[reent]>;
+
+DESCRIPTION
+<> is a macro, defined in <>. You can use <>
+to get the next single character from the standard input stream.
+As a side effect, <> 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 <>, and cast to
+<>), unless there is no more data, or the host system reports a
+read error; in either of these situations, <> returns <>.
+
+You can distinguish the two situations that cause an <> result by
+using `<>' and `<>'.
+
+PORTABILITY
+ANSI C requires <>; it suggests, but does not require, that
+<> be implemented as a macro.
+
+Supporting OS subroutines required: <>, <>, <>,
+<>, <>, <>, <>.
+*/
+
+#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
+#include
+#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)
+{
+ /* CHECK_INIT is called (eventually) by __srefill_r. */
+ _REENT_SMALL_CHECK_INIT (_REENT);
+ return _getc_r (_REENT, _stdin_r (_REENT));
+}
+
+#endif
getchar.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: diprintf.c
===================================================================
--- diprintf.c (nonexistent)
+++ diprintf.c (revision 520)
@@ -0,0 +1,82 @@
+/* Copyright (C) 2005, 2007 Shaun Jackman
+ * Permission to use, copy, modify, and distribute this software
+ * is freely granted, provided that this notice is preserved.
+ */
+
+/*
+FUNCTION
+<>, <>---print to a file descriptor (integer only)
+
+INDEX
+ diprintf
+INDEX
+ _diprintf_r
+INDEX
+ vdiprintf
+INDEX
+ _vdiprintf_r
+
+ANSI_SYNOPSIS
+ #include
+ #include
+ int diprintf(int <[fd]>, const char *<[format]>, ...);
+ int vdiprintf(int <[fd]>, const char *<[format]>, va_list <[ap]>);
+ int _diprintf_r(struct _reent *<[ptr]>, int <[fd]>,
+ const char *<[format]>, ...);
+ int _vdiprintf_r(struct _reent *<[ptr]>, int <[fd]>,
+ const char *<[format]>, va_list <[ap]>);
+
+DESCRIPTION
+<> and <> are similar to <> and <>,
+except that only integer format specifiers are processed.
+
+The functions <<_diprintf_r>> and <<_vdiprintf_r>> are simply
+reentrant versions of the functions above.
+
+RETURNS
+Similar to <> and <>.
+
+PORTABILITY
+This set of functions is an integer-only extension, and is not portable.
+
+Supporting OS subroutines required: <>, <>.
+*/
+
+#include <_ansi.h>
+#include
+#include
+#include
+#include
+
+int
+_DEFUN(_diprintf_r, (ptr, fd, format),
+ struct _reent *ptr _AND
+ int fd _AND
+ const char *format _DOTS)
+{
+ va_list ap;
+ int n;
+
+ va_start (ap, format);
+ n = _vdiprintf_r (ptr, fd, format, ap);
+ va_end (ap);
+ return n;
+}
+
+#ifndef _REENT_ONLY
+
+int
+_DEFUN(diprintf, (fd, format),
+ int fd _AND
+ const char *format _DOTS)
+{
+ va_list ap;
+ int n;
+
+ va_start (ap, format);
+ n = _vdiprintf_r (_REENT, fd, format, ap);
+ va_end (ap);
+ return n;
+}
+
+#endif /* ! _REENT_ONLY */
diprintf.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: feof.c
===================================================================
--- feof.c (nonexistent)
+++ feof.c (revision 520)
@@ -0,0 +1,65 @@
+/*
+ * 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
+<>---test for end of file
+
+INDEX
+ feof
+
+ANSI_SYNOPSIS
+ #include
+ int feof(FILE *<[fp]>);
+
+TRAD_SYNOPSIS
+ #include
+ int feof(<[fp]>)
+ FILE *<[fp]>;
+
+DESCRIPTION
+<> tests whether or not the end of the file identified by <[fp]>
+has been reached.
+
+RETURNS
+<> returns <<0>> if the end of file has not yet been reached; if
+at end of file, the result is nonzero.
+
+PORTABILITY
+<> is required by ANSI C.
+
+No supporting OS subroutines are required.
+*/
+
+#include
+#include "local.h"
+
+/* A subroutine version of the macro feof. */
+
+#undef feof
+
+int
+_DEFUN(feof, (fp),
+ FILE * fp)
+{
+ int result;
+ CHECK_INIT(_REENT, fp);
+ _flockfile (fp);
+ result = __sfeof (fp);
+ _funlockfile (fp);
+ return result;
+}
feof.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: wscanf.c
===================================================================
--- wscanf.c (nonexistent)
+++ wscanf.c (revision 520)
@@ -0,0 +1,54 @@
+/*
+ * 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
+#include
+#include
+#include
+#include "local.h"
+
+#ifndef _REENT_ONLY
+
+int
+wscanf(_CONST wchar_t *fmt, ...)
+{
+ int ret;
+ va_list ap;
+
+ _REENT_SMALL_CHECK_INIT (_REENT);
+ va_start (ap, fmt);
+ ret = __svfwscanf_r (_REENT, _stdin_r (_REENT), fmt, ap);
+ va_end (ap);
+ return ret;
+}
+
+#endif /* !_REENT_ONLY */
+
+int
+_wscanf_r(struct _reent *ptr, _CONST wchar_t *fmt, ...)
+{
+ int ret;
+ va_list ap;
+
+ _REENT_SMALL_CHECK_INIT (ptr);
+ va_start (ap, fmt);
+ ret = __svfwscanf_r (ptr, _stdin_r (ptr), fmt, ap);
+ va_end (ap);
+ return (ret);
+}
+
wscanf.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: stdio.c
===================================================================
--- stdio.c (nonexistent)
+++ stdio.c (revision 520)
@@ -0,0 +1,150 @@
+/*
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by the University of California, Berkeley. The name of the
+ * University may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ */
+/* No user fns here. Pesch 15apr92. */
+
+#include <_ansi.h>
+#include
+#include
+#include
+#include
+#include
+#include "local.h"
+
+/*
+ * Small standard I/O/seek/close functions.
+ * These maintain the `known seek offset' for seek optimisation.
+ */
+
+_READ_WRITE_RETURN_TYPE
+_DEFUN(__sread, (ptr, cookie, buf, n),
+ struct _reent *ptr _AND
+ void *cookie _AND
+ char *buf _AND
+ int n)
+{
+ register FILE *fp = (FILE *) cookie;
+ register int ret;
+
+#ifdef __SCLE
+ int oldmode = 0;
+ if (fp->_flags & __SCLE)
+ oldmode = setmode (fp->_file, O_BINARY);
+#endif
+
+ ret = _read_r (ptr, fp->_file, buf, n);
+
+#ifdef __SCLE
+ if (oldmode)
+ setmode (fp->_file, oldmode);
+#endif
+
+ /* If the read succeeded, update the current offset. */
+
+ if (ret >= 0)
+ fp->_offset += ret;
+ else
+ fp->_flags &= ~__SOFF; /* paranoia */
+ return ret;
+}
+
+/* Dummy function used in sscanf/swscanf. */
+_READ_WRITE_RETURN_TYPE
+_DEFUN(__seofread, (ptr, cookie, buf, len),
+ struct _reent *_ptr _AND
+ _PTR cookie _AND
+ char *buf _AND
+ int len)
+{
+ return 0;
+}
+
+_READ_WRITE_RETURN_TYPE
+_DEFUN(__swrite, (ptr, cookie, buf, n),
+ struct _reent *ptr _AND
+ void *cookie _AND
+ char const *buf _AND
+ int n)
+{
+ register FILE *fp = (FILE *) cookie;
+ int w;
+#ifdef __SCLE
+ int oldmode=0;
+#endif
+
+ if (fp->_flags & __SAPP)
+ _lseek_r (ptr, fp->_file, (_off_t) 0, SEEK_END);
+ fp->_flags &= ~__SOFF; /* in case O_APPEND mode is set */
+
+#ifdef __SCLE
+ if (fp->_flags & __SCLE)
+ oldmode = setmode (fp->_file, O_BINARY);
+#endif
+
+ w = _write_r (ptr, fp->_file, buf, n);
+
+#ifdef __SCLE
+ if (oldmode)
+ setmode (fp->_file, oldmode);
+#endif
+
+ return w;
+}
+
+_fpos_t
+_DEFUN(__sseek, (ptr, cookie, offset, whence),
+ struct _reent *ptr _AND
+ void *cookie _AND
+ _fpos_t offset _AND
+ int whence)
+{
+ register FILE *fp = (FILE *) cookie;
+ register _off_t ret;
+
+ ret = _lseek_r (ptr, fp->_file, (_off_t) offset, whence);
+ if (ret == -1L)
+ fp->_flags &= ~__SOFF;
+ else
+ {
+ fp->_flags |= __SOFF;
+ fp->_offset = ret;
+ }
+ return ret;
+}
+
+int
+_DEFUN(__sclose, (ptr, cookie),
+ struct _reent *ptr _AND
+ void *cookie)
+{
+ FILE *fp = (FILE *) cookie;
+
+ return _close_r (ptr, fp->_file);
+}
+
+#ifdef __SCLE
+int
+_DEFUN(__stextmode, (fd),
+ int fd)
+{
+#ifdef __CYGWIN__
+ extern int _cygwin_istext_for_stdio (int);
+ return _cygwin_istext_for_stdio (fd);
+#else
+ return 0;
+#endif
+}
+#endif
stdio.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: fvwrite.c
===================================================================
--- fvwrite.c (nonexistent)
+++ fvwrite.c (revision 520)
@@ -0,0 +1,271 @@
+/*
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by the University of California, Berkeley. The name of the
+ * University may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ */
+/* No user fns here. Pesch 15apr92. */
+
+#include <_ansi.h>
+#include
+#include
+#include
+#include
+#include "local.h"
+#include "fvwrite.h"
+
+#define MIN(a, b) ((a) < (b) ? (a) : (b))
+#define COPY(n) _CAST_VOID memmove ((_PTR) fp->_p, (_PTR) p, (size_t) (n))
+
+#define GETIOV(extra_work) \
+ while (len == 0) \
+ { \
+ extra_work; \
+ p = iov->iov_base; \
+ len = iov->iov_len; \
+ iov++; \
+ }
+
+/*
+ * Write some memory regions. Return zero on success, EOF on error.
+ *
+ * This routine is large and unsightly, but most of the ugliness due
+ * to the three different kinds of output buffering is handled here.
+ */
+
+int
+_DEFUN(__sfvwrite_r, (ptr, fp, uio),
+ struct _reent *ptr _AND
+ register FILE *fp _AND
+ register struct __suio *uio)
+{
+ register size_t len;
+ register _CONST char *p = NULL;
+ register struct __siov *iov;
+ register int w, s;
+ char *nl;
+ int nlknown, nldist;
+
+ if ((len = uio->uio_resid) == 0)
+ return 0;
+
+ /* make sure we can write */
+ if (cantwrite (ptr, fp))
+ {
+ fp->_flags |= __SERR;
+ ptr->_errno = EBADF;
+ return EOF;
+ }
+
+ iov = uio->uio_iov;
+ len = 0;
+
+#ifdef __SCLE
+ if (fp->_flags & __SCLE) /* text mode */
+ {
+ do
+ {
+ GETIOV (;);
+ while (len > 0)
+ {
+ if (putc (*p, fp) == EOF)
+ return EOF;
+ p++;
+ len--;
+ uio->uio_resid--;
+ }
+ }
+ while (uio->uio_resid > 0);
+ return 0;
+ }
+#endif
+
+ if (fp->_flags & __SNBF)
+ {
+ /*
+ * Unbuffered: write up to BUFSIZ bytes at a time.
+ */
+ do
+ {
+ GETIOV (;);
+ w = fp->_write (ptr, fp->_cookie, p, MIN (len, BUFSIZ));
+ if (w <= 0)
+ goto err;
+ p += w;
+ len -= w;
+ }
+ while ((uio->uio_resid -= w) != 0);
+ }
+ else if ((fp->_flags & __SLBF) == 0)
+ {
+ /*
+ * Fully buffered: fill partially full buffer, if any,
+ * and then flush. If there is no partial buffer, write
+ * one _bf._size byte chunk directly (without copying).
+ *
+ * String output is a special case: write as many bytes
+ * as fit, but pretend we wrote everything. This makes
+ * snprintf() return the number of bytes needed, rather
+ * than the number used, and avoids its write function
+ * (so that the write function can be invalid). If
+ * we are dealing with the asprintf routines, we will
+ * dynamically increase the buffer size as needed.
+ */
+ do
+ {
+ GETIOV (;);
+ w = fp->_w;
+ if (fp->_flags & __SSTR)
+ {
+ if (len >= w && fp->_flags & (__SMBF | __SOPT))
+ { /* must be asprintf family */
+ unsigned char *str;
+ int curpos = (fp->_p - fp->_bf._base);
+ /* Choose a geometric growth factor to avoid
+ quadratic realloc behavior, but use a rate less
+ than (1+sqrt(5))/2 to accomodate malloc
+ overhead. asprintf EXPECTS us to overallocate, so
+ that it can add a trailing \0 without
+ reallocating. The new allocation should thus be
+ max(prev_size*1.5, curpos+len+1). */
+ int newsize = fp->_bf._size * 3 / 2;
+ if (newsize < curpos + len + 1)
+ newsize = curpos + len + 1;
+ if (fp->_flags & __SOPT)
+ {
+ /* asnprintf leaves original buffer alone. */
+ str = (unsigned char *)_malloc_r (ptr, newsize);
+ if (!str)
+ {
+ ptr->_errno = ENOMEM;
+ goto err;
+ }
+ memcpy (str, fp->_bf._base, curpos);
+ fp->_flags = (fp->_flags & ~__SOPT) | __SMBF;
+ }
+ else
+ {
+ str = (unsigned char *)_realloc_r (ptr, fp->_bf._base,
+ newsize);
+ if (!str)
+ {
+ /* Free buffer which is no longer used. */
+ _free_r (ptr, fp->_bf._base);
+ /* Ensure correct errno, even if free changed it. */
+ ptr->_errno = ENOMEM;
+ goto err;
+ }
+ }
+ fp->_bf._base = str;
+ fp->_p = str + curpos;
+ fp->_bf._size = newsize;
+ w = len;
+ fp->_w = newsize - curpos;
+ }
+ if (len < w)
+ w = len;
+ COPY (w); /* copy MIN(fp->_w,len), */
+ fp->_w -= w;
+ fp->_p += w;
+ w = len; /* but pretend copied all */
+ }
+ else if (fp->_p > fp->_bf._base && len > w)
+ {
+ /* fill and flush */
+ COPY (w);
+ /* fp->_w -= w; *//* unneeded */
+ fp->_p += w;
+ if (_fflush_r (ptr, fp))
+ goto err;
+ }
+ else if (len >= (w = fp->_bf._size))
+ {
+ /* write directly */
+ w = fp->_write (ptr, fp->_cookie, p, w);
+ if (w <= 0)
+ goto err;
+ }
+ else
+ {
+ /* fill and done */
+ w = len;
+ COPY (w);
+ fp->_w -= w;
+ fp->_p += w;
+ }
+ p += w;
+ len -= w;
+ }
+ while ((uio->uio_resid -= w) != 0);
+ }
+ else
+ {
+ /*
+ * Line buffered: like fully buffered, but we
+ * must check for newlines. Compute the distance
+ * to the first newline (including the newline),
+ * or `infinity' if there is none, then pretend
+ * that the amount to write is MIN(len,nldist).
+ */
+ nlknown = 0;
+ nldist = 0;
+ do
+ {
+ GETIOV (nlknown = 0);
+ if (!nlknown)
+ {
+ nl = memchr ((_PTR) p, '\n', len);
+ nldist = nl ? nl + 1 - p : len + 1;
+ nlknown = 1;
+ }
+ s = MIN (len, nldist);
+ w = fp->_w + fp->_bf._size;
+ if (fp->_p > fp->_bf._base && s > w)
+ {
+ COPY (w);
+ /* fp->_w -= w; */
+ fp->_p += w;
+ if (_fflush_r (ptr, fp))
+ goto err;
+ }
+ else if (s >= (w = fp->_bf._size))
+ {
+ w = fp->_write (ptr, fp->_cookie, p, w);
+ if (w <= 0)
+ goto err;
+ }
+ else
+ {
+ w = s;
+ COPY (w);
+ fp->_w -= w;
+ fp->_p += w;
+ }
+ if ((nldist -= w) == 0)
+ {
+ /* copied the newline: flush and forget */
+ if (_fflush_r (ptr, fp))
+ goto err;
+ nlknown = 0;
+ }
+ p += w;
+ len -= w;
+ }
+ while ((uio->uio_resid -= w) != 0);
+ }
+ return 0;
+
+err:
+ fp->_flags |= __SERR;
+ return EOF;
+}
fvwrite.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: wsetup.c
===================================================================
--- wsetup.c (nonexistent)
+++ wsetup.c (revision 520)
@@ -0,0 +1,83 @@
+/* No user fns here. Pesch 15apr92. */
+
+/*
+ * 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.
+ */
+
+#include <_ansi.h>
+#include
+#include
+#include "local.h"
+
+/*
+ * Various output routines call wsetup to be sure it is safe to write,
+ * because either _flags does not include __SWR, or _buf is NULL.
+ * _wsetup returns 0 if OK to write, nonzero otherwise.
+ */
+
+int
+_DEFUN(__swsetup_r, (ptr, fp),
+ struct _reent *ptr _AND
+ register FILE * fp)
+{
+ /* Make sure stdio is set up. */
+
+ CHECK_INIT (_REENT, fp);
+
+ /*
+ * If we are not writing, we had better be reading and writing.
+ */
+
+ if ((fp->_flags & __SWR) == 0)
+ {
+ if ((fp->_flags & __SRW) == 0)
+ return EOF;
+ if (fp->_flags & __SRD)
+ {
+ /* clobber any ungetc data */
+ if (HASUB (fp))
+ FREEUB (ptr, fp);
+ fp->_flags &= ~(__SRD | __SEOF);
+ fp->_r = 0;
+ fp->_p = fp->_bf._base;
+ }
+ fp->_flags |= __SWR;
+ }
+
+ /*
+ * Make a buffer if necessary, then set _w.
+ * A string I/O file should not explicitly allocate a buffer
+ * unless asprintf is being used.
+ */
+ if (fp->_bf._base == NULL
+ && (!(fp->_flags & __SSTR) || (fp->_flags & __SMBF)))
+ __smakebuf_r (ptr, fp);
+
+ if (fp->_flags & __SLBF)
+ {
+ /*
+ * It is line buffered, so make _lbfsize be -_bufsize
+ * for the putc() macro. We will change _lbfsize back
+ * to 0 whenever we turn off __SWR.
+ */
+ fp->_w = 0;
+ fp->_lbfsize = -fp->_bf._size;
+ }
+ else
+ fp->_w = fp->_flags & __SNBF ? 0 : fp->_bf._size;
+
+ return (!fp->_bf._base && (fp->_flags & __SMBF)) ? EOF : 0;
+}
wsetup.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: fvwrite.h
===================================================================
--- fvwrite.h (nonexistent)
+++ fvwrite.h (revision 520)
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 1990, 2007 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by the University of California, Berkeley. The name of the
+ * University may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
+/* %W% (Berkeley) %G% */
+#include <_ansi.h>
+
+/*
+ * I/O descriptors for __sfvwrite_r().
+ */
+struct __siov {
+ _CONST _PTR iov_base;
+ size_t iov_len;
+};
+struct __suio {
+ struct __siov *uio_iov;
+ int uio_iovcnt;
+ int uio_resid;
+};
+
+
+extern int _EXFUN(__sfvwrite_r,(struct _reent *, FILE *, struct __suio *));
+extern int _EXFUN(__swsetup_r,(struct _reent *, FILE *));
fvwrite.h
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: mktemp.c
===================================================================
--- mktemp.c (nonexistent)
+++ mktemp.c (revision 520)
@@ -0,0 +1,313 @@
+/*
+ * Copyright (c) 1987 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that: (1) source distributions retain this entire copyright
+ * notice and comment, and (2) distributions including binaries display
+ * the following acknowledgement: ``This product includes software
+ * developed by the University of California, Berkeley and its contributors''
+ * in the documentation or other materials provided with the distribution
+ * and in all advertising materials mentioning features or use of this
+ * software. Neither the name of the University nor the names of its
+ * contributors may 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 is file MKTEMP.C */
+/* This file may have been modified by DJ Delorie (Jan 1991). If so,
+** these modifications are Copyright (C) 1991 DJ Delorie.
+*/
+
+/*
+FUNCTION
+<>, <>, <>---generate unused file name
+<>---generate unused directory
+
+INDEX
+ mktemp
+INDEX
+ mkdtemp
+INDEX
+ mkstemp
+INDEX
+ mkstemps
+INDEX
+ _mktemp_r
+INDEX
+ _mkdtemp_r
+INDEX
+ _mkstemp_r
+INDEX
+ _mkstemps_r
+
+ANSI_SYNOPSIS
+ #include
+ char *mktemp(char *<[path]>);
+ char *mkdtemp(char *<[path]>);
+ int mkstemp(char *<[path]>);
+ int mkstemps(char *<[path]>, int <[suffixlen]>);
+
+ char *_mktemp_r(struct _reent *<[reent]>, char *<[path]>);
+ char *_mkdtemp_r(struct _reent *<[reent]>, char *<[path]>);
+ int *_mkstemp_r(struct _reent *<[reent]>, char *<[path]>);
+ int *_mkstemps_r(struct _reent *<[reent]>, char *<[path]>, int <[len]>);
+
+DESCRIPTION
+<>, <>, and <> attempt to generate a file name
+that is not yet in use for any existing file. <> and <>
+create the file and open it for reading and writing; <> simply
+generates the file name (making <> a security risk). <>
+attempts to create a directory instead of a file, with a permissions
+mask of 0700.
+
+You supply a simple pattern for the generated file name, as the string
+at <[path]>. The pattern should be a valid filename (including path
+information if you wish) ending with at least six `<>'
+characters. The generated filename will match the leading part of the
+name you supply, with the trailing `<>' characters replaced by some
+combination of digits and letters. With <>, the `<>'
+characters end <[suffixlen]> bytes before the end of the string.
+
+The alternate functions <<_mktemp_r>>, <<_mkdtemp_r>>, <<_mkstemp_r>>,
+and <<_mkstemps_r>> are reentrant versions. The extra argument <[reent]>
+is a pointer to a reentrancy structure.
+
+RETURNS
+<> returns the pointer <[path]> to the modified string
+representing an unused filename, unless it could not generate one, or
+the pattern you provided is not suitable for a filename; in that case,
+it returns <>.
+
+<> returns the pointer <[path]> to the modified string if the
+directory was created, otherwise it returns <>.
+
+<> and <> return a file descriptor to the newly created
+file, unless it could not generate an unused filename, or the pattern you
+provided is not suitable for a filename; in that case, it returns
+<<-1>>.
+
+NOTES
+Never use <>. The generated filenames are easy to guess and
+there's a race between the test if the file exists and the creation
+of the file. In combination this makes <> prone to attacks
+and using it is a security risk. Whenever possible use <>
+instead. It doesn't suffer the race condition.
+
+PORTABILITY
+ANSI C does not require either <> or <>; the System
+V Interface Definition requires <> as of Issue 2. POSIX 2001
+requires <>, and POSIX 2008 requires <>, but
+<> is not standardized.
+
+Supporting OS subroutines required: <>, <>, <>, <>.
+*/
+
+#include <_ansi.h>
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+static int
+_DEFUN(_gettemp, (ptr, path, doopen, domkdir, suffixlen),
+ struct _reent *ptr _AND
+ char *path _AND
+ register int *doopen _AND
+ int domkdir _AND
+ size_t suffixlen)
+{
+ register char *start, *trv;
+ char *end;
+#ifdef __USE_INTERNAL_STAT64
+ struct stat64 sbuf;
+#else
+ struct stat sbuf;
+#endif
+ unsigned int pid;
+
+ pid = _getpid_r (ptr);
+ for (trv = path; *trv; ++trv) /* extra X's get set to 0's */
+ continue;
+ if (trv - path < suffixlen)
+ {
+ ptr->_errno = EINVAL;
+ return 0;
+ }
+ trv -= suffixlen;
+ end = trv;
+ while (path < trv && *--trv == 'X')
+ {
+ *trv = (pid % 10) + '0';
+ pid /= 10;
+ }
+ if (end - trv < 6)
+ {
+ ptr->_errno = EINVAL;
+ return 0;
+ }
+
+ /*
+ * Check the target directory; if you have six X's and it
+ * doesn't exist this runs for a *very* long time.
+ */
+
+ for (start = trv + 1;; --trv)
+ {
+ if (trv <= path)
+ break;
+ if (*trv == '/')
+ {
+ *trv = '\0';
+#ifdef __USE_INTERNAL_STAT64
+ if (_stat64_r (ptr, path, &sbuf))
+#else
+ if (_stat_r (ptr, path, &sbuf))
+#endif
+ return (0);
+ if (!(sbuf.st_mode & S_IFDIR))
+ {
+ ptr->_errno = ENOTDIR;
+ return (0);
+ }
+ *trv = '/';
+ break;
+ }
+ }
+
+ for (;;)
+ {
+#if !defined _ELIX_LEVEL || _ELIX_LEVEL >= 4
+ if (domkdir)
+ {
+#ifdef HAVE_MKDIR
+ if (_mkdir_r (ptr, path, 0700) == 0)
+ return 1;
+ if (ptr->_errno != EEXIST)
+ return 0;
+#else /* !HAVE_MKDIR */
+ ptr->_errno = ENOSYS;
+ return 0;
+#endif /* !HAVE_MKDIR */
+ }
+ else
+#endif /* _ELIX_LEVEL */
+ if (doopen)
+ {
+ if ((*doopen = _open_r (ptr, path, O_CREAT | O_EXCL | O_RDWR, 0600))
+ >= 0)
+ return 1;
+ if (ptr->_errno != EEXIST)
+ return 0;
+ }
+#ifdef __USE_INTERNAL_STAT64
+ else if (_stat64_r (ptr, path, &sbuf))
+#else
+ else if (_stat_r (ptr, path, &sbuf))
+#endif
+ return (ptr->_errno == ENOENT ? 1 : 0);
+
+ /* tricky little algorithm for backward compatibility */
+ for (trv = start;;)
+ {
+ if (trv == end)
+ return 0;
+ if (*trv == 'z')
+ *trv++ = 'a';
+ else
+ {
+ /* Safe, since it only encounters 7-bit characters. */
+ if (isdigit (*trv))
+ *trv = 'a';
+ else
+ ++ * trv;
+ break;
+ }
+ }
+ }
+ /*NOTREACHED*/
+}
+
+int
+_DEFUN(_mkstemp_r, (ptr, path),
+ struct _reent *ptr _AND
+ char *path)
+{
+ int fd;
+
+ return (_gettemp (ptr, path, &fd, 0, 0) ? fd : -1);
+}
+
+#if !defined _ELIX_LEVEL || _ELIX_LEVEL >= 4
+char *
+_DEFUN(_mkdtemp_r, (ptr, path),
+ struct _reent *ptr _AND
+ char *path)
+{
+ return (_gettemp (ptr, path, (int *) NULL, 1, 0) ? path : NULL);
+}
+
+int
+_DEFUN(_mkstemps_r, (ptr, path, len),
+ struct _reent *ptr _AND
+ char *path _AND
+ int len)
+{
+ int fd;
+
+ return (_gettemp (ptr, path, &fd, 0, len) ? fd : -1);
+}
+#endif /* _ELIX_LEVEL */
+
+char *
+_DEFUN(_mktemp_r, (ptr, path),
+ struct _reent *ptr _AND
+ char *path)
+{
+ return (_gettemp (ptr, path, (int *) NULL, 0, 0) ? path : (char *) NULL);
+}
+
+#ifndef _REENT_ONLY
+
+int
+_DEFUN(mkstemp, (path),
+ char *path)
+{
+ int fd;
+
+ return (_gettemp (_REENT, path, &fd, 0, 0) ? fd : -1);
+}
+
+# if !defined _ELIX_LEVEL || _ELIX_LEVEL >= 4
+char *
+_DEFUN(mkdtemp, (path),
+ char *path)
+{
+ return (_gettemp (_REENT, path, (int *) NULL, 1, 0) ? path : NULL);
+}
+
+int
+_DEFUN(mkstemps, (path, len),
+ char *path _AND
+ int len)
+{
+ int fd;
+
+ return (_gettemp (_REENT, path, &fd, 0, len) ? fd : -1);
+}
+# endif /* _ELIX_LEVEL */
+
+char *
+_DEFUN(mktemp, (path),
+ char *path)
+{
+ return (_gettemp (_REENT, path, (int *) NULL, 0, 0) ? path : (char *) NULL);
+}
+
+#endif /* ! defined (_REENT_ONLY) */
mktemp.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: fscanf.c
===================================================================
--- fscanf.c (nonexistent)
+++ fscanf.c (revision 520)
@@ -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
+#include
+#ifdef _HAVE_STDC
+#include
+#else
+#include
+#endif
+#include "local.h"
+
+#ifndef _REENT_ONLY
+
+int
+#ifdef _HAVE_STDC
+fscanf(FILE *fp, _CONST char *fmt, ...)
+#else
+fscanf(FILE *fp, fmt, va_alist)
+ FILE *fp;
+ char *fmt;
+ va_dcl
+#endif
+{
+ int ret;
+ va_list ap;
+
+#ifdef _HAVE_STDC
+ va_start (ap, fmt);
+#else
+ va_start (ap);
+#endif
+ ret = __svfscanf_r (_REENT, fp, fmt, ap);
+ va_end (ap);
+ return ret;
+}
+
+#endif /* !_REENT_ONLY */
+
+int
+#ifdef _HAVE_STDC
+_fscanf_r(struct _reent *ptr, FILE *fp, _CONST char *fmt, ...)
+#else
+_fscanf_r(ptr, FILE *fp, fmt, va_alist)
+ struct _reent *ptr;
+ FILE *fp;
+ char *fmt;
+ va_dcl
+#endif
+{
+ int ret;
+ va_list ap;
+
+#ifdef _HAVE_STDC
+ va_start (ap, fmt);
+#else
+ va_start (ap);
+#endif
+ ret = __svfscanf_r (ptr, fp, fmt, ap);
+ va_end (ap);
+ return (ret);
+}
+
fscanf.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: fcloseall.c
===================================================================
--- fcloseall.c (nonexistent)
+++ fcloseall.c (revision 520)
@@ -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
+<>---close all files
+
+INDEX
+ fcloseall
+INDEX
+ _fcloseall_r
+
+ANSI_SYNOPSIS
+ #include
+ int fcloseall(void);
+ int _fcloseall_r (struct _reent *<[ptr]>);
+
+TRAD_SYNOPSIS
+ #include
+ int fcloseall()
+
+ int _fcloseall_r (<[ptr]>)
+ struct _reent *<[ptr]>;
+
+DESCRIPTION
+<> 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
+<> returns <<0>> if all closes are successful. Otherwise,
+EOF is returned.
+
+PORTABILITY
+<> is a glibc extension.
+
+Required OS subroutines: <>, <>, <>, <>,
+<>, <>, <>.
+*/
+/* This file based upon fwalk.c. */
+
+#include <_ansi.h>
+#include
+#include
+#include
+#include
+#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
fcloseall.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: putchar.c
===================================================================
--- putchar.c (nonexistent)
+++ putchar.c (revision 520)
@@ -0,0 +1,97 @@
+/*
+ * 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
+<>---write a character (macro)
+
+INDEX
+ putchar
+INDEX
+ _putchar_r
+
+ANSI_SYNOPSIS
+ #include
+ int putchar(int <[ch]>);
+
+ int _putchar_r(struct _reent *<[reent]>, int <[ch]>);
+
+TRAD_SYNOPSIS
+ #include
+ int putchar(<[ch]>)
+ int <[ch]>;
+
+ int _putchar_r(<[reent]>, <[ch]>)
+ struct _reent *<[reent]>;
+ int <[ch]>;
+
+DESCRIPTION
+<> is a macro, defined in <>. <>
+writes its argument to the standard output stream,
+after converting it from an <> to an <>.
+
+The alternate function <<_putchar_r>> is a reentrant version. The
+extra argument <[reent]> is a pointer to a reentrancy structure.
+
+RETURNS
+If successful, <> returns its argument <[ch]>. If an error
+intervenes, the result is <>. You can use `<>' to
+query for errors.
+
+PORTABILITY
+ANSI C requires <>; it suggests, but does not require, that
+<> be implemented as a macro.
+
+Supporting OS subroutines required: <>, <>, <>,
+<>, <>, <>, <>.
+*/
+
+#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.
+ */
+
+#include <_ansi.h>
+#include
+#include
+#include "local.h"
+
+#undef putchar
+
+int
+_DEFUN(_putchar_r, (ptr, c),
+ struct _reent *ptr _AND
+ int c)
+{
+ _REENT_SMALL_CHECK_INIT (ptr);
+ return _putc_r (ptr, c, _stdout_r (ptr));
+}
+
+#ifndef _REENT_ONLY
+
+int
+_DEFUN(putchar, (c),
+ int c)
+{
+ _REENT_SMALL_CHECK_INIT (_REENT);
+ return _putc_r (_REENT, c, _stdout_r (_REENT));
+}
+
+#endif
putchar.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: dprintf.c
===================================================================
--- dprintf.c (nonexistent)
+++ dprintf.c (revision 520)
@@ -0,0 +1,87 @@
+/* Copyright 2005, 2007 Shaun Jackman
+ * Permission to use, copy, modify, and distribute this software
+ * is freely granted, provided that this notice is preserved.
+ */
+
+/*
+FUNCTION
+<>, <>---print to a file descriptor
+
+INDEX
+ dprintf
+INDEX
+ _dprintf_r
+INDEX
+ vdprintf
+INDEX
+ _vdprintf_r
+
+ANSI_SYNOPSIS
+ #include
+ #include
+ int dprintf(int <[fd]>, const char *<[format]>, ...);
+ int vdprintf(int <[fd]>, const char *<[format]>, va_list <[ap]>);
+ int _dprintf_r(struct _reent *<[ptr]>, int <[fd]>,
+ const char *<[format]>, ...);
+ int _vdprintf_r(struct _reent *<[ptr]>, int <[fd]>,
+ const char *<[format]>, va_list <[ap]>);
+
+DESCRIPTION
+<> and <> allow printing a format, similarly to
+<>, but write to a file descriptor instead of to a <>
+stream.
+
+The functions <<_dprintf_r>> and <<_vdprintf_r>> are simply
+reentrant versions of the functions above.
+
+RETURNS
+The return value and errors are exactly as for <>, except that
+<> may also be set to <> if the heap is exhausted.
+
+PORTABILITY
+This function is originally a GNU extension in glibc and is not portable.
+
+Supporting OS subroutines required: <>, <>.
+*/
+
+#include <_ansi.h>
+#include
+#include
+#include
+#include
+#include "local.h"
+
+int
+_DEFUN(_dprintf_r, (ptr, fd, format),
+ struct _reent *ptr _AND
+ int fd _AND
+ const char *format _DOTS)
+{
+ va_list ap;
+ int n;
+ _REENT_SMALL_CHECK_INIT (ptr);
+ va_start (ap, format);
+ n = _vdprintf_r (ptr, fd, format, ap);
+ va_end (ap);
+ return n;
+}
+
+#ifndef _REENT_ONLY
+
+int
+_DEFUN(dprintf, (fd, format),
+ int fd _AND
+ const char *format _DOTS)
+{
+ va_list ap;
+ int n;
+ struct _reent *ptr = _REENT;
+
+ _REENT_SMALL_CHECK_INIT (ptr);
+ va_start (ap, format);
+ n = _vdprintf_r (ptr, fd, format, ap);
+ va_end (ap);
+ return n;
+}
+
+#endif /* ! _REENT_ONLY */
dprintf.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: ftell.c
===================================================================
--- ftell.c (nonexistent)
+++ ftell.c (revision 520)
@@ -0,0 +1,177 @@
+/*
+ * 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
+<>, <>---return position in a stream or file
+
+INDEX
+ ftell
+INDEX
+ ftello
+INDEX
+ _ftell_r
+INDEX
+ _ftello_r
+
+ANSI_SYNOPSIS
+ #include
+ long ftell(FILE *<[fp]>);
+ off_t ftello(FILE *<[fp]>);
+ long _ftell_r(struct _reent *<[ptr]>, FILE *<[fp]>);
+ off_t _ftello_r(struct _reent *<[ptr]>, FILE *<[fp]>);
+
+TRAD_SYNOPSIS
+ #include
+ long ftell(<[fp]>)
+ FILE *<[fp]>;
+
+ off_t ftello(<[fp]>)
+ FILE *<[fp]>;
+
+ long _ftell_r(<[ptr]>, <[fp]>)
+ struct _reent *<[ptr]>;
+ FILE *<[fp]>;
+
+ off_t _ftello_r(<[ptr]>, <[fp]>)
+ struct _reent *<[ptr]>;
+ FILE *<[fp]>;
+
+DESCRIPTION
+Objects of type <> can have a ``position'' that records how much
+of the file your program has already read. Many of the <> functions
+depend on this position, and many change it as a side effect.
+
+The result of <>/<> is the current position for a file
+identified by <[fp]>. If you record this result, you can later
+use it with <>/<> to return the file to this
+position. The difference between <> and <> is that
+<> returns <> and <> returns <>.
+
+In the current implementation, <>/<> simply uses a character
+count to represent the file position; this is the same number that
+would be recorded by <>.
+
+RETURNS
+<>/<> return the file position, if possible. If they cannot do
+this, they return <<-1L>>. Failure occurs on streams that do not support
+positioning; the global <> indicates this condition with the
+value <>.
+
+PORTABILITY
+<> is required by the ANSI C standard, but the meaning of its
+result (when successful) is not specified beyond requiring that it be
+acceptable as an argument to <>. In particular, other
+conforming C implementations may return a different result from
+<> than what <> records.
+
+<> is defined by the Single Unix specification.
+
+No supporting OS subroutines are required.
+*/
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "%W% (Berkeley) %G%";
+#endif /* LIBC_SCCS and not lint */
+
+/*
+ * ftell: return current offset.
+ */
+
+#include <_ansi.h>
+#include
+#include
+#include
+#include "local.h"
+
+long
+_DEFUN(_ftell_r, (ptr, fp),
+ struct _reent *ptr _AND
+ register FILE * fp)
+{
+ _fpos_t pos;
+
+ /* Ensure stdio is set up. */
+
+ CHECK_INIT (ptr, fp);
+
+ _flockfile (fp);
+
+ if (fp->_seek == NULL)
+ {
+ ptr->_errno = ESPIPE;
+ _funlockfile (fp);
+ return -1L;
+ }
+
+ /* Find offset of underlying I/O object, then adjust for buffered
+ bytes. Flush a write stream, since the offset may be altered if
+ the stream is appending. Do not flush a read stream, since we
+ must not lose the ungetc buffer. */
+ if (fp->_flags & __SWR)
+ _fflush_r (ptr, fp);
+ if (fp->_flags & __SOFF)
+ pos = fp->_offset;
+ else
+ {
+ pos = fp->_seek (ptr, fp->_cookie, (_fpos_t) 0, SEEK_CUR);
+ if (pos == -1L)
+ {
+ _funlockfile (fp);
+ return pos;
+ }
+ }
+ if (fp->_flags & __SRD)
+ {
+ /*
+ * Reading. Any unread characters (including
+ * those from ungetc) cause the position to be
+ * smaller than that in the underlying object.
+ */
+ pos -= fp->_r;
+ if (HASUB (fp))
+ pos -= fp->_ur;
+ }
+ else if ((fp->_flags & __SWR) && fp->_p != NULL)
+ {
+ /*
+ * Writing. Any buffered characters cause the
+ * position to be greater than that in the
+ * underlying object.
+ */
+ pos += fp->_p - fp->_bf._base;
+ }
+
+ _funlockfile (fp);
+ if ((long)pos != pos)
+ {
+ pos = -1;
+ ptr->_errno = EOVERFLOW;
+ }
+ return pos;
+}
+
+#ifndef _REENT_ONLY
+
+long
+_DEFUN(ftell, (fp),
+ register FILE * fp)
+{
+ return _ftell_r (_REENT, fp);
+}
+
+#endif /* !_REENT_ONLY */
ftell.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: fprintf.c
===================================================================
--- fprintf.c (nonexistent)
+++ fprintf.c (revision 520)
@@ -0,0 +1,55 @@
+/*
+ * 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 sprintf.c */
+
+#include <_ansi.h>
+#include
+#include
+#include
+
+int
+_DEFUN(_fprintf_r, (ptr, fp, fmt),
+ struct _reent *ptr _AND
+ FILE *fp _AND
+ const char *fmt _DOTS)
+{
+ int ret;
+ va_list ap;
+
+ va_start (ap, fmt);
+ ret = _vfprintf_r (ptr, fp, fmt, ap);
+ va_end (ap);
+ return ret;
+}
+
+#ifndef _REENT_ONLY
+
+int
+_DEFUN(fprintf, (fp, fmt),
+ FILE *fp _AND
+ const char *fmt _DOTS)
+{
+ int ret;
+ va_list ap;
+
+ va_start (ap, fmt);
+ ret = _vfprintf_r (_REENT, fp, fmt, ap);
+ va_end (ap);
+ return ret;
+}
+
+#endif /* ! _REENT_ONLY */
fprintf.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: fiscanf.c
===================================================================
--- fiscanf.c (nonexistent)
+++ fiscanf.c (revision 520)
@@ -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
+#include
+#ifdef _HAVE_STDC
+#include
+#else
+#include
+#endif
+#include "local.h"
+
+#ifndef _REENT_ONLY
+
+int
+#ifdef _HAVE_STDC
+fiscanf(FILE *fp, _CONST char *fmt, ...)
+#else
+fiscanf(FILE *fp, fmt, va_alist)
+ FILE *fp;
+ char *fmt;
+ va_dcl
+#endif
+{
+ int ret;
+ va_list ap;
+
+#ifdef _HAVE_STDC
+ va_start (ap, fmt);
+#else
+ va_start (ap);
+#endif
+ ret = __svfiscanf_r (_REENT, fp, fmt, ap);
+ va_end (ap);
+ return ret;
+}
+
+#endif /* !_REENT_ONLY */
+
+int
+#ifdef _HAVE_STDC
+_fiscanf_r(struct _reent *ptr, FILE *fp, _CONST char *fmt, ...)
+#else
+_fiscanf_r(ptr, FILE *fp, fmt, va_alist)
+ struct _reent *ptr;
+ FILE *fp;
+ char *fmt;
+ va_dcl
+#endif
+{
+ int ret;
+ va_list ap;
+
+#ifdef _HAVE_STDC
+ va_start (ap, fmt);
+#else
+ va_start (ap);
+#endif
+ ret = __svfiscanf_r (ptr, fp, fmt, ap);
+ va_end (ap);
+ return (ret);
+}
+
fiscanf.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: iprintf.c
===================================================================
--- iprintf.c (nonexistent)
+++ iprintf.c (revision 520)
@@ -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
+#include
+#include
+#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;
+}
iprintf.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: vscanf.c
===================================================================
--- vscanf.c (nonexistent)
+++ vscanf.c (revision 520)
@@ -0,0 +1,52 @@
+/*-
+ * Code created by modifying scanf.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
+#include
+#ifdef _HAVE_STDC
+#include
+#else
+#include
+#endif
+#include "local.h"
+
+#ifndef _REENT_ONLY
+
+int
+_DEFUN(vscanf, (fmt, ap),
+ _CONST char *fmt _AND
+ va_list ap)
+{
+ _REENT_SMALL_CHECK_INIT (_REENT);
+ return __svfscanf_r (_REENT, _stdin_r (_REENT), fmt, ap);
+}
+
+#endif /* !_REENT_ONLY */
+
+int
+_DEFUN(_vscanf_r, (ptr, fmt, ap),
+ struct _reent *ptr _AND
+ _CONST char *fmt _AND
+ va_list ap)
+{
+ _REENT_SMALL_CHECK_INIT (ptr);
+ return __svfscanf_r (ptr, _stdin_r (ptr), fmt, ap);
+}
+
vscanf.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: sccl.c
===================================================================
--- sccl.c (nonexistent)
+++ sccl.c (revision 520)
@@ -0,0 +1,127 @@
+/*-
+ * 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.
+ */
+
+/* Split from vfscanf.c */
+
+#include <_ansi.h>
+#include
+#include
+#include
+#include "local.h"
+
+/*
+ * Fill in the given table from the scanset at the given format
+ * (just after `['). Return a pointer to the character past the
+ * closing `]'. The table has a 1 wherever characters should be
+ * considered part of the scanset.
+ */
+
+u_char *
+_DEFUN(__sccl, (tab, fmt),
+ register char *tab _AND
+ register u_char *fmt)
+{
+ register int c, n, v;
+
+ /* first `clear' the whole table */
+ c = *fmt++; /* first char hat => negated scanset */
+ if (c == '^')
+ {
+ v = 1; /* default => accept */
+ c = *fmt++; /* get new first char */
+ }
+ else
+ v = 0; /* default => reject */
+ /* should probably use memset here */
+ for (n = 0; n < 256; n++)
+ tab[n] = v;
+ if (c == 0)
+ return fmt - 1; /* format ended before closing ] */
+
+ /*
+ * Now set the entries corresponding to the actual scanset to the
+ * opposite of the above.
+ *
+ * The first character may be ']' (or '-') without being special; the
+ * last character may be '-'.
+ */
+
+ v = 1 - v;
+ for (;;)
+ {
+ tab[c] = v; /* take character c */
+ doswitch:
+ n = *fmt++; /* and examine the next */
+ switch (n)
+ {
+
+ case 0: /* format ended too soon */
+ return fmt - 1;
+
+ case '-':
+ /*
+ * A scanset of the form [01+-] is defined as `the digit 0, the
+ * digit 1, the character +, the character -', but the effect of a
+ * scanset such as [a-zA-Z0-9] is implementation defined. The V7
+ * Unix scanf treats `a-z' as `the letters a through z', but treats
+ * `a-a' as `the letter a, the character -, and the letter a'.
+ *
+ * For compatibility, the `-' is not considerd to define a range if
+ * the character following it is either a close bracket (required by
+ * ANSI) or is not numerically greater than the character we just
+ * stored in the table (c).
+ */
+ n = *fmt;
+ if (n == ']' || n < c)
+ {
+ c = '-';
+ break; /* resume the for(;;) */
+ }
+ fmt++;
+ do
+ { /* fill in the range */
+ tab[++c] = v;
+ }
+ while (c < n);
+#if 1 /* XXX another disgusting compatibility hack */
+ /*
+ * Alas, the V7 Unix scanf also treats formats such
+ * as [a-c-e] as `the letters a through e'. This too
+ * is permitted by the standard....
+ */
+ goto doswitch;
+#else
+ c = *fmt++;
+ if (c == 0)
+ return fmt - 1;
+ if (c == ']')
+ return fmt;
+#endif
+
+ break;
+
+
+ case ']': /* end of scanset */
+ return fmt;
+
+ default: /* just another character */
+ c = n;
+ break;
+ }
+ }
+ /* NOTREACHED */
+}
sprintf.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: ftello.c
===================================================================
--- ftello.c (nonexistent)
+++ ftello.c (revision 520)
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2002, Red Hat Inc.
+ * 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
+#include
+
+_off_t
+_DEFUN(_ftello_r, (ptr, fp),
+ struct _reent * ptr _AND
+ register FILE * fp)
+{
+ /* for now we simply cast since off_t should be long */
+ return (_off_t)_ftell_r (ptr, fp);
+}
+
+#ifndef _REENT_ONLY
+
+_off_t
+_DEFUN(ftello, (fp),
+ register FILE * fp)
+{
+ return (_off_t)_ftell_r (_REENT, fp);
+}
+
+#endif /* !_REENT_ONLY */
ftello.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: siscanf.c
===================================================================
--- siscanf.c (nonexistent)
+++ siscanf.c (revision 520)
@@ -0,0 +1,188 @@
+/*
+ * 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
+<>, <>, <>---scan and format non-floating input
+
+INDEX
+ iscanf
+INDEX
+ _iscanf_r
+INDEX
+ fiscanf
+INDEX
+ _fiscanf_r
+INDEX
+ siscanf
+INDEX
+ _siscanf_r
+
+ANSI_SYNOPSIS
+ #include
+
+ int iscanf(const char *<[format]>, ...);
+ int fiscanf(FILE *<[fd]>, const char *<[format]>, ...);
+ int siscanf(const char *<[str]>, const char *<[format]>, ...);
+
+ int _iscanf_r(struct _reent *<[ptr]>, const char *<[format]>, ...);
+ int _fiscanf_r(struct _reent *<[ptr]>, FILE *<[fd]>,
+ const char *<[format]>, ...);
+ int _siscanf_r(struct _reent *<[ptr]>, const char *<[str]>,
+ const char *<[format]>, ...);
+
+
+TRAD_SYNOPSIS
+ #include
+
+ int iscanf(<[format]> [, <[arg]>, ...])
+ char *<[format]>;
+
+ int fiscanf(<[fd]>, <[format]> [, <[arg]>, ...]);
+ FILE *<[fd]>;
+ char *<[format]>;
+
+ int siscanf(<[str]>, <[format]> [, <[arg]>, ...]);
+ char *<[str]>;
+ char *<[format]>;
+
+ int _iscanf_r(<[ptr]>, <[format]> [, <[arg]>, ...])
+ struct _reent *<[ptr]>;
+ char *<[format]>;
+
+ int _fiscanf_r(<[ptr]>, <[fd]>, <[format]> [, <[arg]>, ...]);
+ struct _reent *<[ptr]>;
+ FILE *<[fd]>;
+ char *<[format]>;
+
+ int _siscanf_r(<[ptr]>, <[str]>, <[format]> [, <[arg]>, ...]);
+ struct _reent *<[ptr]>;
+ char *<[str]>;
+ char *<[format]>;
+
+
+DESCRIPTION
+ <>, <>, and <> are the same as
+ <>, <>, and <> respectively, only that
+ they restrict the available formats to non-floating-point
+ format specifiers.
+
+ The routines <<_iscanf_r>>, <<_fiscanf_r>>, and <<_siscanf_r>> are reentrant
+ versions of <>, <>, and <> that take an additional
+ first argument pointing to a reentrancy structure.
+
+RETURNS
+ <> returns the number of input fields successfully
+ scanned, converted and stored; the return value does
+ not include scanned fields which were not stored.
+
+ If <> attempts to read at end-of-file, the return
+ value is <>.
+
+ If no fields were stored, the return value is <<0>>.
+
+PORTABILITY
+<>, <>, and <> are newlib extensions.
+
+Supporting OS subroutines required: <>, <>, <>,
+<>, <>, <>, <>.
+*/
+
+#include <_ansi.h>
+#include
+#include
+#include
+#ifdef _HAVE_STDC
+#include
+#else
+#include
+#endif
+#include "local.h"
+
+#ifndef _REENT_ONLY
+
+#ifdef _HAVE_STDC
+int
+_DEFUN(siscanf, (str, fmt),
+ _CONST char *str _AND
+ _CONST char *fmt _DOTS)
+#else
+int
+siscanf(str, fmt, va_alist)
+ _CONST char *str;
+ _CONST char *fmt;
+ va_dcl
+#endif
+{
+ int ret;
+ 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. */
+#ifdef _HAVE_STDC
+ va_start (ap, fmt);
+#else
+ va_start (ap);
+#endif
+ ret = __ssvfiscanf_r (_REENT, &f, fmt, ap);
+ va_end (ap);
+ return ret;
+}
+
+#endif /* !_REENT_ONLY */
+
+#ifdef _HAVE_STDC
+int
+_DEFUN(_siscanf_r, (ptr, str, fmt),
+ struct _reent *ptr _AND
+ _CONST char *str _AND
+ _CONST char *fmt _DOTS)
+#else
+int
+_siscanf_r(ptr, str, fmt, va_alist)
+ struct _reent *ptr;
+ _CONST char *str;
+ _CONST char *fmt;
+ va_dcl
+#endif
+{
+ int ret;
+ 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. */
+#ifdef _HAVE_STDC
+ va_start (ap, fmt);
+#else
+ va_start (ap);
+#endif
+ ret = __ssvfiscanf_r (ptr, &f, fmt, ap);
+ va_end (ap);
+ return ret;
+}
siscanf.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: vprintf.c
===================================================================
--- vprintf.c (nonexistent)
+++ vprintf.c (revision 520)
@@ -0,0 +1,50 @@
+/*
+ * 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
+#include
+#ifdef _HAVE_STDC
+#include
+#else
+#include
+#endif
+#include "local.h"
+
+#ifndef _REENT_ONLY
+
+int
+_DEFUN(vprintf, (fmt, ap),
+ _CONST char *fmt _AND
+ va_list ap)
+{
+ _REENT_SMALL_CHECK_INIT (_REENT);
+ return _vfprintf_r (_REENT, _stdout_r (_REENT), fmt, ap);
+}
+
+#endif /* !_REENT_ONLY */
+
+int
+_DEFUN(_vprintf_r, (ptr, fmt, ap),
+ struct _reent *ptr _AND
+ _CONST char *fmt _AND
+ va_list ap)
+{
+ _REENT_SMALL_CHECK_INIT (ptr);
+ return _vfprintf_r (ptr, _stdout_r (ptr), fmt, ap);
+}
vprintf.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: rewind.c
===================================================================
--- rewind.c (nonexistent)
+++ rewind.c (revision 520)
@@ -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
+<>---reinitialize a file or stream
+
+INDEX
+ rewind
+INDEX
+ _rewind_r
+
+ANSI_SYNOPSIS
+ #include
+ void rewind(FILE *<[fp]>);
+ void _rewind_r(struct _reent *<[ptr]>, FILE *<[fp]>);
+
+TRAD_SYNOPSIS
+ #include
+ void rewind(<[fp]>)
+ FILE *<[fp]>;
+
+ void _rewind_r(<[ptr]>, <[fp]>)
+ struct _reent *<[ptr]>;
+ FILE *<[fp]>;
+
+DESCRIPTION
+<> returns the file position indicator (if any) for the file
+or stream identified by <[fp]> to the beginning of the file. It also
+clears any error indicator and flushes any pending output.
+
+RETURNS
+<> does not return a result.
+
+PORTABILITY
+ANSI C requires <>.
+
+No supporting OS subroutines are required.
+*/
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "%W% (Berkeley) %G%";
+#endif /* LIBC_SCCS and not lint */
+
+#include <_ansi.h>
+#include
+#include
+
+_VOID
+_DEFUN(_rewind_r, (ptr, fp),
+ struct _reent * ptr _AND
+ register FILE * fp)
+{
+ _CAST_VOID _fseek_r (ptr, fp, 0L, SEEK_SET);
+ clearerr (fp);
+}
+
+#ifndef _REENT_ONLY
+
+_VOID
+_DEFUN(rewind, (fp),
+ register FILE * fp)
+{
+ _rewind_r (_REENT, fp);
+}
+
+#endif /* !_REENT_ONLY */
Makefile.am
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: viscanf.c
===================================================================
--- viscanf.c (nonexistent)
+++ viscanf.c (revision 520)
@@ -0,0 +1,145 @@
+/*-
+ * 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
+<>, <>, <>---format argument list
+
+INDEX
+ viscanf
+INDEX
+ _viscanf_r
+INDEX
+ vfiscanf
+INDEX
+ _vfiscanf_r
+INDEX
+ vsiscanf
+INDEX
+ _vsiscanf_r
+
+ANSI_SYNOPSIS
+ #include
+ #include
+ 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
+ #include
+ 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
+<>, <>, and <> are (respectively) variants
+of <>, <>, and <>. They differ only in
+allowing their caller to pass the variable argument list as a
+<> object (initialized by <>) rather than
+directly accepting a variable number of arguments.
+
+RETURNS
+The return values are consistent with the corresponding functions:
+<> returns the number of input fields successfully scanned,
+converted, and stored; the return value does not include scanned
+fields which were not stored.
+
+If <> attempts to read at end-of-file, the return value
+is <>.
+
+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
+#include
+#ifdef _HAVE_STDC
+#include
+#else
+#include
+#endif
+#include "local.h"
+
+#ifndef _REENT_ONLY
+
+int
+_DEFUN(viscanf, (fmt, ap),
+ _CONST char *fmt _AND
+ va_list ap)
+{
+ _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);
+}
+
viscanf.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: wprintf.c
===================================================================
--- wprintf.c (nonexistent)
+++ wprintf.c (revision 520)
@@ -0,0 +1,58 @@
+/*
+ * 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 swprintf.c */
+
+#include <_ansi.h>
+#include
+#include
+#include
+#include
+#include "local.h"
+
+int
+_DEFUN(_wprintf_r, (ptr, fmt),
+ struct _reent *ptr _AND
+ const wchar_t *fmt _DOTS)
+{
+ int ret;
+ va_list ap;
+
+ _REENT_SMALL_CHECK_INIT (ptr);
+ va_start (ap, fmt);
+ ret = _vfwprintf_r (ptr, _stdout_r (ptr), fmt, ap);
+ va_end (ap);
+ return ret;
+}
+
+#ifndef _REENT_ONLY
+
+int
+_DEFUN(wprintf, (fmt),
+ const wchar_t *fmt _DOTS)
+{
+ int ret;
+ va_list ap;
+ struct _reent *ptr = _REENT;
+
+ _REENT_SMALL_CHECK_INIT (ptr);
+ va_start (ap, fmt);
+ ret = _vfwprintf_r (ptr, _stdout_r (ptr), fmt, ap);
+ va_end (ap);
+ return ret;
+}
+
+#endif /* ! _REENT_ONLY */
wprintf.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: remove.c
===================================================================
--- remove.c (nonexistent)
+++ remove.c (revision 520)
@@ -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
+<>---delete a file's name
+
+INDEX
+ remove
+INDEX
+ _remove_r
+
+ANSI_SYNOPSIS
+ #include
+ int remove(char *<[filename]>);
+
+ int _remove_r(struct _reent *<[reent]>, char *<[filename]>);
+
+TRAD_SYNOPSIS
+ #include
+ int remove(<[filename]>)
+ char *<[filename]>;
+
+ int _remove_r(<[reent]>, <[filename]>)
+ struct _reent *<[reent]>;
+ char *<[filename]>;
+
+DESCRIPTION
+Use <> to dissolve the association between a particular
+filename (the string at <[filename]>) and the file it represents.
+After calling <> with a particular filename, you will no
+longer be able to open the file by that name.
+
+In this implementation, you may use <> on an open file without
+error; existing file descriptors for the file will continue to access
+the file's data until the program using them closes the file.
+
+The alternate function <<_remove_r>> is a reentrant version. The
+extra argument <[reent]> is a pointer to a reentrancy structure.
+
+RETURNS
+<> returns <<0>> if it succeeds, <<-1>> if it fails.
+
+PORTABILITY
+ANSI C requires <>, but only specifies that the result on
+failure be nonzero. The behavior of <> when you call it on an
+open file may vary among implementations.
+
+Supporting OS subroutine required: <>.
+*/
+
+#include <_ansi.h>
+#include
+#include
+
+int
+_DEFUN(_remove_r, (ptr, filename),
+ struct _reent *ptr _AND
+ _CONST char *filename)
+{
+ if (_unlink_r (ptr, filename) == -1)
+ return -1;
+
+ return 0;
+}
+
+#ifndef _REENT_ONLY
+
+int
+_DEFUN(remove, (filename),
+ _CONST char *filename)
+{
+ return _remove_r (_REENT, filename);
+}
+
+#endif
remove.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: freopen.c
===================================================================
--- freopen.c (nonexistent)
+++ freopen.c (revision 520)
@@ -0,0 +1,250 @@
+/*
+ * 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.
+ */
+
+/*
+FUNCTION
+<>---open a file using an existing file descriptor
+
+INDEX
+ freopen
+INDEX
+ _freopen_r
+
+ANSI_SYNOPSIS
+ #include
+ FILE *freopen(const char *<[file]>, const char *<[mode]>,
+ FILE *<[fp]>);
+ FILE *_freopen_r(struct _reent *<[ptr]>, const char *<[file]>,
+ const char *<[mode]>, FILE *<[fp]>);
+
+TRAD_SYNOPSIS
+ #include
+ FILE *freopen(<[file]>, <[mode]>, <[fp]>)
+ char *<[file]>;
+ char *<[mode]>;
+ FILE *<[fp]>;
+
+ FILE *_freopen_r(<[ptr]>, <[file]>, <[mode]>, <[fp]>)
+ struct _reent *<[ptr]>;
+ char *<[file]>;
+ char *<[mode]>;
+ FILE *<[fp]>;
+
+DESCRIPTION
+Use this variant of <> if you wish to specify a particular file
+descriptor <[fp]> (notably <>, <>, or <>) for
+the file.
+
+If <[fp]> was associated with another file or stream, <>
+closes that other file or stream (but ignores any errors while closing
+it).
+
+<[file]> and <[mode]> are used just as in <>.
+
+If <[file]> is <>, the underlying stream is modified rather than
+closed. The file cannot be given a more permissive access mode (for
+example, a <[mode]> of "w" will fail on a read-only file descriptor),
+but can change status such as append or binary mode. If modification
+is not possible, failure occurs.
+
+RETURNS
+If successful, the result is the same as the argument <[fp]>. If the
+file cannot be opened as specified, the result is <>.
+
+PORTABILITY
+ANSI C requires <>.
+
+Supporting OS subroutines required: <>, <>, <>,
+<>, <>, <>, <>, <>.
+*/
+
+#include <_ansi.h>
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include "local.h"
+
+/*
+ * Re-direct an existing, open (probably) file to some other file.
+ */
+
+FILE *
+_DEFUN(_freopen_r, (ptr, file, mode, fp),
+ struct _reent *ptr _AND
+ const char *file _AND
+ const char *mode _AND
+ register FILE *fp)
+{
+ register int f;
+ int flags, oflags;
+ int e = 0;
+
+ __sfp_lock_acquire ();
+
+ CHECK_INIT (ptr, fp);
+
+ _flockfile (fp);
+
+ if ((flags = __sflags (ptr, mode, &oflags)) == 0)
+ {
+ _funlockfile (fp);
+ _fclose_r (ptr, fp);
+ __sfp_lock_release ();
+ return NULL;
+ }
+
+ /*
+ * Remember whether the stream was open to begin with, and
+ * which file descriptor (if any) was associated with it.
+ * If it was attached to a descriptor, defer closing it,
+ * so that, e.g., freopen("/dev/stdin", "r", stdin) works.
+ * This is unnecessary if it was not a Unix file.
+ */
+
+ if (fp->_flags == 0)
+ fp->_flags = __SEOF; /* hold on to it */
+ else
+ {
+ if (fp->_flags & __SWR)
+ _fflush_r (ptr, fp);
+ /*
+ * If close is NULL, closing is a no-op, hence pointless.
+ * If file is NULL, the file should not be closed.
+ */
+ if (fp->_close != NULL && file != NULL)
+ fp->_close (ptr, fp->_cookie);
+ }
+
+ /*
+ * Now get a new descriptor to refer to the new file, or reuse the
+ * existing file descriptor if file is NULL.
+ */
+
+ if (file != NULL)
+ {
+ f = _open_r (ptr, (char *) file, oflags, 0666);
+ e = ptr->_errno;
+ }
+ else
+ {
+#ifdef HAVE_FCNTL
+ int oldflags;
+ /*
+ * Reuse the file descriptor, but only if the new access mode is
+ * equal or less permissive than the old. F_SETFL correctly
+ * ignores creation flags.
+ */
+ f = fp->_file;
+ if ((oldflags = _fcntl_r (ptr, f, F_GETFL, 0)) == -1
+ || ! ((oldflags & O_ACCMODE) == O_RDWR
+ || ((oldflags ^ oflags) & O_ACCMODE) == 0)
+ || _fcntl_r (ptr, f, F_SETFL, oflags) == -1)
+ f = -1;
+#else
+ /* We cannot modify without fcntl support. */
+ f = -1;
+#endif
+
+#ifdef __SCLE
+ /*
+ * F_SETFL doesn't change textmode. Don't mess with modes of ttys.
+ */
+ if (0 <= f && ! _isatty_r (ptr, f)
+ && setmode (f, oflags & (O_BINARY | O_TEXT)) == -1)
+ f = -1;
+#endif
+
+ if (f < 0)
+ {
+ e = EBADF;
+ if (fp->_close != NULL)
+ fp->_close (ptr, fp->_cookie);
+ }
+ }
+
+ /*
+ * Finish closing fp. Even if the open succeeded above,
+ * we cannot keep fp->_base: it may be the wrong size.
+ * This loses the effect of any setbuffer calls,
+ * but stdio has always done this before.
+ */
+
+ if (fp->_flags & __SMBF)
+ _free_r (ptr, (char *) fp->_bf._base);
+ fp->_w = 0;
+ fp->_r = 0;
+ fp->_p = NULL;
+ fp->_bf._base = NULL;
+ fp->_bf._size = 0;
+ fp->_lbfsize = 0;
+ if (HASUB (fp))
+ FREEUB (ptr, fp);
+ fp->_ub._size = 0;
+ if (HASLB (fp))
+ FREELB (ptr, fp);
+ fp->_lb._size = 0;
+ fp->_flags & ~__SORD;
+ fp->_flags2 = 0;
+ memset (&fp->_mbstate, 0, sizeof (_mbstate_t));
+
+ if (f < 0)
+ { /* did not get it after all */
+ fp->_flags = 0; /* set it free */
+ ptr->_errno = e; /* restore in case _close clobbered */
+ _funlockfile (fp);
+#ifndef __SINGLE_THREAD__
+ __lock_close_recursive (fp->_lock);
+#endif
+ __sfp_lock_release ();
+ return NULL;
+ }
+
+ fp->_flags = flags;
+ fp->_file = f;
+ fp->_cookie = (_PTR) fp;
+ fp->_read = __sread;
+ fp->_write = __swrite;
+ fp->_seek = __sseek;
+ fp->_close = __sclose;
+
+#ifdef __SCLE
+ if (__stextmode (fp->_file))
+ fp->_flags |= __SCLE;
+#endif
+
+ _funlockfile (fp);
+ __sfp_lock_release ();
+ return fp;
+}
+
+#ifndef _REENT_ONLY
+
+FILE *
+_DEFUN(freopen, (file, mode, fp),
+ _CONST char *file _AND
+ _CONST char *mode _AND
+ register FILE *fp)
+{
+ return _freopen_r (_REENT, file, mode, fp);
+}
+
+#endif /*!_REENT_ONLY */
freopen.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: fwide.c
===================================================================
--- fwide.c (nonexistent)
+++ fwide.c (revision 520)
@@ -0,0 +1,89 @@
+/*
+FUNCTION
+<>---set and determine the orientation of a FILE stream
+
+INDEX
+ fwide
+INDEX
+ _fwide_r
+
+ANSI_SYNOPSIS
+ #include
+ int fwide(FILE *<[fp]>, int <[mode]>)
+
+ int _fwide_r(struct _reent *<[ptr]>, FILE *<[fp]>, int <[mode]>)
+
+TRAD_SYNOPSIS
+ #include
+ 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 <> 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 <> 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 <> 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
+#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);
+
+ _flockfile (fp);
+ if (mode != 0) {
+ ORIENT (fp, mode);
+ }
+ if (!(fp->_flags & __SORD))
+ ret = 0;
+ else
+ ret = (fp->_flags2 & __SWID) ? 1 : -1;
+ _funlockfile (fp);
+ return ret;
+}
+
+int
+_DEFUN(fwide, (fp, mode),
+ FILE *fp _AND
+ int mode)
+{
+ return _fwide_r (_REENT, fp, mode);
+}
fwide.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: putc_u.c
===================================================================
--- putc_u.c (nonexistent)
+++ putc_u.c (revision 520)
@@ -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
+<>---non-thread-safe version of putc (macro)
+
+INDEX
+ putc_unlocked
+INDEX
+ _putc_unlocked_r
+
+SYNOPSIS
+ #include
+ int putc_unlocked(int <[ch]>, FILE *<[fp]>);
+
+ #include
+ int _putc_unlocked_r(struct _reent *<[ptr]>, int <[ch]>, FILE *<[fp]>);
+
+DESCRIPTION
+<> is a non-thread-safe version of <> declared in
+<>. <> 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
+<> is equivalent to <>.
+
+The function <<_putc_unlocked_r>> is simply the reentrant version of
+<> that takes an additional reentrant structure pointer
+argument: <[ptr]>.
+
+RETURNS
+See <>.
+
+PORTABILITY
+POSIX 1003.1 requires <>. <> may be
+implemented as a macro, so arguments should not have side-effects.
+
+Supporting OS subroutines required: <>, <>, <>,
+<>, <>, <>, <>.
+*/
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "%W% (Berkeley) %G%";
+#endif /* LIBC_SCCS and not lint */
+
+#include <_ansi.h>
+#include
+
+/*
+ * 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 */
putc_u.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: getchar_u.c
===================================================================
--- getchar_u.c (nonexistent)
+++ getchar_u.c (revision 520)
@@ -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
+<>---non-thread-safe version of getchar (macro)
+
+INDEX
+ getchar_unlocked
+INDEX
+ _getchar_unlocked_r
+
+SYNOPSIS
+ #include
+ int getchar_unlocked();
+
+ #include
+ int _getchar_unlocked_r(struct _reent *<[ptr]>);
+
+DESCRIPTION
+<> is a non-thread-safe version of <>
+declared in <>. <> 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 <> is equivalent to <>.
+
+The <<_getchar_unlocked_r>> function is simply the reentrant version of
+<> which passes an addtional reentrancy structure pointer
+argument: <[ptr]>.
+
+RETURNS
+See <>.
+
+PORTABILITY
+POSIX 1003.1 requires <>. <> may
+be implemented as a macro.
+
+Supporting OS subroutines required: <>, <>, <>,
+<>, <>, <>, <>. */
+
+#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
+#include
+
+#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
fopencookie.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: vsniprintf.c
===================================================================
--- vsniprintf.c (nonexistent)
+++ vsniprintf.c (revision 520)
@@ -0,0 +1,70 @@
+/*
+ * 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
+#include
+#include
+#include
+#include
+
+#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;
+}
vsniprintf.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: getc_u.c
===================================================================
--- getc_u.c (nonexistent)
+++ getc_u.c (revision 520)
@@ -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
+<>---non-thread-safe version of getc (macro)
+
+INDEX
+ getc_unlocked
+INDEX
+ _getc_unlocked_r
+
+SYNOPSIS
+ #include
+ int getc_unlocked(FILE *<[fp]>);
+
+ #include
+ int _getc_unlocked_r(FILE *<[fp]>);
+
+DESCRIPTION
+<> is a non-thread-safe version of <> declared in
+<>. <> 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
+<> is equivalent to <>.
+
+The <<_getc_unlocked_r>> function is simply the reentrant version of
+<> which passes an additional reentrancy structure pointer
+argument: <[ptr]>.
+
+RETURNS
+See <>.
+
+PORTABILITY
+POSIX 1003.1 requires <>. <> may be
+implemented as a macro, so arguments should not have side-effects.
+
+Supporting OS subroutines required: <>, <>, <>,
+<>, <>, <>, <>. */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "%W% (Berkeley) %G%";
+#endif /* LIBC_SCCS and not lint */
+
+#include <_ansi.h>
+#include
+
+/*
+ * 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 */
getc_u.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: asniprintf.c
===================================================================
--- asniprintf.c (nonexistent)
+++ asniprintf.c (revision 520)
@@ -0,0 +1,108 @@
+/* Copyright (C) 2007, 2008 Eric Blake
+ * Permission to use, copy, modify, and distribute this software
+ * is freely granted, provided that this notice is preserved.
+ */
+/* This code was derived from asprintf.c */
+/* doc in siprintf.c */
+
+#include <_ansi.h>
+#include
+#include
+#include
+#include
+#include
+#include "local.h"
+
+char *
+_DEFUN(_asniprintf_r, (ptr, buf, lenp, fmt),
+ struct _reent *ptr _AND
+ char *buf _AND
+ size_t *lenp _AND
+ const char *fmt _DOTS)
+{
+ int ret;
+ va_list ap;
+ FILE f;
+ size_t len = *lenp;
+
+ if (buf && len)
+ {
+ /* mark an existing buffer, but allow allocation of larger string */
+ f._flags = __SWR | __SSTR | __SOPT;
+ }
+ else
+ {
+ /* mark a zero-length reallocatable buffer */
+ f._flags = __SWR | __SSTR | __SMBF;
+ len = 0;
+ buf = NULL;
+ }
+ f._bf._base = f._p = (unsigned char *) buf;
+ /* For now, inherit the 32-bit signed limit of FILE._bf._size.
+ FIXME - it would be nice to rewrite sys/reent.h to support size_t
+ for _size. */
+ if (len > INT_MAX)
+ {
+ ptr->_errno = EOVERFLOW;
+ return NULL;
+ }
+ f._bf._size = f._w = len;
+ f._file = -1; /* No file. */
+ va_start (ap, fmt);
+ ret = _svfiprintf_r (ptr, &f, fmt, ap);
+ va_end (ap);
+ if (ret < 0)
+ return NULL;
+ *lenp = ret;
+ *f._p = '\0';
+ return (char *) f._bf._base;
+}
+
+#ifndef _REENT_ONLY
+
+char *
+_DEFUN(asniprintf, (buf, lenp, fmt),
+ char *buf _AND
+ size_t *lenp _AND
+ const char *fmt _DOTS)
+{
+ int ret;
+ va_list ap;
+ FILE f;
+ size_t len = *lenp;
+ struct _reent *ptr = _REENT;
+
+ if (buf && len)
+ {
+ /* mark an existing buffer, but allow allocation of larger string */
+ f._flags = __SWR | __SSTR | __SOPT;
+ }
+ else
+ {
+ /* mark a zero-length reallocatable buffer */
+ f._flags = __SWR | __SSTR | __SMBF;
+ len = 0;
+ buf = NULL;
+ }
+ f._bf._base = f._p = (unsigned char *) buf;
+ /* For now, inherit the 32-bit signed limit of FILE._bf._size.
+ FIXME - it would be nice to rewrite sys/reent.h to support size_t
+ for _size. */
+ if (len > INT_MAX)
+ {
+ ptr->_errno = EOVERFLOW;
+ return NULL;
+ }
+ f._bf._size = f._w = len;
+ f._file = -1; /* No file. */
+ va_start (ap, fmt);
+ ret = _svfiprintf_r (ptr, &f, fmt, ap);
+ va_end (ap);
+ if (ret < 0)
+ return NULL;
+ *lenp = ret;
+ *f._p = '\0';
+ return (char *) f._bf._base;
+}
+
+#endif /* ! _REENT_ONLY */
asniprintf.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: fiprintf.c
===================================================================
--- fiprintf.c (nonexistent)
+++ fiprintf.c (revision 520)
@@ -0,0 +1,55 @@
+/*
+ * 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
+#include
+#include
+
+int
+_DEFUN(_fiprintf_r, (ptr, fp, fmt),
+ struct _reent *ptr _AND
+ FILE * fp _AND
+ const char *fmt _DOTS)
+{
+ int ret;
+ va_list ap;
+
+ va_start (ap, fmt);
+ ret = _vfiprintf_r (ptr, fp, fmt, ap);
+ va_end (ap);
+ return ret;
+}
+
+#ifndef _REENT_ONLY
+
+int
+_DEFUN(fiprintf, (fp, fmt),
+ FILE * fp _AND
+ const char *fmt _DOTS)
+{
+ int ret;
+ va_list ap;
+
+ va_start (ap, fmt);
+ ret = _vfiprintf_r (_REENT, fp, fmt, ap);
+ va_end (ap);
+ return ret;
+}
+
+#endif /* ! _REENT_ONLY */
fiprintf.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: fsetpos.c
===================================================================
--- fsetpos.c (nonexistent)
+++ fsetpos.c (revision 520)
@@ -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
+<>---restore position of a stream or file
+
+INDEX
+ fsetpos
+INDEX
+ _fsetpos_r
+
+ANSI_SYNOPSIS
+ #include
+ int fsetpos(FILE *<[fp]>, const fpos_t *<[pos]>);
+ int _fsetpos_r(struct _reent *<[ptr]>, FILE *<[fp]>,
+ const fpos_t *<[pos]>);
+
+TRAD_SYNOPSIS
+ #include
+ 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 <> can have a ``position'' that records how much
+of the file your program has already read. Many of the <> functions
+depend on this position, and many change it as a side effect.
+
+You can use <> to return the file identified by <[fp]> to a previous
+position <<*<[pos]>>> (after first recording it with <>).
+
+See <> for a similar facility.
+
+RETURNS
+<> returns <<0>> when successful. If <> fails, the
+result is <<1>>. The reason for failure is indicated in <>:
+either <> (the stream identified by <[fp]> doesn't support
+repositioning) or <> (invalid file position).
+
+PORTABILITY
+ANSI C requires <>, but does not specify the nature of
+<<*<[pos]>>> beyond identifying it as written by <>.
+
+Supporting OS subroutines required: <>, <>, <>,
+<>, <>, <>, <>.
+*/
+
+#include <_ansi.h>
+#include
+#include
+
+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 */
fsetpos.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: vasiprintf.c
===================================================================
--- vasiprintf.c (nonexistent)
+++ vasiprintf.c (revision 520)
@@ -0,0 +1,63 @@
+/*
+ * 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
+#include
+#include
+
+#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 = f._bf._base;
+ }
+ return ret;
+}
vasiprintf.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: vfwprintf.c
===================================================================
--- vfwprintf.c (nonexistent)
+++ vfwprintf.c (revision 520)
@@ -0,0 +1,1778 @@
+/*
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * 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.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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
+<>, <>, <>---wide character format argument list
+
+INDEX
+ vfwprintf
+INDEX
+ _vfwprintf_r
+INDEX
+ vwprintf
+INDEX
+ _vwprintf_r
+INDEX
+ vswprintf
+INDEX
+ _vswprintf_r
+
+ANSI_SYNOPSIS
+ #include
+ #include
+ #include
+ int vwprintf(const wchar_t *<[fmt]>, va_list <[list]>);
+ int vfwprintf(FILE *<[fp]>, const wchar_t *<[fmt]>, va_list <[list]>);
+ int vswprintf(wchar_t *<[str]>, size_t <[size]>, const wchar_t *<[fmt]>,
+ va_list <[list]>);
+
+ int _vwprintf_r(struct _reent *<[reent]>, const wchar_t *<[fmt]>,
+ va_list <[list]>);
+ int _vfwprintf_r(struct _reent *<[reent]>, FILE *<[fp]>,
+ const wchar_t *<[fmt]>, va_list <[list]>);
+ int _vswprintf_r(struct _reent *<[reent]>, wchar_t *<[str]>,
+ size_t <[size]>, const wchar_t *<[fmt]>, va_list <[list]>);
+
+DESCRIPTION
+<>, <> and <> are (respectively) variants
+of <>, <> and <>. They differ only in allowing
+their caller to pass the variable argument list as a <> object
+(initialized by <>) rather than directly accepting a variable
+number of arguments. The caller is responsible for calling <>.
+
+<<_vwprintf_r>>, <<_vfwprintf_r>> and <<_vswprintf_r>> are reentrant
+versions of the above.
+
+RETURNS
+The return values are consistent with the corresponding functions.
+
+PORTABILITY
+POSIX-1.2008 with extensions; C99 (compliant except for POSIX extensions).
+
+Supporting OS subroutines required: <>, <>, <>,
+<>, <>, <>, <>.
+
+SEEALSO
+<>, <> and <>.
+*/
+
+/*
+ * Actual wprintf innards.
+ *
+ * This code is large and complicated...
+ */
+#include
+
+#ifdef INTEGER_ONLY
+# define VFWPRINTF vfiwprintf
+# ifdef STRING_ONLY
+# define _VFWPRINTF_R _svfiwprintf_r
+# else
+# define _VFWPRINTF_R _vfiwprintf_r
+# endif
+#else
+# define VFWPRINTF vfwprintf
+# ifdef STRING_ONLY
+# define _VFWPRINTF_R _svfwprintf_r
+# else
+# define _VFWPRINTF_R _vfwprintf_r
+# endif
+# ifndef NO_FLOATING_POINT
+# define FLOATING_POINT
+# endif
+#endif
+
+#define _NO_POS_ARGS
+#ifdef _WANT_IO_POS_ARGS
+# undef _NO_POS_ARGS
+#endif
+
+#include <_ansi.h>
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include "local.h"
+#include "fvwrite.h"
+#include "vfieeefp.h"
+
+/* Currently a test is made to see if long double processing is warranted.
+ This could be changed in the future should the _ldtoa_r code be
+ preferred over _dtoa_r. */
+#define _NO_LONGDBL
+#if defined _WANT_IO_LONG_DOUBLE && (LDBL_MANT_DIG > DBL_MANT_DIG)
+#undef _NO_LONGDBL
+#endif
+
+#define _NO_LONGLONG
+#if defined _WANT_IO_LONG_LONG \
+ && (defined __GNUC__ || __STDC_VERSION__ >= 199901L)
+# undef _NO_LONGLONG
+#endif
+
+int _EXFUN(_VFWPRINTF_R, (struct _reent *, FILE *, _CONST wchar_t *, va_list));
+/* Defined in vfprintf.c. */
+#ifdef STRING_ONLY
+#define __SPRINT __ssprint_r
+#else
+#define __SPRINT __sprint_r
+#endif
+int _EXFUN(__SPRINT, (struct _reent *, FILE *, register struct __suio *));
+
+#ifndef STRING_ONLY
+/*
+ * Helper function for `fprintf to unbuffered unix file': creates a
+ * temporary buffer. We only work on write-only files; this avoids
+ * worries about ungetc buffers and so forth.
+ */
+static int
+_DEFUN(__sbwprintf, (rptr, fp, fmt, ap),
+ struct _reent *rptr _AND
+ register FILE *fp _AND
+ _CONST wchar_t *fmt _AND
+ va_list ap)
+{
+ int ret;
+ FILE fake;
+ unsigned char buf[BUFSIZ];
+
+ /* copy the important variables */
+ fake._flags = fp->_flags & ~__SNBF;
+ fake._flags2 = fp->_flags2;
+ fake._file = fp->_file;
+ fake._cookie = fp->_cookie;
+ fake._write = fp->_write;
+
+ /* set up the buffer */
+ fake._bf._base = fake._p = buf;
+ fake._bf._size = fake._w = sizeof (buf);
+ fake._lbfsize = 0; /* not actually used, but Just In Case */
+#ifndef __SINGLE_THREAD__
+ __lock_init_recursive (fake._lock);
+#endif
+
+ /* do the work, then copy any error status */
+ ret = _VFWPRINTF_R (rptr, &fake, fmt, ap);
+ if (ret >= 0 && _fflush_r (rptr, &fake))
+ ret = EOF;
+ if (fake._flags & __SERR)
+ fp->_flags |= __SERR;
+
+#ifndef __SINGLE_THREAD__
+ __lock_close_recursive (fake._lock);
+#endif
+ return (ret);
+}
+#endif /* !STRING_ONLY */
+
+
+#ifdef FLOATING_POINT
+# include
+# include
+
+/* For %La, an exponent of 15 bits occupies the exponent character, a
+ sign, and up to 5 digits. */
+# define MAXEXPLEN 7
+# define DEFPREC 6
+
+# ifdef _NO_LONGDBL
+
+extern char *_dtoa_r _PARAMS((struct _reent *, double, int,
+ int, int *, int *, char **));
+
+# define _PRINTF_FLOAT_TYPE double
+# define _DTOA_R _dtoa_r
+# define FREXP frexp
+
+# else /* !_NO_LONGDBL */
+
+extern char *_ldtoa_r _PARAMS((struct _reent *, _LONG_DOUBLE, int,
+ int, int *, int *, char **));
+
+extern int _EXFUN(_ldcheck,(_LONG_DOUBLE *));
+
+# define _PRINTF_FLOAT_TYPE _LONG_DOUBLE
+# define _DTOA_R _ldtoa_r
+/* FIXME - frexpl is not yet supported; and cvt infloops if (double)f
+ converts a finite value into infinity. */
+/* # define FREXP frexpl */
+# define FREXP(f,e) ((_LONG_DOUBLE) frexp ((double)f, e))
+# endif /* !_NO_LONGDBL */
+
+static wchar_t *wcvt(struct _reent *, _PRINTF_FLOAT_TYPE, int, int, wchar_t *,
+ int *, int, int *, wchar_t *);
+
+static int wexponent(wchar_t *, int, int);
+
+#endif /* FLOATING_POINT */
+
+/* BUF must be big enough for the maximum %#llo (assuming long long is
+ at most 64 bits, this would be 23 characters), the maximum
+ multibyte character %C, and the maximum default precision of %La
+ (assuming long double is at most 128 bits with 113 bits of
+ mantissa, this would be 29 characters). %e, %f, and %g use
+ reentrant storage shared with mprec. All other formats that use
+ buf get by with fewer characters. Making BUF slightly bigger
+ reduces the need for malloc in %.*a and %ls/%S, when large precision or
+ long strings are processed. */
+#define BUF 40
+#if defined _MB_CAPABLE && MB_LEN_MAX > BUF
+# undef BUF
+# define BUF MB_LEN_MAX
+#endif
+
+#ifndef _NO_LONGLONG
+# define quad_t long long
+# define u_quad_t unsigned long long
+#else
+# define quad_t long
+# define u_quad_t unsigned long
+#endif
+
+typedef quad_t * quad_ptr_t;
+typedef _PTR void_ptr_t;
+typedef char * char_ptr_t;
+typedef wchar_t* wchar_ptr_t;
+typedef long * long_ptr_t;
+typedef int * int_ptr_t;
+typedef short * short_ptr_t;
+
+#ifndef _NO_POS_ARGS
+# ifdef NL_ARGMAX
+# define MAX_POS_ARGS NL_ARGMAX
+# else
+# define MAX_POS_ARGS 32
+# endif
+
+union arg_val
+{
+ int val_int;
+ u_int val_u_int;
+ long val_long;
+ u_long val_u_long;
+ float val_float;
+ double val_double;
+ _LONG_DOUBLE val__LONG_DOUBLE;
+ int_ptr_t val_int_ptr_t;
+ short_ptr_t val_short_ptr_t;
+ long_ptr_t val_long_ptr_t;
+ char_ptr_t val_char_ptr_t;
+ wchar_ptr_t val_wchar_ptr_t;
+ quad_ptr_t val_quad_ptr_t;
+ void_ptr_t val_void_ptr_t;
+ quad_t val_quad_t;
+ u_quad_t val_u_quad_t;
+ wint_t val_wint_t;
+};
+
+static union arg_val *
+_EXFUN(get_arg, (struct _reent *data, int n, wchar_t *fmt,
+ va_list *ap, int *numargs, union arg_val *args,
+ int *arg_type, wchar_t **last_fmt));
+#endif /* !_NO_POS_ARGS */
+
+/*
+ * Macros for converting digits to letters and vice versa
+ */
+#define to_digit(c) ((c) - L'0')
+#define is_digit(c) ((unsigned)to_digit (c) <= 9)
+#define to_char(n) ((n) + L'0')
+
+/*
+ * Flags used during conversion.
+ */
+#define ALT 0x001 /* alternate form */
+#define HEXPREFIX 0x002 /* add 0x or 0X prefix */
+#define LADJUST 0x004 /* left adjustment */
+#define LONGDBL 0x008 /* long double */
+#define LONGINT 0x010 /* long integer */
+#ifndef _NO_LONGLONG
+# define QUADINT 0x020 /* quad integer */
+#else /* ifdef _NO_LONGLONG, make QUADINT equivalent to LONGINT, so
+ that %lld behaves the same as %ld, not as %d, as expected if:
+ sizeof (long long) = sizeof long > sizeof int */
+# define QUADINT LONGINT
+#endif
+#define SHORTINT 0x040 /* short integer */
+#define ZEROPAD 0x080 /* zero (as opposed to blank) pad */
+#define FPT 0x100 /* Floating point number */
+#ifdef _WANT_IO_C99_FORMATS
+# define CHARINT 0x200 /* char as integer */
+#else /* define as 0, to make SARG and UARG occupy fewer instructions */
+# define CHARINT 0
+#endif
+
+#ifndef STRING_ONLY
+int
+_DEFUN(VFWPRINTF, (fp, fmt0, ap),
+ FILE * fp _AND
+ _CONST wchar_t *fmt0 _AND
+ va_list ap)
+{
+ int result;
+ result = _VFWPRINTF_R (_REENT, fp, fmt0, ap);
+ return result;
+}
+#endif /* STRING_ONLY */
+
+int
+_DEFUN(_VFWPRINTF_R, (data, fp, fmt0, ap),
+ struct _reent *data _AND
+ FILE * fp _AND
+ _CONST wchar_t *fmt0 _AND
+ va_list ap)
+{
+ register wchar_t *fmt; /* format string */
+ register wint_t ch; /* character from fmt */
+ register int n, m; /* handy integers (short term usage) */
+ register wchar_t *cp; /* handy char pointer (short term usage) */
+ register struct __siov *iovp;/* for PRINT macro */
+ register int flags; /* flags as above */
+ wchar_t *fmt_anchor; /* current format spec being processed */
+#ifndef _NO_POS_ARGS
+ int N; /* arg number */
+ int arg_index; /* index into args processed directly */
+ int numargs; /* number of varargs read */
+ wchar_t *saved_fmt; /* saved fmt pointer */
+ union arg_val args[MAX_POS_ARGS];
+ int arg_type[MAX_POS_ARGS];
+ int is_pos_arg; /* is current format positional? */
+ int old_is_pos_arg; /* is current format positional? */
+#endif
+ int ret; /* return value accumulator */
+ int width; /* width from format (%8d), or 0 */
+ int prec; /* precision from format (%.3d), or -1 */
+ wchar_t sign; /* sign prefix (' ', '+', '-', or \0) */
+#ifdef FLOATING_POINT
+ wchar_t decimal_point;
+#ifdef _MB_CAPABLE
+ mbstate_t state; /* mbtowc calls from library must not change state */
+#endif
+ wchar_t softsign; /* temporary negative sign for floats */
+ union { int i; _PRINTF_FLOAT_TYPE fp; } _double_ = {0};
+# define _fpvalue (_double_.fp)
+ int expt; /* integer value of exponent */
+ int expsize = 0; /* character count for expstr */
+ int ndig = 0; /* actual number of digits returned by wcvt */
+ wchar_t expstr[MAXEXPLEN]; /* buffer for exponent string */
+#endif /* FLOATING_POINT */
+ u_quad_t _uquad; /* integer arguments %[diouxX] */
+ enum { OCT, DEC, HEX } base;/* base for [diouxX] conversion */
+ int dprec; /* a copy of prec if [diouxX], 0 otherwise */
+ int realsz; /* field size expanded by dprec */
+ int size = 0; /* size of converted field or string */
+ wchar_t *xdigs = NULL; /* digits for [xX] conversion */
+#define NIOV 8
+ struct __suio uio; /* output information: summary */
+ struct __siov iov[NIOV];/* ... and individual io vectors */
+ wchar_t buf[BUF]; /* space for %c, %ls/%S, %[diouxX], %[aA] */
+ wchar_t ox[2]; /* space for 0x hex-prefix */
+ wchar_t *malloc_buf = NULL;/* handy pointer for malloced buffers */
+
+ /*
+ * Choose PADSIZE to trade efficiency vs. size. If larger printf
+ * fields occur frequently, increase PADSIZE and make the initialisers
+ * below longer.
+ */
+#define PADSIZE 16 /* pad chunk size */
+ static _CONST wchar_t blanks[PADSIZE] =
+ {L' ',L' ',L' ',L' ',L' ',L' ',L' ',L' ',
+ L' ',L' ',L' ',L' ',L' ',L' ',L' ',L' '};
+ static _CONST wchar_t zeroes[PADSIZE] =
+ {L'0',L'0',L'0',L'0',L'0',L'0',L'0',L'0',
+ L'0',L'0',L'0',L'0',L'0',L'0',L'0',L'0'};
+
+#ifdef FLOATING_POINT
+#ifdef _MB_CAPABLE
+ memset (&state, '\0', sizeof (state));
+ _mbrtowc_r (data, &decimal_point, _localeconv_r (data)->decimal_point,
+ MB_CUR_MAX, &state);
+#else
+ decimal_point = (wchar_t) *_localeconv_r (data)->decimal_point;
+#endif
+#endif
+ /*
+ * BEWARE, these `goto error' on error, and PAD uses `n'.
+ */
+#define PRINT(ptr, len) { \
+ iovp->iov_base = (char *) (ptr); \
+ iovp->iov_len = (len) * sizeof (wchar_t); \
+ uio.uio_resid += (len) * sizeof (wchar_t); \
+ iovp++; \
+ if (++uio.uio_iovcnt >= NIOV) { \
+ if (__SPRINT(data, fp, &uio)) \
+ goto error; \
+ iovp = iov; \
+ } \
+}
+#define PAD(howmany, with) { \
+ if ((n = (howmany)) > 0) { \
+ while (n > PADSIZE) { \
+ PRINT (with, PADSIZE); \
+ n -= PADSIZE; \
+ } \
+ PRINT (with, n); \
+ } \
+}
+#define FLUSH() { \
+ if (uio.uio_resid && __SPRINT(data, fp, &uio)) \
+ goto error; \
+ uio.uio_iovcnt = 0; \
+ iovp = iov; \
+}
+
+ /* Macros to support positional arguments */
+#ifndef _NO_POS_ARGS
+# define GET_ARG(n, ap, type) \
+ (is_pos_arg \
+ ? (n < numargs \
+ ? args[n].val_##type \
+ : get_arg (data, n, fmt_anchor, &ap, &numargs, args, \
+ arg_type, &saved_fmt)->val_##type) \
+ : (arg_index++ < numargs \
+ ? args[n].val_##type \
+ : (numargs < MAX_POS_ARGS \
+ ? args[numargs++].val_##type = va_arg (ap, type) \
+ : va_arg (ap, type))))
+#else
+# define GET_ARG(n, ap, type) (va_arg (ap, type))
+#endif
+
+ /*
+ * To extend shorts properly, we need both signed and unsigned
+ * argument extraction methods.
+ */
+#ifndef _NO_LONGLONG
+#define SARG() \
+ (flags&QUADINT ? GET_ARG (N, ap, quad_t) : \
+ flags&LONGINT ? GET_ARG (N, ap, long) : \
+ flags&SHORTINT ? (long)(short)GET_ARG (N, ap, int) : \
+ flags&CHARINT ? (long)(signed char)GET_ARG (N, ap, int) : \
+ (long)GET_ARG (N, ap, int))
+#define UARG() \
+ (flags&QUADINT ? GET_ARG (N, ap, u_quad_t) : \
+ flags&LONGINT ? GET_ARG (N, ap, u_long) : \
+ flags&SHORTINT ? (u_long)(u_short)GET_ARG (N, ap, int) : \
+ flags&CHARINT ? (u_long)(unsigned char)GET_ARG (N, ap, int) : \
+ (u_long)GET_ARG (N, ap, u_int))
+#else
+#define SARG() \
+ (flags&LONGINT ? GET_ARG (N, ap, long) : \
+ flags&SHORTINT ? (long)(short)GET_ARG (N, ap, int) : \
+ flags&CHARINT ? (long)(signed char)GET_ARG (N, ap, int) : \
+ (long)GET_ARG (N, ap, int))
+#define UARG() \
+ (flags&LONGINT ? GET_ARG (N, ap, u_long) : \
+ flags&SHORTINT ? (u_long)(u_short)GET_ARG (N, ap, int) : \
+ flags&CHARINT ? (u_long)(unsigned char)GET_ARG (N, ap, int) : \
+ (u_long)GET_ARG (N, ap, u_int))
+#endif
+
+#ifndef STRING_ONLY
+ /* Initialize std streams if not dealing with sprintf family. */
+ CHECK_INIT (data, fp);
+ _flockfile (fp);
+
+ ORIENT(fp, 1);
+
+ /* sorry, fwprintf(read_only_file, "") returns EOF, not 0 */
+ if (cantwrite (data, fp)) {
+ _funlockfile (fp);
+ return (EOF);
+ }
+
+ /* optimise fwprintf(stderr) (and other unbuffered Unix files) */
+ if ((fp->_flags & (__SNBF|__SWR|__SRW)) == (__SNBF|__SWR) &&
+ fp->_file >= 0) {
+ _funlockfile (fp);
+ return (__sbwprintf (data, fp, fmt0, ap));
+ }
+#else /* STRING_ONLY */
+ /* Create initial buffer if we are called by asprintf family. */
+ if (fp->_flags & __SMBF && !fp->_bf._base)
+ {
+ fp->_bf._base = fp->_p = _malloc_r (data, 64);
+ if (!fp->_p)
+ {
+ data->_errno = ENOMEM;
+ return EOF;
+ }
+ fp->_bf._size = 64;
+ }
+#endif /* STRING_ONLY */
+
+ fmt = (wchar_t *)fmt0;
+ uio.uio_iov = iovp = iov;
+ uio.uio_resid = 0;
+ uio.uio_iovcnt = 0;
+ ret = 0;
+#ifndef _NO_POS_ARGS
+ arg_index = 0;
+ saved_fmt = NULL;
+ arg_type[0] = -1;
+ numargs = 0;
+ is_pos_arg = 0;
+#endif
+
+ /*
+ * Scan the format for conversions (`%' character).
+ */
+ for (;;) {
+ cp = fmt;
+ while (*fmt != L'\0' && *fmt != L'%')
+ ++fmt;
+ if ((m = fmt - cp) != 0) {
+ PRINT (cp, m);
+ ret += m;
+ }
+ if (*fmt == L'\0')
+ goto done;
+ fmt_anchor = fmt;
+ fmt++; /* skip over '%' */
+
+ flags = 0;
+ dprec = 0;
+ width = 0;
+ prec = -1;
+ sign = L'\0';
+#ifndef _NO_POS_ARGS
+ N = arg_index;
+ is_pos_arg = 0;
+#endif
+
+rflag: ch = *fmt++;
+reswitch: switch (ch) {
+#ifdef _WANT_IO_C99_FORMATS
+ case L'\'':
+ /* The ' flag is required by POSIX, but not C99.
+ FIXME: this flag is currently a no-op. */
+ goto rflag;
+#endif
+ case L' ':
+ /*
+ * ``If the space and + flags both appear, the space
+ * flag will be ignored.''
+ * -- ANSI X3J11
+ */
+ if (!sign)
+ sign = L' ';
+ goto rflag;
+ case L'#':
+ flags |= ALT;
+ goto rflag;
+ case L'*':
+#ifndef _NO_POS_ARGS
+ /* we must check for positional arg used for dynamic width */
+ n = N;
+ old_is_pos_arg = is_pos_arg;
+ is_pos_arg = 0;
+ if (is_digit (*fmt)) {
+ wchar_t *old_fmt = fmt;
+
+ n = 0;
+ ch = *fmt++;
+ do {
+ n = 10 * n + to_digit (ch);
+ ch = *fmt++;
+ } while (is_digit (ch));
+
+ if (ch == L'$') {
+ if (n <= MAX_POS_ARGS) {
+ n -= 1;
+ is_pos_arg = 1;
+ }
+ else
+ goto error;
+ }
+ else {
+ fmt = old_fmt;
+ goto rflag;
+ }
+ }
+#endif /* !_NO_POS_ARGS */
+
+ /*
+ * ``A negative field width argument is taken as a
+ * - flag followed by a positive field width.''
+ * -- ANSI X3J11
+ * They don't exclude field widths read from args.
+ */
+ width = GET_ARG (n, ap, int);
+#ifndef _NO_POS_ARGS
+ is_pos_arg = old_is_pos_arg;
+#endif
+ if (width >= 0)
+ goto rflag;
+ width = -width;
+ /* FALLTHROUGH */
+ case L'-':
+ flags |= LADJUST;
+ goto rflag;
+ case L'+':
+ sign = L'+';
+ goto rflag;
+ case L'.':
+ if ((ch = *fmt++) == L'*') {
+#ifndef _NO_POS_ARGS
+ /* we must check for positional arg used for dynamic width */
+ n = N;
+ old_is_pos_arg = is_pos_arg;
+ is_pos_arg = 0;
+ if (is_digit (*fmt)) {
+ wchar_t *old_fmt = fmt;
+
+ n = 0;
+ ch = *fmt++;
+ do {
+ n = 10 * n + to_digit (ch);
+ ch = *fmt++;
+ } while (is_digit (ch));
+
+ if (ch == L'$') {
+ if (n <= MAX_POS_ARGS) {
+ n -= 1;
+ is_pos_arg = 1;
+ }
+ else
+ goto error;
+ }
+ else {
+ fmt = old_fmt;
+ goto rflag;
+ }
+ }
+#endif /* !_NO_POS_ARGS */
+ prec = GET_ARG (n, ap, int);
+#ifndef _NO_POS_ARGS
+ is_pos_arg = old_is_pos_arg;
+#endif
+ if (prec < 0)
+ prec = -1;
+ goto rflag;
+ }
+ n = 0;
+ while (is_digit (ch)) {
+ n = 10 * n + to_digit (ch);
+ ch = *fmt++;
+ }
+ prec = n < 0 ? -1 : n;
+ goto reswitch;
+ case L'0':
+ /*
+ * ``Note that 0 is taken as a flag, not as the
+ * beginning of a field width.''
+ * -- ANSI X3J11
+ */
+ flags |= ZEROPAD;
+ goto rflag;
+ case L'1': case L'2': case L'3': case L'4':
+ case L'5': case L'6': case L'7': case L'8': case L'9':
+ n = 0;
+ do {
+ n = 10 * n + to_digit (ch);
+ ch = *fmt++;
+ } while (is_digit (ch));
+#ifndef _NO_POS_ARGS
+ if (ch == L'$') {
+ if (n <= MAX_POS_ARGS) {
+ N = n - 1;
+ is_pos_arg = 1;
+ goto rflag;
+ }
+ else
+ goto error;
+ }
+#endif /* !_NO_POS_ARGS */
+ width = n;
+ goto reswitch;
+#ifdef FLOATING_POINT
+ case L'L':
+ flags |= LONGDBL;
+ goto rflag;
+#endif
+ case L'h':
+#ifdef _WANT_IO_C99_FORMATS
+ if (*fmt == L'h') {
+ fmt++;
+ flags |= CHARINT;
+ } else
+#endif
+ flags |= SHORTINT;
+ goto rflag;
+ case L'l':
+#if defined _WANT_IO_C99_FORMATS || !defined _NO_LONGLONG
+ if (*fmt == L'l') {
+ fmt++;
+ flags |= QUADINT;
+ } else
+#endif
+ flags |= LONGINT;
+ goto rflag;
+ case L'q': /* GNU extension */
+ flags |= QUADINT;
+ goto rflag;
+#ifdef _WANT_IO_C99_FORMATS
+ case L'j':
+ if (sizeof (intmax_t) == sizeof (long))
+ flags |= LONGINT;
+ else
+ flags |= QUADINT;
+ goto rflag;
+ case L'z':
+ if (sizeof (size_t) < sizeof (int))
+ /* POSIX states size_t is 16 or more bits, as is short. */
+ flags |= SHORTINT;
+ else if (sizeof (size_t) == sizeof (int))
+ /* no flag needed */;
+ else if (sizeof (size_t) <= sizeof (long))
+ flags |= LONGINT;
+ else
+ /* POSIX states that at least one programming
+ environment must support size_t no wider than
+ long, but that means other environments can
+ have size_t as wide as long long. */
+ flags |= QUADINT;
+ goto rflag;
+ case L't':
+ if (sizeof (ptrdiff_t) < sizeof (int))
+ /* POSIX states ptrdiff_t is 16 or more bits, as
+ is short. */
+ flags |= SHORTINT;
+ else if (sizeof (ptrdiff_t) == sizeof (int))
+ /* no flag needed */;
+ else if (sizeof (ptrdiff_t) <= sizeof (long))
+ flags |= LONGINT;
+ else
+ /* POSIX states that at least one programming
+ environment must support ptrdiff_t no wider than
+ long, but that means other environments can
+ have ptrdiff_t as wide as long long. */
+ flags |= QUADINT;
+ goto rflag;
+ case L'C': /* POSIX extension */
+#endif /* _WANT_IO_C99_FORMATS */
+ case L'c':
+ cp = buf;
+ if (ch == L'c' && !(flags & LONGINT)) {
+ wint_t wc = btowc ((int) GET_ARG (N, ap, int));
+ if (wc == WEOF) {
+ fp->_flags |= __SERR;
+ goto error;
+ }
+ cp[0] = (wchar_t) wc;
+ }
+ else
+ {
+ cp[0] = GET_ARG (N, ap, int);
+ }
+ cp[1] = L'\0';
+ size = 1;
+ sign = L'\0';
+ break;
+ case L'd':
+ case L'i':
+ _uquad = SARG ();
+#ifndef _NO_LONGLONG
+ if ((quad_t)_uquad < 0)
+#else
+ if ((long) _uquad < 0)
+#endif
+ {
+
+ _uquad = -_uquad;
+ sign = L'-';
+ }
+ base = DEC;
+ goto number;
+#ifdef FLOATING_POINT
+# ifdef _WANT_IO_C99_FORMATS
+ case L'a':
+ case L'A':
+ case L'F':
+# endif
+ case L'e':
+ case L'E':
+ case L'f':
+ case L'g':
+ case L'G':
+# ifdef _NO_LONGDBL
+ if (flags & LONGDBL) {
+ _fpvalue = (double) GET_ARG (N, ap, _LONG_DOUBLE);
+ } else {
+ _fpvalue = GET_ARG (N, ap, double);
+ }
+
+ /* do this before tricky precision changes
+
+ If the output is infinite or NaN, leading
+ zeros are not permitted. Otherwise, scanf
+ could not read what printf wrote.
+ */
+ if (isinf (_fpvalue)) {
+ if (_fpvalue < 0)
+ sign = '-';
+ if (ch <= L'G') /* 'A', 'E', 'F', or 'G' */
+ cp = L"INF";
+ else
+ cp = L"inf";
+ size = 3;
+ flags &= ~ZEROPAD;
+ break;
+ }
+ if (isnan (_fpvalue)) {
+ if (ch <= L'G') /* 'A', 'E', 'F', or 'G' */
+ cp = L"NAN";
+ else
+ cp = L"nan";
+ size = 3;
+ flags &= ~ZEROPAD;
+ break;
+ }
+
+# else /* !_NO_LONGDBL */
+
+ if (flags & LONGDBL) {
+ _fpvalue = GET_ARG (N, ap, _LONG_DOUBLE);
+ } else {
+ _fpvalue = (_LONG_DOUBLE)GET_ARG (N, ap, double);
+ }
+
+ /* do this before tricky precision changes */
+ expt = _ldcheck (&_fpvalue);
+ if (expt == 2) {
+ if (_fpvalue < 0)
+ sign = L'-';
+ if (ch <= L'G') /* 'A', 'E', 'F', or 'G' */
+ cp = L"INF";
+ else
+ cp = L"inf";
+ size = 3;
+ flags &= ~ZEROPAD;
+ break;
+ }
+ if (expt == 1) {
+ if (ch <= L'G') /* 'A', 'E', 'F', or 'G' */
+ cp = L"NAN";
+ else
+ cp = L"nan";
+ size = 3;
+ flags &= ~ZEROPAD;
+ break;
+ }
+# endif /* !_NO_LONGDBL */
+
+ cp = buf;
+# ifdef _WANT_IO_C99_FORMATS
+ if (ch == L'a' || ch == L'A') {
+ ox[0] = L'0';
+ ox[1] = ch == L'a' ? L'x' : L'X';
+ flags |= HEXPREFIX;
+ if (prec >= BUF)
+ {
+ if ((malloc_buf =
+ (wchar_t *)_malloc_r (data, (prec + 1) * sizeof (wchar_t)))
+ == NULL)
+ {
+ fp->_flags |= __SERR;
+ goto error;
+ }
+ cp = malloc_buf;
+ }
+ } else
+# endif /* _WANT_IO_C99_FORMATS */
+ if (prec == -1) {
+ prec = DEFPREC;
+ } else if ((ch == L'g' || ch == L'G') && prec == 0) {
+ prec = 1;
+ }
+
+ flags |= FPT;
+
+ cp = wcvt (data, _fpvalue, prec, flags, &softsign,
+ &expt, ch, &ndig, cp);
+
+ if (ch == L'g' || ch == L'G') {
+ if (expt <= -4 || expt > prec)
+ ch -= 2; /* 'e' or 'E' */
+ else
+ ch = L'g';
+ }
+# ifdef _WANT_IO_C99_FORMATS
+ else if (ch == L'F')
+ ch = L'f';
+# endif
+ if (ch <= L'e') { /* 'a', 'A', 'e', or 'E' fmt */
+ --expt;
+ expsize = wexponent (expstr, expt, ch);
+ size = expsize + ndig;
+ if (ndig > 1 || flags & ALT)
+ ++size;
+ } else if (ch == L'f') { /* f fmt */
+ if (expt > 0) {
+ size = expt;
+ if (prec || flags & ALT)
+ size += prec + 1;
+ } else /* "0.X" */
+ size = (prec || flags & ALT)
+ ? prec + 2
+ : 1;
+ } else if (expt >= ndig) { /* fixed g fmt */
+ size = expt;
+ if (flags & ALT)
+ ++size;
+ } else
+ size = ndig + (expt > 0 ?
+ 1 : 2 - expt);
+
+ if (softsign)
+ sign = L'-';
+ break;
+#endif /* FLOATING_POINT */
+ case L'n':
+#ifndef _NO_LONGLONG
+ if (flags & QUADINT)
+ *GET_ARG (N, ap, quad_ptr_t) = ret;
+ else
+#endif
+ if (flags & LONGINT)
+ *GET_ARG (N, ap, long_ptr_t) = ret;
+ else if (flags & SHORTINT)
+ *GET_ARG (N, ap, short_ptr_t) = ret;
+#ifdef _WANT_IO_C99_FORMATS
+ else if (flags & CHARINT)
+ *GET_ARG (N, ap, char_ptr_t) = ret;
+#endif
+ else
+ *GET_ARG (N, ap, int_ptr_t) = ret;
+ continue; /* no output */
+ case L'o':
+ _uquad = UARG ();
+ base = OCT;
+ goto nosign;
+ case L'p':
+ /*
+ * ``The argument shall be a pointer to void. The
+ * value of the pointer is converted to a sequence
+ * of printable characters, in an implementation-
+ * defined manner.''
+ * -- ANSI X3J11
+ */
+ /* NOSTRICT */
+ _uquad = (uintptr_t) GET_ARG (N, ap, void_ptr_t);
+ base = HEX;
+ xdigs = L"0123456789abcdef";
+ flags |= HEXPREFIX;
+ ox[0] = L'0';
+ ox[1] = ch = L'x';
+ goto nosign;
+ case L's':
+#ifdef _WANT_IO_C99_FORMATS
+ case L'S': /* POSIX extension */
+#endif
+ sign = '\0';
+ cp = GET_ARG (N, ap, wchar_ptr_t);
+#ifndef __OPTIMIZE_SIZE__
+ /* Behavior is undefined if the user passed a
+ NULL string when precision is not 0.
+ However, if we are not optimizing for size,
+ we might as well mirror glibc behavior. */
+ if (cp == NULL) {
+ cp = L"(null)";
+ size = ((unsigned) prec > 6U) ? 6 : prec;
+ }
+ else
+#endif /* __OPTIMIZE_SIZE__ */
+#ifdef _MB_CAPABLE
+ if (ch == L's' && !(flags & LONGINT)) {
+ char *arg = (char *) cp;
+ size_t insize = 0, nchars = 0, nconv = 0;
+ mbstate_t ps;
+ wchar_t *p;
+
+ if (prec >= 0) {
+ char *p = arg;
+ memset ((_PTR)&ps, '\0', sizeof (mbstate_t));
+ while (nchars < (size_t)prec) {
+ nconv = mbrlen (p, MB_CUR_MAX, &ps);
+ if (nconv == 0 || nconv == (size_t)-1 ||
+ nconv == (size_t)-2)
+ break;
+ p += nconv;
+ ++nchars;
+ insize += nconv;
+ }
+ if (nconv == (size_t) -1 || nconv == (size_t) -2) {
+ fp->_flags |= __SERR;
+ goto error;
+ }
+ } else
+ insize = strlen(arg);
+ if (insize >= BUF) {
+ if ((malloc_buf = (wchar_t *) _malloc_r (data, (insize + 1) * sizeof (wchar_t)))
+ == NULL) {
+ fp->_flags |= __SERR;
+ goto error;
+ }
+ cp = malloc_buf;
+ } else
+ cp = buf;
+ memset ((_PTR)&ps, '\0', sizeof (mbstate_t));
+ p = cp;
+ while (insize != 0) {
+ nconv = _mbrtowc_r (data, p, arg, insize, &ps);
+ if (nconv == 0 || nconv == (size_t)-1 || nconv == (size_t)-2)
+ break;
+ ++p;
+ arg += nconv;
+ insize -= nconv;
+ }
+ if (nconv == (size_t) -1 || nconv == (size_t) -2) {
+ fp->_flags |= __SERR;
+ goto error;
+ }
+ *p = L'\0';
+ size = p - cp;
+ }
+ else
+#endif /* _MB_CAPABLE */
+ if (prec >= 0) {
+ /*
+ * can't use wcslen; can only look for the
+ * NUL in the first `prec' characters, and
+ * strlen () will go further.
+ */
+ wchar_t *p = wmemchr (cp, L'\0', prec);
+
+ if (p != NULL) {
+ size = p - cp;
+ if (size > prec)
+ size = prec;
+ } else
+ size = prec;
+ } else
+ size = wcslen (cp);
+
+ break;
+ case L'u':
+ _uquad = UARG ();
+ base = DEC;
+ goto nosign;
+ case L'X':
+ xdigs = L"0123456789ABCDEF";
+ goto hex;
+ case 'x':
+ xdigs = L"0123456789abcdef";
+hex: _uquad = UARG ();
+ base = HEX;
+ /* leading 0x/X only if non-zero */
+ if (flags & ALT && _uquad != 0) {
+ ox[0] = L'0';
+ ox[1] = ch;
+ flags |= HEXPREFIX;
+ }
+
+ /* unsigned conversions */
+nosign: sign = L'\0';
+ /*
+ * ``... diouXx conversions ... if a precision is
+ * specified, the 0 flag will be ignored.''
+ * -- ANSI X3J11
+ */
+number: if ((dprec = prec) >= 0)
+ flags &= ~ZEROPAD;
+
+ /*
+ * ``The result of converting a zero value with an
+ * explicit precision of zero is no characters.''
+ * -- ANSI X3J11
+ */
+ cp = buf + BUF;
+ if (_uquad != 0 || prec != 0) {
+ /*
+ * Unsigned mod is hard, and unsigned mod
+ * by a constant is easier than that by
+ * a variable; hence this switch.
+ */
+ switch (base) {
+ case OCT:
+ do {
+ *--cp = to_char (_uquad & 7);
+ _uquad >>= 3;
+ } while (_uquad);
+ /* handle octal leading 0 */
+ if (flags & ALT && *cp != L'0')
+ *--cp = L'0';
+ break;
+
+ case DEC:
+ /* many numbers are 1 digit */
+ while (_uquad >= 10) {
+ *--cp = to_char (_uquad % 10);
+ _uquad /= 10;
+ }
+ *--cp = to_char (_uquad);
+ break;
+
+ case HEX:
+ do {
+ *--cp = xdigs[_uquad & 15];
+ _uquad >>= 4;
+ } while (_uquad);
+ break;
+
+ default:
+ cp = L"bug in vfprintf: bad base";
+ size = wcslen (cp);
+ goto skipsize;
+ }
+ }
+ /*
+ * ...result is to be converted to an 'alternate form'.
+ * For o conversion, it increases the precision to force
+ * the first digit of the result to be a zero."
+ * -- ANSI X3J11
+ *
+ * To demonstrate this case, compile and run:
+ * printf ("%#.0o",0);
+ */
+ else if (base == OCT && (flags & ALT))
+ *--cp = L'0';
+
+ size = buf + BUF - cp;
+ skipsize:
+ break;
+ default: /* "%?" prints ?, unless ? is NUL */
+ if (ch == L'\0')
+ goto done;
+ /* pretend it was %c with argument ch */
+ cp = buf;
+ *cp = ch;
+ size = 1;
+ sign = L'\0';
+ break;
+ }
+
+ /*
+ * All reasonable formats wind up here. At this point, `cp'
+ * points to a string which (if not flags&LADJUST) should be
+ * padded out to `width' places. If flags&ZEROPAD, it should
+ * first be prefixed by any sign or other prefix; otherwise,
+ * it should be blank padded before the prefix is emitted.
+ * After any left-hand padding and prefixing, emit zeroes
+ * required by a decimal [diouxX] precision, then print the
+ * string proper, then emit zeroes required by any leftover
+ * floating precision; finally, if LADJUST, pad with blanks.
+ * If flags&FPT, ch must be in [aAeEfg].
+ *
+ * Compute actual size, so we know how much to pad.
+ * size excludes decimal prec; realsz includes it.
+ */
+ realsz = dprec > size ? dprec : size;
+ if (sign)
+ realsz++;
+ if (flags & HEXPREFIX)
+ realsz+= 2;
+
+ /* right-adjusting blank padding */
+ if ((flags & (LADJUST|ZEROPAD)) == 0)
+ PAD (width - realsz, blanks);
+
+ /* prefix */
+ if (sign)
+ PRINT (&sign, 1);
+ if (flags & HEXPREFIX)
+ PRINT (ox, 2);
+
+ /* right-adjusting zero padding */
+ if ((flags & (LADJUST|ZEROPAD)) == ZEROPAD)
+ PAD (width - realsz, zeroes);
+
+ /* leading zeroes from decimal precision */
+ PAD (dprec - size, zeroes);
+
+ /* the string or number proper */
+#ifdef FLOATING_POINT
+ if ((flags & FPT) == 0) {
+ PRINT (cp, size);
+ } else { /* glue together f_p fragments */
+ if (ch >= L'f') { /* 'f' or 'g' */
+ if (_fpvalue == 0) {
+ /* kludge for __dtoa irregularity */
+ PRINT (L"0", 1);
+ if (expt < ndig || flags & ALT) {
+ PRINT (&decimal_point, 1);
+ PAD (ndig - 1, zeroes);
+ }
+ } else if (expt <= 0) {
+ PRINT (L"0", 1);
+ if (expt || ndig || flags & ALT) {
+ PRINT (&decimal_point, 1);
+ PAD (-expt, zeroes);
+ PRINT (cp, ndig);
+ }
+ } else if (expt >= ndig) {
+ PRINT (cp, ndig);
+ PAD (expt - ndig, zeroes);
+ if (flags & ALT)
+ PRINT (&decimal_point, 1);
+ } else {
+ PRINT (cp, expt);
+ cp += expt;
+ PRINT (&decimal_point, 1);
+ PRINT (cp, ndig - expt);
+ }
+ } else { /* 'a', 'A', 'e', or 'E' */
+ if (ndig > 1 || flags & ALT) {
+ PRINT (cp, 1);
+ cp++;
+ PRINT (&decimal_point, 1);
+ if (_fpvalue) {
+ PRINT (cp, ndig - 1);
+ } else /* 0.[0..] */
+ /* __dtoa irregularity */
+ PAD (ndig - 1, zeroes);
+ } else /* XeYYY */
+ PRINT (cp, 1);
+ PRINT (expstr, expsize);
+ }
+ }
+#else /* !FLOATING_POINT */
+ PRINT (cp, size);
+#endif
+ /* left-adjusting padding (always blank) */
+ if (flags & LADJUST)
+ PAD (width - realsz, blanks);
+
+ /* finally, adjust ret */
+ ret += width > realsz ? width : realsz;
+
+ FLUSH (); /* copy out the I/O vectors */
+
+ if (malloc_buf != NULL) {
+ _free_r (data, malloc_buf);
+ malloc_buf = NULL;
+ }
+ }
+done:
+ FLUSH ();
+error:
+ if (malloc_buf != NULL)
+ _free_r (data, malloc_buf);
+#ifndef STRING_ONLY
+ _funlockfile (fp);
+#endif
+ return (__sferror (fp) ? EOF : ret);
+ /* NOTREACHED */
+}
+
+#ifdef FLOATING_POINT
+
+/* Using reentrant DATA, convert finite VALUE into a string of digits
+ with no decimal point, using NDIGITS precision and FLAGS as guides
+ to whether trailing zeros must be included. Set *SIGN to nonzero
+ if VALUE was negative. Set *DECPT to the exponent plus one. Set
+ *LENGTH to the length of the returned string. CH must be one of
+ [aAeEfFgG]; if it is [aA], then the return string lives in BUF,
+ otherwise the return value shares the mprec reentrant storage. */
+static wchar_t *
+wcvt(struct _reent *data, _PRINTF_FLOAT_TYPE value, int ndigits, int flags,
+ wchar_t *sign, int *decpt, int ch, int *length, wchar_t *buf)
+{
+ int mode, dsgn;
+# ifdef _NO_LONGDBL
+ union double_union tmp;
+
+ tmp.d = value;
+ if (word0 (tmp) & Sign_bit) { /* this will check for < 0 and -0.0 */
+ value = -value;
+ *sign = L'-';
+ } else
+ *sign = L'\0';
+# else /* !_NO_LONGDBL */
+ union
+ {
+ struct ldieee ieee;
+ _LONG_DOUBLE val;
+ } ld;
+
+ ld.val = value;
+ if (ld.ieee.sign) { /* this will check for < 0 and -0.0 */
+ value = -value;
+ *sign = L'-';
+ } else
+ *sign = L'\0';
+# endif /* !_NO_LONGDBL */
+
+# ifdef _WANT_IO_C99_FORMATS
+ if (ch == L'a' || ch == L'A') {
+ wchar_t *digits, *bp, *rve;
+ /* This code assumes FLT_RADIX is a power of 2. The initial
+ division ensures the digit before the decimal will be less
+ than FLT_RADIX (unless it is rounded later). There is no
+ loss of precision in these calculations. */
+ value = FREXP (value, decpt) / 8;
+ if (!value)
+ *decpt = 1;
+ digits = ch == L'a' ? L"0123456789abcdef" : L"0123456789ABCDEF";
+ bp = buf;
+ do {
+ value *= 16;
+ mode = (int) value;
+ value -= mode;
+ *bp++ = digits[mode];
+ } while (ndigits-- && value);
+ if (value > 0.5 || (value == 0.5 && mode & 1)) {
+ /* round to even */
+ rve = bp;
+ while (*--rve == digits[0xf]) {
+ *rve = L'0';
+ }
+ *rve = *rve == L'9' ? digits[0xa] : *rve + 1;
+ } else {
+ while (ndigits-- >= 0) {
+ *bp++ = L'0';
+ }
+ }
+ *length = bp - buf;
+ return buf;
+ }
+# endif /* _WANT_IO_C99_FORMATS */
+ if (ch == L'f' || ch == L'F') {
+ mode = 3; /* ndigits after the decimal point */
+ } else {
+ /* To obtain ndigits after the decimal point for the 'e'
+ * and 'E' formats, round to ndigits + 1 significant
+ * figures.
+ */
+ if (ch == L'e' || ch == L'E') {
+ ndigits++;
+ }
+ mode = 2; /* ndigits significant digits */
+ }
+
+ {
+ char *digits, *bp, *rve;
+#ifndef _MB_CAPABLE
+ int i;
+#endif
+
+ digits = _DTOA_R (data, value, mode, ndigits, decpt, &dsgn, &rve);
+
+ if ((ch != L'g' && ch != L'G') || flags & ALT) { /* Print trailing zeros */
+ bp = digits + ndigits;
+ if (ch == L'f' || ch == L'F') {
+ if (*digits == L'0' && value)
+ *decpt = -ndigits + 1;
+ bp += *decpt;
+ }
+ if (value == 0) /* kludge for __dtoa irregularity */
+ rve = bp;
+ while (rve < bp)
+ *rve++ = '0';
+ }
+#ifdef _MB_CAPABLE
+ *length = _mbsnrtowcs_r (data, buf, (const char **) &digits,
+ rve - digits, BUF, NULL);
+#else
+ *length = rve - digits;
+ for (i = 0; i < *length && i < BUF; ++i)
+ buf[i] = (wchar_t) digits[i];
+#endif
+ return buf;
+ }
+}
+
+static int
+wexponent(wchar_t *p0, int exp, int fmtch)
+{
+ register wchar_t *p, *t;
+ wchar_t expbuf[MAXEXPLEN];
+# ifdef _WANT_IO_C99_FORMATS
+ int isa = fmtch == L'a' || fmtch == L'A';
+# else
+# define isa 0
+# endif
+
+ p = p0;
+ *p++ = isa ? L'p' - L'a' + fmtch : fmtch;
+ if (exp < 0) {
+ exp = -exp;
+ *p++ = L'-';
+ }
+ else
+ *p++ = L'+';
+ t = expbuf + MAXEXPLEN;
+ if (exp > 9) {
+ do {
+ *--t = to_char (exp % 10);
+ } while ((exp /= 10) > 9);
+ *--t = to_char (exp);
+ for (; t < expbuf + MAXEXPLEN; *p++ = *t++);
+ }
+ else {
+ if (!isa)
+ *p++ = L'0';
+ *p++ = to_char (exp);
+ }
+ return (p - p0);
+}
+#endif /* FLOATING_POINT */
+
+
+#ifndef _NO_POS_ARGS
+
+/* Positional argument support.
+ Written by Jeff Johnston
+
+ Copyright (c) 2002 Red Hat Incorporated.
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ 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.
+
+ The name of Red Hat Incorporated may not be used to endorse
+ or promote products derived from this software without specific
+ prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 RED HAT INCORPORATED 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 to get positional parameter N where n = N - 1 */
+static union arg_val *
+_DEFUN(get_arg, (data, n, fmt, ap, numargs_p, args, arg_type, last_fmt),
+ struct _reent *data _AND
+ int n _AND
+ wchar_t *fmt _AND
+ va_list *ap _AND
+ int *numargs_p _AND
+ union arg_val *args _AND
+ int *arg_type _AND
+ wchar_t **last_fmt)
+{
+ wchar_t ch;
+ int number, flags;
+ int spec_type;
+ int numargs = *numargs_p;
+ __CH_CLASS chtype;
+ __STATE state, next_state;
+ __ACTION action;
+ int pos, last_arg;
+ int max_pos_arg = n;
+ /* Only need types that can be reached via vararg promotions. */
+ enum types { INT, LONG_INT, QUAD_INT, CHAR_PTR, DOUBLE, LONG_DOUBLE, WIDE_CHAR };
+
+ /* if this isn't the first call, pick up where we left off last time */
+ if (*last_fmt != NULL)
+ fmt = *last_fmt;
+
+ /* we need to process either to end of fmt string or until we have actually
+ read the desired parameter from the vararg list. */
+ while (*fmt && n >= numargs)
+ {
+ while (*fmt != L'\0' && *fmt != L'%')
+ fmt += 1;
+
+ if (*fmt == L'\0')
+ break;
+ state = START;
+ flags = 0;
+ pos = -1;
+ number = 0;
+ spec_type = INT;
+
+ /* Use state/action table to process format specifiers. We ignore invalid
+ formats and we are only interested in information that tells us how to
+ read the vararg list. */
+ while (state != DONE)
+ {
+ ch = *fmt++;
+ chtype = ch < (wchar_t) 256 ? __chclass[ch] : OTHER;
+ next_state = __state_table[state][chtype];
+ action = __action_table[state][chtype];
+ state = next_state;
+
+ switch (action)
+ {
+ case GETMOD: /* we have format modifier */
+ switch (ch)
+ {
+ case L'h':
+ /* No flag needed, since short and char promote to int. */
+ break;
+ case L'L':
+ flags |= LONGDBL;
+ break;
+ case L'q':
+ flags |= QUADINT;
+ break;
+# ifdef _WANT_IO_C99_FORMATS
+ case L'j':
+ if (sizeof (intmax_t) == sizeof (long))
+ flags |= LONGINT;
+ else
+ flags |= QUADINT;
+ break;
+ case L'z':
+ if (sizeof (size_t) <= sizeof (int))
+ /* no flag needed */;
+ else if (sizeof (size_t) <= sizeof (long))
+ flags |= LONGINT;
+ else
+ /* POSIX states that at least one programming
+ environment must support size_t no wider than
+ long, but that means other environments can
+ have size_t as wide as long long. */
+ flags |= QUADINT;
+ break;
+ case L't':
+ if (sizeof (ptrdiff_t) <= sizeof (int))
+ /* no flag needed */;
+ else if (sizeof (ptrdiff_t) <= sizeof (long))
+ flags |= LONGINT;
+ else
+ /* POSIX states that at least one programming
+ environment must support ptrdiff_t no wider than
+ long, but that means other environments can
+ have ptrdiff_t as wide as long long. */
+ flags |= QUADINT;
+ break;
+# endif /* _WANT_IO_C99_FORMATS */
+ case L'l':
+ default:
+# if defined _WANT_IO_C99_FORMATS || !defined _NO_LONGLONG
+ if (*fmt == L'l')
+ {
+ flags |= QUADINT;
+ ++fmt;
+ }
+ else
+# endif
+ flags |= LONGINT;
+ break;
+ }
+ break;
+ case GETARG: /* we have format specifier */
+ {
+ numargs &= (MAX_POS_ARGS - 1);
+ /* process the specifier and translate it to a type to fetch from varargs */
+ switch (ch)
+ {
+ case L'd':
+ case L'i':
+ case L'o':
+ case L'x':
+ case L'X':
+ case L'u':
+ if (flags & LONGINT)
+ spec_type = LONG_INT;
+# ifndef _NO_LONGLONG
+ else if (flags & QUADINT)
+ spec_type = QUAD_INT;
+# endif
+ else
+ spec_type = INT;
+ break;
+# ifdef _WANT_IO_C99_FORMATS
+ case L'a':
+ case L'A':
+ case L'F':
+# endif
+ case L'f':
+ case L'g':
+ case L'G':
+ case L'E':
+ case L'e':
+# ifndef _NO_LONGDBL
+ if (flags & LONGDBL)
+ spec_type = LONG_DOUBLE;
+ else
+# endif
+ spec_type = DOUBLE;
+ break;
+ case L's':
+# ifdef _WANT_IO_C99_FORMATS
+ case L'S': /* POSIX extension */
+# endif
+ case L'p':
+ case L'n':
+ spec_type = CHAR_PTR;
+ break;
+ case L'c':
+# ifdef _WANT_IO_C99_FORMATS
+ if (flags & LONGINT)
+ spec_type = WIDE_CHAR;
+ else
+# endif
+ spec_type = INT;
+ break;
+# ifdef _WANT_IO_C99_FORMATS
+ case L'C': /* POSIX extension */
+ spec_type = WIDE_CHAR;
+ break;
+# endif
+ }
+
+ /* if we have a positional parameter, just store the type, otherwise
+ fetch the parameter from the vararg list */
+ if (pos != -1)
+ arg_type[pos] = spec_type;
+ else
+ {
+ switch (spec_type)
+ {
+ case LONG_INT:
+ args[numargs++].val_long = va_arg (*ap, long);
+ break;
+ case QUAD_INT:
+ args[numargs++].val_quad_t = va_arg (*ap, quad_t);
+ break;
+ case WIDE_CHAR:
+ args[numargs++].val_wint_t = va_arg (*ap, wint_t);
+ break;
+ case INT:
+ args[numargs++].val_int = va_arg (*ap, int);
+ break;
+ case CHAR_PTR:
+ args[numargs++].val_wchar_ptr_t = va_arg (*ap, wchar_t *);
+ break;
+ case DOUBLE:
+ args[numargs++].val_double = va_arg (*ap, double);
+ break;
+ case LONG_DOUBLE:
+ args[numargs++].val__LONG_DOUBLE = va_arg (*ap, _LONG_DOUBLE);
+ break;
+ }
+ }
+ }
+ break;
+ case GETPOS: /* we have positional specifier */
+ if (arg_type[0] == -1)
+ memset (arg_type, 0, sizeof (int) * MAX_POS_ARGS);
+ pos = number - 1;
+ max_pos_arg = (max_pos_arg > pos ? max_pos_arg : pos);
+ break;
+ case PWPOS: /* we have positional specifier for width or precision */
+ if (arg_type[0] == -1)
+ memset (arg_type, 0, sizeof (int) * MAX_POS_ARGS);
+ number -= 1;
+ arg_type[number] = INT;
+ max_pos_arg = (max_pos_arg > number ? max_pos_arg : number);
+ break;
+ case GETPWB: /* we require format pushback */
+ --fmt;
+ /* fallthrough */
+ case GETPW: /* we have a variable precision or width to acquire */
+ args[numargs++].val_int = va_arg (*ap, int);
+ break;
+ case NUMBER: /* we have a number to process */
+ number = (ch - '0');
+ while ((ch = *fmt) != '\0' && is_digit (ch))
+ {
+ number = number * 10 + (ch - '0');
+ ++fmt;
+ }
+ break;
+ case SKIPNUM: /* we have a number to skip */
+ while ((ch = *fmt) != '\0' && is_digit (ch))
+ ++fmt;
+ break;
+ case NOOP:
+ default:
+ break; /* do nothing */
+ }
+ }
+ }
+
+ /* process all arguments up to at least the one we are looking for and if we
+ have seen the end of the string, then process up to the max argument needed */
+ if (*fmt == '\0')
+ last_arg = max_pos_arg;
+ else
+ last_arg = n;
+
+ while (numargs <= last_arg)
+ {
+ switch (arg_type[numargs])
+ {
+ case LONG_INT:
+ args[numargs++].val_long = va_arg (*ap, long);
+ break;
+ case QUAD_INT:
+ args[numargs++].val_quad_t = va_arg (*ap, quad_t);
+ break;
+ case CHAR_PTR:
+ args[numargs++].val_wchar_ptr_t = va_arg (*ap, wchar_t *);
+ break;
+ case DOUBLE:
+ args[numargs++].val_double = va_arg (*ap, double);
+ break;
+ case LONG_DOUBLE:
+ args[numargs++].val__LONG_DOUBLE = va_arg (*ap, _LONG_DOUBLE);
+ break;
+ case WIDE_CHAR:
+ args[numargs++].val_wint_t = va_arg (*ap, wint_t);
+ break;
+ case INT:
+ default:
+ args[numargs++].val_int = va_arg (*ap, int);
+ break;
+ }
+ }
+
+ /* alter the global numargs value and keep a reference to the last bit of the fmt
+ string we processed here because the caller will continue processing where we started */
+ *numargs_p = numargs;
+ *last_fmt = fmt;
+ return &args[n];
+}
+#endif /* !_NO_POS_ARGS */
vfwprintf.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: vasnprintf.c
===================================================================
--- vasnprintf.c (nonexistent)
+++ vasnprintf.c (revision 520)
@@ -0,0 +1,71 @@
+/* Copyright (C) 2007 Eric Blake
+ * Permission to use, copy, modify, and distribute this software
+ * is freely granted, provided that this notice is preserved.
+ */
+/* This code was derived from asprintf.c */
+/* doc in vfprintf.c */
+
+#include <_ansi.h>
+#include
+#include
+#include
+#include
+#include
+#include "local.h"
+
+char *
+_DEFUN(_vasnprintf_r, (ptr, buf, lenp, fmt, ap),
+ struct _reent *ptr _AND
+ char *buf _AND
+ size_t *lenp _AND
+ const char *fmt _AND
+ va_list ap)
+{
+ int ret;
+ FILE f;
+ size_t len = *lenp;
+
+ if (buf && len)
+ {
+ /* mark an existing buffer, but allow allocation of larger string */
+ f._flags = __SWR | __SSTR | __SOPT;
+ }
+ else
+ {
+ /* mark a zero-length reallocatable buffer */
+ f._flags = __SWR | __SSTR | __SMBF;
+ len = 0;
+ buf = NULL;
+ }
+ f._bf._base = f._p = (unsigned char *) buf;
+ /* For now, inherit the 32-bit signed limit of FILE._bf._size.
+ FIXME - it would be nice to rewrite sys/reent.h to support size_t
+ for _size. */
+ if (len > INT_MAX)
+ {
+ ptr->_errno = EOVERFLOW;
+ return NULL;
+ }
+ f._bf._size = f._w = len;
+ f._file = -1; /* No file. */
+ ret = _svfprintf_r (ptr, &f, fmt, ap);
+ if (ret < 0)
+ return NULL;
+ *lenp = ret;
+ *f._p = '\0';
+ return (char *) f._bf._base;
+}
+
+#ifndef _REENT_ONLY
+
+char *
+_DEFUN(vasnprintf, (buf, lenp, fmt, ap),
+ char *buf _AND
+ size_t *lenp _AND
+ const char *fmt _AND
+ va_list ap)
+{
+ return _vasnprintf_r (_REENT, buf, lenp, fmt, ap);
+}
+
+#endif /* ! _REENT_ONLY */
vasnprintf.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: vdprintf.c
===================================================================
--- vdprintf.c (nonexistent)
+++ vdprintf.c (revision 520)
@@ -0,0 +1,47 @@
+/* Copyright 2005, 2007 Shaun Jackman
+ * Permission to use, copy, modify, and distribute this software
+ * is freely granted, provided that this notice is preserved.
+ */
+/* doc in dprintf.c */
+
+#include <_ansi.h>
+#include
+#include
+#include
+#include
+#include
+#include "local.h"
+
+int
+_DEFUN(_vdprintf_r, (ptr, fd, format, ap),
+ struct _reent *ptr _AND
+ int fd _AND
+ const char *format _AND
+ va_list ap)
+{
+ char *p;
+ char buf[512];
+ size_t n = sizeof buf;
+
+ _REENT_SMALL_CHECK_INIT (ptr);
+ p = _vasnprintf_r (ptr, buf, &n, format, ap);
+ if (!p)
+ return -1;
+ n = _write_r (ptr, fd, p, n);
+ if (p != buf)
+ _free_r (ptr, p);
+ return n;
+}
+
+#ifndef _REENT_ONLY
+
+int
+_DEFUN(vdprintf, (fd, format, ap),
+ int fd _AND
+ const char *format _AND
+ va_list ap)
+{
+ return _vdprintf_r (_REENT, fd, format, ap);
+}
+
+#endif /* ! _REENT_ONLY */
vdprintf.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: vfprintf.c
===================================================================
--- vfprintf.c (nonexistent)
+++ vfprintf.c (revision 520)
@@ -0,0 +1,2072 @@
+/*
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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
+<>, <>, <>, <>, <>, <>---format argument list
+
+INDEX
+ vfprintf
+INDEX
+ _vfprintf_r
+INDEX
+ vprintf
+INDEX
+ _vprintf_r
+INDEX
+ vsprintf
+INDEX
+ _vsprintf_r
+INDEX
+ vsnprintf
+INDEX
+ _vsnprintf_r
+INDEX
+ vasprintf
+INDEX
+ _vasprintf_r
+INDEX
+ vasnprintf
+INDEX
+ _vasnprintf_r
+
+ANSI_SYNOPSIS
+ #include
+ #include
+ int vprintf(const char *<[fmt]>, va_list <[list]>);
+ int vfprintf(FILE *<[fp]>, const char *<[fmt]>, va_list <[list]>);
+ int vsprintf(char *<[str]>, const char *<[fmt]>, va_list <[list]>);
+ int vsnprintf(char *<[str]>, size_t <[size]>, const char *<[fmt]>,
+ va_list <[list]>);
+ int vasprintf(char **<[strp]>, const char *<[fmt]>, va_list <[list]>);
+ char *vasnprintf(char *<[str]>, size_t *<[size]>, const char *<[fmt]>,
+ va_list <[list]>);
+
+ int _vprintf_r(struct _reent *<[reent]>, const char *<[fmt]>,
+ va_list <[list]>);
+ int _vfprintf_r(struct _reent *<[reent]>, FILE *<[fp]>,
+ const char *<[fmt]>, va_list <[list]>);
+ int _vsprintf_r(struct _reent *<[reent]>, char *<[str]>,
+ const char *<[fmt]>, va_list <[list]>);
+ int _vasprintf_r(struct _reent *<[reent]>, char **<[str]>,
+ const char *<[fmt]>, va_list <[list]>);
+ int _vsnprintf_r(struct _reent *<[reent]>, char *<[str]>,
+ size_t <[size]>, const char *<[fmt]>, va_list <[list]>);
+ char *_vasnprintf_r(struct _reent *<[reent]>, char *<[str]>,
+ size_t *<[size]>, const char *<[fmt]>, va_list <[list]>);
+
+DESCRIPTION
+<>, <>, <>, <>, <>,
+and <> are (respectively) variants of <>,
+<>, <>, <>, <>, and
+<>. They differ only in allowing their caller to pass the
+variable argument list as a <> object (initialized by
+<>) rather than directly accepting a variable number of
+arguments. The caller is responsible for calling <>.
+
+<<_vprintf_r>>, <<_vfprintf_r>>, <<_vasprintf_r>>, <<_vsprintf_r>>,
+<<_vsnprintf_r>>, and <<_vasnprintf_r>> are reentrant versions of the
+above.
+
+RETURNS
+The return values are consistent with the corresponding functions.
+
+PORTABILITY
+ANSI C requires <>, <>, <>, and
+<>. The remaining functions are newlib extensions.
+
+Supporting OS subroutines required: <>, <>, <>,
+<>, <>, <>, <>.
+*/
+
+#if defined(LIBC_SCCS) && !defined(lint)
+/*static char *sccsid = "from: @(#)vfprintf.c 5.50 (Berkeley) 12/16/92";*/
+static char *rcsid = "$Id$";
+#endif /* LIBC_SCCS and not lint */
+
+/*
+ * Actual printf innards.
+ *
+ * This code is large and complicated...
+ */
+#include
+
+#ifdef INTEGER_ONLY
+# define VFPRINTF vfiprintf
+# ifdef STRING_ONLY
+# define _VFPRINTF_R _svfiprintf_r
+# else
+# define _VFPRINTF_R _vfiprintf_r
+# endif
+#else
+# define VFPRINTF vfprintf
+# ifdef STRING_ONLY
+# define _VFPRINTF_R _svfprintf_r
+# else
+# define _VFPRINTF_R _vfprintf_r
+# endif
+# ifndef NO_FLOATING_POINT
+# define FLOATING_POINT
+# endif
+#endif
+
+#define _NO_POS_ARGS
+#ifdef _WANT_IO_POS_ARGS
+# undef _NO_POS_ARGS
+#endif
+
+#include <_ansi.h>
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include "local.h"
+#include "../stdlib/local.h"
+#include "fvwrite.h"
+#include "vfieeefp.h"
+
+/* Currently a test is made to see if long double processing is warranted.
+ This could be changed in the future should the _ldtoa_r code be
+ preferred over _dtoa_r. */
+#define _NO_LONGDBL
+#if defined _WANT_IO_LONG_DOUBLE && (LDBL_MANT_DIG > DBL_MANT_DIG)
+#undef _NO_LONGDBL
+#endif
+
+#define _NO_LONGLONG
+#if defined _WANT_IO_LONG_LONG \
+ && (defined __GNUC__ || __STDC_VERSION__ >= 199901L)
+# undef _NO_LONGLONG
+#endif
+
+#ifdef STRING_ONLY
+#define __SPRINT __ssprint_r
+#else
+#define __SPRINT __sprint_r
+#endif
+
+/* The __sprint_r/__ssprint_r functions are shared between all versions of
+ vfprintf and vfwprintf. They must only be defined once, which we do in
+ the INTEGER_ONLY versions here. */
+#ifdef STRING_ONLY
+#ifdef INTEGER_ONLY
+int
+_DEFUN(__ssprint_r, (ptr, fp, uio),
+ struct _reent *ptr _AND
+ FILE *fp _AND
+ register struct __suio *uio)
+{
+ register size_t len;
+ register int w;
+ register struct __siov *iov;
+ register _CONST char *p = NULL;
+
+ iov = uio->uio_iov;
+ len = 0;
+
+ if (uio->uio_resid == 0) {
+ uio->uio_iovcnt = 0;
+ return (0);
+ }
+
+ do {
+ while (len == 0) {
+ p = iov->iov_base;
+ len = iov->iov_len;
+ iov++;
+ }
+ w = fp->_w;
+ if (len >= w && fp->_flags & (__SMBF | __SOPT)) {
+ /* must be asprintf family */
+ unsigned char *str;
+ int curpos = (fp->_p - fp->_bf._base);
+ /* Choose a geometric growth factor to avoid
+ * quadratic realloc behavior, but use a rate less
+ * than (1+sqrt(5))/2 to accomodate malloc
+ * overhead. asprintf EXPECTS us to overallocate, so
+ * that it can add a trailing \0 without
+ * reallocating. The new allocation should thus be
+ * max(prev_size*1.5, curpos+len+1). */
+ int newsize = fp->_bf._size * 3 / 2;
+ if (newsize < curpos + len + 1)
+ newsize = curpos + len + 1;
+ if (fp->_flags & __SOPT)
+ {
+ /* asnprintf leaves original buffer alone. */
+ str = (unsigned char *)_malloc_r (ptr, newsize);
+ if (!str)
+ {
+ ptr->_errno = ENOMEM;
+ goto err;
+ }
+ memcpy (str, fp->_bf._base, curpos);
+ fp->_flags = (fp->_flags & ~__SOPT) | __SMBF;
+ }
+ else
+ {
+ str = (unsigned char *)_realloc_r (ptr, fp->_bf._base,
+ newsize);
+ if (!str) {
+ /* Free unneeded buffer. */
+ _free_r (ptr, fp->_bf._base);
+ /* Ensure correct errno, even if free
+ * changed it. */
+ ptr->_errno = ENOMEM;
+ goto err;
+ }
+ }
+ fp->_bf._base = str;
+ fp->_p = str + curpos;
+ fp->_bf._size = newsize;
+ w = len;
+ fp->_w = newsize - curpos;
+ }
+ if (len < w)
+ w = len;
+ (void)memmove ((_PTR) fp->_p, (_PTR) p, (size_t) (w));
+ fp->_w -= w;
+ fp->_p += w;
+ w = len; /* pretend we copied all */
+ p += w;
+ len -= w;
+ } while ((uio->uio_resid -= w) != 0);
+
+ uio->uio_resid = 0;
+ uio->uio_iovcnt = 0;
+ return 0;
+
+err:
+ fp->_flags |= __SERR;
+ uio->uio_resid = 0;
+ uio->uio_iovcnt = 0;
+ return EOF;
+}
+#else /* !INTEGER_ONLY */
+int __ssprint_r (struct _reent *, FILE *, register struct __suio *);
+#endif /* !INTEGER_ONLY */
+
+#else /* !STRING_ONLY */
+#ifdef INTEGER_ONLY
+/*
+ * Flush out all the vectors defined by the given uio,
+ * then reset it so that it can be reused.
+ */
+int
+_DEFUN(__sprint_r, (ptr, fp, uio),
+ struct _reent *ptr _AND
+ FILE *fp _AND
+ register struct __suio *uio)
+{
+ register int err = 0;
+
+ if (uio->uio_resid == 0) {
+ uio->uio_iovcnt = 0;
+ return (0);
+ }
+ if (fp->_flags2 & __SWID) {
+ struct __siov *iov;
+ wchar_t *p;
+ int i, len;
+
+ iov = uio->uio_iov;
+ for (; uio->uio_resid != 0;
+ uio->uio_resid -= len * sizeof (wchar_t), iov++) {
+ p = (wchar_t *) iov->iov_base;
+ len = iov->iov_len / sizeof (wchar_t);
+ for (i = 0; i < len; i++) {
+ if (_fputwc_r (ptr, p[i], fp) == WEOF) {
+ err = -1;
+ goto out;
+ }
+ }
+ }
+ } else
+ err = __sfvwrite_r(ptr, fp, uio);
+out:
+ uio->uio_resid = 0;
+ uio->uio_iovcnt = 0;
+ return (err);
+}
+#else /* !INTEGER_ONLY */
+int __sprint_r (struct _reent *, FILE *, register struct __suio *);
+#endif /* !INTEGER_ONLY */
+
+/*
+ * Helper function for `fprintf to unbuffered unix file': creates a
+ * temporary buffer. We only work on write-only files; this avoids
+ * worries about ungetc buffers and so forth.
+ */
+static int
+_DEFUN(__sbprintf, (rptr, fp, fmt, ap),
+ struct _reent *rptr _AND
+ register FILE *fp _AND
+ _CONST char *fmt _AND
+ va_list ap)
+{
+ int ret;
+ FILE fake;
+ unsigned char buf[BUFSIZ];
+
+ /* copy the important variables */
+ fake._flags = fp->_flags & ~__SNBF;
+ fake._flags2 = fp->_flags2;
+ fake._file = fp->_file;
+ fake._cookie = fp->_cookie;
+ fake._write = fp->_write;
+
+ /* set up the buffer */
+ fake._bf._base = fake._p = buf;
+ fake._bf._size = fake._w = sizeof (buf);
+ fake._lbfsize = 0; /* not actually used, but Just In Case */
+#ifndef __SINGLE_THREAD__
+ __lock_init_recursive (fake._lock);
+#endif
+
+ /* do the work, then copy any error status */
+ ret = _VFPRINTF_R (rptr, &fake, fmt, ap);
+ if (ret >= 0 && _fflush_r (rptr, &fake))
+ ret = EOF;
+ if (fake._flags & __SERR)
+ fp->_flags |= __SERR;
+
+#ifndef __SINGLE_THREAD__
+ __lock_close_recursive (fake._lock);
+#endif
+ return (ret);
+}
+#endif /* !STRING_ONLY */
+
+
+#ifdef FLOATING_POINT
+# include
+# include
+
+/* For %La, an exponent of 15 bits occupies the exponent character, a
+ sign, and up to 5 digits. */
+# define MAXEXPLEN 7
+# define DEFPREC 6
+
+# ifdef _NO_LONGDBL
+
+extern char *_dtoa_r _PARAMS((struct _reent *, double, int,
+ int, int *, int *, char **));
+
+# define _PRINTF_FLOAT_TYPE double
+# define _DTOA_R _dtoa_r
+# define FREXP frexp
+
+# else /* !_NO_LONGDBL */
+
+extern char *_ldtoa_r _PARAMS((struct _reent *, _LONG_DOUBLE, int,
+ int, int *, int *, char **));
+
+extern int _EXFUN(_ldcheck,(_LONG_DOUBLE *));
+
+# define _PRINTF_FLOAT_TYPE _LONG_DOUBLE
+# define _DTOA_R _ldtoa_r
+/* FIXME - frexpl is not yet supported; and cvt infloops if (double)f
+ converts a finite value into infinity. */
+/* # define FREXP frexpl */
+# define FREXP(f,e) ((_LONG_DOUBLE) frexp ((double)f, e))
+# endif /* !_NO_LONGDBL */
+
+static char *cvt(struct _reent *, _PRINTF_FLOAT_TYPE, int, int, char *, int *,
+ int, int *, char *);
+
+static int exponent(char *, int, int);
+
+#endif /* FLOATING_POINT */
+
+/* BUF must be big enough for the maximum %#llo (assuming long long is
+ at most 64 bits, this would be 23 characters), the maximum
+ multibyte character %C, and the maximum default precision of %La
+ (assuming long double is at most 128 bits with 113 bits of
+ mantissa, this would be 29 characters). %e, %f, and %g use
+ reentrant storage shared with mprec. All other formats that use
+ buf get by with fewer characters. Making BUF slightly bigger
+ reduces the need for malloc in %.*a and %S, when large precision or
+ long strings are processed. */
+#define BUF 40
+#if defined _MB_CAPABLE && MB_LEN_MAX > BUF
+# undef BUF
+# define BUF MB_LEN_MAX
+#endif
+
+#ifndef _NO_LONGLONG
+# define quad_t long long
+# define u_quad_t unsigned long long
+#else
+# define quad_t long
+# define u_quad_t unsigned long
+#endif
+
+typedef quad_t * quad_ptr_t;
+typedef _PTR void_ptr_t;
+typedef char * char_ptr_t;
+typedef long * long_ptr_t;
+typedef int * int_ptr_t;
+typedef short * short_ptr_t;
+
+#ifndef _NO_POS_ARGS
+# ifdef NL_ARGMAX
+# define MAX_POS_ARGS NL_ARGMAX
+# else
+# define MAX_POS_ARGS 32
+# endif
+
+union arg_val
+{
+ int val_int;
+ u_int val_u_int;
+ long val_long;
+ u_long val_u_long;
+ float val_float;
+ double val_double;
+ _LONG_DOUBLE val__LONG_DOUBLE;
+ int_ptr_t val_int_ptr_t;
+ short_ptr_t val_short_ptr_t;
+ long_ptr_t val_long_ptr_t;
+ char_ptr_t val_char_ptr_t;
+ quad_ptr_t val_quad_ptr_t;
+ void_ptr_t val_void_ptr_t;
+ quad_t val_quad_t;
+ u_quad_t val_u_quad_t;
+ wint_t val_wint_t;
+};
+
+static union arg_val *
+_EXFUN(get_arg, (struct _reent *data, int n, char *fmt,
+ va_list *ap, int *numargs, union arg_val *args,
+ int *arg_type, char **last_fmt));
+#endif /* !_NO_POS_ARGS */
+
+/*
+ * Macros for converting digits to letters and vice versa
+ */
+#define to_digit(c) ((c) - '0')
+#define is_digit(c) ((unsigned)to_digit (c) <= 9)
+#define to_char(n) ((n) + '0')
+
+/*
+ * Flags used during conversion.
+ */
+#define ALT 0x001 /* alternate form */
+#define HEXPREFIX 0x002 /* add 0x or 0X prefix */
+#define LADJUST 0x004 /* left adjustment */
+#define LONGDBL 0x008 /* long double */
+#define LONGINT 0x010 /* long integer */
+#ifndef _NO_LONGLONG
+# define QUADINT 0x020 /* quad integer */
+#else /* ifdef _NO_LONGLONG, make QUADINT equivalent to LONGINT, so
+ that %lld behaves the same as %ld, not as %d, as expected if:
+ sizeof (long long) = sizeof long > sizeof int */
+# define QUADINT LONGINT
+#endif
+#define SHORTINT 0x040 /* short integer */
+#define ZEROPAD 0x080 /* zero (as opposed to blank) pad */
+#define FPT 0x100 /* Floating point number */
+#ifdef _WANT_IO_C99_FORMATS
+# define CHARINT 0x200 /* char as integer */
+#else /* define as 0, to make SARG and UARG occupy fewer instructions */
+# define CHARINT 0
+#endif
+
+int _EXFUN(_VFPRINTF_R, (struct _reent *, FILE *, _CONST char *, va_list));
+
+#ifndef STRING_ONLY
+int
+_DEFUN(VFPRINTF, (fp, fmt0, ap),
+ FILE * fp _AND
+ _CONST char *fmt0 _AND
+ va_list ap)
+{
+ int result;
+ result = _VFPRINTF_R (_REENT, fp, fmt0, ap);
+ return result;
+}
+#endif /* STRING_ONLY */
+
+int
+_DEFUN(_VFPRINTF_R, (data, fp, fmt0, ap),
+ struct _reent *data _AND
+ FILE * fp _AND
+ _CONST char *fmt0 _AND
+ va_list ap)
+{
+ register char *fmt; /* format string */
+ register int ch; /* character from fmt */
+ register int n, m; /* handy integers (short term usage) */
+ register char *cp; /* handy char pointer (short term usage) */
+ register struct __siov *iovp;/* for PRINT macro */
+ register int flags; /* flags as above */
+ char *fmt_anchor; /* current format spec being processed */
+#ifndef _NO_POS_ARGS
+ int N; /* arg number */
+ int arg_index; /* index into args processed directly */
+ int numargs; /* number of varargs read */
+ char *saved_fmt; /* saved fmt pointer */
+ union arg_val args[MAX_POS_ARGS];
+ int arg_type[MAX_POS_ARGS];
+ int is_pos_arg; /* is current format positional? */
+ int old_is_pos_arg; /* is current format positional? */
+#endif
+ int ret; /* return value accumulator */
+ int width; /* width from format (%8d), or 0 */
+ int prec; /* precision from format (%.3d), or -1 */
+ char sign; /* sign prefix (' ', '+', '-', or \0) */
+#ifdef FLOATING_POINT
+ char *decimal_point = _localeconv_r (data)->decimal_point;
+ size_t decp_len = strlen (decimal_point);
+ char softsign; /* temporary negative sign for floats */
+ union { int i; _PRINTF_FLOAT_TYPE fp; } _double_ = {0};
+# define _fpvalue (_double_.fp)
+ int expt; /* integer value of exponent */
+ int expsize = 0; /* character count for expstr */
+ int ndig = 0; /* actual number of digits returned by cvt */
+ char expstr[MAXEXPLEN]; /* buffer for exponent string */
+#endif /* FLOATING_POINT */
+ u_quad_t _uquad; /* integer arguments %[diouxX] */
+ enum { OCT, DEC, HEX } base;/* base for [diouxX] conversion */
+ int dprec; /* a copy of prec if [diouxX], 0 otherwise */
+ int realsz; /* field size expanded by dprec */
+ int size; /* size of converted field or string */
+ char *xdigs = NULL; /* digits for [xX] conversion */
+#define NIOV 8
+ struct __suio uio; /* output information: summary */
+ struct __siov iov[NIOV];/* ... and individual io vectors */
+ char buf[BUF]; /* space for %c, %S, %[diouxX], %[aA] */
+ char ox[2]; /* space for 0x hex-prefix */
+#ifdef _MB_CAPABLE
+ wchar_t wc;
+ mbstate_t state; /* mbtowc calls from library must not change state */
+#endif
+ char *malloc_buf = NULL;/* handy pointer for malloced buffers */
+
+ /*
+ * Choose PADSIZE to trade efficiency vs. size. If larger printf
+ * fields occur frequently, increase PADSIZE and make the initialisers
+ * below longer.
+ */
+#define PADSIZE 16 /* pad chunk size */
+ static _CONST char blanks[PADSIZE] =
+ {' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '};
+ static _CONST char zeroes[PADSIZE] =
+ {'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'};
+
+#ifdef _MB_CAPABLE
+ memset (&state, '\0', sizeof (state));
+#endif
+ /*
+ * BEWARE, these `goto error' on error, and PAD uses `n'.
+ */
+#define PRINT(ptr, len) { \
+ iovp->iov_base = (ptr); \
+ iovp->iov_len = (len); \
+ uio.uio_resid += (len); \
+ iovp++; \
+ if (++uio.uio_iovcnt >= NIOV) { \
+ if (__SPRINT(data, fp, &uio)) \
+ goto error; \
+ iovp = iov; \
+ } \
+}
+#define PAD(howmany, with) { \
+ if ((n = (howmany)) > 0) { \
+ while (n > PADSIZE) { \
+ PRINT (with, PADSIZE); \
+ n -= PADSIZE; \
+ } \
+ PRINT (with, n); \
+ } \
+}
+#define FLUSH() { \
+ if (uio.uio_resid && __SPRINT(data, fp, &uio)) \
+ goto error; \
+ uio.uio_iovcnt = 0; \
+ iovp = iov; \
+}
+
+ /* Macros to support positional arguments */
+#ifndef _NO_POS_ARGS
+# define GET_ARG(n, ap, type) \
+ (is_pos_arg \
+ ? (n < numargs \
+ ? args[n].val_##type \
+ : get_arg (data, n, fmt_anchor, &ap, &numargs, args, \
+ arg_type, &saved_fmt)->val_##type) \
+ : (arg_index++ < numargs \
+ ? args[n].val_##type \
+ : (numargs < MAX_POS_ARGS \
+ ? args[numargs++].val_##type = va_arg (ap, type) \
+ : va_arg (ap, type))))
+#else
+# define GET_ARG(n, ap, type) (va_arg (ap, type))
+#endif
+
+ /*
+ * To extend shorts properly, we need both signed and unsigned
+ * argument extraction methods.
+ */
+#ifndef _NO_LONGLONG
+#define SARG() \
+ (flags&QUADINT ? GET_ARG (N, ap, quad_t) : \
+ flags&LONGINT ? GET_ARG (N, ap, long) : \
+ flags&SHORTINT ? (long)(short)GET_ARG (N, ap, int) : \
+ flags&CHARINT ? (long)(signed char)GET_ARG (N, ap, int) : \
+ (long)GET_ARG (N, ap, int))
+#define UARG() \
+ (flags&QUADINT ? GET_ARG (N, ap, u_quad_t) : \
+ flags&LONGINT ? GET_ARG (N, ap, u_long) : \
+ flags&SHORTINT ? (u_long)(u_short)GET_ARG (N, ap, int) : \
+ flags&CHARINT ? (u_long)(unsigned char)GET_ARG (N, ap, int) : \
+ (u_long)GET_ARG (N, ap, u_int))
+#else
+#define SARG() \
+ (flags&LONGINT ? GET_ARG (N, ap, long) : \
+ flags&SHORTINT ? (long)(short)GET_ARG (N, ap, int) : \
+ flags&CHARINT ? (long)(signed char)GET_ARG (N, ap, int) : \
+ (long)GET_ARG (N, ap, int))
+#define UARG() \
+ (flags&LONGINT ? GET_ARG (N, ap, u_long) : \
+ flags&SHORTINT ? (u_long)(u_short)GET_ARG (N, ap, int) : \
+ flags&CHARINT ? (u_long)(unsigned char)GET_ARG (N, ap, int) : \
+ (u_long)GET_ARG (N, ap, u_int))
+#endif
+
+#ifndef STRING_ONLY
+ /* Initialize std streams if not dealing with sprintf family. */
+ CHECK_INIT (data, fp);
+ _flockfile (fp);
+
+ ORIENT(fp, -1);
+
+ /* sorry, fprintf(read_only_file, "") returns EOF, not 0 */
+ if (cantwrite (data, fp)) {
+ _funlockfile (fp);
+ return (EOF);
+ }
+
+ /* optimise fprintf(stderr) (and other unbuffered Unix files) */
+ if ((fp->_flags & (__SNBF|__SWR|__SRW)) == (__SNBF|__SWR) &&
+ fp->_file >= 0) {
+ _funlockfile (fp);
+ return (__sbprintf (data, fp, fmt0, ap));
+ }
+#else /* STRING_ONLY */
+ /* Create initial buffer if we are called by asprintf family. */
+ if (fp->_flags & __SMBF && !fp->_bf._base)
+ {
+ fp->_bf._base = fp->_p = _malloc_r (data, 64);
+ if (!fp->_p)
+ {
+ data->_errno = ENOMEM;
+ return EOF;
+ }
+ fp->_bf._size = 64;
+ }
+#endif /* STRING_ONLY */
+
+ fmt = (char *)fmt0;
+ uio.uio_iov = iovp = iov;
+ uio.uio_resid = 0;
+ uio.uio_iovcnt = 0;
+ ret = 0;
+#ifndef _NO_POS_ARGS
+ arg_index = 0;
+ saved_fmt = NULL;
+ arg_type[0] = -1;
+ numargs = 0;
+ is_pos_arg = 0;
+#endif
+
+ /*
+ * Scan the format for conversions (`%' character).
+ */
+ for (;;) {
+ cp = fmt;
+#ifdef _MB_CAPABLE
+ while ((n = __mbtowc (data, &wc, fmt, MB_CUR_MAX,
+ __locale_charset (), &state)) > 0) {
+ if (wc == '%')
+ break;
+ fmt += n;
+ }
+#else
+ while (*fmt != '\0' && *fmt != '%')
+ fmt += 1;
+#endif
+ if ((m = fmt - cp) != 0) {
+ PRINT (cp, m);
+ ret += m;
+ }
+#ifdef _MB_CAPABLE
+ if (n <= 0)
+ goto done;
+#else
+ if (*fmt == '\0')
+ goto done;
+#endif
+ fmt_anchor = fmt;
+ fmt++; /* skip over '%' */
+
+ flags = 0;
+ dprec = 0;
+ width = 0;
+ prec = -1;
+ sign = '\0';
+#ifndef _NO_POS_ARGS
+ N = arg_index;
+ is_pos_arg = 0;
+#endif
+
+rflag: ch = *fmt++;
+reswitch: switch (ch) {
+#ifdef _WANT_IO_C99_FORMATS
+ case '\'':
+ /* The ' flag is required by POSIX, but not C99.
+ In the C locale, LC_NUMERIC requires
+ thousands_sep to be the empty string. And since
+ no other locales are supported (yet), this flag
+ is currently a no-op. */
+ goto rflag;
+#endif
+ case ' ':
+ /*
+ * ``If the space and + flags both appear, the space
+ * flag will be ignored.''
+ * -- ANSI X3J11
+ */
+ if (!sign)
+ sign = ' ';
+ goto rflag;
+ case '#':
+ flags |= ALT;
+ goto rflag;
+ case '*':
+#ifndef _NO_POS_ARGS
+ /* we must check for positional arg used for dynamic width */
+ n = N;
+ old_is_pos_arg = is_pos_arg;
+ is_pos_arg = 0;
+ if (is_digit (*fmt)) {
+ char *old_fmt = fmt;
+
+ n = 0;
+ ch = *fmt++;
+ do {
+ n = 10 * n + to_digit (ch);
+ ch = *fmt++;
+ } while (is_digit (ch));
+
+ if (ch == '$') {
+ if (n <= MAX_POS_ARGS) {
+ n -= 1;
+ is_pos_arg = 1;
+ }
+ else
+ goto error;
+ }
+ else {
+ fmt = old_fmt;
+ goto rflag;
+ }
+ }
+#endif /* !_NO_POS_ARGS */
+
+ /*
+ * ``A negative field width argument is taken as a
+ * - flag followed by a positive field width.''
+ * -- ANSI X3J11
+ * They don't exclude field widths read from args.
+ */
+ width = GET_ARG (n, ap, int);
+#ifndef _NO_POS_ARGS
+ is_pos_arg = old_is_pos_arg;
+#endif
+ if (width >= 0)
+ goto rflag;
+ width = -width;
+ /* FALLTHROUGH */
+ case '-':
+ flags |= LADJUST;
+ goto rflag;
+ case '+':
+ sign = '+';
+ goto rflag;
+ case '.':
+ if ((ch = *fmt++) == '*') {
+#ifndef _NO_POS_ARGS
+ /* we must check for positional arg used for dynamic width */
+ n = N;
+ old_is_pos_arg = is_pos_arg;
+ is_pos_arg = 0;
+ if (is_digit (*fmt)) {
+ char *old_fmt = fmt;
+
+ n = 0;
+ ch = *fmt++;
+ do {
+ n = 10 * n + to_digit (ch);
+ ch = *fmt++;
+ } while (is_digit (ch));
+
+ if (ch == '$') {
+ if (n <= MAX_POS_ARGS) {
+ n -= 1;
+ is_pos_arg = 1;
+ }
+ else
+ goto error;
+ }
+ else {
+ fmt = old_fmt;
+ goto rflag;
+ }
+ }
+#endif /* !_NO_POS_ARGS */
+ prec = GET_ARG (n, ap, int);
+#ifndef _NO_POS_ARGS
+ is_pos_arg = old_is_pos_arg;
+#endif
+ if (prec < 0)
+ prec = -1;
+ goto rflag;
+ }
+ n = 0;
+ while (is_digit (ch)) {
+ n = 10 * n + to_digit (ch);
+ ch = *fmt++;
+ }
+ prec = n < 0 ? -1 : n;
+ goto reswitch;
+ case '0':
+ /*
+ * ``Note that 0 is taken as a flag, not as the
+ * beginning of a field width.''
+ * -- ANSI X3J11
+ */
+ flags |= ZEROPAD;
+ goto rflag;
+ case '1': case '2': case '3': case '4':
+ case '5': case '6': case '7': case '8': case '9':
+ n = 0;
+ do {
+ n = 10 * n + to_digit (ch);
+ ch = *fmt++;
+ } while (is_digit (ch));
+#ifndef _NO_POS_ARGS
+ if (ch == '$') {
+ if (n <= MAX_POS_ARGS) {
+ N = n - 1;
+ is_pos_arg = 1;
+ goto rflag;
+ }
+ else
+ goto error;
+ }
+#endif /* !_NO_POS_ARGS */
+ width = n;
+ goto reswitch;
+#ifdef FLOATING_POINT
+ case 'L':
+ flags |= LONGDBL;
+ goto rflag;
+#endif
+ case 'h':
+#ifdef _WANT_IO_C99_FORMATS
+ if (*fmt == 'h') {
+ fmt++;
+ flags |= CHARINT;
+ } else
+#endif
+ flags |= SHORTINT;
+ goto rflag;
+ case 'l':
+#if defined _WANT_IO_C99_FORMATS || !defined _NO_LONGLONG
+ if (*fmt == 'l') {
+ fmt++;
+ flags |= QUADINT;
+ } else
+#endif
+ flags |= LONGINT;
+ goto rflag;
+ case 'q': /* extension */
+ flags |= QUADINT;
+ goto rflag;
+#ifdef _WANT_IO_C99_FORMATS
+ case 'j':
+ if (sizeof (intmax_t) == sizeof (long))
+ flags |= LONGINT;
+ else
+ flags |= QUADINT;
+ goto rflag;
+ case 'z':
+ if (sizeof (size_t) < sizeof (int))
+ /* POSIX states size_t is 16 or more bits, as is short. */
+ flags |= SHORTINT;
+ else if (sizeof (size_t) == sizeof (int))
+ /* no flag needed */;
+ else if (sizeof (size_t) <= sizeof (long))
+ flags |= LONGINT;
+ else
+ /* POSIX states that at least one programming
+ environment must support size_t no wider than
+ long, but that means other environments can
+ have size_t as wide as long long. */
+ flags |= QUADINT;
+ goto rflag;
+ case 't':
+ if (sizeof (ptrdiff_t) < sizeof (int))
+ /* POSIX states ptrdiff_t is 16 or more bits, as
+ is short. */
+ flags |= SHORTINT;
+ else if (sizeof (ptrdiff_t) == sizeof (int))
+ /* no flag needed */;
+ else if (sizeof (ptrdiff_t) <= sizeof (long))
+ flags |= LONGINT;
+ else
+ /* POSIX states that at least one programming
+ environment must support ptrdiff_t no wider than
+ long, but that means other environments can
+ have ptrdiff_t as wide as long long. */
+ flags |= QUADINT;
+ goto rflag;
+ case 'C':
+#endif /* _WANT_IO_C99_FORMATS */
+ case 'c':
+ cp = buf;
+#ifdef _MB_CAPABLE
+ if (ch == 'C' || (flags & LONGINT)) {
+ mbstate_t ps;
+
+ memset ((_PTR)&ps, '\0', sizeof (mbstate_t));
+ if ((size = (int)_wcrtomb_r (data, cp,
+ (wchar_t)GET_ARG (N, ap, wint_t),
+ &ps)) == -1) {
+ fp->_flags |= __SERR;
+ goto error;
+ }
+ }
+ else
+#endif /* _MB_CAPABLE */
+ {
+ *cp = GET_ARG (N, ap, int);
+ size = 1;
+ }
+ sign = '\0';
+ break;
+ case 'D': /* extension */
+ flags |= LONGINT;
+ /*FALLTHROUGH*/
+ case 'd':
+ case 'i':
+ _uquad = SARG ();
+#ifndef _NO_LONGLONG
+ if ((quad_t)_uquad < 0)
+#else
+ if ((long) _uquad < 0)
+#endif
+ {
+
+ _uquad = -_uquad;
+ sign = '-';
+ }
+ base = DEC;
+ goto number;
+#ifdef FLOATING_POINT
+# ifdef _WANT_IO_C99_FORMATS
+ case 'a':
+ case 'A':
+ case 'F':
+# endif
+ case 'e':
+ case 'E':
+ case 'f':
+ case 'g':
+ case 'G':
+# ifdef _NO_LONGDBL
+ if (flags & LONGDBL) {
+ _fpvalue = (double) GET_ARG (N, ap, _LONG_DOUBLE);
+ } else {
+ _fpvalue = GET_ARG (N, ap, double);
+ }
+
+ /* do this before tricky precision changes
+
+ If the output is infinite or NaN, leading
+ zeros are not permitted. Otherwise, scanf
+ could not read what printf wrote.
+ */
+ if (isinf (_fpvalue)) {
+ if (_fpvalue < 0)
+ sign = '-';
+ if (ch <= 'G') /* 'A', 'E', 'F', or 'G' */
+ cp = "INF";
+ else
+ cp = "inf";
+ size = 3;
+ flags &= ~ZEROPAD;
+ break;
+ }
+ if (isnan (_fpvalue)) {
+ if (ch <= 'G') /* 'A', 'E', 'F', or 'G' */
+ cp = "NAN";
+ else
+ cp = "nan";
+ size = 3;
+ flags &= ~ZEROPAD;
+ break;
+ }
+
+# else /* !_NO_LONGDBL */
+
+ if (flags & LONGDBL) {
+ _fpvalue = GET_ARG (N, ap, _LONG_DOUBLE);
+ } else {
+ _fpvalue = (_LONG_DOUBLE)GET_ARG (N, ap, double);
+ }
+
+ /* do this before tricky precision changes */
+ expt = _ldcheck (&_fpvalue);
+ if (expt == 2) {
+ if (_fpvalue < 0)
+ sign = '-';
+ if (ch <= 'G') /* 'A', 'E', 'F', or 'G' */
+ cp = "INF";
+ else
+ cp = "inf";
+ size = 3;
+ flags &= ~ZEROPAD;
+ break;
+ }
+ if (expt == 1) {
+ if (ch <= 'G') /* 'A', 'E', 'F', or 'G' */
+ cp = "NAN";
+ else
+ cp = "nan";
+ size = 3;
+ flags &= ~ZEROPAD;
+ break;
+ }
+# endif /* !_NO_LONGDBL */
+
+# ifdef _WANT_IO_C99_FORMATS
+ if (ch == 'a' || ch == 'A') {
+ ox[0] = '0';
+ ox[1] = ch == 'a' ? 'x' : 'X';
+ flags |= HEXPREFIX;
+ if (prec >= BUF)
+ {
+ if ((malloc_buf =
+ (char *)_malloc_r (data, prec + 1))
+ == NULL)
+ {
+ fp->_flags |= __SERR;
+ goto error;
+ }
+ cp = malloc_buf;
+ }
+ else
+ cp = buf;
+ } else
+# endif /* _WANT_IO_C99_FORMATS */
+ if (prec == -1) {
+ prec = DEFPREC;
+ } else if ((ch == 'g' || ch == 'G') && prec == 0) {
+ prec = 1;
+ }
+
+ flags |= FPT;
+
+ cp = cvt (data, _fpvalue, prec, flags, &softsign,
+ &expt, ch, &ndig, cp);
+
+ if (ch == 'g' || ch == 'G') {
+ if (expt <= -4 || expt > prec)
+ ch -= 2; /* 'e' or 'E' */
+ else
+ ch = 'g';
+ }
+# ifdef _WANT_IO_C99_FORMATS
+ else if (ch == 'F')
+ ch = 'f';
+# endif
+ if (ch <= 'e') { /* 'a', 'A', 'e', or 'E' fmt */
+ --expt;
+ expsize = exponent (expstr, expt, ch);
+ size = expsize + ndig;
+ if (ndig > 1 || flags & ALT)
+ ++size;
+ } else if (ch == 'f') { /* f fmt */
+ if (expt > 0) {
+ size = expt;
+ if (prec || flags & ALT)
+ size += prec + 1;
+ } else /* "0.X" */
+ size = (prec || flags & ALT)
+ ? prec + 2
+ : 1;
+ } else if (expt >= ndig) { /* fixed g fmt */
+ size = expt;
+ if (flags & ALT)
+ ++size;
+ } else
+ size = ndig + (expt > 0 ?
+ 1 : 2 - expt);
+
+ if (softsign)
+ sign = '-';
+ break;
+#endif /* FLOATING_POINT */
+ case 'n':
+#ifndef _NO_LONGLONG
+ if (flags & QUADINT)
+ *GET_ARG (N, ap, quad_ptr_t) = ret;
+ else
+#endif
+ if (flags & LONGINT)
+ *GET_ARG (N, ap, long_ptr_t) = ret;
+ else if (flags & SHORTINT)
+ *GET_ARG (N, ap, short_ptr_t) = ret;
+#ifdef _WANT_IO_C99_FORMATS
+ else if (flags & CHARINT)
+ *GET_ARG (N, ap, char_ptr_t) = ret;
+#endif
+ else
+ *GET_ARG (N, ap, int_ptr_t) = ret;
+ continue; /* no output */
+ case 'O': /* extension */
+ flags |= LONGINT;
+ /*FALLTHROUGH*/
+ case 'o':
+ _uquad = UARG ();
+ base = OCT;
+ goto nosign;
+ case 'p':
+ /*
+ * ``The argument shall be a pointer to void. The
+ * value of the pointer is converted to a sequence
+ * of printable characters, in an implementation-
+ * defined manner.''
+ * -- ANSI X3J11
+ */
+ /* NOSTRICT */
+ _uquad = (uintptr_t) GET_ARG (N, ap, void_ptr_t);
+ base = HEX;
+ xdigs = "0123456789abcdef";
+ flags |= HEXPREFIX;
+ ox[0] = '0';
+ ox[1] = ch = 'x';
+ goto nosign;
+ case 's':
+#ifdef _WANT_IO_C99_FORMATS
+ case 'S':
+#endif
+ sign = '\0';
+ cp = GET_ARG (N, ap, char_ptr_t);
+#ifndef __OPTIMIZE_SIZE__
+ /* Behavior is undefined if the user passed a
+ NULL string when precision is not 0.
+ However, if we are not optimizing for size,
+ we might as well mirror glibc behavior. */
+ if (cp == NULL) {
+ cp = "(null)";
+ size = ((unsigned) prec > 6U) ? 6 : prec;
+ }
+ else
+#endif /* __OPTIMIZE_SIZE__ */
+#ifdef _MB_CAPABLE
+ if (ch == 'S' || (flags & LONGINT)) {
+ mbstate_t ps;
+ _CONST wchar_t *wcp;
+
+ wcp = (_CONST wchar_t *)cp;
+ size = m = 0;
+ memset ((_PTR)&ps, '\0', sizeof (mbstate_t));
+
+ /* Count number of bytes needed for multibyte
+ string that will be produced from widechar
+ string. */
+ if (prec >= 0) {
+ while (1) {
+ if (wcp[m] == L'\0')
+ break;
+ if ((n = (int)_wcrtomb_r (data,
+ buf, wcp[m], &ps)) == -1) {
+ fp->_flags |= __SERR;
+ goto error;
+ }
+ if (n + size > prec)
+ break;
+ m += 1;
+ size += n;
+ if (size == prec)
+ break;
+ }
+ }
+ else {
+ if ((size = (int)_wcsrtombs_r (data,
+ NULL, &wcp, 0, &ps)) == -1) {
+ fp->_flags |= __SERR;
+ goto error;
+ }
+ wcp = (_CONST wchar_t *)cp;
+ }
+
+ if (size == 0)
+ break;
+
+ if (size >= BUF) {
+ if ((malloc_buf =
+ (char *)_malloc_r (data, size + 1))
+ == NULL) {
+ fp->_flags |= __SERR;
+ goto error;
+ }
+ cp = malloc_buf;
+ } else
+ cp = buf;
+
+ /* Convert widechar string to multibyte string. */
+ memset ((_PTR)&ps, '\0', sizeof (mbstate_t));
+ if (_wcsrtombs_r (data, cp, &wcp, size, &ps)
+ != size) {
+ fp->_flags |= __SERR;
+ goto error;
+ }
+ cp[size] = '\0';
+ }
+ else
+#endif /* _MB_CAPABLE */
+ if (prec >= 0) {
+ /*
+ * can't use strlen; can only look for the
+ * NUL in the first `prec' characters, and
+ * strlen () will go further.
+ */
+ char *p = memchr (cp, 0, prec);
+
+ if (p != NULL) {
+ size = p - cp;
+ if (size > prec)
+ size = prec;
+ } else
+ size = prec;
+ } else
+ size = strlen (cp);
+
+ break;
+ case 'U': /* extension */
+ flags |= LONGINT;
+ /*FALLTHROUGH*/
+ case 'u':
+ _uquad = UARG ();
+ base = DEC;
+ goto nosign;
+ case 'X':
+ xdigs = "0123456789ABCDEF";
+ goto hex;
+ case 'x':
+ xdigs = "0123456789abcdef";
+hex: _uquad = UARG ();
+ base = HEX;
+ /* leading 0x/X only if non-zero */
+ if (flags & ALT && _uquad != 0) {
+ ox[0] = '0';
+ ox[1] = ch;
+ flags |= HEXPREFIX;
+ }
+
+ /* unsigned conversions */
+nosign: sign = '\0';
+ /*
+ * ``... diouXx conversions ... if a precision is
+ * specified, the 0 flag will be ignored.''
+ * -- ANSI X3J11
+ */
+number: if ((dprec = prec) >= 0)
+ flags &= ~ZEROPAD;
+
+ /*
+ * ``The result of converting a zero value with an
+ * explicit precision of zero is no characters.''
+ * -- ANSI X3J11
+ */
+ cp = buf + BUF;
+ if (_uquad != 0 || prec != 0) {
+ /*
+ * Unsigned mod is hard, and unsigned mod
+ * by a constant is easier than that by
+ * a variable; hence this switch.
+ */
+ switch (base) {
+ case OCT:
+ do {
+ *--cp = to_char (_uquad & 7);
+ _uquad >>= 3;
+ } while (_uquad);
+ /* handle octal leading 0 */
+ if (flags & ALT && *cp != '0')
+ *--cp = '0';
+ break;
+
+ case DEC:
+ /* many numbers are 1 digit */
+ while (_uquad >= 10) {
+ *--cp = to_char (_uquad % 10);
+ _uquad /= 10;
+ }
+ *--cp = to_char (_uquad);
+ break;
+
+ case HEX:
+ do {
+ *--cp = xdigs[_uquad & 15];
+ _uquad >>= 4;
+ } while (_uquad);
+ break;
+
+ default:
+ cp = "bug in vfprintf: bad base";
+ size = strlen (cp);
+ goto skipsize;
+ }
+ }
+ /*
+ * ...result is to be converted to an 'alternate form'.
+ * For o conversion, it increases the precision to force
+ * the first digit of the result to be a zero."
+ * -- ANSI X3J11
+ *
+ * To demonstrate this case, compile and run:
+ * printf ("%#.0o",0);
+ */
+ else if (base == OCT && (flags & ALT))
+ *--cp = '0';
+
+ size = buf + BUF - cp;
+ skipsize:
+ break;
+ default: /* "%?" prints ?, unless ? is NUL */
+ if (ch == '\0')
+ goto done;
+ /* pretend it was %c with argument ch */
+ cp = buf;
+ *cp = ch;
+ size = 1;
+ sign = '\0';
+ break;
+ }
+
+ /*
+ * All reasonable formats wind up here. At this point, `cp'
+ * points to a string which (if not flags&LADJUST) should be
+ * padded out to `width' places. If flags&ZEROPAD, it should
+ * first be prefixed by any sign or other prefix; otherwise,
+ * it should be blank padded before the prefix is emitted.
+ * After any left-hand padding and prefixing, emit zeroes
+ * required by a decimal [diouxX] precision, then print the
+ * string proper, then emit zeroes required by any leftover
+ * floating precision; finally, if LADJUST, pad with blanks.
+ * If flags&FPT, ch must be in [aAeEfg].
+ *
+ * Compute actual size, so we know how much to pad.
+ * size excludes decimal prec; realsz includes it.
+ */
+ realsz = dprec > size ? dprec : size;
+ if (sign)
+ realsz++;
+ if (flags & HEXPREFIX)
+ realsz+= 2;
+
+ /* right-adjusting blank padding */
+ if ((flags & (LADJUST|ZEROPAD)) == 0)
+ PAD (width - realsz, blanks);
+
+ /* prefix */
+ if (sign)
+ PRINT (&sign, 1);
+ if (flags & HEXPREFIX)
+ PRINT (ox, 2);
+
+ /* right-adjusting zero padding */
+ if ((flags & (LADJUST|ZEROPAD)) == ZEROPAD)
+ PAD (width - realsz, zeroes);
+
+ /* leading zeroes from decimal precision */
+ PAD (dprec - size, zeroes);
+
+ /* the string or number proper */
+#ifdef FLOATING_POINT
+ if ((flags & FPT) == 0) {
+ PRINT (cp, size);
+ } else { /* glue together f_p fragments */
+ if (ch >= 'f') { /* 'f' or 'g' */
+ if (_fpvalue == 0) {
+ /* kludge for __dtoa irregularity */
+ PRINT ("0", 1);
+ if (expt < ndig || flags & ALT) {
+ PRINT (decimal_point, decp_len);
+ PAD (ndig - 1, zeroes);
+ }
+ } else if (expt <= 0) {
+ PRINT ("0", 1);
+ if (expt || ndig || flags & ALT) {
+ PRINT (decimal_point, decp_len);
+ PAD (-expt, zeroes);
+ PRINT (cp, ndig);
+ }
+ } else if (expt >= ndig) {
+ PRINT (cp, ndig);
+ PAD (expt - ndig, zeroes);
+ if (flags & ALT)
+ PRINT (decimal_point, decp_len);
+ } else {
+ PRINT (cp, expt);
+ cp += expt;
+ PRINT (decimal_point, decp_len);
+ PRINT (cp, ndig - expt);
+ }
+ } else { /* 'a', 'A', 'e', or 'E' */
+ if (ndig > 1 || flags & ALT) {
+ PRINT (cp, 1);
+ cp++;
+ PRINT (decimal_point, decp_len);
+ if (_fpvalue) {
+ PRINT (cp, ndig - 1);
+ } else /* 0.[0..] */
+ /* __dtoa irregularity */
+ PAD (ndig - 1, zeroes);
+ } else /* XeYYY */
+ PRINT (cp, 1);
+ PRINT (expstr, expsize);
+ }
+ }
+#else /* !FLOATING_POINT */
+ PRINT (cp, size);
+#endif
+ /* left-adjusting padding (always blank) */
+ if (flags & LADJUST)
+ PAD (width - realsz, blanks);
+
+ /* finally, adjust ret */
+ ret += width > realsz ? width : realsz;
+
+ FLUSH (); /* copy out the I/O vectors */
+
+ if (malloc_buf != NULL) {
+ _free_r (data, malloc_buf);
+ malloc_buf = NULL;
+ }
+ }
+done:
+ FLUSH ();
+error:
+ if (malloc_buf != NULL)
+ _free_r (data, malloc_buf);
+#ifndef STRING_ONLY
+ _funlockfile (fp);
+#endif
+ return (__sferror (fp) ? EOF : ret);
+ /* NOTREACHED */
+}
+
+#ifdef FLOATING_POINT
+
+/* Using reentrant DATA, convert finite VALUE into a string of digits
+ with no decimal point, using NDIGITS precision and FLAGS as guides
+ to whether trailing zeros must be included. Set *SIGN to nonzero
+ if VALUE was negative. Set *DECPT to the exponent plus one. Set
+ *LENGTH to the length of the returned string. CH must be one of
+ [aAeEfFgG]; if it is [aA], then the return string lives in BUF,
+ otherwise the return value shares the mprec reentrant storage. */
+static char *
+cvt(struct _reent *data, _PRINTF_FLOAT_TYPE value, int ndigits, int flags,
+ char *sign, int *decpt, int ch, int *length, char *buf)
+{
+ int mode, dsgn;
+ char *digits, *bp, *rve;
+# ifdef _NO_LONGDBL
+ union double_union tmp;
+
+ tmp.d = value;
+ if (word0 (tmp) & Sign_bit) { /* this will check for < 0 and -0.0 */
+ value = -value;
+ *sign = '-';
+ } else
+ *sign = '\000';
+# else /* !_NO_LONGDBL */
+ union
+ {
+ struct ldieee ieee;
+ _LONG_DOUBLE val;
+ } ld;
+
+ ld.val = value;
+ if (ld.ieee.sign) { /* this will check for < 0 and -0.0 */
+ value = -value;
+ *sign = '-';
+ } else
+ *sign = '\000';
+# endif /* !_NO_LONGDBL */
+
+# ifdef _WANT_IO_C99_FORMATS
+ if (ch == 'a' || ch == 'A') {
+ /* This code assumes FLT_RADIX is a power of 2. The initial
+ division ensures the digit before the decimal will be less
+ than FLT_RADIX (unless it is rounded later). There is no
+ loss of precision in these calculations. */
+ value = FREXP (value, decpt) / 8;
+ if (!value)
+ *decpt = 1;
+ digits = ch == 'a' ? "0123456789abcdef" : "0123456789ABCDEF";
+ bp = buf;
+ do {
+ value *= 16;
+ mode = (int) value;
+ value -= mode;
+ *bp++ = digits[mode];
+ } while (ndigits-- && value);
+ if (value > 0.5 || (value == 0.5 && mode & 1)) {
+ /* round to even */
+ rve = bp;
+ while (*--rve == digits[0xf]) {
+ *rve = '0';
+ }
+ *rve = *rve == '9' ? digits[0xa] : *rve + 1;
+ } else {
+ while (ndigits-- >= 0) {
+ *bp++ = '0';
+ }
+ }
+ *length = bp - buf;
+ return buf;
+ }
+# endif /* _WANT_IO_C99_FORMATS */
+ if (ch == 'f' || ch == 'F') {
+ mode = 3; /* ndigits after the decimal point */
+ } else {
+ /* To obtain ndigits after the decimal point for the 'e'
+ * and 'E' formats, round to ndigits + 1 significant
+ * figures.
+ */
+ if (ch == 'e' || ch == 'E') {
+ ndigits++;
+ }
+ mode = 2; /* ndigits significant digits */
+ }
+
+ digits = _DTOA_R (data, value, mode, ndigits, decpt, &dsgn, &rve);
+
+ if ((ch != 'g' && ch != 'G') || flags & ALT) { /* Print trailing zeros */
+ bp = digits + ndigits;
+ if (ch == 'f' || ch == 'F') {
+ if (*digits == '0' && value)
+ *decpt = -ndigits + 1;
+ bp += *decpt;
+ }
+ if (value == 0) /* kludge for __dtoa irregularity */
+ rve = bp;
+ while (rve < bp)
+ *rve++ = '0';
+ }
+ *length = rve - digits;
+ return (digits);
+}
+
+static int
+exponent(char *p0, int exp, int fmtch)
+{
+ register char *p, *t;
+ char expbuf[MAXEXPLEN];
+# ifdef _WANT_IO_C99_FORMATS
+ int isa = fmtch == 'a' || fmtch == 'A';
+# else
+# define isa 0
+# endif
+
+ p = p0;
+ *p++ = isa ? 'p' - 'a' + fmtch : fmtch;
+ if (exp < 0) {
+ exp = -exp;
+ *p++ = '-';
+ }
+ else
+ *p++ = '+';
+ t = expbuf + MAXEXPLEN;
+ if (exp > 9) {
+ do {
+ *--t = to_char (exp % 10);
+ } while ((exp /= 10) > 9);
+ *--t = to_char (exp);
+ for (; t < expbuf + MAXEXPLEN; *p++ = *t++);
+ }
+ else {
+ if (!isa)
+ *p++ = '0';
+ *p++ = to_char (exp);
+ }
+ return (p - p0);
+}
+#endif /* FLOATING_POINT */
+
+
+#ifndef _NO_POS_ARGS
+
+/* Positional argument support.
+ Written by Jeff Johnston
+
+ Copyright (c) 2002 Red Hat Incorporated.
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ 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.
+
+ The name of Red Hat Incorporated may not be used to endorse
+ or promote products derived from this software without specific
+ prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 RED HAT INCORPORATED 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. */
+
+/* The below constant state tables are shared between all versions of
+ vfprintf and vfwprintf. They must only be defined once, which we do in
+ the STRING_ONLY/INTEGER_ONLY versions here. */
+#if defined (STRING_ONLY) && defined(INTEGER_ONLY)
+
+_CONST __CH_CLASS __chclass[256] = {
+ /* 00-07 */ OTHER, OTHER, OTHER, OTHER, OTHER, OTHER, OTHER, OTHER,
+ /* 08-0f */ OTHER, OTHER, OTHER, OTHER, OTHER, OTHER, OTHER, OTHER,
+ /* 10-17 */ OTHER, OTHER, OTHER, OTHER, OTHER, OTHER, OTHER, OTHER,
+ /* 18-1f */ OTHER, OTHER, OTHER, OTHER, OTHER, OTHER, OTHER, OTHER,
+ /* 20-27 */ FLAG, OTHER, OTHER, FLAG, DOLLAR, OTHER, OTHER, FLAG,
+ /* 28-2f */ OTHER, OTHER, STAR, FLAG, OTHER, FLAG, DOT, OTHER,
+ /* 30-37 */ ZERO, DIGIT, DIGIT, DIGIT, DIGIT, DIGIT, DIGIT, DIGIT,
+ /* 38-3f */ DIGIT, DIGIT, OTHER, OTHER, OTHER, OTHER, OTHER, OTHER,
+ /* 40-47 */ OTHER, SPEC, OTHER, SPEC, SPEC, SPEC, SPEC, SPEC,
+ /* 48-4f */ OTHER, OTHER, OTHER, OTHER, MODFR, OTHER, OTHER, SPEC,
+ /* 50-57 */ OTHER, OTHER, OTHER, SPEC, OTHER, SPEC, OTHER, OTHER,
+ /* 58-5f */ SPEC, OTHER, OTHER, OTHER, OTHER, OTHER, OTHER, OTHER,
+ /* 60-67 */ OTHER, SPEC, OTHER, SPEC, SPEC, SPEC, SPEC, SPEC,
+ /* 68-6f */ MODFR, SPEC, MODFR, OTHER, MODFR, OTHER, SPEC, SPEC,
+ /* 70-77 */ SPEC, MODFR, OTHER, SPEC, MODFR, SPEC, OTHER, OTHER,
+ /* 78-7f */ SPEC, OTHER, MODFR, OTHER, OTHER, OTHER, OTHER, OTHER,
+ /* 80-87 */ OTHER, OTHER, OTHER, OTHER, OTHER, OTHER, OTHER, OTHER,
+ /* 88-8f */ OTHER, OTHER, OTHER, OTHER, OTHER, OTHER, OTHER, OTHER,
+ /* 90-97 */ OTHER, OTHER, OTHER, OTHER, OTHER, OTHER, OTHER, OTHER,
+ /* 98-9f */ OTHER, OTHER, OTHER, OTHER, OTHER, OTHER, OTHER, OTHER,
+ /* a0-a7 */ OTHER, OTHER, OTHER, OTHER, OTHER, OTHER, OTHER, OTHER,
+ /* a8-af */ OTHER, OTHER, OTHER, OTHER, OTHER, OTHER, OTHER, OTHER,
+ /* b0-b7 */ OTHER, OTHER, OTHER, OTHER, OTHER, OTHER, OTHER, OTHER,
+ /* b8-bf */ OTHER, OTHER, OTHER, OTHER, OTHER, OTHER, OTHER, OTHER,
+ /* c0-c7 */ OTHER, OTHER, OTHER, OTHER, OTHER, OTHER, OTHER, OTHER,
+ /* c8-cf */ OTHER, OTHER, OTHER, OTHER, OTHER, OTHER, OTHER, OTHER,
+ /* d0-d7 */ OTHER, OTHER, OTHER, OTHER, OTHER, OTHER, OTHER, OTHER,
+ /* d8-df */ OTHER, OTHER, OTHER, OTHER, OTHER, OTHER, OTHER, OTHER,
+ /* e0-e7 */ OTHER, OTHER, OTHER, OTHER, OTHER, OTHER, OTHER, OTHER,
+ /* e8-ef */ OTHER, OTHER, OTHER, OTHER, OTHER, OTHER, OTHER, OTHER,
+ /* f0-f7 */ OTHER, OTHER, OTHER, OTHER, OTHER, OTHER, OTHER, OTHER,
+ /* f8-ff */ OTHER, OTHER, OTHER, OTHER, OTHER, OTHER, OTHER, OTHER,
+};
+
+_CONST __STATE __state_table[MAX_STATE][MAX_CH_CLASS] = {
+ /* '0' '1-9' '$' MODFR SPEC '.' '*' FLAG OTHER */
+ /* START */ { SFLAG, WDIG, DONE, SMOD, DONE, SDOT, VARW, SFLAG, DONE },
+ /* SFLAG */ { SFLAG, WDIG, DONE, SMOD, DONE, SDOT, VARW, SFLAG, DONE },
+ /* WDIG */ { DONE, DONE, WIDTH, SMOD, DONE, SDOT, DONE, DONE, DONE },
+ /* WIDTH */ { DONE, DONE, DONE, SMOD, DONE, SDOT, DONE, DONE, DONE },
+ /* SMOD */ { DONE, DONE, DONE, DONE, DONE, DONE, DONE, DONE, DONE },
+ /* SDOT */ { SDOT, PREC, DONE, SMOD, DONE, DONE, VARP, DONE, DONE },
+ /* VARW */ { DONE, VWDIG, DONE, SMOD, DONE, SDOT, DONE, DONE, DONE },
+ /* VARP */ { DONE, VPDIG, DONE, SMOD, DONE, DONE, DONE, DONE, DONE },
+ /* PREC */ { DONE, DONE, DONE, SMOD, DONE, DONE, DONE, DONE, DONE },
+ /* VWDIG */ { DONE, DONE, WIDTH, DONE, DONE, DONE, DONE, DONE, DONE },
+ /* VPDIG */ { DONE, DONE, PREC, DONE, DONE, DONE, DONE, DONE, DONE },
+};
+
+_CONST __ACTION __action_table[MAX_STATE][MAX_CH_CLASS] = {
+ /* '0' '1-9' '$' MODFR SPEC '.' '*' FLAG OTHER */
+ /* START */ { NOOP, NUMBER, NOOP, GETMOD, GETARG, NOOP, NOOP, NOOP, NOOP },
+ /* SFLAG */ { NOOP, NUMBER, NOOP, GETMOD, GETARG, NOOP, NOOP, NOOP, NOOP },
+ /* WDIG */ { NOOP, NOOP, GETPOS, GETMOD, GETARG, NOOP, NOOP, NOOP, NOOP },
+ /* WIDTH */ { NOOP, NOOP, NOOP, GETMOD, GETARG, NOOP, NOOP, NOOP, NOOP },
+ /* SMOD */ { NOOP, NOOP, NOOP, NOOP, GETARG, NOOP, NOOP, NOOP, NOOP },
+ /* SDOT */ { NOOP, SKIPNUM, NOOP, GETMOD, GETARG, NOOP, NOOP, NOOP, NOOP },
+ /* VARW */ { NOOP, NUMBER, NOOP, GETPW, GETPWB, GETPW, NOOP, NOOP, NOOP },
+ /* VARP */ { NOOP, NUMBER, NOOP, GETPW, GETPWB, NOOP, NOOP, NOOP, NOOP },
+ /* PREC */ { NOOP, NOOP, NOOP, GETMOD, GETARG, NOOP, NOOP, NOOP, NOOP },
+ /* VWDIG */ { NOOP, NOOP, PWPOS, NOOP, NOOP, NOOP, NOOP, NOOP, NOOP },
+ /* VPDIG */ { NOOP, NOOP, PWPOS, NOOP, NOOP, NOOP, NOOP, NOOP, NOOP },
+};
+
+#endif /* STRING_ONLY && INTEGER_ONLY */
+
+/* function to get positional parameter N where n = N - 1 */
+static union arg_val *
+_DEFUN(get_arg, (data, n, fmt, ap, numargs_p, args, arg_type, last_fmt),
+ struct _reent *data _AND
+ int n _AND
+ char *fmt _AND
+ va_list *ap _AND
+ int *numargs_p _AND
+ union arg_val *args _AND
+ int *arg_type _AND
+ char **last_fmt)
+{
+ int ch;
+ int number, flags;
+ int spec_type;
+ int numargs = *numargs_p;
+ __CH_CLASS chtype;
+ __STATE state, next_state;
+ __ACTION action;
+ int pos, last_arg;
+ int max_pos_arg = n;
+ /* Only need types that can be reached via vararg promotions. */
+ enum types { INT, LONG_INT, QUAD_INT, CHAR_PTR, DOUBLE, LONG_DOUBLE, WIDE_CHAR };
+# ifdef _MB_CAPABLE
+ wchar_t wc;
+ mbstate_t wc_state;
+ int nbytes;
+# endif
+
+ /* if this isn't the first call, pick up where we left off last time */
+ if (*last_fmt != NULL)
+ fmt = *last_fmt;
+
+# ifdef _MB_CAPABLE
+ memset (&wc_state, '\0', sizeof (wc_state));
+# endif
+
+ /* we need to process either to end of fmt string or until we have actually
+ read the desired parameter from the vararg list. */
+ while (*fmt && n >= numargs)
+ {
+# ifdef _MB_CAPABLE
+ while ((nbytes = __mbtowc (data, &wc, fmt, MB_CUR_MAX,
+ __locale_charset (), &wc_state)) > 0)
+ {
+ fmt += nbytes;
+ if (wc == '%')
+ break;
+ }
+
+ if (nbytes <= 0)
+ break;
+# else
+ while (*fmt != '\0' && *fmt != '%')
+ fmt += 1;
+
+ if (*fmt == '\0')
+ break;
+# endif /* ! _MB_CAPABLE */
+ state = START;
+ flags = 0;
+ pos = -1;
+ number = 0;
+ spec_type = INT;
+
+ /* Use state/action table to process format specifiers. We ignore invalid
+ formats and we are only interested in information that tells us how to
+ read the vararg list. */
+ while (state != DONE)
+ {
+ ch = *fmt++;
+ chtype = __chclass[ch];
+ next_state = __state_table[state][chtype];
+ action = __action_table[state][chtype];
+ state = next_state;
+
+ switch (action)
+ {
+ case GETMOD: /* we have format modifier */
+ switch (ch)
+ {
+ case 'h':
+ /* No flag needed, since short and char promote to int. */
+ break;
+ case 'L':
+ flags |= LONGDBL;
+ break;
+ case 'q':
+ flags |= QUADINT;
+ break;
+# ifdef _WANT_IO_C99_FORMATS
+ case 'j':
+ if (sizeof (intmax_t) == sizeof (long))
+ flags |= LONGINT;
+ else
+ flags |= QUADINT;
+ break;
+ case 'z':
+ if (sizeof (size_t) <= sizeof (int))
+ /* no flag needed */;
+ else if (sizeof (size_t) <= sizeof (long))
+ flags |= LONGINT;
+ else
+ /* POSIX states that at least one programming
+ environment must support size_t no wider than
+ long, but that means other environments can
+ have size_t as wide as long long. */
+ flags |= QUADINT;
+ break;
+ case 't':
+ if (sizeof (ptrdiff_t) <= sizeof (int))
+ /* no flag needed */;
+ else if (sizeof (ptrdiff_t) <= sizeof (long))
+ flags |= LONGINT;
+ else
+ /* POSIX states that at least one programming
+ environment must support ptrdiff_t no wider than
+ long, but that means other environments can
+ have ptrdiff_t as wide as long long. */
+ flags |= QUADINT;
+ break;
+# endif /* _WANT_IO_C99_FORMATS */
+ case 'l':
+ default:
+# if defined _WANT_IO_C99_FORMATS || !defined _NO_LONGLONG
+ if (*fmt == 'l')
+ {
+ flags |= QUADINT;
+ ++fmt;
+ }
+ else
+# endif
+ flags |= LONGINT;
+ break;
+ }
+ break;
+ case GETARG: /* we have format specifier */
+ {
+ numargs &= (MAX_POS_ARGS - 1);
+ /* process the specifier and translate it to a type to fetch from varargs */
+ switch (ch)
+ {
+ case 'd':
+ case 'i':
+ case 'o':
+ case 'x':
+ case 'X':
+ case 'u':
+ if (flags & LONGINT)
+ spec_type = LONG_INT;
+# ifndef _NO_LONGLONG
+ else if (flags & QUADINT)
+ spec_type = QUAD_INT;
+# endif
+ else
+ spec_type = INT;
+ break;
+ case 'D':
+ case 'U':
+ case 'O':
+ spec_type = LONG_INT;
+ break;
+# ifdef _WANT_IO_C99_FORMATS
+ case 'a':
+ case 'A':
+ case 'F':
+# endif
+ case 'f':
+ case 'g':
+ case 'G':
+ case 'E':
+ case 'e':
+# ifndef _NO_LONGDBL
+ if (flags & LONGDBL)
+ spec_type = LONG_DOUBLE;
+ else
+# endif
+ spec_type = DOUBLE;
+ break;
+ case 's':
+# ifdef _WANT_IO_C99_FORMATS
+ case 'S':
+# endif
+ case 'p':
+ case 'n':
+ spec_type = CHAR_PTR;
+ break;
+ case 'c':
+# ifdef _WANT_IO_C99_FORMATS
+ if (flags & LONGINT)
+ spec_type = WIDE_CHAR;
+ else
+# endif
+ spec_type = INT;
+ break;
+# ifdef _WANT_IO_C99_FORMATS
+ case 'C':
+ spec_type = WIDE_CHAR;
+ break;
+# endif
+ }
+
+ /* if we have a positional parameter, just store the type, otherwise
+ fetch the parameter from the vararg list */
+ if (pos != -1)
+ arg_type[pos] = spec_type;
+ else
+ {
+ switch (spec_type)
+ {
+ case LONG_INT:
+ args[numargs++].val_long = va_arg (*ap, long);
+ break;
+ case QUAD_INT:
+ args[numargs++].val_quad_t = va_arg (*ap, quad_t);
+ break;
+ case WIDE_CHAR:
+ args[numargs++].val_wint_t = va_arg (*ap, wint_t);
+ break;
+ case INT:
+ args[numargs++].val_int = va_arg (*ap, int);
+ break;
+ case CHAR_PTR:
+ args[numargs++].val_char_ptr_t = va_arg (*ap, char *);
+ break;
+ case DOUBLE:
+ args[numargs++].val_double = va_arg (*ap, double);
+ break;
+ case LONG_DOUBLE:
+ args[numargs++].val__LONG_DOUBLE = va_arg (*ap, _LONG_DOUBLE);
+ break;
+ }
+ }
+ }
+ break;
+ case GETPOS: /* we have positional specifier */
+ if (arg_type[0] == -1)
+ memset (arg_type, 0, sizeof (int) * MAX_POS_ARGS);
+ pos = number - 1;
+ max_pos_arg = (max_pos_arg > pos ? max_pos_arg : pos);
+ break;
+ case PWPOS: /* we have positional specifier for width or precision */
+ if (arg_type[0] == -1)
+ memset (arg_type, 0, sizeof (int) * MAX_POS_ARGS);
+ number -= 1;
+ arg_type[number] = INT;
+ max_pos_arg = (max_pos_arg > number ? max_pos_arg : number);
+ break;
+ case GETPWB: /* we require format pushback */
+ --fmt;
+ /* fallthrough */
+ case GETPW: /* we have a variable precision or width to acquire */
+ args[numargs++].val_int = va_arg (*ap, int);
+ break;
+ case NUMBER: /* we have a number to process */
+ number = (ch - '0');
+ while ((ch = *fmt) != '\0' && is_digit (ch))
+ {
+ number = number * 10 + (ch - '0');
+ ++fmt;
+ }
+ break;
+ case SKIPNUM: /* we have a number to skip */
+ while ((ch = *fmt) != '\0' && is_digit (ch))
+ ++fmt;
+ break;
+ case NOOP:
+ default:
+ break; /* do nothing */
+ }
+ }
+ }
+
+ /* process all arguments up to at least the one we are looking for and if we
+ have seen the end of the string, then process up to the max argument needed */
+ if (*fmt == '\0')
+ last_arg = max_pos_arg;
+ else
+ last_arg = n;
+
+ while (numargs <= last_arg)
+ {
+ switch (arg_type[numargs])
+ {
+ case LONG_INT:
+ args[numargs++].val_long = va_arg (*ap, long);
+ break;
+ case QUAD_INT:
+ args[numargs++].val_quad_t = va_arg (*ap, quad_t);
+ break;
+ case CHAR_PTR:
+ args[numargs++].val_char_ptr_t = va_arg (*ap, char *);
+ break;
+ case DOUBLE:
+ args[numargs++].val_double = va_arg (*ap, double);
+ break;
+ case LONG_DOUBLE:
+ args[numargs++].val__LONG_DOUBLE = va_arg (*ap, _LONG_DOUBLE);
+ break;
+ case WIDE_CHAR:
+ args[numargs++].val_wint_t = va_arg (*ap, wint_t);
+ break;
+ case INT:
+ default:
+ args[numargs++].val_int = va_arg (*ap, int);
+ break;
+ }
+ }
+
+ /* alter the global numargs value and keep a reference to the last bit of the fmt
+ string we processed here because the caller will continue processing where we started */
+ *numargs_p = numargs;
+ *last_fmt = fmt;
+ return &args[n];
+}
+#endif /* !_NO_POS_ARGS */
vfprintf.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: local.h
===================================================================
--- local.h (nonexistent)
+++ local.h (revision 520)
@@ -0,0 +1,227 @@
+/*
+ * Copyright (c) 1990, 2007 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by the University of California, Berkeley. The name of the
+ * University may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * %W% (UofMD/Berkeley) %G%
+ */
+
+/*
+ * Information local to this implementation of stdio,
+ * in particular, macros and private variables.
+ */
+
+#include <_ansi.h>
+#include
+#include
+#include
+#include
+#include
+#ifdef __SCLE
+# include
+#endif
+
+
+extern u_char *_EXFUN(__sccl, (char *, u_char *fmt));
+extern int _EXFUN(__svfscanf_r,(struct _reent *,FILE *, _CONST char *,va_list));
+extern int _EXFUN(__ssvfscanf_r,(struct _reent *,FILE *, _CONST char *,va_list));
+extern int _EXFUN(__svfiscanf_r,(struct _reent *,FILE *, _CONST char *,va_list));
+extern int _EXFUN(__ssvfiscanf_r,(struct _reent *,FILE *, _CONST char *,va_list));
+extern int _EXFUN(__svfwscanf_r,(struct _reent *,FILE *, _CONST wchar_t *,va_list));
+extern int _EXFUN(__ssvfwscanf_r,(struct _reent *,FILE *, _CONST wchar_t *,va_list));
+extern int _EXFUN(__svfiwscanf_r,(struct _reent *,FILE *, _CONST wchar_t *,va_list));
+extern int _EXFUN(__ssvfiwscanf_r,(struct _reent *,FILE *, _CONST wchar_t *,va_list));
+int _EXFUN(_svfprintf_r,(struct _reent *, FILE *, const char *,
+ va_list)
+ _ATTRIBUTE ((__format__ (__printf__, 3, 0))));
+int _EXFUN(_svfiprintf_r,(struct _reent *, FILE *, const char *,
+ va_list)
+ _ATTRIBUTE ((__format__ (__printf__, 3, 0))));
+int _EXFUN(_svfwprintf_r,(struct _reent *, FILE *, const wchar_t *,
+ va_list));
+int _EXFUN(_svfiwprintf_r,(struct _reent *, FILE *, const wchar_t *,
+ va_list));
+extern FILE *_EXFUN(__sfp,(struct _reent *));
+extern int _EXFUN(__sflags,(struct _reent *,_CONST char*, int*));
+extern int _EXFUN(__srefill_r,(struct _reent *,FILE *));
+extern _READ_WRITE_RETURN_TYPE _EXFUN(__sread,(struct _reent *, void *, char *,
+ int));
+extern _READ_WRITE_RETURN_TYPE _EXFUN(__seofread,(struct _reent *, void *,
+ char *, int));
+extern _READ_WRITE_RETURN_TYPE _EXFUN(__swrite,(struct _reent *, void *,
+ const char *, int));
+extern _fpos_t _EXFUN(__sseek,(struct _reent *, void *, _fpos_t, int));
+extern int _EXFUN(__sclose,(struct _reent *, void *));
+extern int _EXFUN(__stextmode,(int));
+extern _VOID _EXFUN(__sinit,(struct _reent *));
+extern _VOID _EXFUN(_cleanup_r,(struct _reent *));
+extern _VOID _EXFUN(__smakebuf_r,(struct _reent *, FILE *));
+extern int _EXFUN(_fwalk,(struct _reent *, int (*)(FILE *)));
+extern int _EXFUN(_fwalk_reent,(struct _reent *, int (*)(struct _reent *, FILE *)));
+struct _glue * _EXFUN(__sfmoreglue,(struct _reent *,int n));
+extern int _EXFUN(__submore, (struct _reent *, FILE *));
+
+#ifdef __LARGE64_FILES
+extern _fpos64_t _EXFUN(__sseek64,(struct _reent *, void *, _fpos64_t, int));
+extern _READ_WRITE_RETURN_TYPE _EXFUN(__swrite64,(struct _reent *, void *,
+ const char *, int));
+#endif
+
+/* Called by the main entry point fns to ensure stdio has been initialized. */
+
+#ifdef _REENT_SMALL
+#define CHECK_INIT(ptr, fp) \
+ do \
+ { \
+ if ((ptr) && !(ptr)->__sdidinit) \
+ __sinit (ptr); \
+ if ((fp) == (FILE *)&__sf_fake_stdin) \
+ (fp) = _stdin_r(ptr); \
+ else if ((fp) == (FILE *)&__sf_fake_stdout) \
+ (fp) = _stdout_r(ptr); \
+ else if ((fp) == (FILE *)&__sf_fake_stderr) \
+ (fp) = _stderr_r(ptr); \
+ } \
+ while (0)
+#else /* !_REENT_SMALL */
+#define CHECK_INIT(ptr, fp) \
+ do \
+ { \
+ if ((ptr) && !(ptr)->__sdidinit) \
+ __sinit (ptr); \
+ } \
+ while (0)
+#endif /* !_REENT_SMALL */
+
+#define CHECK_STD_INIT(ptr) \
+ do \
+ { \
+ if ((ptr) && !(ptr)->__sdidinit) \
+ __sinit (ptr); \
+ } \
+ while (0)
+
+/* Return true iff the given FILE cannot be written now. */
+
+#define cantwrite(ptr, fp) \
+ ((((fp)->_flags & __SWR) == 0 || (fp)->_bf._base == NULL) && \
+ __swsetup_r(ptr, fp))
+
+/* Test whether the given stdio file has an active ungetc buffer;
+ release such a buffer, without restoring ordinary unread data. */
+
+#define HASUB(fp) ((fp)->_ub._base != NULL)
+#define FREEUB(ptr, fp) { \
+ if ((fp)->_ub._base != (fp)->_ubuf) \
+ _free_r(ptr, (char *)(fp)->_ub._base); \
+ (fp)->_ub._base = NULL; \
+}
+
+/* Test for an fgetline() buffer. */
+
+#define HASLB(fp) ((fp)->_lb._base != NULL)
+#define FREELB(ptr, fp) { _free_r(ptr,(char *)(fp)->_lb._base); \
+ (fp)->_lb._base = NULL; }
+
+/*
+ * Set the orientation for a stream. If o > 0, the stream has wide-
+ * orientation. If o < 0, the stream has byte-orientation.
+ */
+#define ORIENT(fp,ori) \
+ do \
+ { \
+ if (!((fp)->_flags & __SORD)) \
+ { \
+ (fp)->_flags |= __SORD; \
+ if (ori > 0) \
+ (fp)->_flags2 |= __SWID; \
+ else \
+ (fp)->_flags2 &= ~__SWID; \
+ } \
+ } \
+ while (0)
+
+/* WARNING: _dcvt is defined in the stdlib directory, not here! */
+
+char *_EXFUN(_dcvt,(struct _reent *, char *, double, int, int, char, int));
+char *_EXFUN(_sicvt,(char *, short, char));
+char *_EXFUN(_icvt,(char *, int, char));
+char *_EXFUN(_licvt,(char *, long, char));
+#ifdef __GNUC__
+char *_EXFUN(_llicvt,(char *, long long, char));
+#endif
+
+#define CVT_BUF_SIZE 128
+
+#define NDYNAMIC 4 /* add four more whenever necessary */
+
+#ifdef __SINGLE_THREAD__
+#define __sfp_lock_acquire()
+#define __sfp_lock_release()
+#define __sinit_lock_acquire()
+#define __sinit_lock_release()
+#else
+_VOID _EXFUN(__sfp_lock_acquire,(_VOID));
+_VOID _EXFUN(__sfp_lock_release,(_VOID));
+_VOID _EXFUN(__sinit_lock_acquire,(_VOID));
+_VOID _EXFUN(__sinit_lock_release,(_VOID));
+#endif
+
+/* Types used in positional argument support in vfprinf/vfwprintf.
+ The implementation is char/wchar_t dependent but the class and state
+ tables are only defined once in vfprintf.c. */
+typedef enum {
+ ZERO, /* '0' */
+ DIGIT, /* '1-9' */
+ DOLLAR, /* '$' */
+ MODFR, /* spec modifier */
+ SPEC, /* format specifier */
+ DOT, /* '.' */
+ STAR, /* '*' */
+ FLAG, /* format flag */
+ OTHER, /* all other chars */
+ MAX_CH_CLASS /* place-holder */
+} __CH_CLASS;
+
+typedef enum {
+ START, /* start */
+ SFLAG, /* seen a flag */
+ WDIG, /* seen digits in width area */
+ WIDTH, /* processed width */
+ SMOD, /* seen spec modifier */
+ SDOT, /* seen dot */
+ VARW, /* have variable width specifier */
+ VARP, /* have variable precision specifier */
+ PREC, /* processed precision */
+ VWDIG, /* have digits in variable width specification */
+ VPDIG, /* have digits in variable precision specification */
+ DONE, /* done */
+ MAX_STATE, /* place-holder */
+} __STATE;
+
+typedef enum {
+ NOOP, /* do nothing */
+ NUMBER, /* build a number from digits */
+ SKIPNUM, /* skip over digits */
+ GETMOD, /* get and process format modifier */
+ GETARG, /* get and process argument */
+ GETPW, /* get variable precision or width */
+ GETPWB, /* get variable precision or width and pushback fmt char */
+ GETPOS, /* get positional parameter value */
+ PWPOS, /* get positional parameter value for variable width or precision */
+} __ACTION;
+
+extern _CONST __CH_CLASS __chclass[256];
+extern _CONST __STATE __state_table[MAX_STATE][MAX_CH_CLASS];
+extern _CONST __ACTION __action_table[MAX_STATE][MAX_CH_CLASS];
local.h
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: fwprintf.c
===================================================================
--- fwprintf.c (nonexistent)
+++ fwprintf.c (revision 520)
@@ -0,0 +1,56 @@
+/*
+ * 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 swprintf.c */
+
+#include <_ansi.h>
+#include
+#include
+#include
+#include
+
+int
+_DEFUN(_fwprintf_r, (ptr, fp, fmt),
+ struct _reent *ptr _AND
+ FILE *fp _AND
+ const wchar_t *fmt _DOTS)
+{
+ int ret;
+ va_list ap;
+
+ va_start (ap, fmt);
+ ret = _vfwprintf_r (ptr, fp, fmt, ap);
+ va_end (ap);
+ return ret;
+}
+
+#ifndef _REENT_ONLY
+
+int
+_DEFUN(fwprintf, (fp, fmt),
+ FILE *fp _AND
+ const wchar_t *fmt _DOTS)
+{
+ int ret;
+ va_list ap;
+
+ va_start (ap, fmt);
+ ret = _vfwprintf_r (_REENT, fp, fmt, ap);
+ va_end (ap);
+ return ret;
+}
+
+#endif /* ! _REENT_ONLY */
fwprintf.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: tmpfile.c
===================================================================
--- tmpfile.c (nonexistent)
+++ tmpfile.c (revision 520)
@@ -0,0 +1,96 @@
+/*
+FUNCTION
+<>---create a temporary file
+
+INDEX
+ tmpfile
+INDEX
+ _tmpfile_r
+
+ANSI_SYNOPSIS
+ #include
+ FILE *tmpfile(void);
+
+ FILE *_tmpfile_r(struct _reent *<[reent]>);
+
+TRAD_SYNOPSIS
+ #include
+ FILE *tmpfile();
+
+ FILE *_tmpfile_r(<[reent]>)
+ struct _reent *<[reent]>;
+
+DESCRIPTION
+Create a temporary file (a file which will be deleted automatically),
+using a name generated by <>. The temporary file is opened with
+the mode <<"wb+">>, permitting you to read and write anywhere in it
+as a binary file (without any data transformations the host system may
+perform for text files).
+
+The alternate function <<_tmpfile_r>> is a reentrant version. The
+argument <[reent]> is a pointer to a reentrancy structure.
+
+RETURNS
+<> normally returns a pointer to the temporary file. If no
+temporary file could be created, the result is NULL, and <>
+records the reason for failure.
+
+PORTABILITY
+Both ANSI C and the System V Interface Definition (Issue 2) require
+<>.
+
+Supporting OS subroutines required: <>, <>, <>,
+<>, <>, <>, <>, <>, <>.
+
+<> also requires the global pointer <>.
+*/
+
+#include <_ansi.h>
+#include
+#include
+#include
+#include
+#include
+
+#ifndef O_BINARY
+# define O_BINARY 0
+#endif
+
+FILE *
+_DEFUN(_tmpfile_r, (ptr),
+ struct _reent *ptr)
+{
+ FILE *fp;
+ int e;
+ char *f;
+ char buf[L_tmpnam];
+ int fd;
+
+ do
+ {
+ if ((f = _tmpnam_r (ptr, buf)) == NULL)
+ return NULL;
+ fd = _open_r (ptr, f, O_RDWR | O_CREAT | O_EXCL | O_BINARY,
+ S_IRUSR | S_IWUSR);
+ }
+ while (fd < 0 && ptr->_errno == EEXIST);
+ if (fd < 0)
+ return NULL;
+ fp = _fdopen_r (ptr, fd, "wb+");
+ e = ptr->_errno;
+ if (!fp)
+ _close_r (ptr, fd);
+ _CAST_VOID _remove_r (ptr, f);
+ ptr->_errno = e;
+ return fp;
+}
+
+#ifndef _REENT_ONLY
+
+FILE *
+_DEFUN_VOID(tmpfile)
+{
+ return _tmpfile_r (_REENT);
+}
+
+#endif
tmpfile.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: rget.c
===================================================================
--- rget.c (nonexistent)
+++ rget.c (revision 520)
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by the University of California, Berkeley. The name of the
+ * University may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ */
+/* No user fns here. Pesch 15apr92. */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "%W% (Berkeley) %G%";
+#endif /* LIBC_SCCS and not lint */
+
+#include <_ansi.h>
+#include
+#include
+#include "local.h"
+
+/*
+ * Handle getc() when the buffer ran out:
+ * Refill, then return the first character
+ * in the newly-filled buffer.
+ */
+
+int
+_DEFUN(__srget_r, (ptr, fp),
+ struct _reent *ptr _AND
+ register FILE *fp)
+{
+ /* Ensure that any fake std stream is resolved before
+ we call __srefill_r so we may access the true read buffer. */
+ CHECK_INIT(ptr, fp);
+
+ if (__srefill_r (ptr, fp) == 0)
+ {
+ fp->_r--;
+ return *fp->_p++;
+ }
+ return EOF;
+}
+
+/* This function isn't any longer declared in stdio.h, but it's
+ required for backward compatibility with applications built against
+ earlier dynamically built newlib libraries. */
+int
+_DEFUN(__srget, (fp),
+ register FILE *fp)
+{
+ return __srget_r (_REENT, fp);
+}
rget.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: viprintf.c
===================================================================
--- viprintf.c (nonexistent)
+++ viprintf.c (revision 520)
@@ -0,0 +1,126 @@
+/*
+ * 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
+<>, <>, <>, <>, <>, <>---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
+ #include
+ 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
+<>, <>, <>, <>,
+<>, and <> are (respectively) variants of
+<>, <>, <>, <>, <>,
+and <>. They differ only in allowing their caller to pass
+the variable argument list as a <> object (initialized by
+<>) rather than directly accepting a variable number of
+arguments. The caller is responsible for calling <>.
+
+<<_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: <>, <>, <>,
+<>, <>, <>, <>.
+*/
+
+#include <_ansi.h>
+#include
+#include
+#ifdef _HAVE_STDC
+#include
+#else
+#include
+#endif
+#include "local.h"
+
+#ifndef _REENT_ONLY
+
+int
+_DEFUN(viprintf, (fmt, ap),
+ _CONST char *fmt _AND
+ va_list ap)
+{
+ _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);
+}
fopen.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: rename.c
===================================================================
--- rename.c (nonexistent)
+++ rename.c (revision 520)
@@ -0,0 +1,70 @@
+/*
+ * 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
+<>---rename a file
+
+INDEX
+ rename
+
+ANSI_SYNOPSIS
+ #include
+ int rename(const char *<[old]>, const char *<[new]>);
+
+TRAD_SYNOPSIS
+ #include
+ int rename(<[old]>, <[new]>)
+ char *<[old]>;
+ char *<[new]>;
+
+DESCRIPTION
+Use <> to establish a new name (the string at <[new]>) for a
+file now known by the string at <[old]>. After a successful
+<>, the file is no longer accessible by the string at <[old]>.
+
+If <> fails, the file named <<*<[old]>>> is unaffected. The
+conditions for failure depend on the host operating system.
+
+RETURNS
+The result is either <<0>> (when successful) or <<-1>> (when the file
+could not be renamed).
+
+PORTABILITY
+ANSI C requires <>, but only specifies that the result on
+failure be nonzero. The effects of using the name of an existing file
+as <<*<[new]>>> may vary from one implementation to another.
+
+Supporting OS subroutines required: <>, <>, or <>.
+*/
+
+#include <_ansi.h>
+#include
+#include
+#include
+
+#ifndef _REENT_ONLY
+
+int
+_DEFUN(rename, (old, new),
+ _CONST char *old _AND
+ _CONST char *new)
+{
+ return _rename_r (_REENT, old, new);
+}
+
+#endif
rename.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: fputwc.c
===================================================================
--- fputwc.c (nonexistent)
+++ fputwc.c (revision 520)
@@ -0,0 +1,177 @@
+/*-
+ * Copyright (c) 2002-2004 Tim J. Robbins.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+FUNCTION
+<>, <>---write a wide character on a stream or file
+
+INDEX
+ fputwc
+INDEX
+ _fputwc_r
+INDEX
+ putwc
+INDEX
+ _putwc_r
+
+ANSI_SYNOPSIS
+ #include
+ #include
+ wint_t fputwc(wchar_t <[wc]>, FILE *<[fp]>);
+
+ #include
+ #include
+ wint_t _fputwc_r(struct _reent *<[ptr]>, wchar_t <[wc]>, FILE *<[fp]>);
+
+ #include
+ #include
+ wint_t putwc(wchar_t <[wc]>, FILE *<[fp]>);
+
+ #include
+ #include
+ wint_t _putwc_r(struct _reent *<[ptr]>, wchar_t <[wc]>, FILE *<[fp]>);
+
+TRAD_SYNOPSIS
+ #include
+ #include
+ wint_t fputwc(<[wc]>, <[fp]>)
+ wchar_t <[wc]>;
+ FILE *<[fp]>;
+
+ #include
+ #include
+ wint_t _fputwc_r(<[ptr]>, <[wc]>, <[fp]>)
+ struct _reent *<[ptr]>;
+ wchar_t <[wc]>;
+ FILE *<[fp]>;
+
+ #include
+ #include
+ wint_t putwc(<[wc]>, <[fp]>)
+ wchar_t <[wc]>;
+ FILE *<[fp]>;
+
+ #include
+ #include
+ wint_t _putwc_r(<[ptr]>, <[wc]>, <[fp]>)
+ struct _reent *<[ptr]>;
+ wchar_t <[wc]>;
+ FILE *<[fp]>;
+
+DESCRIPTION
+<> writes the wide character argument <[wc]> to the file or
+stream identified by <[fp]>.
+
+If the file was opened with append mode (or if the stream cannot
+support positioning), then the new wide character goes at the end of the
+file or stream. Otherwise, the new wide character is written at the
+current value of the position indicator, and the position indicator
+oadvances by one.
+
+The <> function or macro functions identically to <>. It
+may be implemented as a macro, and may evaluate its argument more than
+once. There is no reason ever to use it.
+
+The <<_fputwc_r>> and <<_putwc_r>> functions are simply reentrant versions
+of <> and <> that take an additional reentrant structure
+argument: <[ptr]>.
+
+RETURNS
+If successful, <> and <> return their argument <[wc]>.
+If an error intervenes, the result is <>. You can use
+`<)>>' to query for errors.
+
+PORTABILITY
+C99, POSIX.1-2001
+*/
+
+#include <_ansi.h>
+#include
+#include
+#include
+#include
+#include
+#include
+#include "local.h"
+
+static wint_t
+_DEFUN(__fputwc, (ptr, wc, fp),
+ struct _reent *ptr _AND
+ wchar_t wc _AND
+ FILE *fp)
+{
+ char buf[MB_LEN_MAX];
+ size_t i, len;
+
+ if (MB_CUR_MAX == 1 && wc > 0 && wc <= UCHAR_MAX)
+ {
+ /*
+ * Assume single-byte locale with no special encoding.
+ * A more careful test would be to check
+ * _CurrentRuneLocale->encoding.
+ */
+ *buf = (unsigned char)wc;
+ len = 1;
+ }
+ else
+ {
+ if ((len = _wcrtomb_r (ptr, buf, wc, &fp->_mbstate)) == (size_t) -1)
+ {
+ fp->_flags |= __SERR;
+ return WEOF;
+ }
+ }
+
+ for (i = 0; i < len; i++)
+ if (__sputc_r (ptr, (unsigned char) buf[i], fp) == EOF)
+ return WEOF;
+
+ return (wint_t) wc;
+}
+
+wint_t
+_DEFUN(_fputwc_r, (ptr, wc, fp),
+ struct _reent *ptr _AND
+ wchar_t wc _AND
+ FILE *fp)
+{
+ wint_t r;
+
+ _flockfile (fp);
+ ORIENT(fp, 1);
+ r = __fputwc(ptr, wc, fp);
+ _funlockfile (fp);
+ return r;
+}
+
+wint_t
+_DEFUN(fputwc, (wc, fp),
+ wchar_t wc _AND
+ FILE *fp)
+{
+ CHECK_INIT(_REENT, fp);
+ return _fputwc_r (_REENT, wc, fp);
+}
fputwc.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: fclose.c
===================================================================
--- fclose.c (nonexistent)
+++ fclose.c (revision 520)
@@ -0,0 +1,121 @@
+/*
+ * 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
+<>---close a file
+
+INDEX
+ fclose
+INDEX
+ _fclose_r
+
+ANSI_SYNOPSIS
+ #include
+ int fclose(FILE *<[fp]>);
+ int _fclose_r(struct _reent *<[reent]>, FILE *<[fp]>);
+
+TRAD_SYNOPSIS
+ #include
+ int fclose(<[fp]>)
+ FILE *<[fp]>;
+
+ int fclose(<[fp]>)
+ struct _reent *<[reent]>
+ FILE *<[fp]>;
+
+DESCRIPTION
+If the file or stream identified by <[fp]> is open, <> closes
+it, after first ensuring that any pending data is written (by calling
+<)>>).
+
+The alternate function <<_fclose_r>> is a reentrant version.
+The extra argument <[reent]> is a pointer to a reentrancy structure.
+
+RETURNS
+<> returns <<0>> if successful (including when <[fp]> is
+<> or not an open file); otherwise, it returns <>.
+
+PORTABILITY
+<> is required by ANSI C.
+
+Required OS subroutines: <>, <>, <>, <>,
+<>, <>, <>.
+*/
+
+#include <_ansi.h>
+#include
+#include
+#include
+#include
+#include "local.h"
+
+int
+_DEFUN(_fclose_r, (rptr, fp),
+ struct _reent *rptr _AND
+ register FILE * fp)
+{
+ int r;
+
+ if (fp == NULL)
+ return (0); /* on NULL */
+
+ __sfp_lock_acquire ();
+
+ CHECK_INIT (rptr, fp);
+
+ _flockfile (fp);
+
+ if (fp->_flags == 0) /* not open! */
+ {
+ _funlockfile (fp);
+ __sfp_lock_release ();
+ return (0);
+ }
+ /* Unconditionally flush to allow special handling for seekable read
+ files to reposition file to last byte processed as opposed to
+ last byte read ahead into the buffer. */
+ r = _fflush_r (rptr, fp);
+ if (fp->_close != NULL && fp->_close (rptr, fp->_cookie) < 0)
+ r = EOF;
+ if (fp->_flags & __SMBF)
+ _free_r (rptr, (char *) fp->_bf._base);
+ if (HASUB (fp))
+ FREEUB (rptr, fp);
+ if (HASLB (fp))
+ FREELB (rptr, fp);
+ fp->_flags = 0; /* release this FILE for reuse */
+ _funlockfile (fp);
+#ifndef __SINGLE_THREAD__
+ __lock_close_recursive (fp->_lock);
+#endif
+
+ __sfp_lock_release ();
+
+ return (r);
+}
+
+#ifndef _REENT_ONLY
+
+int
+_DEFUN(fclose, (fp),
+ register FILE * fp)
+{
+ return _fclose_r(_REENT, fp);
+}
+
+#endif
fclose.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: vsprintf.c
===================================================================
--- vsprintf.c (nonexistent)
+++ vsprintf.c (revision 520)
@@ -0,0 +1,59 @@
+/*
+ * 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 */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "%W% (Berkeley) %G%";
+#endif /* LIBC_SCCS and not lint */
+
+#include <_ansi.h>
+#include
+#include
+#include
+#include
+
+#ifndef _REENT_ONLY
+
+int
+_DEFUN(vsprintf, (str, fmt, ap),
+ char *str _AND
+ const char *fmt _AND
+ va_list ap)
+{
+ return _vsprintf_r (_REENT, str, fmt, ap);
+}
+
+#endif /* !_REENT_ONLY */
+
+int
+_DEFUN(_vsprintf_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 = _svfprintf_r (ptr, &f, fmt, ap);
+ *f._p = 0;
+ return ret;
+}
vsprintf.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: vsiscanf.c
===================================================================
--- vsiscanf.c (nonexistent)
+++ vsiscanf.c (revision 520)
@@ -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
+#include
+#include
+#ifdef _HAVE_STDC
+#include
+#else
+#include
+#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);
+}
vsiscanf.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: vwprintf.c
===================================================================
--- vwprintf.c (nonexistent)
+++ vwprintf.c (revision 520)
@@ -0,0 +1,47 @@
+/*
+ * 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 vfwprintf.c */
+
+#include <_ansi.h>
+#include
+#include
+#include
+#include
+#include "local.h"
+
+#ifndef _REENT_ONLY
+
+int
+_DEFUN(vwprintf, (fmt, ap),
+ _CONST wchar_t *fmt _AND
+ va_list ap)
+{
+ _REENT_SMALL_CHECK_INIT (_REENT);
+ return _vfwprintf_r (_REENT, _stdout_r (_REENT), fmt, ap);
+}
+
+#endif /* !_REENT_ONLY */
+
+int
+_DEFUN(_vwprintf_r, (ptr, fmt, ap),
+ struct _reent *ptr _AND
+ _CONST wchar_t *fmt _AND
+ va_list ap)
+{
+ _REENT_SMALL_CHECK_INIT (ptr);
+ return _vfwprintf_r (ptr, _stdout_r (ptr), fmt, ap);
+}
vwprintf.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: fputc.c
===================================================================
--- fputc.c (nonexistent)
+++ fputc.c (revision 520)
@@ -0,0 +1,109 @@
+/*
+ * 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
+<>---write a character on a stream or file
+
+INDEX
+ fputc
+INDEX
+ _fputc_r
+
+ANSI_SYNOPSIS
+ #include
+ int fputc(int <[ch]>, FILE *<[fp]>);
+
+ #include
+ int _fputc_r(struct _rent *<[ptr]>, int <[ch]>, FILE *<[fp]>);
+
+TRAD_SYNOPSIS
+ #include
+ int fputc(<[ch]>, <[fp]>)
+ int <[ch]>;
+ FILE *<[fp]>;
+
+ #include
+ int _fputc_r(<[ptr]>, <[ch]>, <[fp]>)
+ struct _reent *<[ptr]>;
+ int <[ch]>;
+ FILE *<[fp]>;
+
+DESCRIPTION
+<> converts the argument <[ch]> from an <> to an
+<>, then writes it to the file or stream identified by
+<[fp]>.
+
+If the file was opened with append mode (or if the stream cannot
+support positioning), then the new character goes at the end of the
+file or stream. Otherwise, the new character is written at the
+current value of the position indicator, and the position indicator
+oadvances by one.
+
+For a macro version of this function, see <>.
+
+The <<_fputc_r>> function is simply a reentrant version of <>
+that takes an additional reentrant structure argument: <[ptr]>.
+
+RETURNS
+If successful, <> returns its argument <[ch]>. If an error
+intervenes, the result is <>. You can use `<)>>' to
+query for errors.
+
+PORTABILITY
+<> is required by ANSI C.
+
+Supporting OS subroutines required: <>, <>, <>,
+<>, <>, <>, <>.
+*/
+
+#include <_ansi.h>
+#include
+#include "local.h"
+
+int
+_DEFUN(_fputc_r, (ptr, ch, file),
+ struct _reent *ptr _AND
+ int ch _AND
+ FILE * file)
+{
+ int result;
+ CHECK_INIT(ptr, file);
+ _flockfile (file);
+ result = _putc_r (ptr, ch, file);
+ _funlockfile (file);
+ return result;
+}
+
+#ifndef _REENT_ONLY
+int
+_DEFUN(fputc, (ch, file),
+ int ch _AND
+ FILE * file)
+{
+#if !defined(__OPTIMIZE_SIZE__) && !defined(PREFER_SIZE_OVER_SPEED)
+ int result;
+ CHECK_INIT(_REENT, file);
+ _flockfile (file);
+ result = _putc_r (_REENT, ch, file);
+ _funlockfile (file);
+ return result;
+#else
+ return _fputc_r (_REENT, ch, file);
+#endif
+}
+#endif /* !_REENT_ONLY */
fputc.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: fwscanf.c
===================================================================
--- fwscanf.c (nonexistent)
+++ fwscanf.c (revision 520)
@@ -0,0 +1,52 @@
+/*
+ * 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
+#include
+#include
+#include
+#include "local.h"
+
+#ifndef _REENT_ONLY
+
+int
+fwscanf (FILE *fp, _CONST wchar_t *fmt, ...)
+{
+ int ret;
+ va_list ap;
+
+ va_start (ap, fmt);
+ ret = __svfwscanf_r (_REENT, fp, fmt, ap);
+ va_end (ap);
+ return ret;
+}
+
+#endif /* !_REENT_ONLY */
+
+int
+_fwscanf_r (struct _reent *ptr, FILE *fp, _CONST wchar_t *fmt, ...)
+{
+ int ret;
+ va_list ap;
+
+ va_start (ap, fmt);
+ ret = __svfwscanf_r (ptr, fp, fmt, ap);
+ va_end (ap);
+ return (ret);
+}
+
fwscanf.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: fflush.c
===================================================================
--- fflush.c (nonexistent)
+++ fflush.c (revision 520)
@@ -0,0 +1,240 @@
+/*
+ * 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
+<>---flush buffered file output
+
+INDEX
+ fflush
+INDEX
+ _fflush_r
+
+ANSI_SYNOPSIS
+ #include
+ int fflush(FILE *<[fp]>);
+
+ int _fflush_r(struct _reent *<[reent]>, FILE *<[fp]>);
+
+DESCRIPTION
+The <> output functions can buffer output before delivering it
+to the host system, in order to minimize the overhead of system calls.
+
+Use <> to deliver any such pending output (for the file
+or stream identified by <[fp]>) to the host system.
+
+If <[fp]> is <>, <> delivers pending output from all
+open files.
+
+Additionally, if <[fp]> is a seekable input stream visiting a file
+descriptor, set the position of the file descriptor to match next
+unread byte, useful for obeying POSIX semantics when ending a process
+without consuming all input from the stream.
+
+The alternate function <<_fflush_r>> is a reentrant version, where the
+extra argument <[reent]> is a pointer to a reentrancy structure, and
+<[fp]> must not be NULL.
+
+RETURNS
+<> returns <<0>> unless it encounters a write error; in that
+situation, it returns <>.
+
+PORTABILITY
+ANSI C requires <>. The behavior on input streams is only
+specified by POSIX, and not all implementations follow POSIX rules.
+
+No supporting OS subroutines are required.
+*/
+
+#include <_ansi.h>
+#include
+#include
+#include "local.h"
+
+/* Flush a single file, or (if fp is NULL) all files. */
+
+int
+_DEFUN(_fflush_r, (ptr, fp),
+ struct _reent *ptr _AND
+ register FILE * fp)
+{
+ register unsigned char *p;
+ register int n, t;
+
+#ifdef _REENT_SMALL
+ /* For REENT_SMALL platforms, it is possible we are being
+ called for the first time on a std stream. This std
+ stream can belong to a reentrant struct that is not
+ _REENT. If CHECK_INIT gets called below based on _REENT,
+ we will end up changing said file pointers to the equivalent
+ std stream off of _REENT. This causes unexpected behavior if
+ there is any data to flush on the _REENT std stream. There
+ are two alternatives to fix this: 1) make a reentrant fflush
+ or 2) simply recognize that this file has nothing to flush
+ and return immediately before performing a CHECK_INIT. Choice
+ 2 is implemented here due to its simplicity. */
+ if (fp->_bf._base == NULL)
+ return 0;
+#endif /* _REENT_SMALL */
+
+ CHECK_INIT (ptr, fp);
+
+ if (!fp->_flags)
+ return 0;
+
+ _flockfile (fp);
+
+ t = fp->_flags;
+ if ((t & __SWR) == 0)
+ {
+ /* For a read stream, an fflush causes the next seek to be
+ unoptimized (i.e. forces a system-level seek). This conforms
+ to the POSIX and SUSv3 standards. */
+ fp->_flags |= __SNPT;
+
+ /* For a seekable stream with buffered read characters, we will attempt
+ a seek to the current position now. A subsequent read will then get
+ the next byte from the file rather than the buffer. This conforms
+ to the POSIX and SUSv3 standards. Note that the standards allow
+ this seek to be deferred until necessary, but we choose to do it here
+ to make the change simpler, more contained, and less likely
+ to miss a code scenario. */
+ if ((fp->_r > 0 || fp->_ur > 0) && fp->_seek != NULL)
+ {
+ int tmp_errno;
+#ifdef __LARGE64_FILES
+ _fpos64_t curoff;
+#else
+ _fpos_t curoff;
+#endif
+
+ /* Save last errno and set errno to 0, so we can check if a device
+ returns with a valid position -1. We restore the last errno if
+ no other error condition has been encountered. */
+ tmp_errno = ptr->_errno;
+ ptr->_errno = 0;
+ /* Get the physical position we are at in the file. */
+ if (fp->_flags & __SOFF)
+ curoff = fp->_offset;
+ else
+ {
+ /* We don't know current physical offset, so ask for it.
+ Only ESPIPE and EINVAL are ignorable. */
+#ifdef __LARGE64_FILES
+ if (fp->_flags & __SL64)
+ curoff = fp->_seek64 (ptr, fp->_cookie, 0, SEEK_CUR);
+ else
+#endif
+ curoff = fp->_seek (ptr, fp->_cookie, 0, SEEK_CUR);
+ if (curoff == -1L && ptr->_errno != 0)
+ {
+ int result = EOF;
+ if (ptr->_errno == ESPIPE || ptr->_errno == EINVAL)
+ {
+ result = 0;
+ ptr->_errno = tmp_errno;
+ }
+ else
+ fp->_flags |= __SERR;
+ _funlockfile (fp);
+ return result;
+ }
+ }
+ if (fp->_flags & __SRD)
+ {
+ /* Current offset is at end of buffer. Compensate for
+ characters not yet read. */
+ curoff -= fp->_r;
+ if (HASUB (fp))
+ curoff -= fp->_ur;
+ }
+ /* Now physically seek to after byte last read. */
+#ifdef __LARGE64_FILES
+ if (fp->_flags & __SL64)
+ curoff = fp->_seek64 (ptr, fp->_cookie, curoff, SEEK_SET);
+ else
+#endif
+ curoff = fp->_seek (ptr, fp->_cookie, curoff, SEEK_SET);
+ if (curoff != -1 || ptr->_errno == 0
+ || ptr->_errno == ESPIPE || ptr->_errno == EINVAL)
+ {
+ /* Seek successful or ignorable error condition.
+ We can clear read buffer now. */
+ fp->_flags &= ~__SNPT;
+ fp->_r = 0;
+ fp->_p = fp->_bf._base;
+ if ((fp->_flags & __SOFF) && (curoff != -1 || ptr->_errno == 0))
+ fp->_offset = curoff;
+ ptr->_errno = tmp_errno;
+ if (HASUB (fp))
+ FREEUB (ptr, fp);
+ }
+ else
+ {
+ fp->_flags |= __SERR;
+ _funlockfile (fp);
+ return EOF;
+ }
+ }
+ _funlockfile (fp);
+ return 0;
+ }
+ if ((p = fp->_bf._base) == NULL)
+ {
+ /* Nothing to flush. */
+ _funlockfile (fp);
+ return 0;
+ }
+ n = fp->_p - p; /* write this much */
+
+ /*
+ * Set these immediately to avoid problems with longjmp
+ * and to allow exchange buffering (via setvbuf) in user
+ * write function.
+ */
+ fp->_p = p;
+ fp->_w = t & (__SLBF | __SNBF) ? 0 : fp->_bf._size;
+
+ while (n > 0)
+ {
+ t = fp->_write (ptr, fp->_cookie, (char *) p, n);
+ if (t <= 0)
+ {
+ fp->_flags |= __SERR;
+ _funlockfile (fp);
+ return EOF;
+ }
+ p += t;
+ n -= t;
+ }
+ _funlockfile (fp);
+ return 0;
+}
+
+#ifndef _REENT_ONLY
+
+int
+_DEFUN(fflush, (fp),
+ register FILE * fp)
+{
+ if (fp == NULL)
+ return _fwalk_reent (_GLOBAL_REENT, _fflush_r);
+
+ return _fflush_r (_REENT, fp);
+}
+
+#endif /* _REENT_ONLY */
fflush.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: fputws.c
===================================================================
--- fputws.c (nonexistent)
+++ fputws.c (revision 520)
@@ -0,0 +1,122 @@
+/*-
+ * Copyright (c) 2002-2004 Tim J. Robbins.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+FUNCTION
+<>---write a wide character string in a file or stream
+
+INDEX
+ fputws
+INDEX
+ _fputws_r
+
+ANSI_SYNOPSIS
+ #include
+ int fputws(const wchar_t *<[ws]>, FILE *<[fp]>);
+
+ #include
+ int _fputws_r(struct _reent *<[ptr]>, const wchar_t *<[ws]>, FILE *<[fp]>);
+
+TRAD_SYNOPSIS
+ #include
+ int fputws(<[ws]>, <[fp]>)
+ wchar_t *<[ws]>;
+ FILE *<[fp]>;
+
+ #include
+ int _fputws_r(<[ptr]>, <[ws]>, <[fp]>)
+ struct _reent *<[ptr]>;
+ wchar_t *<[ws]>;
+ FILE *<[fp]>;
+
+DESCRIPTION
+<> writes the wide character string at <[ws]> (but without the
+trailing null) to the file or stream identified by <[fp]>.
+
+<<_fputws_r>> is simply the reentrant version of <> that takes
+an additional reentrant struct pointer argument: <[ptr]>.
+
+RETURNS
+If successful, the result is a non-negative integer; otherwise, the result
+is <<-1>> to indicate an error.
+
+PORTABILITY
+C99, POSIX.1-2001
+*/
+
+#include <_ansi.h>
+#include
+#include
+#include
+#include
+#include
+#include "fvwrite.h"
+#include "local.h"
+
+int
+_DEFUN(_fputws_r, (ptr, ws, fp),
+ struct _reent *ptr _AND
+ const wchar_t *ws _AND
+ FILE *fp)
+{
+ size_t nbytes;
+ char buf[BUFSIZ];
+ struct __suio uio;
+ struct __siov iov;
+
+ _flockfile (fp);
+ ORIENT (fp, 1);
+ if (cantwrite (ptr, fp) != 0)
+ goto error;
+ uio.uio_iov = &iov;
+ uio.uio_iovcnt = 1;
+ iov.iov_base = buf;
+ do
+ {
+ nbytes = _wcsrtombs_r(ptr, buf, &ws, sizeof (buf), &fp->_mbstate);
+ if (nbytes == (size_t) -1)
+ goto error;
+ iov.iov_len = uio.uio_resid = nbytes;
+ if (__sfvwrite_r(ptr, fp, &uio) != 0)
+ goto error;
+ }
+ while (ws != NULL);
+ _funlockfile (fp);
+ return (0);
+
+error:
+ _funlockfile(fp);
+ return (-1);
+}
+
+int
+_DEFUN(fputws, (ws, fp),
+ const wchar_t *ws _AND
+ FILE *fp)
+{
+ CHECK_INIT (_REENT, fp);
+ return _fputws_r (_REENT, ws, fp);
+}
fputws.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: getdelim.c
===================================================================
--- getdelim.c (nonexistent)
+++ getdelim.c (revision 520)
@@ -0,0 +1,144 @@
+/* Copyright 2002, Red Hat Inc. - all rights reserved */
+/*
+FUNCTION
+<>---read a line up to a specified line delimiter
+
+INDEX
+ getdelim
+
+ANSI_SYNOPSIS
+ #include
+ int getdelim(char **<[bufptr]>, size_t *<[n]>,
+ int <[delim]>, FILE *<[fp]>);
+
+TRAD_SYNOPSIS
+ #include
+ int getdelim(<[bufptr]>, <[n]>, <[delim]>, <[fp]>)
+ char **<[bufptr]>;
+ size_t *<[n]>;
+ int <[delim]>;
+ FILE *<[fp]>;
+
+DESCRIPTION
+<> 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 <>.
+As the buffer is grown, the pointer to the size <[n]> will be
+updated.
+
+RETURNS
+<> 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
+<> is a glibc extension.
+
+No supporting OS subroutines are directly required.
+*/
+
+#include <_ansi.h>
+#include
+#include
+#include
+#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);
+
+ __sfp_lock_acquire ();
+ _flockfile (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;
+ }
+ }
+
+ _funlockfile (fp);
+ __sfp_lock_release ();
+
+ /* 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);
+}
+
getdelim.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: scanf.c
===================================================================
--- scanf.c (nonexistent)
+++ scanf.c (revision 520)
@@ -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
+#include
+#ifdef _HAVE_STDC
+#include
+#else
+#include
+#endif
+#include "local.h"
+
+#ifndef _REENT_ONLY
+
+int
+#ifdef _HAVE_STDC
+scanf(_CONST char *fmt, ...)
+#else
+scanf(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 = __svfscanf_r (_REENT, _stdin_r (_REENT), fmt, ap);
+ va_end (ap);
+ return ret;
+}
+
+#endif /* !_REENT_ONLY */
+
+int
+#ifdef _HAVE_STDC
+_scanf_r(struct _reent *ptr, _CONST char *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 = __svfscanf_r (ptr, _stdin_r (ptr), fmt, ap);
+ va_end (ap);
+ return (ret);
+}
+
scanf.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: tmpnam.c
===================================================================
--- tmpnam.c (nonexistent)
+++ tmpnam.c (revision 520)
@@ -0,0 +1,209 @@
+/*
+ * tmpname.c
+ * Original Author: G. Haley
+ */
+/*
+FUNCTION
+<>, <>---name for a temporary file
+
+INDEX
+ tmpnam
+INDEX
+ tempnam
+INDEX
+ _tmpnam_r
+INDEX
+ _tempnam_r
+
+ANSI_SYNOPSIS
+ #include
+ char *tmpnam(char *<[s]>);
+ char *tempnam(char *<[dir]>, char *<[pfx]>);
+ char *_tmpnam_r(struct _reent *<[reent]>, char *<[s]>);
+ char *_tempnam_r(struct _reent *<[reent]>, char *<[dir]>, char *<[pfx]>);
+
+TRAD_SYNOPSIS
+ #include
+ char *tmpnam(<[s]>)
+ char *<[s]>;
+
+ char *tempnam(<[dir]>, <[pfx]>)
+ char *<[dir]>;
+ char *<[pfx]>;
+
+ char *_tmpnam_r(<[reent]>, <[s]>)
+ struct _reent *<[reent]>;
+ char *<[s]>;
+
+ char *_tempnam_r(<[reent]>, <[dir]>, <[pfx]>)
+ struct *<[reent]>;
+ char *<[dir]>;
+ char *<[pfx]>;
+
+DESCRIPTION
+Use either of these functions to generate a name for a temporary file.
+The generated name is guaranteed to avoid collision with other files
+(for up to <> calls of either function).
+
+<> generates file names with the value of <>
+(defined in `<>') as the leading directory component of the path.
+
+You can use the <> argument <[s]> to specify a suitable area
+of memory for the generated filename; otherwise, you can call
+<> to use an internal static buffer.
+
+<> allows you more control over the generated filename: you
+can use the argument <[dir]> to specify the path to a directory for
+temporary files, and you can use the argument <[pfx]> to specify a
+prefix for the base filename.
+
+If <[dir]> is <>, <> will attempt to use the value of
+environment variable <> instead; if there is no such value,
+<> uses the value of <> (defined in `<>').
+
+If you don't need any particular prefix to the basename of temporary
+files, you can pass <> as the <[pfx]> argument to <>.
+
+<<_tmpnam_r>> and <<_tempnam_r>> are reentrant versions of <>
+and <> respectively. The extra argument <[reent]> is a
+pointer to a reentrancy structure.
+
+WARNINGS
+The generated filenames are suitable for temporary files, but do not
+in themselves make files temporary. Files with these names must still
+be explicitly removed when you no longer want them.
+
+If you supply your own data area <[s]> for <>, you must ensure
+that it has room for at least <> elements of type <>.
+
+RETURNS
+Both <> and <> return a pointer to the newly
+generated filename.
+
+PORTABILITY
+ANSI C requires <>, but does not specify the use of
+<>. The System V Interface Definition (Issue 2) requires
+both <> and <>.
+
+Supporting OS subroutines required: <>, <>, <>,
+<>, <>, <>, <>, <>, <>.
+
+The global pointer <> is also required.
+*/
+
+#include <_ansi.h>
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+/* Try to open the file specified, if it can't be opened then try
+ another one. Return nonzero if successful, otherwise zero. */
+
+static int
+_DEFUN(worker, (ptr, result, part1, part2, part3, part4),
+ struct _reent *ptr _AND
+ char *result _AND
+ _CONST char *part1 _AND
+ _CONST char *part2 _AND
+ int part3 _AND
+ int *part4)
+{
+ /* Generate the filename and make sure that there isn't one called
+ it already. */
+
+ while (1)
+ {
+ int t;
+ _sprintf_r (ptr, result, "%s/%s%x.%x", part1, part2, part3, *part4);
+ (*part4)++;
+ t = _open_r (ptr, result, O_RDONLY, 0);
+ if (t == -1)
+ {
+ if (ptr->_errno == ENOSYS)
+ {
+ result[0] = '\0';
+ return 0;
+ }
+ break;
+ }
+ _close_r (ptr, t);
+ }
+ return 1;
+}
+
+char *
+_DEFUN(_tmpnam_r, (p, s),
+ struct _reent *p _AND
+ char *s)
+{
+ char *result;
+ int pid;
+
+ if (s == NULL)
+ {
+ /* ANSI states we must use an internal static buffer if s is NULL */
+ _REENT_CHECK_EMERGENCY(p);
+ result = _REENT_EMERGENCY(p);
+ }
+ else
+ {
+ result = s;
+ }
+ pid = _getpid_r (p);
+
+ if (worker (p, result, P_tmpdir, "t", pid, &p->_inc))
+ {
+ p->_inc++;
+ return result;
+ }
+
+ return NULL;
+}
+
+char *
+_DEFUN(_tempnam_r, (p, dir, pfx),
+ struct _reent *p _AND
+ _CONST char *dir _AND
+ _CONST char *pfx)
+{
+ char *filename;
+ int length;
+ _CONST char *prefix = (pfx) ? pfx : "";
+ if (dir == NULL && (dir = getenv ("TMPDIR")) == NULL)
+ dir = P_tmpdir;
+
+ /* two 8 digit numbers + . / */
+ length = strlen (dir) + strlen (prefix) + (4 * sizeof (int)) + 2 + 1;
+
+ filename = _malloc_r (p, length);
+ if (filename)
+ {
+ if (! worker (p, filename, dir, prefix,
+ _getpid_r (p) ^ (int) (_POINTER_INT) p, &p->_inc))
+ return NULL;
+ }
+ return filename;
+}
+
+#ifndef _REENT_ONLY
+
+char *
+_DEFUN(tempnam, (dir, pfx),
+ _CONST char *dir _AND
+ _CONST char *pfx)
+{
+ return _tempnam_r (_REENT, dir, pfx);
+}
+
+char *
+_DEFUN(tmpnam, (s),
+ char *s)
+{
+ return _tmpnam_r (_REENT, s);
+}
+
+#endif
tmpnam.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: fputs.c
===================================================================
--- fputs.c (nonexistent)
+++ fputs.c (revision 520)
@@ -0,0 +1,106 @@
+/*
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by the University of California, Berkeley. The name of the
+ * University may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
+/*
+FUNCTION
+<>---write a character string in a file or stream
+
+INDEX
+ fputs
+INDEX
+ _fputs_r
+
+ANSI_SYNOPSIS
+ #include
+ int fputs(const char *<[s]>, FILE *<[fp]>);
+
+ #include
+ int _fputs_r(struct _reent *<[ptr]>, const char *<[s]>, FILE *<[fp]>);
+
+TRAD_SYNOPSIS
+ #include
+ int fputs(<[s]>, <[fp]>)
+ char *<[s]>;
+ FILE *<[fp]>;
+
+ #include
+ int _fputs_r(<[ptr]>, <[s]>, <[fp]>)
+ struct _reent *<[ptr]>;
+ char *<[s]>;
+ FILE *<[fp]>;
+
+DESCRIPTION
+<> writes the string at <[s]> (but without the trailing null)
+to the file or stream identified by <[fp]>.
+
+<<_fputs_r>> is simply the reentrant version of <> that takes
+an additional reentrant struct pointer argument: <[ptr]>.
+
+RETURNS
+If successful, the result is <<0>>; otherwise, the result is <>.
+
+PORTABILITY
+ANSI C requires <>, but does not specify that the result on
+success must be <<0>>; any non-negative value is permitted.
+
+Supporting OS subroutines required: <>, <>, <>,
+<>, <>, <>, <>.
+*/
+
+#include <_ansi.h>
+#include
+#include
+#include "fvwrite.h"
+#include "local.h"
+
+/*
+ * Write the given string to the given file.
+ */
+
+int
+_DEFUN(_fputs_r, (ptr, s, fp),
+ struct _reent * ptr _AND
+ char _CONST * s _AND
+ FILE * fp)
+{
+ int result;
+ struct __suio uio;
+ struct __siov iov;
+
+ iov.iov_base = s;
+ iov.iov_len = uio.uio_resid = strlen (s);
+ uio.uio_iov = &iov;
+ uio.uio_iovcnt = 1;
+
+ CHECK_INIT(ptr, fp);
+
+ _flockfile (fp);
+ ORIENT (fp, -1);
+ result = __sfvwrite_r (ptr, fp, &uio);
+ _funlockfile (fp);
+ return result;
+}
+
+#ifndef _REENT_ONLY
+int
+_DEFUN(fputs, (s, fp),
+ char _CONST * s _AND
+ FILE * fp)
+{
+ return _fputs_r (_REENT, s, fp);
+}
+#endif /* !_REENT_ONLY */
fputs.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: floatio.h
===================================================================
--- floatio.h (nonexistent)
+++ floatio.h (revision 520)
@@ -0,0 +1,32 @@
+/*
+ * 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.
+ *
+ * %W% (Berkeley) %G%
+ */
+
+/*
+ * Floating point scanf/printf (input/output) definitions.
+ */
+
+#ifdef _NO_LONGDBL
+/* 11-bit exponent (VAX G floating point) is 308 decimal digits */
+#define MAXEXP 308
+#else /* !_NO_LONGDBL */
+/* 15-bit exponent (Intel extended floating point) is 4932 decimal digits */
+#define MAXEXP 4932
+#endif /* !_NO_LONGDBL */
+/* 128 bit fraction takes up 39 decimal digits; max reasonable precision */
+#define MAXFRACT 39
floatio.h
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: wbuf.c
===================================================================
--- wbuf.c (nonexistent)
+++ wbuf.c (revision 520)
@@ -0,0 +1,100 @@
+/*
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by the University of California, Berkeley. The name of the
+ * University may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ */
+/* No user fns here. Pesch 15apr92. */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "%W% (Berkeley) %G%";
+#endif /* LIBC_SCCS and not lint */
+
+#include <_ansi.h>
+#include
+#include
+#include "local.h"
+#include "fvwrite.h"
+
+/*
+ * Write the given character into the (probably full) buffer for
+ * the given file. Flush the buffer out if it is or becomes full,
+ * or if c=='\n' and the file is line buffered.
+ */
+
+int
+_DEFUN(__swbuf_r, (ptr, c, fp),
+ struct _reent *ptr _AND
+ register int c _AND
+ register FILE *fp)
+{
+ register int n;
+
+ /* Ensure stdio has been initialized. */
+
+ CHECK_INIT (ptr, fp);
+
+ /*
+ * In case we cannot write, or longjmp takes us out early,
+ * make sure _w is 0 (if fully- or un-buffered) or -_bf._size
+ * (if line buffered) so that we will get called again.
+ * If we did not do this, a sufficient number of putc()
+ * calls might wrap _w from negative to positive.
+ */
+
+ fp->_w = fp->_lbfsize;
+ if (cantwrite (ptr, fp))
+ {
+ fp->_flags |= __SERR;
+ ptr->_errno = EBADF;
+ return EOF;
+ }
+ c = (unsigned char) c;
+
+ ORIENT (fp, -1);
+
+ /*
+ * If it is completely full, flush it out. Then, in any case,
+ * stuff c into the buffer. If this causes the buffer to fill
+ * completely, or if c is '\n' and the file is line buffered,
+ * flush it (perhaps a second time). The second flush will always
+ * happen on unbuffered streams, where _bf._size==1; fflush()
+ * guarantees that putc() will always call wbuf() by setting _w
+ * to 0, so we need not do anything else.
+ */
+
+ n = fp->_p - fp->_bf._base;
+ if (n >= fp->_bf._size)
+ {
+ if (_fflush_r (ptr, fp))
+ return EOF;
+ n = 0;
+ }
+ fp->_w--;
+ *fp->_p++ = c;
+ if (++n == fp->_bf._size || (fp->_flags & __SLBF && c == '\n'))
+ if (_fflush_r (ptr, fp))
+ return EOF;
+ return c;
+}
+
+/* This function isn't any longer declared in stdio.h, but it's
+ required for backward compatibility with applications built against
+ earlier dynamically built newlib libraries. */
+int
+_DEFUN(__swbuf, (c, fp),
+ register int c _AND
+ register FILE *fp)
+{
+ return __swbuf_r (_REENT, c, fp);
+}
swscanf.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: findfp.c
===================================================================
--- findfp.c (nonexistent)
+++ findfp.c (revision 520)
@@ -0,0 +1,294 @@
+/*
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by the University of California, Berkeley. The name of the
+ * University may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ */
+/* No user fns here. Pesch 15apr92. */
+
+#include <_ansi.h>
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include "local.h"
+
+#ifdef _REENT_SMALL
+const struct __sFILE_fake __sf_fake_stdin =
+ {_NULL, 0, 0, 0, 0, {_NULL, 0}, 0, _NULL};
+const struct __sFILE_fake __sf_fake_stdout =
+ {_NULL, 0, 0, 0, 0, {_NULL, 0}, 0, _NULL};
+const struct __sFILE_fake __sf_fake_stderr =
+ {_NULL, 0, 0, 0, 0, {_NULL, 0}, 0, _NULL};
+#endif
+
+static _VOID
+_DEFUN(std, (ptr, flags, file, data),
+ FILE *ptr _AND
+ int flags _AND
+ int file _AND
+ struct _reent *data)
+{
+ ptr->_p = 0;
+ ptr->_r = 0;
+ ptr->_w = 0;
+ ptr->_flags = flags;
+ ptr->_flags2 = 0;
+ ptr->_file = file;
+ ptr->_bf._base = 0;
+ ptr->_bf._size = 0;
+ ptr->_lbfsize = 0;
+ memset (&ptr->_mbstate, 0, sizeof (_mbstate_t));
+ ptr->_cookie = ptr;
+ ptr->_read = __sread;
+#ifndef __LARGE64_FILES
+ ptr->_write = __swrite;
+#else /* __LARGE64_FILES */
+ ptr->_write = __swrite64;
+ ptr->_seek64 = __sseek64;
+ ptr->_flags |= __SL64;
+#endif /* __LARGE64_FILES */
+ ptr->_seek = __sseek;
+ ptr->_close = __sclose;
+#if !defined(__SINGLE_THREAD__) && !defined(_REENT_SMALL)
+ __lock_init_recursive (ptr->_lock);
+ /*
+ * #else
+ * lock is already initialized in __sfp
+ */
+#endif
+
+#ifdef __SCLE
+ if (__stextmode (ptr->_file))
+ ptr->_flags |= __SCLE;
+#endif
+}
+
+struct _glue *
+_DEFUN(__sfmoreglue, (d, n),
+ struct _reent *d _AND
+ register int n)
+{
+ struct _glue *g;
+ FILE *p;
+
+ g = (struct _glue *) _malloc_r (d, sizeof (*g) + n * sizeof (FILE));
+ if (g == NULL)
+ return NULL;
+ p = (FILE *) (g + 1);
+ g->_next = NULL;
+ g->_niobs = n;
+ g->_iobs = p;
+ memset (p, 0, n * sizeof (FILE));
+ return g;
+}
+
+/*
+ * Find a free FILE for fopen et al.
+ */
+
+FILE *
+_DEFUN(__sfp, (d),
+ struct _reent *d)
+{
+ FILE *fp;
+ int n;
+ struct _glue *g;
+
+ __sfp_lock_acquire ();
+
+ if (!_GLOBAL_REENT->__sdidinit)
+ __sinit (_GLOBAL_REENT);
+ for (g = &_GLOBAL_REENT->__sglue;; g = g->_next)
+ {
+ for (fp = g->_iobs, n = g->_niobs; --n >= 0; fp++)
+ if (fp->_flags == 0)
+ goto found;
+ if (g->_next == NULL &&
+ (g->_next = __sfmoreglue (d, NDYNAMIC)) == NULL)
+ break;
+ }
+ __sfp_lock_release ();
+ d->_errno = ENOMEM;
+ return NULL;
+
+found:
+ fp->_file = -1; /* no file */
+ fp->_flags = 1; /* reserve this slot; caller sets real flags */
+ fp->_flags2 = 0;
+#ifndef __SINGLE_THREAD__
+ __lock_init_recursive (fp->_lock);
+#endif
+ __sfp_lock_release ();
+
+ fp->_p = NULL; /* no current pointer */
+ fp->_w = 0; /* nothing to read or write */
+ fp->_r = 0;
+ fp->_bf._base = NULL; /* no buffer */
+ fp->_bf._size = 0;
+ fp->_lbfsize = 0; /* not line buffered */
+ memset (&fp->_mbstate, 0, sizeof (_mbstate_t));
+ /* fp->_cookie = ; */ /* caller sets cookie, _read/_write etc */
+ fp->_ub._base = NULL; /* no ungetc buffer */
+ fp->_ub._size = 0;
+ fp->_lb._base = NULL; /* no line buffer */
+ fp->_lb._size = 0;
+
+ return fp;
+}
+
+/*
+ * exit() calls _cleanup() through *__cleanup, set whenever we
+ * open or buffer a file. This chicanery is done so that programs
+ * that do not use stdio need not link it all in.
+ *
+ * The name `_cleanup' is, alas, fairly well known outside stdio.
+ */
+
+_VOID
+_DEFUN(_cleanup_r, (ptr),
+ struct _reent *ptr)
+{
+ _CAST_VOID _fwalk(ptr, fclose);
+ /* _CAST_VOID _fwalk (ptr, fflush); */ /* `cheating' */
+}
+
+#ifndef _REENT_ONLY
+_VOID
+_DEFUN_VOID(_cleanup)
+{
+ _cleanup_r (_GLOBAL_REENT);
+}
+#endif
+
+/*
+ * __sinit() is called whenever stdio's internal variables must be set up.
+ */
+
+_VOID
+_DEFUN(__sinit, (s),
+ struct _reent *s)
+{
+ __sinit_lock_acquire ();
+
+ if (s->__sdidinit)
+ {
+ __sinit_lock_release ();
+ return;
+ }
+
+ /* make sure we clean up on exit */
+ s->__cleanup = _cleanup_r; /* conservative */
+ s->__sdidinit = 1;
+
+ s->__sglue._next = NULL;
+#ifndef _REENT_SMALL
+ s->__sglue._niobs = 3;
+ s->__sglue._iobs = &s->__sf[0];
+#else
+ s->__sglue._niobs = 0;
+ s->__sglue._iobs = NULL;
+ s->_stdin = __sfp(s);
+ s->_stdout = __sfp(s);
+ s->_stderr = __sfp(s);
+#endif
+
+ std (s->_stdin, __SRD, 0, s);
+
+ /* On platforms that have true file system I/O, we can verify
+ whether stdout is an interactive terminal or not, as part of
+ __smakebuf on first use of the stream. For all other platforms,
+ we will default to line buffered mode here. Technically, POSIX
+ requires both stdin and stdout to be line-buffered, but tradition
+ leaves stdin alone on systems without fcntl. */
+#ifdef HAVE_FCNTL
+ std (s->_stdout, __SWR, 1, s);
+#else
+ std (s->_stdout, __SWR | __SLBF, 1, s);
+#endif
+
+ /* POSIX requires stderr to be opened for reading and writing, even
+ when the underlying fd 2 is write-only. */
+ std (s->_stderr, __SRW | __SNBF, 2, s);
+
+ __sinit_lock_release ();
+}
+
+#ifndef __SINGLE_THREAD__
+
+__LOCK_INIT_RECURSIVE(static, __sfp_lock);
+__LOCK_INIT_RECURSIVE(static, __sinit_lock);
+
+_VOID
+_DEFUN_VOID(__sfp_lock_acquire)
+{
+ __lock_acquire_recursive (__sfp_lock);
+}
+
+_VOID
+_DEFUN_VOID(__sfp_lock_release)
+{
+ __lock_release_recursive (__sfp_lock);
+}
+
+_VOID
+_DEFUN_VOID(__sinit_lock_acquire)
+{
+ __lock_acquire_recursive (__sinit_lock);
+}
+
+_VOID
+_DEFUN_VOID(__sinit_lock_release)
+{
+ __lock_release_recursive (__sinit_lock);
+}
+
+/* Walkable file locking routine. */
+static int
+_DEFUN(__fp_lock, (ptr),
+ FILE * ptr)
+{
+ _flockfile (ptr);
+
+ return 0;
+}
+
+/* Walkable file unlocking routine. */
+static int
+_DEFUN(__fp_unlock, (ptr),
+ FILE * ptr)
+{
+ _funlockfile (ptr);
+
+ return 0;
+}
+
+_VOID
+_DEFUN_VOID(__fp_lock_all)
+{
+ __sfp_lock_acquire ();
+
+ _CAST_VOID _fwalk (_REENT, __fp_lock);
+}
+
+_VOID
+_DEFUN_VOID(__fp_unlock_all)
+{
+ _CAST_VOID _fwalk (_REENT, __fp_unlock);
+
+ __sfp_lock_release ();
+}
+#endif
findfp.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: vwscanf.c
===================================================================
--- vwscanf.c (nonexistent)
+++ vwscanf.c (revision 520)
@@ -0,0 +1,48 @@
+/*-
+ * Code created by modifying scanf.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
+#include
+#include
+#ifdef _HAVE_STDC
+#include
+#else
+#include
+#endif
+#include "local.h"
+
+#ifndef _REENT_ONLY
+
+int
+vwscanf (_CONST wchar_t *fmt, va_list ap)
+{
+ _REENT_SMALL_CHECK_INIT (_REENT);
+ return __svfwscanf_r (_REENT, _stdin_r (_REENT), fmt, ap);
+}
+
+#endif /* !_REENT_ONLY */
+
+int
+_vwscanf_r (struct _reent *ptr, _CONST wchar_t *fmt, va_list ap)
+{
+ _REENT_SMALL_CHECK_INIT (ptr);
+ return __svfwscanf_r (ptr, _stdin_r (ptr), fmt, ap);
+}
+
vwscanf.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: makebuf.c
===================================================================
--- makebuf.c (nonexistent)
+++ makebuf.c (revision 520)
@@ -0,0 +1,113 @@
+/*
+ * 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.
+ */
+/* No user fns here. Pesch 15apr92. */
+
+#include <_ansi.h>
+#include
+#include
+#include
+#include
+#include
+#include "local.h"
+
+#define _DEFAULT_ASPRINTF_BUFSIZE 64
+
+/*
+ * Allocate a file buffer, or switch to unbuffered I/O.
+ * Per the ANSI C standard, ALL tty devices default to line buffered.
+ *
+ * As a side effect, we set __SOPT or __SNPT (en/dis-able fseek
+ * optimization) right after the _fstat() that finds the buffer size.
+ */
+
+_VOID
+_DEFUN(__smakebuf_r, (ptr, fp),
+ 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
+
+ if (fp->_flags & __SNBF)
+ {
+ fp->_bf._base = fp->_p = fp->_nbuf;
+ 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;
+ /* do not try to optimise fseek() */
+ fp->_flags |= __SNPT;
+ }
+ 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
+ /*
+ * 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;
+ }
+ if ((p = _malloc_r (ptr, size)) == NULL)
+ {
+ if (!(fp->_flags & __SSTR))
+ {
+ fp->_flags |= __SNBF;
+ fp->_bf._base = fp->_p = fp->_nbuf;
+ fp->_bf._size = 1;
+ }
+ }
+ else
+ {
+ ptr->__cleanup = _cleanup_r;
+ fp->_flags |= __SMBF;
+ fp->_bf._base = fp->_p = (unsigned char *) p;
+ fp->_bf._size = size;
+ if (couldbetty && _isatty_r (ptr, fp->_file))
+ fp->_flags |= __SLBF;
+ }
+}
makebuf.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: fdopen.c
===================================================================
--- fdopen.c (nonexistent)
+++ fdopen.c (revision 520)
@@ -0,0 +1,144 @@
+/*
+ * 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
+<>---turn open file into a stream
+
+INDEX
+ fdopen
+INDEX
+ _fdopen_r
+
+ANSI_SYNOPSIS
+ #include
+ FILE *fdopen(int <[fd]>, const char *<[mode]>);
+ FILE *_fdopen_r(struct _reent *<[reent]>,
+ int <[fd]>, const char *<[mode]>);
+
+TRAD_SYNOPSIS
+ #include
+ FILE *fdopen(<[fd]>, <[mode]>)
+ int <[fd]>;
+ char *<[mode]>;
+
+ FILE *_fdopen_r(<[reent]>, <[fd]>, <[mode]>)
+ struct _reent *<[reent]>;
+ int <[fd]>;
+ char *<[mode]>);
+
+DESCRIPTION
+<> produces a file descriptor of type <>, from a
+descriptor for an already-open file (returned, for example, by the
+system subroutine <> rather than by <>).
+The <[mode]> argument has the same meanings as in <>.
+
+RETURNS
+File pointer or <>, as for <>.
+
+PORTABILITY
+<> is ANSI.
+*/
+
+#include <_ansi.h>
+#include
+#include
+#include
+#include
+#include
+#include "local.h"
+#include <_syslist.h>
+
+FILE *
+_DEFUN(_fdopen_r, (ptr, fd, mode),
+ struct _reent *ptr _AND
+ int fd _AND
+ _CONST char *mode)
+{
+ register FILE *fp;
+ int flags, oflags;
+#ifdef HAVE_FCNTL
+ int fdflags, fdmode;
+#endif
+
+ if ((flags = __sflags (ptr, mode, &oflags)) == 0)
+ return 0;
+
+ /* make sure the mode the user wants is a subset of the actual mode */
+#ifdef HAVE_FCNTL
+ if ((fdflags = _fcntl_r (ptr, fd, F_GETFL, 0)) < 0)
+ return 0;
+ fdmode = fdflags & O_ACCMODE;
+ if (fdmode != O_RDWR && (fdmode != (oflags & O_ACCMODE)))
+ {
+ ptr->_errno = EBADF;
+ return 0;
+ }
+#endif
+
+ if ((fp = __sfp (ptr)) == 0)
+ return 0;
+
+ _flockfile (fp);
+
+ fp->_flags = flags;
+ /* POSIX recommends setting the O_APPEND bit on fd to match append
+ streams. Someone may later clear O_APPEND on fileno(fp), but the
+ stream must still remain in append mode. Rely on __sflags
+ setting __SAPP properly. */
+#ifdef HAVE_FCNTL
+ if ((oflags & O_APPEND) && !(fdflags & O_APPEND))
+ _fcntl_r (ptr, fd, F_SETFL, fdflags | O_APPEND);
+#endif
+ fp->_file = fd;
+ fp->_cookie = (_PTR) fp;
+
+#undef _read
+#undef _write
+#undef _seek
+#undef _close
+
+ fp->_read = __sread;
+ fp->_write = __swrite;
+ fp->_seek = __sseek;
+ fp->_close = __sclose;
+
+#ifdef __SCLE
+ /* Explicit given mode results in explicit setting mode on fd */
+ if (oflags & O_BINARY)
+ setmode (fp->_file, O_BINARY);
+ else if (oflags & O_TEXT)
+ setmode (fp->_file, O_TEXT);
+ if (__stextmode (fp->_file))
+ fp->_flags |= __SCLE;
+#endif
+
+ _funlockfile (fp);
+ return fp;
+}
+
+#ifndef _REENT_ONLY
+
+FILE *
+_DEFUN(fdopen, (fd, mode),
+ int fd _AND
+ _CONST char *mode)
+{
+ return _fdopen_r (_REENT, fd, mode);
+}
+
+#endif
fdopen.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: putc.c
===================================================================
--- putc.c (nonexistent)
+++ putc.c (revision 520)
@@ -0,0 +1,124 @@
+/*
+ * 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
+<>---write a character (macro)
+
+INDEX
+ putc
+INDEX
+ _putc_r
+
+ANSI_SYNOPSIS
+ #include
+ int putc(int <[ch]>, FILE *<[fp]>);
+
+ #include
+ int _putc_r(struct _reent *<[ptr]>, int <[ch]>, FILE *<[fp]>);
+
+TRAD_SYNOPSIS
+ #include
+ int putc(<[ch]>, <[fp]>)
+ int <[ch]>;
+ FILE *<[fp]>;
+
+ #include
+ int _putc_r(<[ptr]>, <[ch]>, <[fp]>)
+ struct _reent *<[ptr]>;
+ int <[ch]>;
+ FILE *<[fp]>;
+
+DESCRIPTION
+<> is a macro, defined in <>. <>
+writes the argument <[ch]> to the file or stream identified by
+<[fp]>, after converting it from an <> to an <>.
+
+If the file was opened with append mode (or if the stream cannot
+support positioning), then the new character goes at the end of the
+file or stream. Otherwise, the new character is written at the
+current value of the position indicator, and the position indicator
+advances by one.
+
+For a subroutine version of this macro, see <>.
+
+The <<_putc_r>> function is simply the reentrant version of
+<> that takes an additional reentrant structure argument: <[ptr]>.
+
+RETURNS
+If successful, <> returns its argument <[ch]>. If an error
+intervenes, the result is <>. You can use `<)>>' to
+query for errors.
+
+PORTABILITY
+ANSI C requires <>; it suggests, but does not require, that
+<> be implemented as a macro. The standard explicitly permits
+macro implementations of <> to use the <[fp]> argument more than once;
+therefore, in a portable program, you should not use an expression
+with side effects as this argument.
+
+Supporting OS subroutines required: <>, <>, <>,
+<>, <>, <>, <>.
+*/
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "%W% (Berkeley) %G%";
+#endif /* LIBC_SCCS and not lint */
+
+#include <_ansi.h>
+#include
+#include "local.h"
+
+/*
+ * A subroutine version of the macro putc.
+ */
+
+#undef putc
+
+int
+_DEFUN(_putc_r, (ptr, c, fp),
+ struct _reent *ptr _AND
+ int c _AND
+ register FILE *fp)
+{
+ int result;
+ CHECK_INIT (ptr, fp);
+ _flockfile (fp);
+ result = __sputc_r (ptr, c, fp);
+ _funlockfile (fp);
+ return result;
+}
+
+#ifndef _REENT_ONLY
+int
+_DEFUN(putc, (c, fp),
+ int c _AND
+ register FILE *fp)
+{
+#if !defined(PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__)
+ int result;
+ CHECK_INIT (_REENT, fp);
+ _flockfile (fp);
+ result = __sputc_r (_REENT, c, fp);
+ _funlockfile (fp);
+ return result;
+#else
+ return _putc_r (_REENT, c, fp);
+#endif
+}
+#endif /* !_REENT_ONLY */
+
putc.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: fseeko.c
===================================================================
--- fseeko.c (nonexistent)
+++ fseeko.c (revision 520)
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2002, Red Hat Inc.
+ * 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
+#include
+
+int
+_DEFUN(_fseeko_r, (ptr, fp, offset, whence),
+ struct _reent *ptr _AND
+ register FILE *fp _AND
+ _off_t offset _AND
+ int whence)
+{
+ return _fseek_r (ptr, fp, (long)offset, whence);
+}
+
+#ifndef _REENT_ONLY
+
+int
+_DEFUN(fseeko, (fp, offset, whence),
+ register FILE *fp _AND
+ _off_t offset _AND
+ int whence)
+{
+ /* for now we simply cast since off_t should be long */
+ return _fseek_r (_REENT, fp, (long)offset, whence);
+}
+
+#endif /* !_REENT_ONLY */
fseeko.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: fileno.c
===================================================================
--- fileno.c (nonexistent)
+++ fileno.c (revision 520)
@@ -0,0 +1,62 @@
+/*
+ * 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
+<>---return file descriptor associated with stream
+
+INDEX
+ fileno
+
+ANSI_SYNOPSIS
+ #include
+ int fileno(FILE *<[fp]>);
+
+TRAD_SYNOPSIS
+ #include
+ int fileno(<[fp]>)
+ FILE *<[fp]>;
+
+DESCRIPTION
+You can use <> to return the file descriptor identified by <[fp]>.
+
+RETURNS
+<> returns a non-negative integer when successful.
+If <[fp]> is not an open stream, <> returns -1.
+
+PORTABILITY
+<> is not part of ANSI C.
+POSIX requires <>.
+
+Supporting OS subroutines required: none.
+*/
+
+#include <_ansi.h>
+#include
+#include "local.h"
+
+int
+_DEFUN(fileno, (f),
+ FILE * f)
+{
+ int result;
+ CHECK_INIT (_REENT, f);
+ _flockfile (f);
+ result = __sfileno (f);
+ _funlockfile (f);
+ return result;
+}
fileno.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: sniprintf.c
===================================================================
--- sniprintf.c (nonexistent)
+++ sniprintf.c (revision 520)
@@ -0,0 +1,120 @@
+/*
+ * Copyright (c) 1990, 2007 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by the University of California, Berkeley. The name of the
+ * University may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
+/* This code created by modifying snprintf.c so copyright inherited. */
+/* doc in siprintf.c */
+
+#include <_ansi.h>
+#include
+#include
+#ifdef _HAVE_STDC
+#include
+#else
+#include
+#endif
+#include
+#include
+#include "local.h"
+
+int
+#ifdef _HAVE_STDC
+_DEFUN (_sniprintf_r, (ptr, str, size, fmt),
+ struct _reent *ptr _AND
+ char *str _AND
+ size_t size _AND
+ _CONST char *fmt _DOTS)
+#else
+_sniprintf_r (ptr, str, size, fmt, va_alist)
+ struct _reent *ptr;
+ char *str;
+ size_t size;
+ _CONST char *fmt;
+ va_dcl
+#endif
+{
+ int ret;
+ va_list ap;
+ FILE f;
+
+ if (size > INT_MAX)
+ {
+ ptr->_errno = EOVERFLOW;
+ return EOF;
+ }
+ f._flags = __SWR | __SSTR;
+ f._bf._base = f._p = (unsigned char *) str;
+ f._bf._size = f._w = (size > 0 ? size - 1 : 0);
+ f._file = -1; /* No file. */
+#ifdef _HAVE_STDC
+ va_start (ap, fmt);
+#else
+ va_start (ap);
+#endif
+ ret = _svfiprintf_r (ptr, &f, fmt, ap);
+ va_end (ap);
+ if (ret < EOF)
+ ptr->_errno = EOVERFLOW;
+ if (size > 0)
+ *f._p = 0;
+ return (ret);
+}
+
+#ifndef _REENT_ONLY
+
+int
+#ifdef _HAVE_STDC
+_DEFUN (sniprintf, (str, size, fmt),
+ char *str _AND
+ size_t size _AND
+ _CONST char *fmt _DOTS)
+#else
+sniprintf (str, size, fmt, va_alist)
+ char *str;
+ size_t size;
+ _CONST char *fmt;
+ va_dcl
+#endif
+{
+ int ret;
+ va_list ap;
+ FILE f;
+ struct _reent *ptr = _REENT;
+
+ if (size > INT_MAX)
+ {
+ ptr->_errno = EOVERFLOW;
+ return EOF;
+ }
+ f._flags = __SWR | __SSTR;
+ f._bf._base = f._p = (unsigned char *) str;
+ f._bf._size = f._w = (size > 0 ? size - 1 : 0);
+ f._file = -1; /* No file. */
+#ifdef _HAVE_STDC
+ va_start (ap, fmt);
+#else
+ va_start (ap);
+#endif
+ ret = _svfiprintf_r (ptr, &f, fmt, ap);
+ va_end (ap);
+ if (ret < EOF)
+ ptr->_errno = EOVERFLOW;
+ if (size > 0)
+ *f._p = 0;
+ return (ret);
+}
+
+#endif
sscanf.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: setvbuf.c
===================================================================
--- setvbuf.c (nonexistent)
+++ setvbuf.c (revision 520)
@@ -0,0 +1,198 @@
+/*
+ * 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
+<>---specify file or stream buffering
+
+INDEX
+ setvbuf
+
+ANSI_SYNOPSIS
+ #include
+ int setvbuf(FILE *<[fp]>, char *<[buf]>,
+ int <[mode]>, size_t <[size]>);
+
+TRAD_SYNOPSIS
+ #include
+ int setvbuf(<[fp]>, <[buf]>, <[mode]>, <[size]>)
+ FILE *<[fp]>;
+ char *<[buf]>;
+ int <[mode]>;
+ size_t <[size]>;
+
+DESCRIPTION
+Use <> to specify what kind of buffering you want for the
+file or stream identified by <[fp]>, by using one of the following
+values (from <>) as the <[mode]> argument:
+
+o+
+o _IONBF
+Do not use a buffer: send output directly to the host system for the
+file or stream identified by <[fp]>.
+
+o _IOFBF
+Use full output buffering: output will be passed on to the host system
+only when the buffer is full, or when an input operation intervenes.
+
+o _IOLBF
+Use line buffering: pass on output to the host system at every
+newline, as well as when the buffer is full, or when an input
+operation intervenes.
+o-
+
+Use the <[size]> argument to specify how large a buffer you wish. You
+can supply the buffer itself, if you wish, by passing a pointer to a
+suitable area of memory as <[buf]>. Otherwise, you may pass <>
+as the <[buf]> argument, and <> will allocate the buffer.
+
+WARNINGS
+You may only use <> 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
+A <<0>> result indicates success, <> failure (invalid <[mode]> or
+<[size]> can cause failure).
+
+PORTABILITY
+Both ANSI C and the System V Interface Definition (Issue 2) require
+<>. However, they differ on the meaning of a <> buffer
+pointer: the SVID issue 2 specification says that a <> buffer
+pointer requests unbuffered output. For maximum portability, avoid
+<> buffer pointers.
+
+Both specifications describe the result on failure only as a
+nonzero value.
+
+Supporting OS subroutines required: <>, <>, <>,
+<>, <>, <>, <>.
+*/
+
+#include <_ansi.h>
+#include
+#include
+#include "local.h"
+
+/*
+ * Set one of the three kinds of buffering, optionally including a buffer.
+ */
+
+int
+_DEFUN(setvbuf, (fp, buf, mode, size),
+ register FILE * fp _AND
+ char *buf _AND
+ register int mode _AND
+ register size_t size)
+{
+ int ret = 0;
+
+ CHECK_INIT (_REENT, fp);
+
+ _flockfile (fp);
+
+ /*
+ * Verify arguments. The `int' limit on `size' is due to this
+ * particular implementation.
+ */
+
+ if ((mode != _IOFBF && mode != _IOLBF && mode != _IONBF) || (int)(_POINTER_INT) size < 0)
+ {
+ _funlockfile (fp);
+ return (EOF);
+ }
+
+ /*
+ * Write current buffer, if any; drop read count, if any.
+ * Make sure putc() will not think fp is line buffered.
+ * Free old buffer if it was from malloc(). Clear line and
+ * non buffer flags, and clear malloc flag.
+ */
+
+ _fflush_r (_REENT, fp);
+ fp->_r = 0;
+ fp->_lbfsize = 0;
+ if (fp->_flags & __SMBF)
+ _free_r (_REENT, (_PTR) fp->_bf._base);
+ fp->_flags &= ~(__SLBF | __SNBF | __SMBF);
+
+ if (mode == _IONBF)
+ goto nbf;
+
+ /*
+ * 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)
+ {
+ ret = EOF;
+ /* Try another size... */
+ buf = malloc (BUFSIZ);
+ size = BUFSIZ;
+ }
+ if (buf == NULL)
+ {
+ /* Can't allocate it, let's try another approach */
+nbf:
+ fp->_flags |= __SNBF;
+ fp->_w = 0;
+ fp->_bf._base = fp->_p = fp->_nbuf;
+ fp->_bf._size = 1;
+ _funlockfile (fp);
+ return (ret);
+ }
+ 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
+ */
+
+ switch (mode)
+ {
+ case _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;
+ }
+
+ /*
+ * Patch up write count if necessary.
+ */
+
+ if (fp->_flags & __SWR)
+ fp->_w = fp->_flags & (__SLBF | __SNBF) ? 0 : size;
+
+ _funlockfile (fp);
+ return 0;
+}
setvbuf.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: fgetwc.c
===================================================================
--- fgetwc.c (nonexistent)
+++ fgetwc.c (revision 520)
@@ -0,0 +1,182 @@
+/*-
+ * Copyright (c) 2002-2004 Tim J. Robbins.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+FUNCTION
+<>, <>---get a wide character from a file or stream
+
+INDEX
+ fgetwc
+INDEX
+ _fgetwc_r
+INDEX
+ getwc
+INDEX
+ _getwc_r
+
+ANSI_SYNOPSIS
+ #include
+ #include
+ wint_t fgetwc(FILE *<[fp]>);
+
+ #include
+ #include
+ wint_t _fgetwc_r(struct _reent *<[ptr]>, FILE *<[fp]>);
+
+ #include
+ #include
+ wint_t getwc(FILE *<[fp]>);
+
+ #include
+ #include
+ wint_t _getwc_r(struct _reent *<[ptr]>, FILE *<[fp]>);
+
+TRAD_SYNOPSIS
+ #include
+ #include
+ wint_t fgetwc(<[fp]>)
+ FILE *<[fp]>;
+
+ #include
+ #include
+ wint_t _fgetwc_r(<[ptr]>, <[fp]>)
+ struct _reent *<[ptr]>;
+ FILE *<[fp]>;
+
+ #include
+ #include
+ wint_t getwc(<[fp]>)
+ FILE *<[fp]>;
+
+ #include
+ #include
+ wint_t _getwc_r(<[ptr]>, <[fp]>)
+ struct _reent *<[ptr]>;
+ FILE *<[fp]>;
+
+DESCRIPTION
+Use <> to get the next wide character from the file or stream
+identified by <[fp]>. As a side effect, <> advances the file's
+current position indicator.
+
+The <> function or macro functions identically to <>. It
+may be implemented as a macro, and may evaluate its argument more than
+once. There is no reason ever to use it.
+
+<<_fgetwc_r>> and <<_getwc_r>> are simply reentrant versions of
+<> and <> that are passed the additional reentrant
+structure pointer argument: <[ptr]>.
+
+RETURNS
+The next wide character cast to <>), unless there is no more data,
+or the host system reports a read error; in either of these situations,
+<> and <> return <>.
+
+You can distinguish the two situations that cause an <> result by
+using the <> and <> functions.
+
+PORTABILITY
+C99, POSIX.1-2001
+*/
+
+#include <_ansi.h>
+#include
+#include
+#include
+#include
+#include
+#include "local.h"
+
+static wint_t
+_DEFUN(__fgetwc, (ptr, fp),
+ struct _reent *ptr _AND
+ register FILE *fp)
+{
+ wchar_t wc;
+ size_t nconv;
+
+ if (fp->_r <= 0 && __srefill_r (ptr, fp))
+ return (WEOF);
+ if (MB_CUR_MAX == 1)
+ {
+ /* Fast path for single-byte encodings. */
+ wc = *fp->_p++;
+ fp->_r--;
+ return (wc);
+ }
+ do
+ {
+ nconv = _mbrtowc_r (ptr, &wc, (char *) fp->_p, fp->_r, &fp->_mbstate);
+ if (nconv == (size_t)-1)
+ break;
+ else if (nconv == (size_t)-2)
+ continue;
+ else if (nconv == 0)
+ {
+ /*
+ * Assume that the only valid representation of
+ * the null wide character is a single null byte.
+ */
+ fp->_p++;
+ fp->_r--;
+ return (L'\0');
+ }
+ else
+ {
+ fp->_p += nconv;
+ fp->_r -= nconv;
+ return (wc);
+ }
+ }
+ while (__srefill_r(ptr, fp) == 0);
+ fp->_flags |= __SERR;
+ errno = EILSEQ;
+ return (WEOF);
+}
+
+wint_t
+_DEFUN(_fgetwc_r, (ptr, fp),
+ struct _reent *ptr _AND
+ register FILE *fp)
+{
+ wint_t r;
+
+ __sfp_lock_acquire ();
+ _flockfile (fp);
+ ORIENT(fp, 1);
+ r = __fgetwc (ptr, fp);
+ _funlockfile (fp);
+ __sfp_lock_release ();
+ return r;
+}
+
+wint_t
+_DEFUN(fgetwc, (fp),
+ FILE *fp)
+{
+ CHECK_INIT(_REENT, fp);
+ return _fgetwc_r (_REENT, fp);
+}
fgetwc.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: ungetc.c
===================================================================
--- ungetc.c (nonexistent)
+++ ungetc.c (revision 520)
@@ -0,0 +1,217 @@
+/*
+ * 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
+<>---push data back into a stream
+
+INDEX
+ ungetc
+INDEX
+ _ungetc_r
+
+ANSI_SYNOPSIS
+ #include
+ int ungetc(int <[c]>, FILE *<[stream]>);
+
+ int _ungetc_r(struct _reent *<[reent]>, int <[c]>, FILE *<[stream]>);
+
+DESCRIPTION
+<> is used to return bytes back to <[stream]> to be read again.
+If <[c]> is EOF, the stream is unchanged. Otherwise, the unsigned
+char <[c]> is put back on the stream, and subsequent reads will see
+the bytes pushed back in reverse order. Pushed byes are lost if the
+stream is repositioned, such as by <>, <>, or
+<>.
+
+The underlying file is not changed, but it is possible to push back
+something different than what was originally read. Ungetting a
+character will clear the end-of-stream marker, and decrement the file
+position indicator. Pushing back beyond the beginning of a file gives
+unspecified behavior.
+
+The alternate function <<_ungetc_r>> is a reentrant version. The
+extra argument <[reent]> is a pointer to a reentrancy structure.
+
+RETURNS
+The character pushed back, or <> on error.
+
+PORTABILITY
+ANSI C requires <>, but only requires a pushback buffer of one
+byte; although this implementation can handle multiple bytes, not all
+can. Pushing back a signed char is a common application bug.
+
+Supporting OS subroutines required: <>.
+*/
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "%W% (Berkeley) %G%";
+#endif /* LIBC_SCCS and not lint */
+
+#include <_ansi.h>
+#include
+#include
+#include
+#include
+#include "local.h"
+
+/*
+ * Expand the ungetc buffer `in place'. That is, adjust fp->_p when
+ * the buffer moves, so that it points the same distance from the end,
+ * and move the bytes in the buffer around as necessary so that they
+ * are all at the end (stack-style).
+ */
+
+/*static*/
+int
+_DEFUN(__submore, (rptr, fp),
+ struct _reent *rptr _AND
+ register FILE *fp)
+{
+ register int i;
+ register unsigned char *p;
+
+ if (fp->_ub._base == fp->_ubuf)
+ {
+ /*
+ * Get a new buffer (rather than expanding the old one).
+ */
+ if ((p = (unsigned char *) _malloc_r (rptr, (size_t) BUFSIZ)) == NULL)
+ return EOF;
+ fp->_ub._base = p;
+ fp->_ub._size = BUFSIZ;
+ p += BUFSIZ - sizeof (fp->_ubuf);
+ for (i = sizeof (fp->_ubuf); --i >= 0;)
+ p[i] = fp->_ubuf[i];
+ fp->_p = p;
+ return 0;
+ }
+ i = fp->_ub._size;
+ p = (unsigned char *) _realloc_r (rptr, (_PTR) (fp->_ub._base), i << 1);
+ if (p == NULL)
+ return EOF;
+ _CAST_VOID memcpy ((_PTR) (p + i), (_PTR) p, (size_t) i);
+ fp->_p = p + i;
+ fp->_ub._base = p;
+ fp->_ub._size = i << 1;
+ return 0;
+}
+
+int
+_DEFUN(_ungetc_r, (rptr, c, fp),
+ struct _reent *rptr _AND
+ int c _AND
+ register FILE *fp)
+{
+ if (c == EOF)
+ return (EOF);
+
+ /* Ensure stdio has been initialized.
+ ??? Might be able to remove this as some other stdio routine should
+ have already been called to get the char we are un-getting. */
+
+ CHECK_INIT (rptr, fp);
+
+ _flockfile (fp);
+
+ ORIENT (fp, -1);
+
+ /* After ungetc, we won't be at eof anymore */
+ fp->_flags &= ~__SEOF;
+
+ if ((fp->_flags & __SRD) == 0)
+ {
+ /*
+ * Not already reading: no good unless reading-and-writing.
+ * Otherwise, flush any current write stuff.
+ */
+ if ((fp->_flags & __SRW) == 0)
+ {
+ _funlockfile (fp);
+ return EOF;
+ }
+ if (fp->_flags & __SWR)
+ {
+ if (_fflush_r (rptr, fp))
+ {
+ _funlockfile (fp);
+ return EOF;
+ }
+ fp->_flags &= ~__SWR;
+ fp->_w = 0;
+ fp->_lbfsize = 0;
+ }
+ fp->_flags |= __SRD;
+ }
+ c = (unsigned char) c;
+
+ /*
+ * If we are in the middle of ungetc'ing, just continue.
+ * This may require expanding the current ungetc buffer.
+ */
+
+ if (HASUB (fp))
+ {
+ if (fp->_r >= fp->_ub._size && __submore (rptr, fp))
+ {
+ _funlockfile (fp);
+ return EOF;
+ }
+ *--fp->_p = c;
+ fp->_r++;
+ _funlockfile (fp);
+ return c;
+ }
+
+ /*
+ * If we can handle this by simply backing up, do so,
+ * but never replace the original character.
+ * (This makes sscanf() work when scanning `const' data.)
+ */
+
+ if (fp->_bf._base != NULL && fp->_p > fp->_bf._base && fp->_p[-1] == c)
+ {
+ fp->_p--;
+ fp->_r++;
+ _funlockfile (fp);
+ return c;
+ }
+
+ /*
+ * Create an ungetc buffer.
+ * Initially, we will use the `reserve' buffer.
+ */
+
+ fp->_ur = fp->_r;
+ fp->_up = fp->_p;
+ fp->_ub._base = fp->_ubuf;
+ fp->_ub._size = sizeof (fp->_ubuf);
+ fp->_ubuf[sizeof (fp->_ubuf) - 1] = c;
+ fp->_p = &fp->_ubuf[sizeof (fp->_ubuf) - 1];
+ fp->_r = 1;
+ _funlockfile (fp);
+ return c;
+}
+
+#ifndef _REENT_ONLY
+int
+_DEFUN(ungetc, (c, fp),
+ int c _AND
+ register FILE *fp)
+{
+ return _ungetc_r (_REENT, c, fp);
+}
+#endif /* !_REENT_ONLY */
ungetc.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: vfscanf.c
===================================================================
--- vfscanf.c (nonexistent)
+++ vfscanf.c (revision 520)
@@ -0,0 +1,1611 @@
+/*-
+ * 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
+<>, <>, <>---format argument list
+
+INDEX
+ vfscanf
+INDEX
+ _vfscanf_r
+INDEX
+ vscanf
+INDEX
+ _vscanf_r
+INDEX
+ vsscanf
+INDEX
+ _vsscanf_r
+
+ANSI_SYNOPSIS
+ #include
+ #include
+ int vscanf(const char *<[fmt]>, va_list <[list]>);
+ int vfscanf(FILE *<[fp]>, const char *<[fmt]>, va_list <[list]>);
+ int vsscanf(const char *<[str]>, const char *<[fmt]>, va_list <[list]>);
+
+ int _vscanf_r(struct _reent *<[reent]>, const char *<[fmt]>,
+ va_list <[list]>);
+ int _vfscanf_r(struct _reent *<[reent]>, FILE *<[fp]>, const char *<[fmt]>,
+ va_list <[list]>);
+ int _vsscanf_r(struct _reent *<[reent]>, const char *<[str]>,
+ const char *<[fmt]>, va_list <[list]>);
+
+TRAD_SYNOPSIS
+ #include
+ #include
+ int vscanf( <[fmt]>, <[ist]>)
+ char *<[fmt]>;
+ va_list <[list]>;
+
+ int vfscanf( <[fp]>, <[fmt]>, <[list]>)
+ FILE *<[fp]>;
+ char *<[fmt]>;
+ va_list <[list]>;
+
+ int vsscanf( <[str]>, <[fmt]>, <[list]>)
+ char *<[str]>;
+ char *<[fmt]>;
+ va_list <[list]>;
+
+ int _vscanf_r( <[reent]>, <[fmt]>, <[ist]>)
+ struct _reent *<[reent]>;
+ char *<[fmt]>;
+ va_list <[list]>;
+
+ int _vfscanf_r( <[reent]>, <[fp]>, <[fmt]>, <[list]>)
+ struct _reent *<[reent]>;
+ FILE *<[fp]>;
+ char *<[fmt]>;
+ va_list <[list]>;
+
+ int _vsscanf_r( <[reent]>, <[str]>, <[fmt]>, <[list]>)
+ struct _reent *<[reent]>;
+ char *<[str]>;
+ char *<[fmt]>;
+ va_list <[list]>;
+
+DESCRIPTION
+<>, <>, and <> are (respectively) variants
+of <>, <>, and <>. They differ only in
+allowing their caller to pass the variable argument list as a
+<> object (initialized by <>) rather than
+directly accepting a variable number of arguments.
+
+RETURNS
+The return values are consistent with the corresponding functions:
+<> returns the number of input fields successfully scanned,
+converted, and stored; the return value does not include scanned
+fields which were not stored.
+
+If <> attempts to read at end-of-file, the return value
+is <>.
+
+If no fields were stored, the return value is <<0>>.
+
+The routines <<_vscanf_r>>, <<_vfscanf_f>>, and <<_vsscanf_r>> are
+reentrant versions which take an additional first parameter which points to the
+reentrancy structure.
+
+PORTABILITY
+These are GNU extensions.
+
+Supporting OS subroutines required:
+*/
+
+#include <_ansi.h>
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include "local.h"
+#include "../stdlib/local.h"
+
+#ifdef INTEGER_ONLY
+#define VFSCANF vfiscanf
+#define _VFSCANF_R _vfiscanf_r
+#define __SVFSCANF __svfiscanf
+#ifdef STRING_ONLY
+# define __SVFSCANF_R __ssvfiscanf_r
+#else
+# define __SVFSCANF_R __svfiscanf_r
+#endif
+#else
+#define VFSCANF vfscanf
+#define _VFSCANF_R _vfscanf_r
+#define __SVFSCANF __svfscanf
+#ifdef STRING_ONLY
+# define __SVFSCANF_R __ssvfscanf_r
+#else
+# define __SVFSCANF_R __svfscanf_r
+#endif
+#ifndef NO_FLOATING_POINT
+#define FLOATING_POINT
+#endif
+#endif
+
+#ifdef STRING_ONLY
+#undef _flockfile
+#undef _funlockfile
+#define _flockfile(x) {}
+#define _funlockfile(x) {}
+#define _ungetc_r _sungetc_r
+#define __srefill_r __ssrefill_r
+#define _fread_r _sfread_r
+#endif
+
+#ifdef FLOATING_POINT
+#include
+#include
+
+/* Currently a test is made to see if long double processing is warranted.
+ This could be changed in the future should the _ldtoa_r code be
+ preferred over _dtoa_r. */
+#define _NO_LONGDBL
+#if defined _WANT_IO_LONG_DOUBLE && (LDBL_MANT_DIG > DBL_MANT_DIG)
+#undef _NO_LONGDBL
+extern _LONG_DOUBLE _strtold _PARAMS((char *s, char **sptr));
+#endif
+
+#include "floatio.h"
+
+#if ((MAXEXP+MAXFRACT+3) > MB_LEN_MAX)
+# define BUF (MAXEXP+MAXFRACT+3) /* 3 = sign + decimal point + NUL */
+#else
+# define BUF MB_LEN_MAX
+#endif
+
+/* An upper bound for how long a long prints in decimal. 4 / 13 approximates
+ log (2). Add one char for roundoff compensation and one for the sign. */
+#define MAX_LONG_LEN ((CHAR_BIT * sizeof (long) - 1) * 4 / 13 + 2)
+#else
+#define BUF 40
+#endif
+
+#define _NO_LONGLONG
+#if defined _WANT_IO_LONG_LONG \
+ && (defined __GNUC__ || __STDC_VERSION__ >= 199901L)
+# undef _NO_LONGLONG
+#endif
+
+#define _NO_POS_ARGS
+#ifdef _WANT_IO_POS_ARGS
+# undef _NO_POS_ARGS
+# ifdef NL_ARGMAX
+# define MAX_POS_ARGS NL_ARGMAX
+# else
+# define MAX_POS_ARGS 32
+# endif
+
+static void * get_arg (int, va_list *, int *, void **);
+#endif /* _WANT_IO_POS_ARGS */
+
+/*
+ * Flags used during conversion.
+ */
+
+#define LONG 0x01 /* l: long or double */
+#define LONGDBL 0x02 /* L/ll: long double or long long */
+#define SHORT 0x04 /* h: short */
+#define CHAR 0x08 /* hh: 8 bit integer */
+#define SUPPRESS 0x10 /* suppress assignment */
+#define POINTER 0x20 /* weird %p pointer (`fake hex') */
+#define NOSKIP 0x40 /* do not skip blanks */
+
+/*
+ * The following are used in numeric conversions only:
+ * SIGNOK, NDIGITS, DPTOK, and EXPOK are for floating point;
+ * SIGNOK, NDIGITS, PFXOK, and NZDIGITS are for integral.
+ */
+
+#define SIGNOK 0x80 /* +/- is (still) legal */
+#define NDIGITS 0x100 /* no digits detected */
+
+#define DPTOK 0x200 /* (float) decimal point is still legal */
+#define EXPOK 0x400 /* (float) exponent (e+3, etc) still legal */
+
+#define PFXOK 0x200 /* 0x prefix is (still) legal */
+#define NZDIGITS 0x400 /* no zero digits detected */
+#define NNZDIGITS 0x800 /* no non-zero digits detected */
+
+/*
+ * Conversion types.
+ */
+
+#define CT_CHAR 0 /* %c conversion */
+#define CT_CCL 1 /* %[...] conversion */
+#define CT_STRING 2 /* %s conversion */
+#define CT_INT 3 /* integer, i.e., strtol or strtoul */
+#define CT_FLOAT 4 /* floating, i.e., strtod */
+
+#if 0
+#define u_char unsigned char
+#endif
+#define u_char char
+#define u_long unsigned long
+
+#ifndef _NO_LONGLONG
+typedef unsigned long long u_long_long;
+#endif
+
+/*
+ * vfscanf
+ */
+
+#define BufferEmpty (fp->_r <= 0 && __srefill_r(rptr, fp))
+
+#ifndef STRING_ONLY
+
+#ifndef _REENT_ONLY
+
+int
+_DEFUN(VFSCANF, (fp, fmt, ap),
+ register FILE *fp _AND
+ _CONST char *fmt _AND
+ va_list ap)
+{
+ CHECK_INIT(_REENT, fp);
+ return __SVFSCANF_R (_REENT, fp, fmt, ap);
+}
+
+int
+_DEFUN(__SVFSCANF, (fp, fmt0, ap),
+ register FILE *fp _AND
+ char _CONST *fmt0 _AND
+ va_list ap)
+{
+ return __SVFSCANF_R (_REENT, fp, fmt0, ap);
+}
+
+#endif /* !_REENT_ONLY */
+
+int
+_DEFUN(_VFSCANF_R, (data, fp, fmt, ap),
+ struct _reent *data _AND
+ register FILE *fp _AND
+ _CONST char *fmt _AND
+ va_list ap)
+{
+ CHECK_INIT(data, fp);
+ return __SVFSCANF_R (data, fp, fmt, ap);
+}
+#endif /* !STRING_ONLY */
+
+#if defined (STRING_ONLY) && defined (INTEGER_ONLY)
+/* When dealing with the sscanf family, we don't want to use the
+ * regular ungetc which will drag in file I/O items we don't need.
+ * So, we create our own trimmed-down version. */
+int
+_DEFUN(_sungetc_r, (data, fp, ch),
+ struct _reent *data _AND
+ int c _AND
+ register FILE *fp)
+{
+ if (c == EOF)
+ return (EOF);
+
+ /* After ungetc, we won't be at eof anymore */
+ fp->_flags &= ~__SEOF;
+ c = (unsigned char) c;
+
+ /*
+ * If we are in the middle of ungetc'ing, just continue.
+ * This may require expanding the current ungetc buffer.
+ */
+
+ if (HASUB (fp))
+ {
+ if (fp->_r >= fp->_ub._size && __submore (data, fp))
+ {
+ return EOF;
+ }
+ *--fp->_p = c;
+ fp->_r++;
+ return c;
+ }
+
+ /*
+ * If we can handle this by simply backing up, do so,
+ * but never replace the original character.
+ * (This makes sscanf() work when scanning `const' data.)
+ */
+
+ if (fp->_bf._base != NULL && fp->_p > fp->_bf._base && fp->_p[-1] == c)
+ {
+ fp->_p--;
+ fp->_r++;
+ return c;
+ }
+
+ /*
+ * Create an ungetc buffer.
+ * Initially, we will use the `reserve' buffer.
+ */
+
+ fp->_ur = fp->_r;
+ fp->_up = fp->_p;
+ fp->_ub._base = fp->_ubuf;
+ fp->_ub._size = sizeof (fp->_ubuf);
+ fp->_ubuf[sizeof (fp->_ubuf) - 1] = c;
+ fp->_p = &fp->_ubuf[sizeof (fp->_ubuf) - 1];
+ fp->_r = 1;
+ return c;
+}
+
+/* String only version of __srefill_r for sscanf family. */
+int
+_DEFUN(__ssrefill_r, (ptr, fp),
+ struct _reent * ptr _AND
+ register FILE * fp)
+{
+ /*
+ * Our only hope of further input is the ungetc buffer.
+ * If there is anything in that buffer to read, return.
+ */
+ if (HASUB (fp))
+ {
+ FREEUB (ptr, fp);
+ if ((fp->_r = fp->_ur) != 0)
+ {
+ fp->_p = fp->_up;
+ return 0;
+ }
+ }
+
+ /* Otherwise we are out of character input. */
+ fp->_p = fp->_bf._base;
+ fp->_r = 0;
+ fp->_flags |= __SEOF;
+ return EOF;
+}
+
+size_t
+_DEFUN(_sfread_r, (ptr, buf, size, count, fp),
+ struct _reent * ptr _AND
+ _PTR buf _AND
+ size_t size _AND
+ size_t count _AND
+ FILE * fp)
+{
+ register size_t resid;
+ register char *p;
+ register int r;
+ size_t total;
+
+ if ((resid = count * size) == 0)
+ return 0;
+
+ total = resid;
+ p = buf;
+
+ while (resid > (r = fp->_r))
+ {
+ _CAST_VOID memcpy ((_PTR) p, (_PTR) fp->_p, (size_t) r);
+ fp->_p += r;
+ fp->_r = 0;
+ p += r;
+ resid -= r;
+ if (__ssrefill_r (ptr, fp))
+ {
+ /* no more input: return partial result */
+ return (total - resid) / size;
+ }
+ }
+ _CAST_VOID memcpy ((_PTR) p, (_PTR) fp->_p, resid);
+ fp->_r -= resid;
+ fp->_p += resid;
+ return count;
+}
+#else /* !STRING_ONLY || !INTEGER_ONLY */
+int _EXFUN (_sungetc_r, (struct _reent *, int, register FILE *));
+int _EXFUN (__ssrefill_r, (struct _reent *, register FILE *));
+size_t _EXFUN (_sfread_r, (struct _reent *, _PTR buf, size_t, size_t, FILE *));
+#endif /* !STRING_ONLY || !INTEGER_ONLY */
+
+int
+_DEFUN(__SVFSCANF_R, (rptr, fp, fmt0, ap),
+ struct _reent *rptr _AND
+ register FILE *fp _AND
+ char _CONST *fmt0 _AND
+ va_list ap)
+{
+ register u_char *fmt = (u_char *) fmt0;
+ register int c; /* character from format, or conversion */
+ register size_t width; /* field width, or 0 */
+ register char *p; /* points into all kinds of strings */
+ register int n; /* handy integer */
+ register int flags; /* flags as defined above */
+ register char *p0; /* saves original value of p when necessary */
+ int nassigned; /* number of fields assigned */
+ int nread; /* number of characters consumed from fp */
+#ifndef _NO_POS_ARGS
+ int N; /* arg number */
+ int arg_index = 0; /* index into args processed directly */
+ int numargs = 0; /* number of varargs read */
+ void *args[MAX_POS_ARGS]; /* positional args read */
+ int is_pos_arg; /* is current format positional? */
+#endif
+ int base = 0; /* base argument to strtol/strtoul */
+ int nbytes = 1; /* number of bytes read from fmt string */
+ wchar_t wc; /* wchar to use to read format string */
+ wchar_t *wcp; /* handy wide character pointer */
+ size_t mbslen; /* length of converted multibyte sequence */
+ mbstate_t state; /* value to keep track of multibyte state */
+
+ #define CCFN_PARAMS _PARAMS((struct _reent *, const char *, char **, int))
+ u_long (*ccfn)CCFN_PARAMS=0; /* conversion function (strtol/strtoul) */
+ char ccltab[256]; /* character class table for %[...] */
+ char buf[BUF]; /* buffer for numeric conversions */
+ char *lptr; /* literal pointer */
+
+ char *cp;
+ short *sp;
+ int *ip;
+#ifdef FLOATING_POINT
+ float *flp;
+ _LONG_DOUBLE *ldp;
+ double *dp;
+#endif
+ long *lp;
+#ifndef _NO_LONGLONG
+ long long *llp;
+#endif
+
+ /* `basefix' is used to avoid `if' tests in the integer scanner */
+ static _CONST short basefix[17] =
+ {10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
+
+ /* Macro to support positional arguments */
+#ifndef _NO_POS_ARGS
+# define GET_ARG(n, ap, type) \
+ ((type) (is_pos_arg \
+ ? (n < numargs \
+ ? args[n] \
+ : get_arg (n, &ap, &numargs, args)) \
+ : (arg_index++ < numargs \
+ ? args[n] \
+ : (numargs < MAX_POS_ARGS \
+ ? args[numargs++] = va_arg (ap, void *) \
+ : va_arg (ap, void *)))))
+#else
+# define GET_ARG(n, ap, type) (va_arg (ap, type))
+#endif
+
+ __sfp_lock_acquire ();
+ _flockfile (fp);
+
+ ORIENT (fp, -1);
+
+ nassigned = 0;
+ nread = 0;
+ for (;;)
+ {
+#ifndef _MB_CAPABLE
+ wc = *fmt;
+#else
+ memset (&state, '\0', sizeof (state));
+ nbytes = __mbtowc (rptr, &wc, fmt, MB_CUR_MAX, __locale_charset (),
+ &state);
+#endif
+ fmt += nbytes;
+ if (wc == 0)
+ goto all_done;
+ if (nbytes == 1 && isspace (wc))
+ {
+ for (;;)
+ {
+ if (BufferEmpty || !isspace (*fp->_p))
+ break;
+ nread++, fp->_r--, fp->_p++;
+ }
+ continue;
+ }
+ if (wc != '%')
+ goto literal;
+ width = 0;
+ flags = 0;
+#ifndef _NO_POS_ARGS
+ N = arg_index;
+ is_pos_arg = 0;
+#endif
+
+ /*
+ * switch on the format. continue if done; break once format
+ * type is derived.
+ */
+
+ again:
+ c = *fmt++;
+
+ switch (c)
+ {
+ case '%':
+ literal:
+ lptr = fmt - nbytes;
+ for (n = 0; n < nbytes; ++n)
+ {
+ if (BufferEmpty)
+ goto input_failure;
+ if (*fp->_p != *lptr)
+ goto match_failure;
+ fp->_r--, fp->_p++;
+ nread++;
+ ++lptr;
+ }
+ continue;
+
+ case '*':
+ flags |= SUPPRESS;
+ goto again;
+ case 'l':
+#if defined _WANT_IO_C99_FORMATS || !defined _NO_LONGLONG
+ if (*fmt == 'l') /* Check for 'll' = long long (SUSv3) */
+ {
+ ++fmt;
+ flags |= LONGDBL;
+ }
+ else
+#endif
+ flags |= LONG;
+ goto again;
+ case 'L':
+ flags |= LONGDBL;
+ goto again;
+ case 'h':
+#ifdef _WANT_IO_C99_FORMATS
+ if (*fmt == 'h') /* Check for 'hh' = char int (SUSv3) */
+ {
+ ++fmt;
+ flags |= CHAR;
+ }
+ else
+#endif
+ flags |= SHORT;
+ goto again;
+#ifdef _WANT_IO_C99_FORMATS
+ case 'j': /* intmax_t */
+ if (sizeof (intmax_t) == sizeof (long))
+ flags |= LONG;
+ else
+ flags |= LONGDBL;
+ goto again;
+ case 't': /* ptrdiff_t */
+ if (sizeof (ptrdiff_t) < sizeof (int))
+ /* POSIX states ptrdiff_t is 16 or more bits, as
+ is short. */
+ flags |= SHORT;
+ else if (sizeof (ptrdiff_t) == sizeof (int))
+ /* no flag needed */;
+ else if (sizeof (ptrdiff_t) <= sizeof (long))
+ flags |= LONG;
+ else
+ /* POSIX states that at least one programming
+ environment must support ptrdiff_t no wider than
+ long, but that means other environments can
+ have ptrdiff_t as wide as long long. */
+ flags |= LONGDBL;
+ goto again;
+ case 'z': /* size_t */
+ if (sizeof (size_t) < sizeof (int))
+ /* POSIX states size_t is 16 or more bits, as is short. */
+ flags |= SHORT;
+ else if (sizeof (size_t) == sizeof (int))
+ /* no flag needed */;
+ else if (sizeof (size_t) <= sizeof (long))
+ flags |= LONG;
+ else
+ /* POSIX states that at least one programming
+ environment must support size_t no wider than
+ long, but that means other environments can
+ have size_t as wide as long long. */
+ flags |= LONGDBL;
+ goto again;
+#endif /* _WANT_IO_C99_FORMATS */
+
+ case '0':
+ case '1':
+ case '2':
+ case '3':
+ case '4':
+ case '5':
+ case '6':
+ case '7':
+ case '8':
+ case '9':
+ width = width * 10 + c - '0';
+ goto again;
+
+#ifndef _NO_POS_ARGS
+ case '$':
+ if (width <= MAX_POS_ARGS)
+ {
+ N = width - 1;
+ is_pos_arg = 1;
+ width = 0;
+ goto again;
+ }
+ rptr->_errno = EINVAL;
+ goto input_failure;
+#endif /* !_NO_POS_ARGS */
+
+ /*
+ * Conversions. Those marked `compat' are for
+ * 4.[123]BSD compatibility.
+ *
+ * (According to ANSI, E and X formats are supposed to
+ * the same as e and x. Sorry about that.)
+ */
+
+ case 'D': /* compat */
+ flags |= LONG;
+ /* FALLTHROUGH */
+ case 'd':
+ c = CT_INT;
+ ccfn = (u_long (*)CCFN_PARAMS)_strtol_r;
+ base = 10;
+ break;
+
+ case 'i':
+ c = CT_INT;
+ ccfn = (u_long (*)CCFN_PARAMS)_strtol_r;
+ base = 0;
+ break;
+
+ case 'O': /* compat */
+ flags |= LONG;
+ /* FALLTHROUGH */
+ case 'o':
+ c = CT_INT;
+ ccfn = _strtoul_r;
+ base = 8;
+ break;
+
+ case 'u':
+ c = CT_INT;
+ ccfn = _strtoul_r;
+ base = 10;
+ break;
+
+ case 'X':
+ case 'x':
+ flags |= PFXOK; /* enable 0x prefixing */
+ c = CT_INT;
+ ccfn = _strtoul_r;
+ base = 16;
+ break;
+
+#ifdef FLOATING_POINT
+# ifdef _WANT_IO_C99_FORMATS
+ case 'a':
+ case 'A':
+ case 'F':
+# endif
+ case 'E':
+ case 'G':
+ case 'e':
+ case 'f':
+ case 'g':
+ c = CT_FLOAT;
+ break;
+#endif
+
+#ifdef _WANT_IO_C99_FORMATS
+ case 'S':
+ flags |= LONG;
+ /* FALLTHROUGH */
+#endif
+
+ case 's':
+ c = CT_STRING;
+ break;
+
+ case '[':
+ fmt = (u_char *) __sccl (ccltab, (unsigned char *) fmt);
+ flags |= NOSKIP;
+ c = CT_CCL;
+ break;
+
+#ifdef _WANT_IO_C99_FORMATS
+ case 'C':
+ flags |= LONG;
+ /* FALLTHROUGH */
+#endif
+
+ case 'c':
+ flags |= NOSKIP;
+ c = CT_CHAR;
+ break;
+
+ case 'p': /* pointer format is like hex */
+ flags |= POINTER | PFXOK;
+ c = CT_INT;
+ ccfn = _strtoul_r;
+ base = 16;
+ break;
+
+ case 'n':
+ if (flags & SUPPRESS) /* ??? */
+ continue;
+#ifdef _WANT_IO_C99_FORMATS
+ if (flags & CHAR)
+ {
+ cp = GET_ARG (N, ap, char *);
+ *cp = nread;
+ }
+ else
+#endif
+ if (flags & SHORT)
+ {
+ sp = GET_ARG (N, ap, short *);
+ *sp = nread;
+ }
+ else if (flags & LONG)
+ {
+ lp = GET_ARG (N, ap, long *);
+ *lp = nread;
+ }
+#ifndef _NO_LONGLONG
+ else if (flags & LONGDBL)
+ {
+ llp = GET_ARG (N, ap, long long*);
+ *llp = nread;
+ }
+#endif
+ else
+ {
+ ip = GET_ARG (N, ap, int *);
+ *ip = nread;
+ }
+ continue;
+
+ /*
+ * Disgusting backwards compatibility hacks. XXX
+ */
+ case '\0': /* compat */
+ _funlockfile (fp);
+ __sfp_lock_release ();
+ return EOF;
+
+ default: /* compat */
+ if (isupper (c))
+ flags |= LONG;
+ c = CT_INT;
+ ccfn = (u_long (*)CCFN_PARAMS)_strtol_r;
+ base = 10;
+ break;
+ }
+
+ /*
+ * We have a conversion that requires input.
+ */
+ if (BufferEmpty)
+ goto input_failure;
+
+ /*
+ * Consume leading white space, except for formats that
+ * suppress this.
+ */
+ if ((flags & NOSKIP) == 0)
+ {
+ while (isspace (*fp->_p))
+ {
+ nread++;
+ if (--fp->_r > 0)
+ fp->_p++;
+ else
+ if (__srefill_r (rptr, fp))
+ goto input_failure;
+ }
+ /*
+ * Note that there is at least one character in the
+ * buffer, so conversions that do not set NOSKIP ca
+ * no longer result in an input failure.
+ */
+ }
+
+ /*
+ * Do the conversion.
+ */
+ switch (c)
+ {
+
+ case CT_CHAR:
+ /* scan arbitrary characters (sets NOSKIP) */
+ if (width == 0)
+ width = 1;
+#if !defined(_ELIX_LEVEL) || _ELIX_LEVEL >= 2
+ if (flags & LONG)
+ {
+ if ((flags & SUPPRESS) == 0)
+ wcp = GET_ARG (N, ap, wchar_t *);
+ else
+ wcp = NULL;
+ n = 0;
+ while (width != 0)
+ {
+ if (n == MB_CUR_MAX)
+ goto input_failure;
+ buf[n++] = *fp->_p;
+ fp->_r -= 1;
+ fp->_p += 1;
+ memset ((_PTR)&state, '\0', sizeof (mbstate_t));
+ if ((mbslen = _mbrtowc_r (rptr, wcp, buf, n, &state))
+ == (size_t)-1)
+ goto input_failure; /* Invalid sequence */
+ if (mbslen == 0 && !(flags & SUPPRESS))
+ *wcp = L'\0';
+ if (mbslen != (size_t)-2) /* Incomplete sequence */
+ {
+ nread += n;
+ width -= 1;
+ if (!(flags & SUPPRESS))
+ wcp += 1;
+ n = 0;
+ }
+ if (BufferEmpty)
+ {
+ if (n != 0)
+ goto input_failure;
+ break;
+ }
+ }
+ if (!(flags & SUPPRESS))
+ nassigned++;
+ }
+ else
+#endif
+ if (flags & SUPPRESS)
+ {
+ size_t sum = 0;
+ for (;;)
+ {
+ if ((n = fp->_r) < (int)width)
+ {
+ sum += n;
+ width -= n;
+ fp->_p += n;
+ if (__srefill_r (rptr, fp))
+ {
+ if (sum == 0)
+ goto input_failure;
+ break;
+ }
+ }
+ else
+ {
+ sum += width;
+ fp->_r -= width;
+ fp->_p += width;
+ break;
+ }
+ }
+ nread += sum;
+ }
+ else
+ {
+ size_t r = _fread_r (rptr, (_PTR) GET_ARG (N, ap, char *), 1, width, fp);
+
+ if (r == 0)
+ goto input_failure;
+ nread += r;
+ nassigned++;
+ }
+ break;
+
+ case CT_CCL:
+ /* scan a (nonempty) character class (sets NOSKIP) */
+ if (width == 0)
+ width = ~0; /* `infinity' */
+ /* take only those things in the class */
+ if (flags & SUPPRESS)
+ {
+ n = 0;
+ while (ccltab[*fp->_p])
+ {
+ n++, fp->_r--, fp->_p++;
+ if (--width == 0)
+ break;
+ if (BufferEmpty)
+ {
+ if (n == 0)
+ goto input_failure;
+ break;
+ }
+ }
+ if (n == 0)
+ goto match_failure;
+ }
+ else
+ {
+ p0 = p = GET_ARG (N, ap, char *);
+ while (ccltab[*fp->_p])
+ {
+ fp->_r--;
+ *p++ = *fp->_p++;
+ if (--width == 0)
+ break;
+ if (BufferEmpty)
+ {
+ if (p == p0)
+ goto input_failure;
+ break;
+ }
+ }
+ n = p - p0;
+ if (n == 0)
+ goto match_failure;
+ *p = 0;
+ nassigned++;
+ }
+ nread += n;
+ break;
+
+ case CT_STRING:
+ /* like CCL, but zero-length string OK, & no NOSKIP */
+ if (width == 0)
+ width = (size_t)~0;
+#if !defined(_ELIX_LEVEL) || _ELIX_LEVEL >= 2
+ if (flags & LONG)
+ {
+ /* Process %S and %ls placeholders */
+ if ((flags & SUPPRESS) == 0)
+ wcp = GET_ARG (N, ap, wchar_t *);
+ else
+ wcp = &wc;
+ n = 0;
+ while (!isspace (*fp->_p) && width != 0)
+ {
+ if (n == MB_CUR_MAX)
+ goto input_failure;
+ buf[n++] = *fp->_p;
+ fp->_r -= 1;
+ fp->_p += 1;
+ memset ((_PTR)&state, '\0', sizeof (mbstate_t));
+ if ((mbslen = _mbrtowc_r (rptr, wcp, buf, n, &state))
+ == (size_t)-1)
+ goto input_failure;
+ if (mbslen == 0)
+ *wcp = L'\0';
+ if (mbslen != (size_t)-2) /* Incomplete sequence */
+ {
+ if (iswspace(*wcp))
+ {
+ while (n != 0)
+ _ungetc_r (rptr, (unsigned char) buf[--n], fp);
+ break;
+ }
+ nread += n;
+ width -= 1;
+ if ((flags & SUPPRESS) == 0)
+ wcp += 1;
+ n = 0;
+ }
+ if (BufferEmpty)
+ {
+ if (n != 0)
+ goto input_failure;
+ break;
+ }
+ }
+ if (!(flags & SUPPRESS))
+ {
+ *wcp = L'\0';
+ nassigned++;
+ }
+ }
+ else
+#endif
+ if (flags & SUPPRESS)
+ {
+ n = 0;
+ while (!isspace (*fp->_p))
+ {
+ n++, fp->_r--, fp->_p++;
+ if (--width == 0)
+ break;
+ if (BufferEmpty)
+ break;
+ }
+ nread += n;
+ }
+ else
+ {
+ p0 = p = GET_ARG (N, ap, char *);
+ while (!isspace (*fp->_p))
+ {
+ fp->_r--;
+ *p++ = *fp->_p++;
+ if (--width == 0)
+ break;
+ if (BufferEmpty)
+ break;
+ }
+ *p = 0;
+ nread += p - p0;
+ nassigned++;
+ }
+ continue;
+
+ case CT_INT:
+ {
+ /* scan an integer as if by strtol/strtoul */
+ unsigned width_left = 0;
+ int skips = 0;
+#ifdef hardway
+ if (width == 0 || width > sizeof (buf) - 1)
+#else
+ /* size_t is unsigned, hence this optimisation */
+ if (width - 1 > sizeof (buf) - 2)
+#endif
+ {
+ width_left = width - (sizeof (buf) - 1);
+ width = sizeof (buf) - 1;
+ }
+ flags |= SIGNOK | NDIGITS | NZDIGITS | NNZDIGITS;
+ for (p = buf; width; width--)
+ {
+ c = *fp->_p;
+ /*
+ * Switch on the character; `goto ok' if we
+ * accept it as a part of number.
+ */
+ switch (c)
+ {
+ /*
+ * The digit 0 is always legal, but is special.
+ * For %i conversions, if no digits (zero or nonzero)
+ * have been scanned (only signs), we will have base==0.
+ * In that case, we should set it to 8 and enable 0x
+ * prefixing. Also, if we have not scanned zero digits
+ * before this, do not turn off prefixing (someone else
+ * will turn it off if we have scanned any nonzero digits).
+ */
+ case '0':
+ if (! (flags & NNZDIGITS))
+ goto ok;
+ if (base == 0)
+ {
+ base = 8;
+ flags |= PFXOK;
+ }
+ if (flags & NZDIGITS)
+ {
+ flags &= ~(SIGNOK | NZDIGITS | NDIGITS);
+ goto ok;
+ }
+ flags &= ~(SIGNOK | PFXOK | NDIGITS);
+ if (width_left)
+ {
+ width_left--;
+ width++;
+ }
+ ++skips;
+ goto skip;
+
+ /* 1 through 7 always legal */
+ case '1':
+ case '2':
+ case '3':
+ case '4':
+ case '5':
+ case '6':
+ case '7':
+ base = basefix[base];
+ flags &= ~(SIGNOK | PFXOK | NDIGITS | NNZDIGITS);
+ goto ok;
+
+ /* digits 8 and 9 ok iff decimal or hex */
+ case '8':
+ case '9':
+ base = basefix[base];
+ if (base <= 8)
+ break; /* not legal here */
+ flags &= ~(SIGNOK | PFXOK | NDIGITS | NNZDIGITS);
+ goto ok;
+
+ /* letters ok iff hex */
+ case 'A':
+ case 'B':
+ case 'C':
+ case 'D':
+ case 'E':
+ case 'F':
+ case 'a':
+ case 'b':
+ case 'c':
+ case 'd':
+ case 'e':
+ case 'f':
+ /* no need to fix base here */
+ if (base <= 10)
+ break; /* not legal here */
+ flags &= ~(SIGNOK | PFXOK | NDIGITS | NNZDIGITS);
+ goto ok;
+
+ /* sign ok only as first character */
+ case '+':
+ case '-':
+ if (flags & SIGNOK)
+ {
+ flags &= ~SIGNOK;
+ goto ok;
+ }
+ break;
+
+ /* x ok iff flag still set & single 0 seen */
+ case 'x':
+ case 'X':
+ if ((flags & (PFXOK | NZDIGITS)) == PFXOK)
+ {
+ base = 16;/* if %i */
+ flags &= ~PFXOK;
+ /* We must reset the NZDIGITS and NDIGITS
+ flags that would have been unset by seeing
+ the zero that preceded the X or x. */
+ flags |= NZDIGITS | NDIGITS;
+ goto ok;
+ }
+ break;
+ }
+
+ /*
+ * If we got here, c is not a legal character
+ * for a number. Stop accumulating digits.
+ */
+ break;
+ ok:
+ /*
+ * c is legal: store it and look at the next.
+ */
+ *p++ = c;
+ skip:
+ if (--fp->_r > 0)
+ fp->_p++;
+ else
+ if (__srefill_r (rptr, fp))
+ break; /* EOF */
+ }
+ /*
+ * If we had only a sign, it is no good; push back the sign.
+ * If the number ends in `x', it was [sign] '0' 'x', so push back
+ * the x and treat it as [sign] '0'.
+ * Use of ungetc here and below assumes ASCII encoding; we are only
+ * pushing back 7-bit characters, so casting to unsigned char is
+ * not necessary.
+ */
+ if (flags & NDIGITS)
+ {
+ if (p > buf)
+ _ungetc_r (rptr, *--p, fp); /* [-+xX] */
+ if (p == buf)
+ goto match_failure;
+ }
+ if ((flags & SUPPRESS) == 0)
+ {
+ u_long res;
+
+ *p = 0;
+ res = (*ccfn) (rptr, buf, (char **) NULL, base);
+ if (flags & POINTER)
+ {
+ void **vp = GET_ARG (N, ap, void **);
+#ifndef _NO_LONGLONG
+ if (sizeof (uintptr_t) > sizeof (u_long))
+ {
+ u_long_long resll;
+ resll = _strtoull_r (rptr, buf, (char **) NULL, base);
+ *vp = (void *) (uintptr_t) resll;
+ }
+ else
+#endif /* !_NO_LONGLONG */
+ *vp = (void *) (uintptr_t) res;
+ }
+#ifdef _WANT_IO_C99_FORMATS
+ else if (flags & CHAR)
+ {
+ cp = GET_ARG (N, ap, char *);
+ *cp = res;
+ }
+#endif
+ else if (flags & SHORT)
+ {
+ sp = GET_ARG (N, ap, short *);
+ *sp = res;
+ }
+ else if (flags & LONG)
+ {
+ lp = GET_ARG (N, ap, long *);
+ *lp = res;
+ }
+#ifndef _NO_LONGLONG
+ else if (flags & LONGDBL)
+ {
+ u_long_long resll;
+ if (ccfn == _strtoul_r)
+ resll = _strtoull_r (rptr, buf, (char **) NULL, base);
+ else
+ resll = _strtoll_r (rptr, buf, (char **) NULL, base);
+ llp = GET_ARG (N, ap, long long*);
+ *llp = resll;
+ }
+#endif
+ else
+ {
+ ip = GET_ARG (N, ap, int *);
+ *ip = res;
+ }
+ nassigned++;
+ }
+ nread += p - buf + skips;
+ break;
+ }
+#ifdef FLOATING_POINT
+ case CT_FLOAT:
+ {
+ /* scan a floating point number as if by strtod */
+ /* This code used to assume that the number of digits is reasonable.
+ However, ANSI / ISO C makes no such stipulation; we have to get
+ exact results even when there is an unreasonable amount of
+ leading zeroes. */
+ long leading_zeroes = 0;
+ long zeroes, exp_adjust;
+ char *exp_start = NULL;
+ unsigned width_left = 0;
+ char nancount = 0;
+ char infcount = 0;
+#ifdef hardway
+ if (width == 0 || width > sizeof (buf) - 1)
+#else
+ /* size_t is unsigned, hence this optimisation */
+ if (width - 1 > sizeof (buf) - 2)
+#endif
+ {
+ width_left = width - (sizeof (buf) - 1);
+ width = sizeof (buf) - 1;
+ }
+ flags |= SIGNOK | NDIGITS | DPTOK | EXPOK;
+ zeroes = 0;
+ exp_adjust = 0;
+ for (p = buf; width; )
+ {
+ c = *fp->_p;
+ /*
+ * This code mimicks the integer conversion
+ * code, but is much simpler.
+ */
+ switch (c)
+ {
+ case '0':
+ if (flags & NDIGITS)
+ {
+ flags &= ~SIGNOK;
+ zeroes++;
+ if (width_left)
+ {
+ width_left--;
+ width++;
+ }
+ goto fskip;
+ }
+ /* Fall through. */
+ case '1':
+ case '2':
+ case '3':
+ case '4':
+ case '5':
+ case '6':
+ case '7':
+ case '8':
+ case '9':
+ if (nancount + infcount == 0)
+ {
+ flags &= ~(SIGNOK | NDIGITS);
+ goto fok;
+ }
+ break;
+
+ case '+':
+ case '-':
+ if (flags & SIGNOK)
+ {
+ flags &= ~SIGNOK;
+ goto fok;
+ }
+ break;
+ case 'n':
+ case 'N':
+ if (nancount == 0 && zeroes == 0
+ && (flags & (NDIGITS | DPTOK | EXPOK)) ==
+ (NDIGITS | DPTOK | EXPOK))
+ {
+ flags &= ~(SIGNOK | DPTOK | EXPOK | NDIGITS);
+ nancount = 1;
+ goto fok;
+ }
+ if (nancount == 2)
+ {
+ nancount = 3;
+ goto fok;
+ }
+ if (infcount == 1 || infcount == 4)
+ {
+ infcount++;
+ goto fok;
+ }
+ break;
+ case 'a':
+ case 'A':
+ if (nancount == 1)
+ {
+ nancount = 2;
+ goto fok;
+ }
+ break;
+ case 'i':
+ case 'I':
+ if (infcount == 0 && zeroes == 0
+ && (flags & (NDIGITS | DPTOK | EXPOK)) ==
+ (NDIGITS | DPTOK | EXPOK))
+ {
+ flags &= ~(SIGNOK | DPTOK | EXPOK | NDIGITS);
+ infcount = 1;
+ goto fok;
+ }
+ if (infcount == 3 || infcount == 5)
+ {
+ infcount++;
+ goto fok;
+ }
+ break;
+ case 'f':
+ case 'F':
+ if (infcount == 2)
+ {
+ infcount = 3;
+ goto fok;
+ }
+ break;
+ case 't':
+ case 'T':
+ if (infcount == 6)
+ {
+ infcount = 7;
+ goto fok;
+ }
+ break;
+ case 'y':
+ case 'Y':
+ if (infcount == 7)
+ {
+ infcount = 8;
+ goto fok;
+ }
+ break;
+ case '.':
+ if (flags & DPTOK)
+ {
+ flags &= ~(SIGNOK | DPTOK);
+ leading_zeroes = zeroes;
+ goto fok;
+ }
+ break;
+ case 'e':
+ case 'E':
+ /* no exponent without some digits */
+ if ((flags & (NDIGITS | EXPOK)) == EXPOK
+ || ((flags & EXPOK) && zeroes))
+ {
+ if (! (flags & DPTOK))
+ {
+ exp_adjust = zeroes - leading_zeroes;
+ exp_start = p;
+ }
+ flags =
+ (flags & ~(EXPOK | DPTOK)) |
+ SIGNOK | NDIGITS;
+ zeroes = 0;
+ goto fok;
+ }
+ break;
+ }
+ break;
+ fok:
+ *p++ = c;
+ fskip:
+ width--;
+ ++nread;
+ if (--fp->_r > 0)
+ fp->_p++;
+ else
+ if (__srefill_r (rptr, fp))
+ break; /* EOF */
+ }
+ if (zeroes)
+ flags &= ~NDIGITS;
+ /* We may have a 'N' or possibly even [sign] 'N' 'a' as the
+ start of 'NaN', only to run out of chars before it was
+ complete (or having encountered a non-matching char). So
+ check here if we have an outstanding nancount, and if so
+ put back the chars we did swallow and treat as a failed
+ match.
+
+ FIXME - we still don't handle NAN([0xdigits]). */
+ if (nancount - 1U < 2U) /* nancount && nancount < 3 */
+ {
+ /* Newlib's ungetc works even if we called __srefill in
+ the middle of a partial parse, but POSIX does not
+ guarantee that in all implementations of ungetc. */
+ while (p > buf)
+ {
+ _ungetc_r (rptr, *--p, fp); /* [-+nNaA] */
+ --nread;
+ }
+ goto match_failure;
+ }
+ /* Likewise for 'inf' and 'infinity'. But be careful that
+ 'infinite' consumes only 3 characters, leaving the stream
+ at the second 'i'. */
+ if (infcount - 1U < 7U) /* infcount && infcount < 8 */
+ {
+ if (infcount >= 3) /* valid 'inf', but short of 'infinity' */
+ while (infcount-- > 3)
+ {
+ _ungetc_r (rptr, *--p, fp); /* [iInNtT] */
+ --nread;
+ }
+ else
+ {
+ while (p > buf)
+ {
+ _ungetc_r (rptr, *--p, fp); /* [-+iInN] */
+ --nread;
+ }
+ goto match_failure;
+ }
+ }
+ /*
+ * If no digits, might be missing exponent digits
+ * (just give back the exponent) or might be missing
+ * regular digits, but had sign and/or decimal point.
+ */
+ if (flags & NDIGITS)
+ {
+ if (flags & EXPOK)
+ {
+ /* no digits at all */
+ while (p > buf)
+ {
+ _ungetc_r (rptr, *--p, fp); /* [-+.] */
+ --nread;
+ }
+ goto match_failure;
+ }
+ /* just a bad exponent (e and maybe sign) */
+ c = *--p;
+ --nread;
+ if (c != 'e' && c != 'E')
+ {
+ _ungetc_r (rptr, c, fp); /* [-+] */
+ c = *--p;
+ --nread;
+ }
+ _ungetc_r (rptr, c, fp); /* [eE] */
+ }
+ if ((flags & SUPPRESS) == 0)
+ {
+ double res = 0;
+#ifdef _NO_LONGDBL
+#define QUAD_RES res;
+#else /* !_NO_LONG_DBL */
+ long double qres = 0;
+#define QUAD_RES qres;
+#endif /* !_NO_LONG_DBL */
+ long new_exp = 0;
+
+ *p = 0;
+ if ((flags & (DPTOK | EXPOK)) == EXPOK)
+ {
+ exp_adjust = zeroes - leading_zeroes;
+ new_exp = -exp_adjust;
+ exp_start = p;
+ }
+ else if (exp_adjust)
+ new_exp = _strtol_r (rptr, (exp_start + 1), NULL, 10) - exp_adjust;
+ if (exp_adjust)
+ {
+
+ /* If there might not be enough space for the new exponent,
+ truncate some trailing digits to make room. */
+ if (exp_start >= buf + sizeof (buf) - MAX_LONG_LEN)
+ exp_start = buf + sizeof (buf) - MAX_LONG_LEN - 1;
+ sprintf (exp_start, "e%ld", new_exp);
+ }
+
+ /* Current _strtold routine is markedly slower than
+ _strtod_r. Only use it if we have a long double
+ result. */
+#ifndef _NO_LONGDBL /* !_NO_LONGDBL */
+ if (flags & LONGDBL)
+ qres = _strtold (buf, NULL);
+ else
+#endif
+ res = _strtod_r (rptr, buf, NULL);
+
+ if (flags & LONG)
+ {
+ dp = GET_ARG (N, ap, double *);
+ *dp = res;
+ }
+ else if (flags & LONGDBL)
+ {
+ ldp = GET_ARG (N, ap, _LONG_DOUBLE *);
+ *ldp = QUAD_RES;
+ }
+ else
+ {
+ flp = GET_ARG (N, ap, float *);
+ if (isnan (res))
+ *flp = nanf (NULL);
+ else
+ *flp = res;
+ }
+ nassigned++;
+ }
+ break;
+ }
+#endif /* FLOATING_POINT */
+ }
+ }
+input_failure:
+ /* On read failure, return EOF failure regardless of matches; errno
+ should have been set prior to here. On EOF failure (including
+ invalid format string), return EOF if no matches yet, else number
+ of matches made prior to failure. */
+ _funlockfile (fp);
+ __sfp_lock_release ();
+ return nassigned && !(fp->_flags & __SERR) ? nassigned : EOF;
+match_failure:
+all_done:
+ /* Return number of matches, which can be 0 on match failure. */
+ _funlockfile (fp);
+ __sfp_lock_release ();
+ return nassigned;
+}
+
+#ifndef _NO_POS_ARGS
+/* Process all intermediate arguments. Fortunately, with scanf, all
+ intermediate arguments are sizeof(void*), so we don't need to scan
+ ahead in the format string. */
+static void *
+get_arg (int n, va_list *ap, int *numargs_p, void **args)
+{
+ int numargs = *numargs_p;
+ while (n >= numargs)
+ args[numargs++] = va_arg (*ap, void *);
+ *numargs_p = numargs;
+ return args[n];
+}
+#endif /* !_NO_POS_ARGS */
vfscanf.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: putchar_u.c
===================================================================
--- putchar_u.c (nonexistent)
+++ putchar_u.c (revision 520)
@@ -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
+<>---non-thread-safe version of putchar (macro)
+
+INDEX
+ putchar_unlocked
+
+SYNOPSIS
+ #include
+ int putchar_unlocked(int <[ch]>);
+
+DESCRIPTION
+<> is a non-thread-safe version of <>
+declared in <>. <> 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 <> is equivalent to <>.
+
+RETURNS
+See <>.
+
+PORTABILITY
+POSIX 1003.1 requires <>. <> may
+be implemented as a macro.
+
+Supporting OS subroutines required: <>, <>, <>,
+<>, <>, <>, <>. */
+
+#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
+#include
+
+#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
putchar_u.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: puts.c
===================================================================
--- puts.c (nonexistent)
+++ puts.c (revision 520)
@@ -0,0 +1,106 @@
+/*
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by the University of California, Berkeley. The name of the
+ * University may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
+/*
+FUNCTION
+<>---write a character string
+
+INDEX
+ puts
+INDEX
+ _puts_r
+
+ANSI_SYNOPSIS
+ #include
+ int puts(const char *<[s]>);
+
+ int _puts_r(struct _reent *<[reent]>, const char *<[s]>);
+
+TRAD_SYNOPSIS
+ #include
+ int puts(<[s]>)
+ char *<[s]>;
+
+ int _puts_r(<[reent]>, <[s]>)
+ struct _reent *<[reent]>;
+ char *<[s]>;
+
+DESCRIPTION
+<> writes the string at <[s]> (followed by a newline, instead of
+the trailing null) to the standard output stream.
+
+The alternate function <<_puts_r>> is a reentrant version. The extra
+argument <[reent]> is a pointer to a reentrancy structure.
+
+RETURNS
+If successful, the result is a nonnegative integer; otherwise, the
+result is <>.
+
+PORTABILITY
+ANSI C requires <>, but does not specify that the result on
+success must be <<0>>; any non-negative value is permitted.
+
+Supporting OS subroutines required: <>, <>, <>,
+<>, <>, <>, <>.
+*/
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "%W% (Berkeley) %G%";
+#endif /* LIBC_SCCS and not lint */
+
+#include <_ansi.h>
+#include
+#include
+#include
+#include "fvwrite.h"
+#include "local.h"
+
+/*
+ * Write the given string to stdout, appending a newline.
+ */
+
+int
+_DEFUN(_puts_r, (ptr, s),
+ struct _reent *ptr _AND
+ _CONST char * s)
+{
+ size_t c = strlen (s);
+ struct __suio uio;
+ struct __siov iov[2];
+
+ iov[0].iov_base = s;
+ iov[0].iov_len = c;
+ iov[1].iov_base = "\n";
+ iov[1].iov_len = 1;
+ uio.uio_resid = c + 1;
+ uio.uio_iov = &iov[0];
+ uio.uio_iovcnt = 2;
+ _REENT_SMALL_CHECK_INIT (ptr);
+ ORIENT (stdout, -1);
+ return (__sfvwrite_r (ptr, _stdout_r (ptr), &uio) ? EOF : '\n');
+}
+
+#ifndef _REENT_ONLY
+
+int
+_DEFUN(puts, (s),
+ char _CONST * s)
+{
+ return _puts_r (_REENT, s);
+}
+
+#endif
puts.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: fseek.c
===================================================================
--- fseek.c (nonexistent)
+++ fseek.c (revision 520)
@@ -0,0 +1,406 @@
+/*
+ * 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
+<>, <>---set file position
+
+INDEX
+ fseek
+INDEX
+ fseeko
+INDEX
+ _fseek_r
+INDEX
+ _fseeko_r
+
+ANSI_SYNOPSIS
+ #include
+ int fseek(FILE *<[fp]>, long <[offset]>, int <[whence]>)
+ int fseeko(FILE *<[fp]>, off_t <[offset]>, int <[whence]>)
+ int _fseek_r(struct _reent *<[ptr]>, FILE *<[fp]>,
+ long <[offset]>, int <[whence]>)
+ int _fseeko_r(struct _reent *<[ptr]>, FILE *<[fp]>,
+ off_t <[offset]>, int <[whence]>)
+
+TRAD_SYNOPSIS
+ #include
+ int fseek(<[fp]>, <[offset]>, <[whence]>)
+ FILE *<[fp]>;
+ long <[offset]>;
+ int <[whence]>;
+
+ int fseeko(<[fp]>, <[offset]>, <[whence]>)
+ FILE *<[fp]>;
+ off_t <[offset]>;
+ int <[whence]>;
+
+ int _fseek_r(<[ptr]>, <[fp]>, <[offset]>, <[whence]>)
+ struct _reent *<[ptr]>;
+ FILE *<[fp]>;
+ long <[offset]>;
+ int <[whence]>;
+
+ int _fseeko_r(<[ptr]>, <[fp]>, <[offset]>, <[whence]>)
+ struct _reent *<[ptr]>;
+ FILE *<[fp]>;
+ off_t <[offset]>;
+ int <[whence]>;
+
+DESCRIPTION
+Objects of type <> can have a ``position'' that records how much
+of the file your program has already read. Many of the <> functions
+depend on this position, and many change it as a side effect.
+
+You can use <>/<> to set the position for the file identified by
+<[fp]>. The value of <[offset]> determines the new position, in one
+of three ways selected by the value of <[whence]> (defined as macros
+in `<>'):
+
+<>---<[offset]> is the absolute file position (an offset
+from the beginning of the file) desired. <[offset]> must be positive.
+
+<>---<[offset]> is relative to the current file position.
+<[offset]> can meaningfully be either positive or negative.
+
+<>---<[offset]> is relative to the current end of file.
+<[offset]> can meaningfully be either positive (to increase the size
+of the file) or negative.
+
+See <>/<> to determine the current file position.
+
+RETURNS
+<>/<> return <<0>> when successful. On failure, the
+result is <>. The reason for failure is indicated in <>:
+either <> (the stream identified by <[fp]> doesn't support
+repositioning) or <> (invalid file position).
+
+PORTABILITY
+ANSI C requires <>.
+
+<> is defined by the Single Unix specification.
+
+Supporting OS subroutines required: <>, <>, <>,
+<>, <>, <>, <>.
+*/
+
+#include <_ansi.h>
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include "local.h"
+
+#define POS_ERR (-(_fpos_t)1)
+
+/*
+ * Seek the given file to the given offset.
+ * `Whence' must be one of the three SEEK_* macros.
+ */
+
+int
+_DEFUN(_fseek_r, (ptr, fp, offset, whence),
+ struct _reent *ptr _AND
+ register FILE *fp _AND
+ long offset _AND
+ int whence)
+{
+ _fpos_t _EXFNPTR(seekfn, (struct _reent *, _PTR, _fpos_t, int));
+ _fpos_t target;
+ _fpos_t curoff = 0;
+ size_t n;
+#ifdef __USE_INTERNAL_STAT64
+ struct stat64 st;
+#else
+ struct stat st;
+#endif
+ int havepos;
+
+ /* Make sure stdio is set up. */
+
+ CHECK_INIT (ptr, fp);
+
+ __sfp_lock_acquire ();
+ _flockfile (fp);
+
+ /* If we've been doing some writing, and we're in append mode
+ then we don't really know where the filepos is. */
+
+ if (fp->_flags & __SAPP && fp->_flags & __SWR)
+ {
+ /* So flush the buffer and seek to the end. */
+ _fflush_r (ptr, fp);
+ }
+
+ /* Have to be able to seek. */
+
+ if ((seekfn = fp->_seek) == NULL)
+ {
+ ptr->_errno = ESPIPE; /* ??? */
+ _funlockfile (fp);
+ __sfp_lock_release ();
+ return EOF;
+ }
+
+ /*
+ * Change any SEEK_CUR to SEEK_SET, and check `whence' argument.
+ * After this, whence is either SEEK_SET or SEEK_END.
+ */
+
+ switch (whence)
+ {
+ case SEEK_CUR:
+ /*
+ * In order to seek relative to the current stream offset,
+ * we have to first find the current stream offset a la
+ * ftell (see ftell for details).
+ */
+ _fflush_r (ptr, fp); /* may adjust seek offset on append stream */
+ if (fp->_flags & __SOFF)
+ curoff = fp->_offset;
+ else
+ {
+ curoff = seekfn (ptr, fp->_cookie, (_fpos_t) 0, SEEK_CUR);
+ if (curoff == -1L)
+ {
+ _funlockfile (fp);
+ __sfp_lock_release ();
+ return EOF;
+ }
+ }
+ if (fp->_flags & __SRD)
+ {
+ curoff -= fp->_r;
+ if (HASUB (fp))
+ curoff -= fp->_ur;
+ }
+ else if (fp->_flags & __SWR && fp->_p != NULL)
+ curoff += fp->_p - fp->_bf._base;
+
+ offset += curoff;
+ whence = SEEK_SET;
+ havepos = 1;
+ break;
+
+ case SEEK_SET:
+ case SEEK_END:
+ havepos = 0;
+ break;
+
+ default:
+ ptr->_errno = EINVAL;
+ _funlockfile (fp);
+ __sfp_lock_release ();
+ return (EOF);
+ }
+
+ /*
+ * Can only optimise if:
+ * reading (and not reading-and-writing);
+ * not unbuffered; and
+ * this is a `regular' Unix file (and hence seekfn==__sseek).
+ * We must check __NBF first, because it is possible to have __NBF
+ * and __SOPT both set.
+ */
+
+ if (fp->_bf._base == NULL)
+ __smakebuf_r (ptr, fp);
+ if (fp->_flags & (__SWR | __SRW | __SNBF | __SNPT))
+ goto dumb;
+ if ((fp->_flags & __SOPT) == 0)
+ {
+ if (seekfn != __sseek
+ || fp->_file < 0
+#ifdef __USE_INTERNAL_STAT64
+ || _fstat64_r (ptr, fp->_file, &st)
+#else
+ || _fstat_r (ptr, fp->_file, &st)
+#endif
+ || (st.st_mode & S_IFMT) != S_IFREG)
+ {
+ fp->_flags |= __SNPT;
+ goto dumb;
+ }
+#ifdef HAVE_BLKSIZE
+ fp->_blksize = st.st_blksize;
+#else
+ fp->_blksize = 1024;
+#endif
+ fp->_flags |= __SOPT;
+ }
+
+ /*
+ * We are reading; we can try to optimise.
+ * Figure out where we are going and where we are now.
+ */
+
+ if (whence == SEEK_SET)
+ target = offset;
+ else
+ {
+#ifdef __USE_INTERNAL_STAT64
+ if (_fstat64_r (ptr, fp->_file, &st))
+#else
+ if (_fstat_r (ptr, fp->_file, &st))
+#endif
+ goto dumb;
+ target = st.st_size + offset;
+ }
+ if ((long)target != target)
+ {
+ ptr->_errno = EOVERFLOW;
+ _funlockfile (fp);
+ __sfp_lock_release ();
+ return EOF;
+ }
+
+ if (!havepos)
+ {
+ if (fp->_flags & __SOFF)
+ curoff = fp->_offset;
+ else
+ {
+ curoff = seekfn (ptr, fp->_cookie, 0L, SEEK_CUR);
+ if (curoff == POS_ERR)
+ goto dumb;
+ }
+ curoff -= fp->_r;
+ if (HASUB (fp))
+ curoff -= fp->_ur;
+ }
+
+ /*
+ * Compute the number of bytes in the input buffer (pretending
+ * that any ungetc() input has been discarded). Adjust current
+ * offset backwards by this count so that it represents the
+ * file offset for the first byte in the current input buffer.
+ */
+
+ if (HASUB (fp))
+ {
+ curoff += fp->_r; /* kill off ungetc */
+ n = fp->_up - fp->_bf._base;
+ curoff -= n;
+ n += fp->_ur;
+ }
+ else
+ {
+ n = fp->_p - fp->_bf._base;
+ curoff -= n;
+ n += fp->_r;
+ }
+
+ /*
+ * If the target offset is within the current buffer,
+ * simply adjust the pointers, clear EOF, undo ungetc(),
+ * and return.
+ */
+
+ if (target >= curoff && target < curoff + n)
+ {
+ register int o = target - curoff;
+
+ fp->_p = fp->_bf._base + o;
+ fp->_r = n - o;
+ if (HASUB (fp))
+ FREEUB (ptr, fp);
+ fp->_flags &= ~__SEOF;
+ memset (&fp->_mbstate, 0, sizeof (_mbstate_t));
+ _funlockfile (fp);
+ __sfp_lock_release ();
+ return 0;
+ }
+
+ /*
+ * The place we want to get to is not within the current buffer,
+ * but we can still be kind to the kernel copyout mechanism.
+ * By aligning the file offset to a block boundary, we can let
+ * the kernel use the VM hardware to map pages instead of
+ * copying bytes laboriously. Using a block boundary also
+ * ensures that we only read one block, rather than two.
+ */
+
+ curoff = target & ~(fp->_blksize - 1);
+ if (seekfn (ptr, fp->_cookie, curoff, SEEK_SET) == POS_ERR)
+ goto dumb;
+ fp->_r = 0;
+ fp->_p = fp->_bf._base;
+ if (HASUB (fp))
+ FREEUB (ptr, fp);
+ fp->_flags &= ~__SEOF;
+ n = target - curoff;
+ if (n)
+ {
+ if (__srefill_r (ptr, fp) || fp->_r < n)
+ goto dumb;
+ fp->_p += n;
+ fp->_r -= n;
+ }
+ memset (&fp->_mbstate, 0, sizeof (_mbstate_t));
+ _funlockfile (fp);
+ __sfp_lock_release ();
+ return 0;
+
+ /*
+ * We get here if we cannot optimise the seek ... just
+ * do it. Allow the seek function to change fp->_bf._base.
+ */
+
+dumb:
+ if (_fflush_r (ptr, fp)
+ || seekfn (ptr, fp->_cookie, offset, whence) == POS_ERR)
+ {
+ _funlockfile (fp);
+ __sfp_lock_release ();
+ return EOF;
+ }
+ /* success: clear EOF indicator and discard ungetc() data */
+ if (HASUB (fp))
+ FREEUB (ptr, fp);
+ fp->_p = fp->_bf._base;
+ fp->_r = 0;
+ /* fp->_w = 0; *//* unnecessary (I think...) */
+ fp->_flags &= ~__SEOF;
+ /* Reset no-optimization flag after successful seek. The
+ no-optimization flag may be set in the case of a read
+ stream that is flushed which by POSIX/SUSv3 standards,
+ means that a corresponding seek must not optimize. The
+ optimization is then allowed if no subsequent flush
+ is performed. */
+ fp->_flags &= ~__SNPT;
+ memset (&fp->_mbstate, 0, sizeof (_mbstate_t));
+ _funlockfile (fp);
+ __sfp_lock_release ();
+ return 0;
+}
+
+#ifndef _REENT_ONLY
+
+int
+_DEFUN(fseek, (fp, offset, whence),
+ register FILE *fp _AND
+ long offset _AND
+ int whence)
+{
+ return _fseek_r (_REENT, fp, offset, whence);
+}
+
+#endif /* !_REENT_ONLY */
fseek.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: vfieeefp.h
===================================================================
--- vfieeefp.h (nonexistent)
+++ vfieeefp.h (revision 520)
@@ -0,0 +1,283 @@
+/****************************************************************
+ *
+ * The author of this software is David M. Gay.
+ *
+ * Copyright (c) 1991 by AT&T.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose without fee is hereby granted, provided that this entire notice
+ * is included in all copies of any software which is or includes a copy
+ * or modification of this software and in all copies of the supporting
+ * documentation for such software.
+ *
+ * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED
+ * WARRANTY. IN PARTICULAR, NEITHER THE AUTHOR NOR AT&T MAKES ANY
+ * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY
+ * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
+ *
+ ***************************************************************/
+
+/* Please send bug reports to
+ David M. Gay
+ AT&T Bell Laboratories, Room 2C-463
+ 600 Mountain Avenue
+ Murray Hill, NJ 07974-2070
+ U.S.A.
+ dmg@research.att.com or research!dmg
+ */
+
+/* This header file is a modification of mprec.h that only contains floating
+ point union code. */
+
+#include
+#include
+#include
+#include
+#include
+#include
+
+#ifdef __IEEE_LITTLE_ENDIAN
+#define IEEE_8087
+#endif
+
+#ifdef __IEEE_BIG_ENDIAN
+#define IEEE_MC68k
+#endif
+
+#ifdef __Z8000__
+#define Just_16
+#endif
+
+#ifdef Unsigned_Shifts
+#define Sign_Extend(a,b) if (b < 0) a |= (__uint32_t)0xffff0000;
+#else
+#define Sign_Extend(a,b) /*no-op*/
+#endif
+
+#if defined(IEEE_8087) + defined(IEEE_MC68k) + defined(VAX) + defined(IBM) != 1
+Exactly one of IEEE_8087, IEEE_MC68k, VAX, or IBM should be defined.
+#endif
+
+#ifdef _WANT_IO_LONG_DOUBLE
+/* If we are going to examine or modify specific bits in a long double using
+ the lword0 or lwordx macros, then we must wrap the long double inside
+ a union. This is necessary to avoid undefined behavior according to
+ the ANSI C spec. */
+
+#ifdef IEEE_8087
+#if LDBL_MANT_DIG == 24
+struct ldieee
+{
+ unsigned manh:23;
+ unsigned exp:8;
+ unsigned sign:1;
+};
+#elif LDBL_MANT_DIG == 53
+struct ldieee
+{
+ unsigned manl:20;
+ unsigned manh:32;
+ unsigned exp:11;
+ unsigned sign:1;
+};
+#elif LDBL_MANT_DIG == 64
+struct ldieee
+{
+ unsigned manl:32;
+ unsigned manh:32;
+ unsigned exp:15;
+ unsigned sign:1;
+};
+#elif LDBL_MANT_DIG > 64
+struct ldieee
+{
+ unsigned manl3:16;
+ unsigned manl2:32;
+ unsigned manl:32;
+ unsigned manh:32;
+ unsigned exp:15;
+ unsigned sign:1;
+};
+#endif /* LDBL_MANT_DIG */
+#else /* !IEEE_8087 */
+#if LDBL_MANT_DIG == 24
+struct ldieee
+{
+ unsigned sign:1;
+ unsigned exp:8;
+ unsigned manh:23;
+};
+#elif LDBL_MANT_DIG == 53
+struct ldieee
+{
+ unsigned sign:1;
+ unsigned exp:11;
+ unsigned manh:32;
+ unsigned manl:20;
+};
+#elif LDBL_MANT_DIG == 64
+struct ldieee
+{
+ unsigned sign:1;
+ unsigned exp:15;
+ unsigned manh:32;
+ unsigned manl:32;
+};
+#elif LDBL_MANT_DIG > 64
+struct ldieee
+{
+ unsigned sign:1;
+ unsigned exp:15;
+ unsigned manh:32;
+ unsigned manl:32;
+ unsigned manl2:32;
+ unsigned manl3;16;
+};
+#endif /* LDBL_MANT_DIG */
+#endif /* !IEEE_8087 */
+#endif /* _WANT_IO_LONG_DOUBLE */
+
+/* If we are going to examine or modify specific bits in a double using
+ the word0 and/or word1 macros, then we must wrap the double inside
+ a union. This is necessary to avoid undefined behavior according to
+ the ANSI C spec. */
+union double_union
+{
+ double d;
+ __uint32_t i[2];
+};
+
+#ifdef IEEE_8087
+#define word0(x) (x.i[1])
+#define word1(x) (x.i[0])
+#else
+#define word0(x) (x.i[0])
+#define word1(x) (x.i[1])
+#endif
+
+/* #define P DBL_MANT_DIG */
+/* Ten_pmax = floor(P*log(2)/log(5)) */
+/* Bletch = (highest power of 2 < DBL_MAX_10_EXP) / 16 */
+/* Quick_max = floor((P-1)*log(FLT_RADIX)/log(10) - 1) */
+/* Int_max = floor(P*log(FLT_RADIX)/log(10) - 1) */
+
+#if defined(IEEE_8087) + defined(IEEE_MC68k)
+#if defined (_DOUBLE_IS_32BITS)
+#define Exp_shift 23
+#define Exp_shift1 23
+#define Exp_msk1 ((__uint32_t)0x00800000L)
+#define Exp_msk11 ((__uint32_t)0x00800000L)
+#define Exp_mask ((__uint32_t)0x7f800000L)
+#define P 24
+#define Bias 127
+#define IEEE_Arith
+#define Emin (-126)
+#define Exp_1 ((__uint32_t)0x3f800000L)
+#define Exp_11 ((__uint32_t)0x3f800000L)
+#define Ebits 8
+#define Frac_mask ((__uint32_t)0x007fffffL)
+#define Frac_mask1 ((__uint32_t)0x007fffffL)
+#define Ten_pmax 10
+#define Sign_bit ((__uint32_t)0x80000000L)
+#define Ten_pmax 10
+#define Bletch 2
+#define Bndry_mask ((__uint32_t)0x007fffffL)
+#define Bndry_mask1 ((__uint32_t)0x007fffffL)
+#define LSB 1
+#define Sign_bit ((__uint32_t)0x80000000L)
+#define Log2P 1
+#define Tiny0 0
+#define Tiny1 1
+#define Quick_max 5
+#define Int_max 6
+#define Infinite(x) (word0(x) == ((__uint32_t)0x7f800000L))
+#undef word0
+#undef word1
+
+#define word0(x) (x.i[0])
+#define word1(x) 0
+#else
+
+#define Exp_shift 20
+#define Exp_shift1 20
+#define Exp_msk1 ((__uint32_t)0x100000L)
+#define Exp_msk11 ((__uint32_t)0x100000L)
+#define Exp_mask ((__uint32_t)0x7ff00000L)
+#define P 53
+#define Bias 1023
+#define IEEE_Arith
+#define Emin (-1022)
+#define Exp_1 ((__uint32_t)0x3ff00000L)
+#define Exp_11 ((__uint32_t)0x3ff00000L)
+#define Ebits 11
+#define Frac_mask ((__uint32_t)0xfffffL)
+#define Frac_mask1 ((__uint32_t)0xfffffL)
+#define Ten_pmax 22
+#define Bletch 0x10
+#define Bndry_mask ((__uint32_t)0xfffffL)
+#define Bndry_mask1 ((__uint32_t)0xfffffL)
+#define LSB 1
+#define Sign_bit ((__uint32_t)0x80000000L)
+#define Log2P 1
+#define Tiny0 0
+#define Tiny1 1
+#define Quick_max 14
+#define Int_max 14
+#define Infinite(x) (word0(x) == ((__uint32_t)0x7ff00000L)) /* sufficient test for here */
+#endif
+
+#else
+#undef Sudden_Underflow
+#define Sudden_Underflow
+#ifdef IBM
+#define Exp_shift 24
+#define Exp_shift1 24
+#define Exp_msk1 ((__uint32_t)0x1000000L)
+#define Exp_msk11 ((__uint32_t)0x1000000L)
+#define Exp_mask ((__uint32_t)0x7f000000L)
+#define P 14
+#define Bias 65
+#define Exp_1 ((__uint32_t)0x41000000L)
+#define Exp_11 ((__uint32_t)0x41000000L)
+#define Ebits 8 /* exponent has 7 bits, but 8 is the right value in b2d */
+#define Frac_mask ((__uint32_t)0xffffffL)
+#define Frac_mask1 ((__uint32_t)0xffffffL)
+#define Bletch 4
+#define Ten_pmax 22
+#define Bndry_mask ((__uint32_t)0xefffffL)
+#define Bndry_mask1 ((__uint32_t)0xffffffL)
+#define LSB 1
+#define Sign_bit ((__uint32_t)0x80000000L)
+#define Log2P 4
+#define Tiny0 ((__uint32_t)0x100000L)
+#define Tiny1 0
+#define Quick_max 14
+#define Int_max 15
+#else /* VAX */
+#define Exp_shift 23
+#define Exp_shift1 7
+#define Exp_msk1 0x80
+#define Exp_msk11 ((__uint32_t)0x800000L)
+#define Exp_mask ((__uint32_t)0x7f80L)
+#define P 56
+#define Bias 129
+#define Exp_1 ((__uint32_t)0x40800000L)
+#define Exp_11 ((__uint32_t)0x4080L)
+#define Ebits 8
+#define Frac_mask ((__uint32_t)0x7fffffL)
+#define Frac_mask1 ((__uint32_t)0xffff007fL)
+#define Ten_pmax 24
+#define Bletch 2
+#define Bndry_mask ((__uint32_t)0xffff007fL)
+#define Bndry_mask1 ((__uint32_t)0xffff007fL)
+#define LSB ((__uint32_t)0x10000L)
+#define Sign_bit ((__uint32_t)0x8000L)
+#define Log2P 1
+#define Tiny0 0x80
+#define Tiny1 0
+#define Quick_max 15
+#define Int_max 15
+#endif
+#endif
+
+
vfieeefp.h
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: asiprintf.c
===================================================================
--- asiprintf.c (nonexistent)
+++ asiprintf.c (revision 520)
@@ -0,0 +1,80 @@
+/*
+ * 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.
+ */
+/* This code was copied from asprintf.c */
+/* doc in siprintf.c */
+
+#include <_ansi.h>
+#include
+#include
+#include
+#include
+#include "local.h"
+
+int
+_DEFUN(_asiprintf_r, (ptr, strp, fmt),
+ struct _reent *ptr _AND
+ char **strp _AND
+ const char *fmt _DOTS)
+{
+ int ret;
+ va_list ap;
+ FILE f;
+
+ /* mark a zero-length reallocatable buffer */
+ f._flags = __SWR | __SSTR | __SMBF;
+ f._bf._base = f._p = NULL;
+ f._bf._size = f._w = 0;
+ f._file = -1; /* No file. */
+ va_start (ap, fmt);
+ ret = _svfiprintf_r (ptr, &f, fmt, ap);
+ va_end (ap);
+ if (ret >= 0)
+ {
+ *f._p = 0;
+ *strp = f._bf._base;
+ }
+ return (ret);
+}
+
+#ifndef _REENT_ONLY
+
+int
+_DEFUN(asiprintf, (strp, fmt),
+ char **strp _AND
+ const char *fmt _DOTS)
+{
+ int ret;
+ va_list ap;
+ FILE f;
+
+ /* mark a zero-length reallocatable buffer */
+ f._flags = __SWR | __SSTR | __SMBF;
+ f._bf._base = f._p = NULL;
+ f._bf._size = f._w = 0;
+ f._file = -1; /* No file. */
+ va_start (ap, fmt);
+ ret = _svfiprintf_r (_REENT, &f, fmt, ap);
+ va_end (ap);
+ if (ret >= 0)
+ {
+ *f._p = 0;
+ *strp = f._bf._base;
+ }
+ return (ret);
+}
+
+#endif /* ! _REENT_ONLY */
asiprintf.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: fgetws.c
===================================================================
--- fgetws.c (nonexistent)
+++ fgetws.c (revision 520)
@@ -0,0 +1,164 @@
+/*-
+ * Copyright (c) 2002-2004 Tim J. Robbins.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+FUNCTION
+<>---get wide character string from a file or stream
+
+INDEX
+ fgetws
+INDEX
+ _fgetws_r
+
+ANSI_SYNOPSIS
+ #include
+ wchar_t *fgetws(wchar_t *<[ws]>, int <[n]>, FILE *<[fp]>);
+
+ #include
+ wchar_t *_fgetws_r(struct _reent *<[ptr]>, wchar_t *<[ws]>, int <[n]>, FILE *<[fp]>);
+
+TRAD_SYNOPSIS
+ #include
+ wchar_t *fgetws(<[ws]>,<[n]>,<[fp]>)
+ wchar_t *<[ws]>;
+ int <[n]>;
+ FILE *<[fp]>;
+
+ #include
+ wchar_t *_fgetws_r(<[ptr]>, <[ws]>,<[n]>,<[fp]>)
+ struct _reent *<[ptr]>;
+ wchar_t *<[ws]>;
+ int <[n]>;
+ FILE *<[fp]>;
+
+DESCRIPTION
+Reads at most <[n-1]> wide characters from <[fp]> until a newline
+is found. The wide characters including to the newline are stored
+in <[ws]>. The buffer is terminated with a 0.
+
+The <<_fgetws_r>> function is simply the reentrant version of
+<> and is passed an additional reentrancy structure
+pointer: <[ptr]>.
+
+RETURNS
+<> 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
+no data are read, NULL is returned instead.
+
+PORTABILITY
+C99, POSIX.1-2001
+*/
+
+#include <_ansi.h>
+#include
+#include
+#include
+#include
+#include
+#include "local.h"
+
+wchar_t *
+_DEFUN(_fgetws_r, (ptr, ws, n, fp),
+ struct _reent *ptr _AND
+ wchar_t * ws _AND
+ int n _AND
+ FILE * fp)
+{
+ wchar_t *wsp;
+ size_t nconv;
+ const char *src;
+ unsigned char *nl;
+
+ __sfp_lock_acquire ();
+ _flockfile (fp);
+ ORIENT (fp, 1);
+
+ if (n <= 0)
+ {
+ errno = EINVAL;
+ goto error;
+ }
+
+ if (fp->_r <= 0 && __srefill_r (ptr, fp))
+ /* EOF */
+ goto error;
+ wsp = ws;
+ do
+ {
+ src = (char *) fp->_p;
+ nl = memchr (fp->_p, '\n', fp->_r);
+ nconv = _mbsrtowcs_r (ptr, wsp, &src,
+ nl != NULL ? (nl - fp->_p + 1) : fp->_r,
+ &fp->_mbstate);
+ if (nconv == (size_t) -1)
+ /* Conversion error */
+ goto error;
+ if (src == NULL)
+ {
+ /*
+ * We hit a null byte. Increment the character count,
+ * since mbsnrtowcs()'s return value doesn't include
+ * the terminating null, then resume conversion
+ * after the null.
+ */
+ nconv++;
+ src = memchr (fp->_p, '\0', fp->_r);
+ src++;
+ }
+ fp->_r -= (unsigned char *) src - fp->_p;
+ fp->_p = (unsigned char *) src;
+ n -= nconv;
+ wsp += nconv;
+ }
+ while (wsp[-1] != L'\n' && n > 1 && (fp->_r > 0
+ || __srefill_r (ptr, fp) == 0));
+ if (wsp == ws)
+ /* EOF */
+ goto error;
+ if (!mbsinit (&fp->_mbstate))
+ /* Incomplete character */
+ goto error;
+ *wsp++ = L'\0';
+ _funlockfile (fp);
+ __sfp_lock_release ();
+ return ws;
+
+error:
+ _funlockfile (fp);
+ __sfp_lock_release ();
+ return NULL;
+}
+
+wchar_t *
+_DEFUN(fgetws, (ws, n, fp),
+ wchar_t *ws _AND
+ int n _AND
+ FILE *fp)
+{
+ CHECK_INIT (_REENT, fp);
+ return _fgetws_r (_REENT, ws, n, fp);
+}
fgetws.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: putw.c
===================================================================
--- putw.c (nonexistent)
+++ putw.c (revision 520)
@@ -0,0 +1,65 @@
+/*
+ * 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
+<>---write a word (int)
+
+INDEX
+ putw
+
+ANSI_SYNOPSIS
+ #include
+ int putw(int <[w]>, FILE *<[fp]>);
+
+TRAD_SYNOPSIS
+ #include
+ int putw(, <[fp]>)
+ int ;
+ FILE *<[fp]>;
+
+DESCRIPTION
+<> is a function, defined in <>. You can use <>
+to write a word to the file or stream identified by <[fp]>. As a side
+effect, <> advances the file's current position indicator.
+
+RETURNS
+Zero on success, <> on failure.
+
+PORTABILITY
+<> is a remnant of K&R C; it is not part of any ISO C Standard.
+<> should be used instead. In fact, this implementation of
+<> is based upon <>.
+
+Supporting OS subroutines required: <>.
+*/
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "%W% (Berkeley) %G%";
+#endif /* LIBC_SCCS and not lint */
+
+#include
+
+int
+_DEFUN(putw, (w, fp),
+ int w _AND
+ register FILE *fp)
+{
+ if (fwrite ((_CONST char*)&w, sizeof (w), 1, fp) != 1)
+ return EOF;
+ return 0;
+}
putw.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: fwrite.c
===================================================================
--- fwrite.c (nonexistent)
+++ fwrite.c (revision 520)
@@ -0,0 +1,143 @@
+/*
+ * 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
+<>---write array elements
+
+INDEX
+ fwrite
+INDEX
+ _fwrite_r
+
+ANSI_SYNOPSIS
+ #include
+ size_t fwrite(const void *<[buf]>, size_t <[size]>,
+ size_t <[count]>, FILE *<[fp]>);
+
+ #include
+ size_t _fwrite_r(struct _reent *<[ptr]>, const void *<[buf]>, size_t <[size]>,
+ size_t <[count]>, FILE *<[fp]>);
+
+TRAD_SYNOPSIS
+ #include
+ size_t fwrite(<[buf]>, <[size]>, <[count]>, <[fp]>)
+ char *<[buf]>;
+ size_t <[size]>;
+ size_t <[count]>;
+ FILE *<[fp]>;
+
+ #include
+ size_t _fwrite_r(<[ptr]>, <[buf]>, <[size]>, <[count]>, <[fp]>)
+ struct _reent *<[ptr]>;
+ char *<[buf]>;
+ size_t <[size]>;
+ size_t <[count]>;
+ FILE *<[fp]>;
+
+DESCRIPTION
+<> attempts to copy, starting from the memory location
+<[buf]>, <[count]> elements (each of size <[size]>) into the file or
+stream identified by <[fp]>. <> may copy fewer elements than
+<[count]> if an error intervenes.
+
+<> also advances the file position indicator (if any) for
+<[fp]> by the number of @emph{characters} actually written.
+
+<<_fwrite_r>> is simply the reentrant version of <> that
+takes an additional reentrant structure argument: <[ptr]>.
+
+RETURNS
+If <> succeeds in writing all the elements you specify, the
+result is the same as the argument <[count]>. In any event, the
+result is the number of complete elements that <> copied to
+the file.
+
+PORTABILITY
+ANSI C requires <>.
+
+Supporting OS subroutines required: <>, <>, <>,
+<>, <>, <>, <>.
+*/
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "%W% (Berkeley) %G%";
+#endif /* LIBC_SCCS and not lint */
+
+#include <_ansi.h>
+#include
+#include
+#if 0
+#include
+#endif
+#include "local.h"
+#if 1
+#include "fvwrite.h"
+#endif
+
+/*
+ * Write `count' objects (each size `size') from memory to the given file.
+ * Return the number of whole objects written.
+ */
+
+size_t
+_DEFUN(_fwrite_r, (ptr, buf, size, count, fp),
+ struct _reent * ptr _AND
+ _CONST _PTR buf _AND
+ size_t size _AND
+ size_t count _AND
+ FILE * fp)
+{
+ size_t n;
+ struct __suio uio;
+ struct __siov iov;
+
+ iov.iov_base = buf;
+ uio.uio_resid = iov.iov_len = n = count * size;
+ uio.uio_iov = &iov;
+ uio.uio_iovcnt = 1;
+
+ /*
+ * The usual case is success (__sfvwrite_r returns 0);
+ * skip the divide if this happens, since divides are
+ * generally slow and since this occurs whenever size==0.
+ */
+
+ CHECK_INIT(ptr, fp);
+
+ _flockfile (fp);
+ ORIENT (fp, -1);
+ if (__sfvwrite_r (ptr, fp, &uio) == 0)
+ {
+ _funlockfile (fp);
+ return count;
+ }
+ _funlockfile (fp);
+ return (n - uio.uio_resid) / size;
+}
+
+#ifndef _REENT_ONLY
+size_t
+_DEFUN(fwrite, (buf, size, count, fp),
+ _CONST _PTR buf _AND
+ size_t size _AND
+ size_t count _AND
+ FILE * fp)
+{
+ return _fwrite_r (_REENT, buf, size, count, fp);
+}
+#endif
fwrite.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: asnprintf.c
===================================================================
--- asnprintf.c (nonexistent)
+++ asnprintf.c (revision 520)
@@ -0,0 +1,108 @@
+/* Copyright (C) 2007, 2008 Eric Blake
+ * Permission to use, copy, modify, and distribute this software
+ * is freely granted, provided that this notice is preserved.
+ */
+/* This code was derived from asprintf.c */
+/* doc in sprintf.c */
+
+#include <_ansi.h>
+#include
+#include
+#include
+#include
+#include
+#include "local.h"
+
+char *
+_DEFUN(_asnprintf_r, (ptr, buf, lenp, fmt),
+ struct _reent *ptr _AND
+ char *buf _AND
+ size_t *lenp _AND
+ const char *fmt _DOTS)
+{
+ int ret;
+ va_list ap;
+ FILE f;
+ size_t len = *lenp;
+
+ if (buf && len)
+ {
+ /* mark an existing buffer, but allow allocation of larger string */
+ f._flags = __SWR | __SSTR | __SOPT;
+ }
+ else
+ {
+ /* mark a zero-length reallocatable buffer */
+ f._flags = __SWR | __SSTR | __SMBF;
+ len = 0;
+ buf = NULL;
+ }
+ f._bf._base = f._p = (unsigned char *) buf;
+ /* For now, inherit the 32-bit signed limit of FILE._bf._size.
+ FIXME - it would be nice to rewrite sys/reent.h to support size_t
+ for _size. */
+ if (len > INT_MAX)
+ {
+ ptr->_errno = EOVERFLOW;
+ return NULL;
+ }
+ f._bf._size = f._w = len;
+ f._file = -1; /* No file. */
+ va_start (ap, fmt);
+ ret = _svfprintf_r (ptr, &f, fmt, ap);
+ va_end (ap);
+ if (ret < 0)
+ return NULL;
+ *lenp = ret;
+ *f._p = '\0';
+ return (char *) f._bf._base;
+}
+
+#ifndef _REENT_ONLY
+
+char *
+_DEFUN(asnprintf, (buf, lenp, fmt),
+ char *buf _AND
+ size_t *lenp _AND
+ const char *fmt _DOTS)
+{
+ int ret;
+ va_list ap;
+ FILE f;
+ size_t len = *lenp;
+ struct _reent *ptr = _REENT;
+
+ if (buf && len)
+ {
+ /* mark an existing buffer, but allow allocation of larger string */
+ f._flags = __SWR | __SSTR | __SOPT;
+ }
+ else
+ {
+ /* mark a zero-length reallocatable buffer */
+ f._flags = __SWR | __SSTR | __SMBF;
+ len = 0;
+ buf = NULL;
+ }
+ f._bf._base = f._p = (unsigned char *) buf;
+ /* For now, inherit the 32-bit signed limit of FILE._bf._size.
+ FIXME - it would be nice to rewrite sys/reent.h to support size_t
+ for _size. */
+ if (len > INT_MAX)
+ {
+ ptr->_errno = EOVERFLOW;
+ return NULL;
+ }
+ f._bf._size = f._w = len;
+ f._file = -1; /* No file. */
+ va_start (ap, fmt);
+ ret = _svfprintf_r (ptr, &f, fmt, ap);
+ va_end (ap);
+ if (ret < 0)
+ return NULL;
+ *lenp = ret;
+ *f._p = '\0';
+ return (char *) f._bf._base;
+}
+
+#endif /* ! _REENT_ONLY */
asnprintf.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: funopen.c
===================================================================
--- funopen.c (nonexistent)
+++ funopen.c (revision 520)
@@ -0,0 +1,278 @@
+/* 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 a stream with custom callbacks
+
+INDEX
+ funopen
+INDEX
+ fropen
+INDEX
+ fwopen
+
+ANSI_SYNOPSIS
+ #include
+ 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
+<> creates a <> 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 <>, except that rather
+than 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 <>, except that rather than
+ 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 <>, 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 <>, except that <[cookie]> will be passed as the
+first argument. A NULL <[closefn]> merely flushes all data then lets
+<> 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
+<>. 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 <> and <> are convenience macros around
+<> that only use the specified callback.
+
+RETURNS
+The return value is an open FILE pointer on success. On error,
+<> is returned, and <> 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 <> interface from Linux.
+
+Supporting OS subroutines required: <>.
+*/
+
+#include
+#include
+#include
+#include "local.h"
+
+typedef int (*funread)(void *_cookie, char *_buf, int _n);
+typedef int (*funwrite)(void *_cookie, const char *_buf, int _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
+ int 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
+ int 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)
+ {
+ __sfp_lock_acquire ();
+ fp->_flags = 0; /* release */
+#ifndef __SINGLE_THREAD__
+ __lock_close_recursive (fp->_lock);
+#endif
+ __sfp_lock_release ();
+ return NULL;
+ }
+
+ _flockfile (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;
+ _funlockfile (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 */
funopen.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: open_memstream.c
===================================================================
--- open_memstream.c (nonexistent)
+++ open_memstream.c (revision 520)
@@ -0,0 +1,411 @@
+/* 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 a write stream around an arbitrary-length string
+
+INDEX
+ open_memstream
+INDEX
+ open_wmemstream
+
+ANSI_SYNOPSIS
+ #include
+ FILE *open_memstream(char **restrict <[buf]>,
+ size_t *restrict <[size]>);
+
+ #include
+ FILE *open_wmemstream(wchar_t **restrict <[buf]>,
+ size_t *restrict <[size]>);
+
+DESCRIPTION
+<> creates a seekable, byte-oriented <> stream that
+wraps an arbitrary-length buffer, created as if by <>. 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 <> or <>, 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 <>.
+
+<> is like <> 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 <> for a way to wrap a string with a
+readable stream. The user is responsible for calling <> on
+the final *<[buf]> after <>.
+
+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 <>). 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,
+<> is returned, and <> 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: <>.
+*/
+
+#include
+#include
+#include
+#include
+#include
+#include
+#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
+ int 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)
+ {
+ __sfp_lock_acquire ();
+ fp->_flags = 0; /* release */
+#ifndef __SINGLE_THREAD__
+ __lock_close_recursive (fp->_lock);
+#endif
+ __sfp_lock_release ();
+ 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;
+ else if (c->max > 64 * 1024)
+ c->max = 64 * 1024;
+ *size = 0;
+ *buf = _malloc_r (ptr, c->max);
+ if (!*buf)
+ {
+ __sfp_lock_acquire ();
+ fp->_flags = 0; /* release */
+#ifndef __SINGLE_THREAD__
+ __lock_close_recursive (fp->_lock);
+#endif
+ __sfp_lock_release ();
+ _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->eof = 0;
+ c->saved.w = L'\0';
+ c->wide = (int8_t) wide;
+
+ _flockfile (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);
+ _funlockfile (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 */
open_memstream.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: vasprintf.c
===================================================================
--- vasprintf.c (nonexistent)
+++ vasprintf.c (revision 520)
@@ -0,0 +1,63 @@
+/*
+ * 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
+#include
+#include
+
+#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);
+}
+
+#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 = f._bf._base;
+ }
+ return ret;
+}
vasprintf.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: vfwscanf.c
===================================================================
--- vfwscanf.c (nonexistent)
+++ vfwscanf.c (revision 520)
@@ -0,0 +1,1469 @@
+/*-
+ * 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
+<>, <>, <>---scan and format argument list from wide character input
+
+INDEX
+ vfwscanf
+INDEX
+ _vfwscanf
+INDEX
+ vwscanf
+INDEX
+ _vwscanf
+INDEX
+ vswscanf
+INDEX
+ _vswscanf
+
+ANSI_SYNOPSIS
+ #include
+ #include
+ int vwscanf(const wchar_t *<[fmt]>, va_list <[list]>);
+ int vfwscanf(FILE *<[fp]>, const wchar_t *<[fmt]>, va_list <[list]>);
+ int vswscanf(const wchar_t *<[str]>, const wchar_t *<[fmt]>, va_list <[list]>);
+
+ int _vwscanf(struct _reent *<[reent]>, const wchar_t *<[fmt]>,
+ va_list <[list]>);
+ int _vfwscanf(struct _reent *<[reent]>, FILE *<[fp]>, const wchar_t *<[fmt]>,
+ va_list <[list]>);
+ int _vswscanf(struct _reent *<[reent]>, const wchar_t *<[str]>,
+ const wchar_t *<[fmt]>, va_list <[list]>);
+
+TRAD_SYNOPSIS
+ #include
+ #include
+ int vwscanf( <[fmt]>, <[ist]>)
+ wchar_t *<[fmt]>;
+ va_list <[list]>;
+
+ int vfwscanf( <[fp]>, <[fmt]>, <[list]>)
+ FILE *<[fp]>;
+ wchar_t *<[fmt]>;
+ va_list <[list]>;
+
+ int vswscanf( <[str]>, <[fmt]>, <[list]>)
+ wchar_t *<[str]>;
+ wchar_t *<[fmt]>;
+ va_list <[list]>;
+
+ int _vwscanf( <[reent]>, <[fmt]>, <[ist]>)
+ struct _reent *<[reent]>;
+ wchar_t *<[fmt]>;
+ va_list <[list]>;
+
+ int _vfwscanf( <[reent]>, <[fp]>, <[fmt]>, <[list]>)
+ struct _reent *<[reent]>;
+ FILE *<[fp]>;
+ wchar_t *<[fmt]>;
+ va_list <[list]>;
+
+ int _vswscanf( <[reent]>, <[str]>, <[fmt]>, <[list]>)
+ struct _reent *<[reent]>;
+ wchar_t *<[str]>;
+ wchar_t *<[fmt]>;
+ va_list <[list]>;
+
+DESCRIPTION
+<>, <>, and <> are (respectively) variants
+of <>, <>, and <>. They differ only in
+allowing their caller to pass the variable argument list as a
+<> object (initialized by <>) rather than
+directly accepting a variable number of arguments.
+
+RETURNS
+The return values are consistent with the corresponding functions:
+<> returns the number of input fields successfully scanned,
+converted, and stored; the return value does not include scanned
+fields which were not stored.
+
+If <> attempts to read at end-of-file, the return value
+is <>.
+
+If no fields were stored, the return value is <<0>>.
+
+The routines <<_vwscanf>>, <<_vfwscanf>>, and <<_vswscanf>> are
+reentrant versions which take an additional first parameter which points
+to the reentrancy structure.
+
+PORTABILITY
+C99, POSIX-1.2008
+*/
+
+#include <_ansi.h>
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include "local.h"
+
+#ifdef INTEGER_ONLY
+#define VFWSCANF vfiwscanf
+#define _VFWSCANF_R _vfiwscanf_r
+#define __SVFWSCANF __svfiwscanf
+#ifdef STRING_ONLY
+# define __SVFWSCANF_R __ssvfiwscanf_r
+#else
+# define __SVFWSCANF_R __svfiwscanf_r
+#endif
+#else
+#define VFWSCANF vfwscanf
+#define _VFWSCANF_R _vfwscanf_r
+#define __SVFWSCANF __svfwscanf
+#ifdef STRING_ONLY
+# define __SVFWSCANF_R __ssvfwscanf_r
+#else
+# define __SVFWSCANF_R __svfwscanf_r
+#endif
+#ifndef NO_FLOATING_POINT
+#define FLOATING_POINT
+#endif
+#endif
+
+#ifdef STRING_ONLY
+#undef _flockfile
+#undef _funlockfile
+#define _flockfile(x) {}
+#define _funlockfile(x) {}
+#define _ungetwc_r _sungetwc_r
+#define __srefill_r __ssrefill_r
+#define _fgetwc_r _sfgetwc_r
+#endif
+
+#ifdef FLOATING_POINT
+#include
+#include
+
+/* Currently a test is made to see if long double processing is warranted.
+ This could be changed in the future should the _ldtoa_r code be
+ preferred over _dtoa_r. */
+#define _NO_LONGDBL
+#if defined _WANT_IO_LONG_DOUBLE && (LDBL_MANT_DIG > DBL_MANT_DIG)
+#undef _NO_LONGDBL
+extern _LONG_DOUBLE _wcstold_r _PARAMS((wchar_t *s, wchar_t **sptr));
+#endif
+
+#include "floatio.h"
+
+#if ((MAXEXP+MAXFRACT+3) > MB_LEN_MAX)
+# define BUF (MAXEXP+MAXFRACT+3) /* 3 = sign + decimal point + NUL */
+#else
+# define BUF MB_LEN_MAX
+#endif
+
+/* An upper bound for how long a long prints in decimal. 4 / 13 approximates
+ log (2). Add one char for roundoff compensation and one for the sign. */
+#define MAX_LONG_LEN ((CHAR_BIT * sizeof (long) - 1) * 4 / 13 + 2)
+#else
+#define BUF 40
+#endif
+
+#define _NO_LONGLONG
+#if defined _WANT_IO_LONG_LONG \
+ && (defined __GNUC__ || __STDC_VERSION__ >= 199901L)
+# undef _NO_LONGLONG
+#endif
+
+#define _NO_POS_ARGS
+#ifdef _WANT_IO_POS_ARGS
+# undef _NO_POS_ARGS
+# ifdef NL_ARGMAX
+# define MAX_POS_ARGS NL_ARGMAX
+# else
+# define MAX_POS_ARGS 32
+# endif
+
+static void * get_arg (int, va_list *, int *, void **);
+#endif /* _WANT_IO_POS_ARGS */
+
+/*
+ * Flags used during conversion.
+ */
+
+#define LONG 0x01 /* l: long or double */
+#define LONGDBL 0x02 /* L/ll: long double or long long */
+#define SHORT 0x04 /* h: short */
+#define CHAR 0x08 /* hh: 8 bit integer */
+#define SUPPRESS 0x10 /* suppress assignment */
+#define POINTER 0x20 /* weird %p pointer (`fake hex') */
+#define NOSKIP 0x40 /* do not skip blanks */
+
+/*
+ * The following are used in numeric conversions only:
+ * SIGNOK, NDIGITS, DPTOK, and EXPOK are for floating point;
+ * SIGNOK, NDIGITS, PFXOK, and NZDIGITS are for integral.
+ */
+
+#define SIGNOK 0x80 /* +/- is (still) legal */
+#define NDIGITS 0x100 /* no digits detected */
+
+#define DPTOK 0x200 /* (float) decimal point is still legal */
+#define EXPOK 0x400 /* (float) exponent (e+3, etc) still legal */
+
+#define PFXOK 0x200 /* 0x prefix is (still) legal */
+#define NZDIGITS 0x400 /* no zero digits detected */
+#define HAVESIGN 0x10000 /* sign detected */
+
+/*
+ * Conversion types.
+ */
+
+#define CT_CHAR 0 /* %c conversion */
+#define CT_CCL 1 /* %[...] conversion */
+#define CT_STRING 2 /* %s conversion */
+#define CT_INT 3 /* integer, i.e., wcstol or wcstoul */
+#define CT_FLOAT 4 /* floating, i.e., wcstod */
+
+#define INCCL(_c) \
+ (cclcompl ? (wmemchr(ccls, (_c), ccle - ccls) == NULL) : \
+ (wmemchr(ccls, (_c), ccle - ccls) != NULL))
+
+/*
+ * vfwscanf
+ */
+
+#ifndef STRING_ONLY
+
+#ifndef _REENT_ONLY
+
+int
+_DEFUN(VFWSCANF, (fp, fmt, ap),
+ register FILE *fp _AND
+ _CONST wchar_t *fmt _AND
+ va_list ap)
+{
+ CHECK_INIT(_REENT, fp);
+ return __SVFWSCANF_R (_REENT, fp, fmt, ap);
+}
+
+int
+_DEFUN(__SVFWSCANF, (fp, fmt0, ap),
+ register FILE *fp _AND
+ wchar_t _CONST *fmt0 _AND
+ va_list ap)
+{
+ return __SVFWSCANF_R (_REENT, fp, fmt0, ap);
+}
+
+#endif /* !_REENT_ONLY */
+
+int
+_DEFUN(_VFWSCANF_R, (data, fp, fmt, ap),
+ struct _reent *data _AND
+ register FILE *fp _AND
+ _CONST wchar_t *fmt _AND
+ va_list ap)
+{
+ CHECK_INIT(data, fp);
+ return __SVFWSCANF_R (data, fp, fmt, ap);
+}
+#endif /* !STRING_ONLY */
+
+#ifdef STRING_ONLY
+/* When dealing with the swscanf family, we don't want to use the
+ * regular ungetwc which will drag in file I/O items we don't need.
+ * So, we create our own trimmed-down version. */
+static wint_t
+_DEFUN(_sungetwc_r, (data, fp, ch),
+ struct _reent *data _AND
+ wint_t wc _AND
+ register FILE *fp)
+{
+ if (wc == WEOF)
+ return (WEOF);
+
+ /* After ungetc, we won't be at eof anymore */
+ fp->_flags &= ~__SEOF;
+
+ /*
+ * If we are in the middle of ungetwc'ing, just continue.
+ * This may require expanding the current ungetc buffer.
+ */
+
+ if (HASUB (fp))
+ {
+ if (fp->_r >= fp->_ub._size && __submore (data, fp))
+ {
+ return EOF;
+ }
+ fp->_p -= sizeof (wchar_t);
+ *fp->_p = (wchar_t) wc;
+ fp->_r += sizeof (wchar_t);
+ return wc;
+ }
+
+ /*
+ * If we can handle this by simply backing up, do so,
+ * but never replace the original character.
+ * (This makes swscanf() work when scanning `const' data.)
+ */
+
+ if (fp->_bf._base != NULL && fp->_p > fp->_bf._base
+ && ((wchar_t *)fp->_p)[-1] == wc)
+ {
+ fp->_p -= sizeof (wchar_t);
+ fp->_r += sizeof (wchar_t);
+ return wc;
+ }
+
+ /*
+ * Create an ungetc buffer.
+ * Initially, we will use the `reserve' buffer.
+ */
+
+ fp->_ur = fp->_r;
+ fp->_up = fp->_p;
+ fp->_ub._base = fp->_ubuf;
+ fp->_ub._size = sizeof (fp->_ubuf);
+ fp->_p = &fp->_ubuf[sizeof (fp->_ubuf) - sizeof (wchar_t)];
+ *(wchar_t *) fp->_p = wc;
+ fp->_r = 2;
+ return wc;
+}
+
+extern int __ssrefill_r _PARAMS ((struct _reent *ptr, register FILE * fp));
+
+static size_t
+_DEFUN(_sfgetwc_r, (ptr, fp),
+ struct _reent * ptr _AND
+ FILE * fp)
+{
+ wchar_t wc;
+
+ if (fp->_r <= 0 && __ssrefill_r (ptr, fp))
+ return (WEOF);
+ wc = *(wchar_t *) fp->_p;
+ fp->_p += sizeof (wchar_t);
+ fp->_r -= sizeof (wchar_t);
+ return (wc);
+}
+#endif /* STRING_ONLY */
+
+int
+_DEFUN(__SVFWSCANF_R, (rptr, fp, fmt0, ap),
+ struct _reent *rptr _AND
+ register FILE *fp _AND
+ wchar_t _CONST *fmt0 _AND
+ va_list ap)
+{
+ register wchar_t *fmt = (wchar_t *) fmt0;
+ register wint_t c; /* character from format, or conversion */
+ register size_t width; /* field width, or 0 */
+ register wchar_t *p = NULL; /* points into all kinds of strings */
+ register int n; /* handy integer */
+ register int flags; /* flags as defined above */
+ register wchar_t *p0; /* saves original value of p when necessary */
+ int nassigned; /* number of fields assigned */
+ int nread; /* number of characters consumed from fp */
+#ifndef _NO_POS_ARGS
+ int N; /* arg number */
+ int arg_index = 0; /* index into args processed directly */
+ int numargs = 0; /* number of varargs read */
+ void *args[MAX_POS_ARGS]; /* positional args read */
+ int is_pos_arg; /* is current format positional? */
+#endif
+ int base = 0; /* base argument to wcstol/wcstoul */
+
+ mbstate_t mbs; /* value to keep track of multibyte state */
+
+ #define CCFN_PARAMS _PARAMS((struct _reent *, const wchar_t *, wchar_t **, int))
+ unsigned long (*ccfn)CCFN_PARAMS=0; /* conversion function (wcstol/wcstoul) */
+ wchar_t buf[BUF]; /* buffer for numeric conversions */
+ const wchar_t *ccls; /* character class start */
+ const wchar_t *ccle; /* character class end */
+ int cclcompl = 0; /* ccl is complemented? */
+ wint_t wi; /* handy wint_t */
+ char *mbp = NULL; /* multibyte string pointer for %c %s %[ */
+ size_t nconv; /* number of bytes in mb. conversion */
+ char mbbuf[MB_LEN_MAX]; /* temporary mb. character buffer */
+
+ char *cp;
+ short *sp;
+ int *ip;
+#ifdef FLOATING_POINT
+ float *flp;
+ _LONG_DOUBLE *ldp;
+ double *dp;
+#endif
+ long *lp;
+#ifndef _NO_LONGLONG
+ long long *llp;
+#endif
+
+ /* `basefix' is used to avoid `if' tests in the integer scanner */
+ static _CONST short basefix[17] =
+ {10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
+
+ /* Macro to support positional arguments */
+#ifndef _NO_POS_ARGS
+# define GET_ARG(n, ap, type) \
+ ((type) (is_pos_arg \
+ ? (n < numargs \
+ ? args[n] \
+ : get_arg (n, &ap, &numargs, args)) \
+ : (arg_index++ < numargs \
+ ? args[n] \
+ : (numargs < MAX_POS_ARGS \
+ ? args[numargs++] = va_arg (ap, void *) \
+ : va_arg (ap, void *)))))
+#else
+# define GET_ARG(n, ap, type) (va_arg (ap, type))
+#endif
+
+ __sfp_lock_acquire ();
+ _flockfile (fp);
+
+ ORIENT (fp, 1);
+
+ nassigned = 0;
+ nread = 0;
+ ccls = ccle = NULL;
+ for (;;)
+ {
+ c = *fmt++;
+ if (c == L'\0')
+ goto all_done;
+ if (iswspace (c))
+ {
+ while ((c = _fgetwc_r (rptr, fp)) != WEOF && iswspace(c))
+ ;
+ if (c != WEOF)
+ _ungetwc_r (rptr, c, fp);
+ continue;
+ }
+ if (c != L'%')
+ goto literal;
+ width = 0;
+ flags = 0;
+#ifndef _NO_POS_ARGS
+ N = arg_index;
+ is_pos_arg = 0;
+#endif
+
+ /*
+ * switch on the format. continue if done; break once format
+ * type is derived.
+ */
+
+ again:
+ c = *fmt++;
+
+ switch (c)
+ {
+ case L'%':
+ literal:
+ if ((wi = _fgetwc_r (rptr, fp)) == WEOF)
+ goto input_failure;
+ if (wi != c)
+ {
+ _ungetwc_r (rptr, wi, fp);
+ goto input_failure;
+ }
+ nread++;
+ continue;
+
+ case L'*':
+ flags |= SUPPRESS;
+ goto again;
+ case L'l':
+#if defined _WANT_IO_C99_FORMATS || !defined _NO_LONGLONG
+ if (*fmt == L'l') /* Check for 'll' = long long (SUSv3) */
+ {
+ ++fmt;
+ flags |= LONGDBL;
+ }
+ else
+#endif
+ flags |= LONG;
+ goto again;
+ case L'L':
+ flags |= LONGDBL;
+ goto again;
+ case L'h':
+#ifdef _WANT_IO_C99_FORMATS
+ if (*fmt == 'h') /* Check for 'hh' = char int (SUSv3) */
+ {
+ ++fmt;
+ flags |= CHAR;
+ }
+ else
+#endif
+ flags |= SHORT;
+ goto again;
+#ifdef _WANT_IO_C99_FORMATS
+ case L'j': /* intmax_t */
+ if (sizeof (intmax_t) == sizeof (long))
+ flags |= LONG;
+ else
+ flags |= LONGDBL;
+ goto again;
+ case L't': /* ptrdiff_t */
+ if (sizeof (ptrdiff_t) < sizeof (int))
+ /* POSIX states ptrdiff_t is 16 or more bits, as
+ is short. */
+ flags |= SHORT;
+ else if (sizeof (ptrdiff_t) == sizeof (int))
+ /* no flag needed */;
+ else if (sizeof (ptrdiff_t) <= sizeof (long))
+ flags |= LONG;
+ else
+ /* POSIX states that at least one programming
+ environment must support ptrdiff_t no wider than
+ long, but that means other environments can
+ have ptrdiff_t as wide as long long. */
+ flags |= LONGDBL;
+ goto again;
+ case L'z': /* size_t */
+ if (sizeof (size_t) < sizeof (int))
+ /* POSIX states size_t is 16 or more bits, as is short. */
+ flags |= SHORT;
+ else if (sizeof (size_t) == sizeof (int))
+ /* no flag needed */;
+ else if (sizeof (size_t) <= sizeof (long))
+ flags |= LONG;
+ else
+ /* POSIX states that at least one programming
+ environment must support size_t no wider than
+ long, but that means other environments can
+ have size_t as wide as long long. */
+ flags |= LONGDBL;
+ goto again;
+#endif /* _WANT_IO_C99_FORMATS */
+
+ case L'0':
+ case L'1':
+ case L'2':
+ case L'3':
+ case L'4':
+ case L'5':
+ case L'6':
+ case L'7':
+ case L'8':
+ case L'9':
+ width = width * 10 + c - L'0';
+ goto again;
+
+#ifndef _NO_POS_ARGS
+ case L'$':
+ if (width <= MAX_POS_ARGS)
+ {
+ N = width - 1;
+ is_pos_arg = 1;
+ width = 0;
+ goto again;
+ }
+ rptr->_errno = EINVAL;
+ goto input_failure;
+#endif /* !_NO_POS_ARGS */
+
+ case L'd':
+ c = CT_INT;
+ ccfn = (unsigned long (*)CCFN_PARAMS)_wcstol_r;
+ base = 10;
+ break;
+
+ case L'i':
+ c = CT_INT;
+ ccfn = (unsigned long (*)CCFN_PARAMS)_wcstol_r;
+ base = 0;
+ break;
+
+ case L'o':
+ c = CT_INT;
+ ccfn = _wcstoul_r;
+ base = 8;
+ break;
+
+ case L'u':
+ c = CT_INT;
+ ccfn = _wcstoul_r;
+ base = 10;
+ break;
+
+ case L'X':
+ case L'x':
+ flags |= PFXOK; /* enable 0x prefixing */
+ c = CT_INT;
+ ccfn = _wcstoul_r;
+ base = 16;
+ break;
+
+#ifdef FLOATING_POINT
+# ifdef _WANT_IO_C99_FORMATS
+ case L'A':
+ case L'a':
+ case L'F':
+# endif
+ case L'E':
+ case L'G':
+ case L'e':
+ case L'f':
+ case L'g':
+ c = CT_FLOAT;
+ break;
+#endif
+
+#ifdef _WANT_IO_C99_FORMATS
+ case L'S':
+ flags |= LONG;
+ /* FALLTHROUGH */
+#endif
+
+ case L's':
+ c = CT_STRING;
+ break;
+
+ case L'[':
+ ccls = fmt;
+ if (*fmt == '^')
+ {
+ cclcompl = 1;
+ ++fmt;
+ }
+ else
+ cclcompl = 0;
+ if (*fmt == ']')
+ fmt++;
+ while (*fmt != '\0' && *fmt != ']')
+ fmt++;
+ ccle = fmt;
+ fmt++;
+ flags |= NOSKIP;
+ c = CT_CCL;
+ break;
+
+#ifdef _WANT_IO_C99_FORMATS
+ case 'C':
+ flags |= LONG;
+ /* FALLTHROUGH */
+#endif
+
+ case 'c':
+ flags |= NOSKIP;
+ c = CT_CHAR;
+ break;
+
+ case 'p': /* pointer format is like hex */
+ flags |= POINTER | PFXOK;
+ c = CT_INT;
+ ccfn = _wcstoul_r;
+ base = 16;
+ break;
+
+ case 'n':
+ if (flags & SUPPRESS) /* ??? */
+ continue;
+#ifdef _WANT_IO_C99_FORMATS
+ if (flags & CHAR)
+ {
+ cp = GET_ARG (N, ap, char *);
+ *cp = nread;
+ }
+ else
+#endif
+ if (flags & SHORT)
+ {
+ sp = GET_ARG (N, ap, short *);
+ *sp = nread;
+ }
+ else if (flags & LONG)
+ {
+ lp = GET_ARG (N, ap, long *);
+ *lp = nread;
+ }
+#ifndef _NO_LONGLONG
+ else if (flags & LONGDBL)
+ {
+ llp = GET_ARG (N, ap, long long*);
+ *llp = nread;
+ }
+#endif
+ else
+ {
+ ip = GET_ARG (N, ap, int *);
+ *ip = nread;
+ }
+ continue;
+
+ /*
+ * Disgusting backwards compatibility hacks. XXX
+ */
+ case L'\0': /* compat */
+ _funlockfile (fp);
+ __sfp_lock_release ();
+ return EOF;
+
+ default: /* compat */
+ goto match_failure;
+ }
+
+ /*
+ * Consume leading white space, except for formats that
+ * suppress this.
+ */
+ if ((flags & NOSKIP) == 0)
+ {
+ while ((wi = _fgetwc_r (rptr, fp)) != WEOF && iswspace (wi))
+ nread++;
+ if (wi == WEOF)
+ goto input_failure;
+ _ungetwc_r (rptr, wi, fp);
+ }
+
+ /*
+ * Do the conversion.
+ */
+ switch (c)
+ {
+
+ case CT_CHAR:
+ /* scan arbitrary characters (sets NOSKIP) */
+ if (width == 0)
+ width = 1;
+ if (flags & LONG)
+ {
+ if (!(flags & SUPPRESS))
+ p = va_arg(ap, wchar_t *);
+ n = 0;
+ while (width-- != 0 && (wi = _fgetwc_r (rptr, fp)) != WEOF)
+ {
+ if (!(flags & SUPPRESS))
+ *p++ = (wchar_t) wi;
+ n++;
+ }
+ if (n == 0)
+ goto input_failure;
+ nread += n;
+ if (!(flags & SUPPRESS))
+ nassigned++;
+ }
+ else
+ {
+ if (!(flags & SUPPRESS))
+ mbp = va_arg(ap, char *);
+ n = 0;
+ memset ((_PTR)&mbs, '\0', sizeof (mbstate_t));
+ while (width != 0 && (wi = _fgetwc_r (rptr, fp)) != WEOF)
+ {
+ if (width >= MB_CUR_MAX && !(flags & SUPPRESS))
+ {
+ nconv = _wcrtomb_r (rptr, mbp, wi, &mbs);
+ if (nconv == (size_t) -1)
+ goto input_failure;
+ }
+ else
+ {
+ nconv = _wcrtomb_r (rptr, mbbuf, wi, &mbs);
+ if (nconv == (size_t) -1)
+ goto input_failure;
+ if (nconv > width)
+ {
+ _ungetwc_r (rptr, wi, fp);
+ break;
+ }
+ if (!(flags & SUPPRESS))
+ memcpy(mbp, mbbuf, nconv);
+ }
+ if (!(flags & SUPPRESS))
+ mbp += nconv;
+ width -= nconv;
+ n++;
+ }
+ if (n == 0)
+ goto input_failure;
+ nread += n;
+ if (!(flags & SUPPRESS))
+ nassigned++;
+ }
+ break;
+
+ case CT_CCL:
+ /* scan a (nonempty) character class (sets NOSKIP) */
+ if (width == 0)
+ width = (size_t) ~0; /* `infinity' */
+ /* take only those things in the class */
+ if ((flags & SUPPRESS) && (flags & LONG))
+ {
+ n = 0;
+ while ((wi = _fgetwc_r (rptr, fp)) != WEOF
+ && width-- != 0 && INCCL (wi))
+ n++;
+ if (wi != WEOF)
+ _ungetwc_r (rptr, wi, fp);
+ if (n == 0)
+ goto match_failure;
+ }
+ else if (flags & LONG)
+ {
+ p0 = p = va_arg(ap, wchar_t *);
+ while ((wi = _fgetwc_r (rptr, fp)) != WEOF
+ && width-- != 0 && INCCL (wi))
+ *p++ = (wchar_t) wi;
+ if (wi != WEOF)
+ _ungetwc_r (rptr, wi, fp);
+ n = p - p0;
+ if (n == 0)
+ goto match_failure;
+ }
+ else
+ {
+ if (!(flags & SUPPRESS))
+ mbp = va_arg(ap, char *);
+ n = 0;
+ memset ((_PTR) &mbs, '\0', sizeof (mbstate_t));
+ while ((wi = _fgetwc_r (rptr, fp)) != WEOF
+ && width-- != 0 && INCCL (wi))
+ {
+ if (width >= MB_CUR_MAX && !(flags & SUPPRESS))
+ {
+ nconv = _wcrtomb_r (rptr, mbp, wi, &mbs);
+ if (nconv == (size_t) -1)
+ goto input_failure;
+ }
+ else
+ {
+ nconv = wcrtomb(mbbuf, wi, &mbs);
+ if (nconv == (size_t) -1)
+ goto input_failure;
+ if (nconv > width)
+ break;
+ if (!(flags & SUPPRESS))
+ memcpy(mbp, mbbuf, nconv);
+ }
+ if (!(flags & SUPPRESS))
+ mbp += nconv;
+ width -= nconv;
+ n++;
+ }
+ if (wi != WEOF)
+ _ungetwc_r (rptr, wi, fp);
+ if (!(flags & SUPPRESS))
+ {
+ *mbp = 0;
+ nassigned++;
+ }
+ }
+ nread += n;
+ break;
+
+ case CT_STRING:
+ /* like CCL, but zero-length string OK, & no NOSKIP */
+ if (width == 0)
+ width = (size_t)~0;
+ if ((flags & SUPPRESS) && (flags & LONG))
+ {
+ while ((wi = _fgetwc_r (rptr, fp)) != WEOF
+ && width-- != 0 && !iswspace (wi))
+ nread++;
+ if (wi != WEOF)
+ _ungetwc_r (rptr, wi, fp);
+ }
+ else if (flags & LONG)
+ {
+ p0 = p = va_arg(ap, wchar_t *);
+ while ((wi = _fgetwc_r (rptr, fp)) != WEOF
+ && width-- != 0 && !iswspace (wi))
+ {
+ *p++ = (wchar_t) wi;
+ nread++;
+ }
+ if (wi != WEOF)
+ _ungetwc_r (rptr, wi, fp);
+ *p = '\0';
+ nassigned++;
+ }
+ else
+ {
+ if (!(flags & SUPPRESS))
+ mbp = va_arg(ap, char *);
+ memset ((_PTR) &mbs, '\0', sizeof (mbstate_t));
+ while ((wi = _fgetwc_r (rptr, fp)) != WEOF
+ && width != 0 && !iswspace (wi))
+ {
+ if (width >= MB_CUR_MAX && !(flags & SUPPRESS))
+ {
+ nconv = wcrtomb(mbp, wi, &mbs);
+ if (nconv == (size_t)-1)
+ goto input_failure;
+ }
+ else
+ {
+ nconv = wcrtomb(mbbuf, wi, &mbs);
+ if (nconv == (size_t)-1)
+ goto input_failure;
+ if (nconv > width)
+ break;
+ if (!(flags & SUPPRESS))
+ memcpy(mbp, mbbuf, nconv);
+ }
+ if (!(flags & SUPPRESS))
+ mbp += nconv;
+ width -= nconv;
+ nread++;
+ }
+ if (wi != WEOF)
+ _ungetwc_r (rptr, wi, fp);
+ if (!(flags & SUPPRESS))
+ {
+ *mbp = 0;
+ nassigned++;
+ }
+ }
+ continue;
+
+ case CT_INT:
+ {
+ /* scan an integer as if by wcstol/wcstoul */
+ if (width == 0 || width > sizeof (buf) / sizeof (*buf) - 1)
+ width = sizeof(buf) / sizeof (*buf) - 1;
+ flags |= SIGNOK | NDIGITS | NZDIGITS;
+ for (p = buf; width; width--)
+ {
+ c = _fgetwc_r (rptr, fp);
+ /*
+ * Switch on the character; `goto ok' if we
+ * accept it as a part of number.
+ */
+ switch (c)
+ {
+ /*
+ * The digit 0 is always legal, but is special.
+ * For %i conversions, if no digits (zero or nonzero)
+ * have been scanned (only signs), we will have base==0.
+ * In that case, we should set it to 8 and enable 0x
+ * prefixing. Also, if we have not scanned zero digits
+ * before this, do not turn off prefixing (someone else
+ * will turn it off if we have scanned any nonzero digits).
+ */
+ case L'0':
+ if (base == 0)
+ {
+ base = 8;
+ flags |= PFXOK;
+ }
+ if (flags & NZDIGITS)
+ flags &= ~(SIGNOK | NZDIGITS | NDIGITS);
+ else
+ flags &= ~(SIGNOK | PFXOK | NDIGITS);
+ goto ok;
+
+ /* 1 through 7 always legal */
+ case L'1':
+ case L'2':
+ case L'3':
+ case L'4':
+ case L'5':
+ case L'6':
+ case L'7':
+ base = basefix[base];
+ flags &= ~(SIGNOK | PFXOK | NDIGITS);
+ goto ok;
+
+ /* digits 8 and 9 ok iff decimal or hex */
+ case L'8':
+ case L'9':
+ base = basefix[base];
+ if (base <= 8)
+ break; /* not legal here */
+ flags &= ~(SIGNOK | PFXOK | NDIGITS);
+ goto ok;
+
+ /* letters ok iff hex */
+ case L'A':
+ case L'B':
+ case L'C':
+ case L'D':
+ case L'E':
+ case L'F':
+ case L'a':
+ case L'b':
+ case L'c':
+ case L'd':
+ case L'e':
+ case L'f':
+ /* no need to fix base here */
+ if (base <= 10)
+ break; /* not legal here */
+ flags &= ~(SIGNOK | PFXOK | NDIGITS);
+ goto ok;
+
+ /* sign ok only as first character */
+ case L'+':
+ case L'-':
+ if (flags & SIGNOK)
+ {
+ flags &= ~SIGNOK;
+ flags |= HAVESIGN;
+ goto ok;
+ }
+ break;
+
+ /* x ok iff flag still set & single 0 seen */
+ case L'x':
+ case L'X':
+ if ((flags & PFXOK) && p == buf + 1 + !!(flags & HAVESIGN))
+ {
+ base = 16;/* if %i */
+ flags &= ~PFXOK;
+ goto ok;
+ }
+ break;
+ }
+
+ /*
+ * If we got here, c is not a legal character
+ * for a number. Stop accumulating digits.
+ */
+ if (c != WEOF)
+ _ungetwc_r (rptr, c, fp);
+ break;
+ ok:
+ /*
+ * c is legal: store it and look at the next.
+ */
+ *p++ = (wchar_t) c;
+ }
+ /*
+ * If we had only a sign, it is no good; push back the sign.
+ * If the number ends in `x', it was [sign] '0' 'x', so push back
+ * the x and treat it as [sign] '0'.
+ * Use of ungetc here and below assumes ASCII encoding; we are only
+ * pushing back 7-bit characters, so casting to unsigned char is
+ * not necessary.
+ */
+ if (flags & NDIGITS)
+ {
+ if (p > buf)
+ _ungetwc_r (rptr, *--p, fp); /* [-+xX] */
+ goto match_failure;
+ }
+ c = p[-1];
+ if (c == L'x' || c == L'X')
+ {
+ --p;
+ _ungetwc_r (rptr, c, fp);
+ }
+ if ((flags & SUPPRESS) == 0)
+ {
+ unsigned long res;
+
+ *p = 0;
+ res = (*ccfn) (rptr, buf, (wchar_t **) NULL, base);
+ if (flags & POINTER)
+ {
+ void **vp = GET_ARG (N, ap, void **);
+#ifndef _NO_LONGLONG
+ if (sizeof (uintptr_t) > sizeof (unsigned long))
+ {
+ unsigned long long resll;
+ resll = _wcstoull_r (rptr, buf, (wchar_t **) NULL, base);
+ *vp = (void *) (uintptr_t) resll;
+ }
+ else
+#endif /* !_NO_LONGLONG */
+ *vp = (void *) (uintptr_t) res;
+ }
+#ifdef _WANT_IO_C99_FORMATS
+ else if (flags & CHAR)
+ {
+ cp = GET_ARG (N, ap, char *);
+ *cp = res;
+ }
+#endif
+ else if (flags & SHORT)
+ {
+ sp = GET_ARG (N, ap, short *);
+ *sp = res;
+ }
+ else if (flags & LONG)
+ {
+ lp = GET_ARG (N, ap, long *);
+ *lp = res;
+ }
+#ifndef _NO_LONGLONG
+ else if (flags & LONGDBL)
+ {
+ unsigned long long resll;
+ if (ccfn == _wcstoul_r)
+ resll = _wcstoull_r (rptr, buf, (wchar_t **) NULL, base);
+ else
+ resll = _wcstoll_r (rptr, buf, (wchar_t **) NULL, base);
+ llp = GET_ARG (N, ap, long long*);
+ *llp = resll;
+ }
+#endif
+ else
+ {
+ ip = GET_ARG (N, ap, int *);
+ *ip = res;
+ }
+ nassigned++;
+ }
+ nread += p - buf;
+ break;
+ }
+#ifdef FLOATING_POINT
+ case CT_FLOAT:
+ {
+ /* scan a floating point number as if by wcstod */
+ /* This code used to assume that the number of digits is reasonable.
+ However, ANSI / ISO C makes no such stipulation; we have to get
+ exact results even when there is an unreasonable amount of
+ leading zeroes. */
+ long leading_zeroes = 0;
+ long zeroes, exp_adjust;
+ wchar_t *exp_start = NULL;
+ unsigned width_left = 0;
+ char nancount = 0;
+ char infcount = 0;
+#ifdef hardway
+ if (width == 0 || width > sizeof (buf) - 1)
+#else
+ /* size_t is unsigned, hence this optimisation */
+ if (width - 1 > sizeof (buf) - 2)
+#endif
+ {
+ width_left = width - (sizeof (buf) - 1);
+ width = sizeof (buf) - 1;
+ }
+ flags |= SIGNOK | NDIGITS | DPTOK | EXPOK;
+ zeroes = 0;
+ exp_adjust = 0;
+ for (p = buf; width; )
+ {
+ c = _fgetwc_r (rptr, fp);
+ /*
+ * This code mimicks the integer conversion
+ * code, but is much simpler.
+ */
+ switch (c)
+ {
+ case L'0':
+ if (flags & NDIGITS)
+ {
+ flags &= ~SIGNOK;
+ zeroes++;
+ if (width_left)
+ {
+ width_left--;
+ width++;
+ }
+ goto fskip;
+ }
+ /* Fall through. */
+ case L'1':
+ case L'2':
+ case L'3':
+ case L'4':
+ case L'5':
+ case L'6':
+ case L'7':
+ case L'8':
+ case L'9':
+ if (nancount + infcount == 0)
+ {
+ flags &= ~(SIGNOK | NDIGITS);
+ goto fok;
+ }
+ break;
+
+ case L'+':
+ case L'-':
+ if (flags & SIGNOK)
+ {
+ flags &= ~SIGNOK;
+ goto fok;
+ }
+ break;
+ case L'n':
+ case L'N':
+ if (nancount == 0 && zeroes == 0
+ && (flags & (NDIGITS | DPTOK | EXPOK)) ==
+ (NDIGITS | DPTOK | EXPOK))
+ {
+ flags &= ~(SIGNOK | DPTOK | EXPOK | NDIGITS);
+ nancount = 1;
+ goto fok;
+ }
+ if (nancount == 2)
+ {
+ nancount = 3;
+ goto fok;
+ }
+ if (infcount == 1 || infcount == 4)
+ {
+ infcount++;
+ goto fok;
+ }
+ break;
+ case L'a':
+ case L'A':
+ if (nancount == 1)
+ {
+ nancount = 2;
+ goto fok;
+ }
+ break;
+ case L'i':
+ if (infcount == 0 && zeroes == 0
+ && (flags & (NDIGITS | DPTOK | EXPOK)) ==
+ (NDIGITS | DPTOK | EXPOK))
+ {
+ flags &= ~(SIGNOK | DPTOK | EXPOK | NDIGITS);
+ infcount = 1;
+ goto fok;
+ }
+ if (infcount == 3 || infcount == 5)
+ {
+ infcount++;
+ goto fok;
+ }
+ break;
+ case L'f':
+ case L'F':
+ if (infcount == 2)
+ {
+ infcount = 3;
+ goto fok;
+ }
+ break;
+ case L't':
+ case L'T':
+ if (infcount == 6)
+ {
+ infcount = 7;
+ goto fok;
+ }
+ break;
+ case L'y':
+ case L'Y':
+ if (infcount == 7)
+ {
+ infcount = 8;
+ goto fok;
+ }
+ break;
+ case L'.':
+ if (flags & DPTOK)
+ {
+ flags &= ~(SIGNOK | DPTOK);
+ leading_zeroes = zeroes;
+ goto fok;
+ }
+ break;
+ case L'e':
+ case L'E':
+ /* no exponent without some digits */
+ if ((flags & (NDIGITS | EXPOK)) == EXPOK
+ || ((flags & EXPOK) && zeroes))
+ {
+ if (! (flags & DPTOK))
+ {
+ exp_adjust = zeroes - leading_zeroes;
+ exp_start = p;
+ }
+ flags =
+ (flags & ~(EXPOK | DPTOK)) |
+ SIGNOK | NDIGITS;
+ zeroes = 0;
+ goto fok;
+ }
+ break;
+ }
+ if (c != WEOF)
+ _ungetwc_r (rptr, c, fp);
+ break;
+ fok:
+ *p++ = c;
+ fskip:
+ width--;
+ ++nread;
+ }
+ if (zeroes)
+ flags &= ~NDIGITS;
+ /* We may have a 'N' or possibly even [sign] 'N' 'a' as the
+ start of 'NaN', only to run out of chars before it was
+ complete (or having encountered a non-matching char). So
+ check here if we have an outstanding nancount, and if so
+ put back the chars we did swallow and treat as a failed
+ match.
+
+ FIXME - we still don't handle NAN([0xdigits]). */
+ if (nancount - 1U < 2U) /* nancount && nancount < 3 */
+ {
+ /* Newlib's ungetc works even if we called __srefill in
+ the middle of a partial parse, but POSIX does not
+ guarantee that in all implementations of ungetc. */
+ while (p > buf)
+ {
+ _ungetwc_r (rptr, *--p, fp); /* [-+nNaA] */
+ --nread;
+ }
+ goto match_failure;
+ }
+ /* Likewise for 'inf' and 'infinity'. But be careful that
+ 'infinite' consumes only 3 characters, leaving the stream
+ at the second 'i'. */
+ if (infcount - 1U < 7U) /* infcount && infcount < 8 */
+ {
+ if (infcount >= 3) /* valid 'inf', but short of 'infinity' */
+ while (infcount-- > 3)
+ {
+ _ungetwc_r (rptr, *--p, fp); /* [iInNtT] */
+ --nread;
+ }
+ else
+ {
+ while (p > buf)
+ {
+ _ungetwc_r (rptr, *--p, fp); /* [-+iInN] */
+ --nread;
+ }
+ goto match_failure;
+ }
+ }
+ /*
+ * If no digits, might be missing exponent digits
+ * (just give back the exponent) or might be missing
+ * regular digits, but had sign and/or decimal point.
+ */
+ if (flags & NDIGITS)
+ {
+ if (flags & EXPOK)
+ {
+ /* no digits at all */
+ while (p > buf)
+ {
+ _ungetwc_r (rptr, *--p, fp); /* [-+.] */
+ --nread;
+ }
+ goto match_failure;
+ }
+ /* just a bad exponent (e and maybe sign) */
+ c = *--p;
+ --nread;
+ if (c != L'e' && c != L'E')
+ {
+ _ungetwc_r (rptr, c, fp); /* [-+] */
+ c = *--p;
+ --nread;
+ }
+ _ungetwc_r (rptr, c, fp); /* [eE] */
+ }
+ if ((flags & SUPPRESS) == 0)
+ {
+ double res = 0;
+#ifdef _NO_LONGDBL
+#define QUAD_RES res;
+#else /* !_NO_LONG_DBL */
+ long double qres = 0;
+#define QUAD_RES qres;
+#endif /* !_NO_LONG_DBL */
+ long new_exp = 0;
+
+ *p = 0;
+ if ((flags & (DPTOK | EXPOK)) == EXPOK)
+ {
+ exp_adjust = zeroes - leading_zeroes;
+ new_exp = -exp_adjust;
+ exp_start = p;
+ }
+ else if (exp_adjust)
+ new_exp = _wcstol_r (rptr, (exp_start + 1), NULL, 10) - exp_adjust;
+ if (exp_adjust)
+ {
+
+ /* If there might not be enough space for the new exponent,
+ truncate some trailing digits to make room. */
+ if (exp_start >= buf + sizeof (buf) - MAX_LONG_LEN)
+ exp_start = buf + sizeof (buf) - MAX_LONG_LEN - 1;
+ swprintf (exp_start, MAX_LONG_LEN, L"e%ld", new_exp);
+ }
+
+ /* FIXME: We don't have wcstold yet. */
+#if 0//ndef _NO_LONGDBL /* !_NO_LONGDBL */
+ if (flags & LONGDBL)
+ qres = _wcstold_r (rptr, buf, NULL);
+ else
+#endif
+ res = _wcstod_r (rptr, buf, NULL);
+
+ if (flags & LONG)
+ {
+ dp = GET_ARG (N, ap, double *);
+ *dp = res;
+ }
+ else if (flags & LONGDBL)
+ {
+ ldp = GET_ARG (N, ap, _LONG_DOUBLE *);
+ *ldp = QUAD_RES;
+ }
+ else
+ {
+ flp = GET_ARG (N, ap, float *);
+ if (isnan (res))
+ *flp = nanf (NULL);
+ else
+ *flp = res;
+ }
+ nassigned++;
+ }
+ break;
+ }
+#endif /* FLOATING_POINT */
+ }
+ }
+input_failure:
+ /* On read failure, return EOF failure regardless of matches; errno
+ should have been set prior to here. On EOF failure (including
+ invalid format string), return EOF if no matches yet, else number
+ of matches made prior to failure. */
+ _funlockfile (fp);
+ __sfp_lock_release ();
+ return nassigned && !(fp->_flags & __SERR) ? nassigned : EOF;
+match_failure:
+all_done:
+ /* Return number of matches, which can be 0 on match failure. */
+ _funlockfile (fp);
+ __sfp_lock_release ();
+ return nassigned;
+}
+
+#ifndef _NO_POS_ARGS
+/* Process all intermediate arguments. Fortunately, with wscanf, all
+ intermediate arguments are sizeof(void*), so we don't need to scan
+ ahead in the format string. */
+static void *
+get_arg (int n, va_list *ap, int *numargs_p, void **args)
+{
+ int numargs = *numargs_p;
+ while (n >= numargs)
+ args[numargs++] = va_arg (*ap, void *);
+ *numargs_p = numargs;
+ return args[n];
+}
+#endif /* !_NO_POS_ARGS */
vfwscanf.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: fread.c
===================================================================
--- fread.c (nonexistent)
+++ fread.c (revision 520)
@@ -0,0 +1,265 @@
+/*
+ * 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.
+ */
+
+/*
+FUNCTION
+<>---read array elements from a file
+
+INDEX
+ fread
+INDEX
+ _fread_r
+
+ANSI_SYNOPSIS
+ #include
+ size_t fread(void *<[buf]>, size_t <[size]>, size_t <[count]>,
+ FILE *<[fp]>);
+
+ #include
+ size_t _fread_r(struct _reent *<[ptr]>, void *<[buf]>,
+ size_t <[size]>, size_t <[count]>, FILE *<[fp]>);
+
+TRAD_SYNOPSIS
+ #include
+ size_t fread(<[buf]>, <[size]>, <[count]>, <[fp]>)
+ char *<[buf]>;
+ size_t <[size]>;
+ size_t <[count]>;
+ FILE *<[fp]>;
+
+ #include
+ size_t _fread_r(<[ptr]>, <[buf]>, <[size]>, <[count]>, <[fp]>)
+ struct _reent *<[ptr]>;
+ char *<[buf]>;
+ size_t <[size]>;
+ size_t <[count]>;
+ FILE *<[fp]>;
+
+DESCRIPTION
+<> attempts to copy, from the file or stream identified by
+<[fp]>, <[count]> elements (each of size <[size]>) into memory,
+starting at <[buf]>. <> may copy fewer elements than
+<[count]> if an error, or end of file, intervenes.
+
+<> also advances the file position indicator (if any) for
+<[fp]> by the number of @emph{characters} actually read.
+
+<<_fread_r>> is simply the reentrant version of <> that
+takes an additional reentrant structure pointer argument: <[ptr]>.
+
+RETURNS
+The result of <> is the number of elements it succeeded in
+reading.
+
+PORTABILITY
+ANSI C requires <>.
+
+Supporting OS subroutines required: <>, <>, <>,
+<>, <>, <>, <>.
+*/
+
+#include <_ansi.h>
+#include
+#include
+#include
+#include "local.h"
+
+#ifdef __SCLE
+static size_t
+_DEFUN(crlf_r, (ptr, fp, buf, count, eof),
+ struct _reent * ptr _AND
+ FILE * fp _AND
+ char * buf _AND
+ size_t count _AND
+ int eof)
+{
+ int r;
+ char *s, *d, *e;
+
+ if (count == 0)
+ return 0;
+
+ e = buf + count;
+ for (s=d=buf; s_r < 0)
+ fp->_r = 0;
+ total = resid;
+ p = buf;
+
+#if !defined(PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__)
+
+ /* Optimize unbuffered I/O. */
+ if (fp->_flags & __SNBF)
+ {
+ /* First copy any available characters from ungetc buffer. */
+ int copy_size = resid > fp->_r ? fp->_r : resid;
+ _CAST_VOID memcpy ((_PTR) p, (_PTR) fp->_p, (size_t) copy_size);
+ fp->_p += copy_size;
+ fp->_r -= copy_size;
+ p += copy_size;
+ resid -= copy_size;
+
+ /* If still more data needed, free any allocated ungetc buffer. */
+ if (HASUB (fp) && resid > 0)
+ FREEUB (ptr, fp);
+
+ /* Finally read directly into user's buffer if needed. */
+ while (resid > 0)
+ {
+ int rc = 0;
+ /* save fp buffering state */
+ void *old_base = fp->_bf._base;
+ void * old_p = fp->_p;
+ int old_size = fp->_bf._size;
+ /* allow __refill to use user's buffer */
+ fp->_bf._base = (unsigned char *) p;
+ fp->_bf._size = resid;
+ fp->_p = (unsigned char *) p;
+ rc = __srefill_r (ptr, fp);
+ /* restore fp buffering back to original state */
+ fp->_bf._base = old_base;
+ fp->_bf._size = old_size;
+ fp->_p = old_p;
+ resid -= fp->_r;
+ p += fp->_r;
+ fp->_r = 0;
+ if (rc)
+ {
+#ifdef __SCLE
+ if (fp->_flags & __SCLE)
+ {
+ _funlockfile (fp);
+ __sfp_lock_release ();
+ return crlf_r (ptr, fp, buf, total-resid, 1) / size;
+ }
+#endif
+ _funlockfile (fp);
+ __sfp_lock_release ();
+ return (total - resid) / size;
+ }
+ }
+ }
+ else
+#endif /* !PREFER_SIZE_OVER_SPEED && !__OPTIMIZE_SIZE__ */
+ {
+ while (resid > (r = fp->_r))
+ {
+ _CAST_VOID memcpy ((_PTR) p, (_PTR) fp->_p, (size_t) r);
+ fp->_p += r;
+ /* fp->_r = 0 ... done in __srefill */
+ p += r;
+ resid -= r;
+ if (__srefill_r (ptr, fp))
+ {
+ /* no more input: return partial result */
+#ifdef __SCLE
+ if (fp->_flags & __SCLE)
+ {
+ _funlockfile (fp);
+ __sfp_lock_release ();
+ return crlf_r (ptr, fp, buf, total-resid, 1) / size;
+ }
+#endif
+ _funlockfile (fp);
+ __sfp_lock_release ();
+ return (total - resid) / size;
+ }
+ }
+ _CAST_VOID memcpy ((_PTR) p, (_PTR) fp->_p, resid);
+ fp->_r -= resid;
+ fp->_p += resid;
+ }
+
+ /* Perform any CR/LF clean-up if necessary. */
+#ifdef __SCLE
+ if (fp->_flags & __SCLE)
+ {
+ _funlockfile (fp);
+ __sfp_lock_release ();
+ return crlf_r(ptr, fp, buf, total, 0) / size;
+ }
+#endif
+ _funlockfile (fp);
+ __sfp_lock_release ();
+ return count;
+}
+
+#ifndef _REENT_ONLY
+size_t
+_DEFUN(fread, (buf, size, count, fp),
+ _PTR buf _AND
+ size_t size _AND
+ size_t count _AND
+ FILE * fp)
+{
+ return _fread_r (_REENT, buf, size, count, fp);
+}
+#endif
fread.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: asprintf.c
===================================================================
--- asprintf.c (nonexistent)
+++ asprintf.c (revision 520)
@@ -0,0 +1,80 @@
+/*
+ * 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 copied from sprintf.c */
+/* doc in sprintf.c */
+
+#include <_ansi.h>
+#include
+#include
+#include
+#include
+#include "local.h"
+
+int
+_DEFUN(_asprintf_r, (ptr, strp, fmt),
+ struct _reent *ptr _AND
+ char **strp _AND
+ const char *fmt _DOTS)
+{
+ int ret;
+ va_list ap;
+ FILE f;
+
+ /* mark a zero-length reallocatable buffer */
+ f._flags = __SWR | __SSTR | __SMBF;
+ f._bf._base = f._p = NULL;
+ f._bf._size = f._w = 0;
+ f._file = -1; /* No file. */
+ va_start (ap, fmt);
+ ret = _svfprintf_r (ptr, &f, fmt, ap);
+ va_end (ap);
+ if (ret >= 0)
+ {
+ *f._p = 0;
+ *strp = f._bf._base;
+ }
+ return (ret);
+}
+
+#ifndef _REENT_ONLY
+
+int
+_DEFUN(asprintf, (strp, fmt),
+ char **strp _AND
+ const char *fmt _DOTS)
+{
+ int ret;
+ va_list ap;
+ FILE f;
+
+ /* mark a zero-length reallocatable buffer */
+ f._flags = __SWR | __SSTR | __SMBF;
+ f._bf._base = f._p = NULL;
+ f._bf._size = f._w = 0;
+ f._file = -1; /* No file. */
+ va_start (ap, fmt);
+ ret = _svfprintf_r (_REENT, &f, fmt, ap);
+ va_end (ap);
+ if (ret >= 0)
+ {
+ *f._p = 0;
+ *strp = f._bf._base;
+ }
+ return (ret);
+}
+
+#endif /* ! _REENT_ONLY */
asprintf.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: fgetc.c
===================================================================
--- fgetc.c (nonexistent)
+++ fgetc.c (revision 520)
@@ -0,0 +1,108 @@
+/*
+ * 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
+<>---get a character from a file or stream
+
+INDEX
+ fgetc
+INDEX
+ _fgetc_r
+
+ANSI_SYNOPSIS
+ #include
+ int fgetc(FILE *<[fp]>);
+
+ #include
+ int _fgetc_r(struct _reent *<[ptr]>, FILE *<[fp]>);
+
+TRAD_SYNOPSIS
+ #include
+ int fgetc(<[fp]>)
+ FILE *<[fp]>;
+
+ #include
+ int _fgetc_r(<[ptr]>, <[fp]>)
+ struct _reent *<[ptr]>;
+ FILE *<[fp]>;
+
+DESCRIPTION
+Use <> to get the next single character from the file or stream
+identified by <[fp]>. As a side effect, <> advances the file's
+current position indicator.
+
+For a macro version of this function, see <>.
+
+The function <<_fgetc_r>> is simply a reentrant version of
+<> that is passed the additional reentrant structure
+pointer argument: <[ptr]>.
+
+RETURNS
+The next character (read as an <>, and cast to
+<>), unless there is no more data, or the host system reports a
+read error; in either of these situations, <> returns <>.
+
+You can distinguish the two situations that cause an <> result by
+using the <> and <> functions.
+
+PORTABILITY
+ANSI C requires <>.
+
+Supporting OS subroutines required: <>, <>, <>,
+<>, <>, <>, <>.
+*/
+
+#include <_ansi.h>
+#include
+#include "local.h"
+
+int
+_DEFUN(_fgetc_r, (ptr, fp),
+ struct _reent * ptr _AND
+ FILE * fp)
+{
+ int result;
+ CHECK_INIT(ptr, fp);
+ _flockfile (fp);
+ result = __sgetc_r (ptr, fp);
+ _funlockfile (fp);
+ return result;
+}
+
+#ifndef _REENT_ONLY
+
+int
+_DEFUN(fgetc, (fp),
+ FILE * fp)
+{
+#if !defined(PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__)
+ int result;
+ CHECK_INIT(_REENT, fp);
+ __sfp_lock_acquire ();
+ _flockfile (fp);
+ result = __sgetc_r (_REENT, fp);
+ _funlockfile (fp);
+ __sfp_lock_release ();
+ return result;
+#else
+ return _fgetc_r (_REENT, fp);
+#endif
+}
+
+#endif /* !_REENT_ONLY */
+
fgetc.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: vswscanf.c
===================================================================
--- vswscanf.c (nonexistent)
+++ vswscanf.c (revision 520)
@@ -0,0 +1,60 @@
+/*
+ * Code created by modifying scanf.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
+#include
+#include
+#include
+#ifdef _HAVE_STDC
+#include
+#else
+#include
+#endif
+#include "local.h"
+
+/*
+ * vsscanf
+ */
+
+#ifndef _REENT_ONLY
+
+int
+vswscanf (_CONST wchar_t *str, _CONST wchar_t *fmt, va_list ap)
+{
+ return _vswscanf_r (_REENT, str, fmt, ap);
+}
+
+#endif /* !_REENT_ONLY */
+
+int
+_vswscanf_r (struct _reent *ptr, _CONST wchar_t *str, _CONST wchar_t *fmt,
+ va_list ap)
+{
+ FILE f;
+
+ f._flags = __SRD | __SSTR;
+ f._bf._base = f._p = (unsigned char *) str;
+ f._bf._size = f._r = wcslen (str) * sizeof (wchar_t);
+ f._read = __seofread;
+ f._ub._base = NULL;
+ f._lb._base = NULL;
+ f._file = -1; /* No file. */
+ return __ssvfwscanf_r (ptr, &f, fmt, ap);
+}
vswscanf.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property