aboutsummaryrefslogtreecommitdiff
path: root/newlib
diff options
context:
space:
mode:
authorJeff Johnston <jjohnstn@redhat.com>2001-04-20 22:50:51 +0000
committerJeff Johnston <jjohnstn@redhat.com>2001-04-20 22:50:51 +0000
commit52cb9e6934c1417a03fe20f6be8f479b8f9fb3d5 (patch)
treea1446b632877f034bd4ff0892d7c89bcb099bb56 /newlib
parent3c8e92d9fc43e7b8c8e5ad4a0235599d7b285274 (diff)
downloadnewlib-52cb9e6934c1417a03fe20f6be8f479b8f9fb3d5.zip
newlib-52cb9e6934c1417a03fe20f6be8f479b8f9fb3d5.tar.gz
newlib-52cb9e6934c1417a03fe20f6be8f479b8f9fb3d5.tar.bz2
2001-04-20 Jeff Johnston <jjohnstn@redhat.com>
* libc/include/stdio.h[!_REENT_ONLY]: Moved various functions together into one list. [!__STRICT_ANSI__]: Moved non-ANSI I/O functions in this list. (vfscanf, vscanf, vsscanf, _vfscanf_r, _vscanf_r, _vsscanf_r): New function prototypes. (_fscanf_r, _sscanf_r): Ditto. * libc/include/stdlib.h: Added _strtod_r prototype. * libc/stdio/Makefile.am: Add new v*scanf functions. * libc/stdio/Makefile.in: Regenerate. * libc/stdio/fscanf.c: Reorganized so HAVE_STDC only affects prototype and code is shared. Added reentrant _fscanf_r which calls __svfscanf_r. * libc/stdio/scanf.c: Changed to call __svfscanf_r. * libc/stdio/sscanf.c: Changed documentation to add reentrant routines. (sscanf): Changed to call __svfscanf_r with _REENT argument. (_sscanf_r): New routine. * libc/stdio/local.h: Removed __svfscanf prototype and replaced it with __svfscanf_r prototype. * libc/stdio/vfscanf.c (vfscanf, _vfscanf_r: New routines. (__svfscanf_r): Reentrant version of __svfscanf which takes reetrancy structure as argument as calls reentrant versions of helper functions (e.g. _strtol_r, _strtoul_r). Also replaced calls to atol and atof to _strtol_r and _strtod_r respectively. * libc/stdio/vfscanf.c: Also changed __svfscanf to call __svfscanf_r. * libc/stdlib/strtod.c (strtod): Changed to call _strtod_r with _REENT argument. * libc/stdio/vscanf.c: New file. * libc/stdio/vsscanf.c: Ditto.
Diffstat (limited to 'newlib')
-rw-r--r--newlib/ChangeLog31
-rw-r--r--newlib/libc/include/stdio.h22
-rw-r--r--newlib/libc/include/stdlib.h1
-rw-r--r--newlib/libc/stdio/Makefile.am7
-rw-r--r--newlib/libc/stdio/Makefile.in26
-rw-r--r--newlib/libc/stdio/fscanf.c45
-rw-r--r--newlib/libc/stdio/local.h2
-rw-r--r--newlib/libc/stdio/scanf.c10
-rw-r--r--newlib/libc/stdio/sscanf.c62
-rw-r--r--newlib/libc/stdio/vfscanf.c146
-rw-r--r--newlib/libc/stdio/vscanf.c54
-rw-r--r--newlib/libc/stdio/vsscanf.c76
-rw-r--r--newlib/libc/stdlib/strtod.c2
13 files changed, 434 insertions, 50 deletions
diff --git a/newlib/ChangeLog b/newlib/ChangeLog
index 1200ab9..e9ffca3 100644
--- a/newlib/ChangeLog
+++ b/newlib/ChangeLog
@@ -1,3 +1,34 @@
+2001-04-20 Jeff Johnston <jjohnstn@redhat.com>
+
+ * libc/include/stdio.h[!_REENT_ONLY]: Moved various functions together
+ into one list.
+ [!__STRICT_ANSI__]: Moved non-ANSI I/O functions in this list.
+ (vfscanf, vscanf, vsscanf, _vfscanf_r, _vscanf_r, _vsscanf_r): New
+ function prototypes.
+ (_fscanf_r, _sscanf_r): Ditto.
+ * libc/include/stdlib.h: Added _strtod_r prototype.
+ * libc/stdio/Makefile.am: Add new v*scanf functions.
+ * libc/stdio/Makefile.in: Regenerate.
+ * libc/stdio/fscanf.c: Reorganized so HAVE_STDC only affects prototype
+ and code is shared. Added reentrant _fscanf_r which calls __svfscanf_r.
+ * libc/stdio/scanf.c: Changed to call __svfscanf_r.
+ * libc/stdio/sscanf.c: Changed documentation to add reentrant routines.
+ (sscanf): Changed to call __svfscanf_r with _REENT argument.
+ (_sscanf_r): New routine.
+ * libc/stdio/local.h: Removed __svfscanf prototype and replaced it
+ with __svfscanf_r prototype.
+ * libc/stdio/vfscanf.c (vfscanf, _vfscanf_r: New
+ routines.
+ (__svfscanf_r): Reentrant version of __svfscanf which takes reetrancy
+ structure as argument as calls reentrant versions of helper functions
+ (e.g. _strtol_r, _strtoul_r). Also replaced calls to atol and atof
+ to _strtol_r and _strtod_r respectively.
+ * libc/stdio/vfscanf.c: Also changed __svfscanf to call __svfscanf_r.
+ * libc/stdlib/strtod.c (strtod): Changed to call _strtod_r with
+ _REENT argument.
+ * libc/stdio/vscanf.c: New file.
+ * libc/stdio/vsscanf.c: Ditto.
+
2001-04-19 Robert Collins <rbtcollins@hotmail.com>
* include/time.h[__CYGWIN__]: Define tzname to _tzname if not defined.
diff --git a/newlib/libc/include/stdio.h b/newlib/libc/include/stdio.h
index 9c1a06f..a03dcb1 100644
--- a/newlib/libc/include/stdio.h
+++ b/newlib/libc/include/stdio.h
@@ -142,11 +142,6 @@ typedef struct __sFILE FILE;
#define __VALIST char*
#endif
-#ifndef _REENT_ONLY
-int _EXFUN(remove, (const char *));
-int _EXFUN(rename, (const char *, const char *));
-#endif
-char * _EXFUN(tempnam, (const char *, const char *));
FILE * _EXFUN(tmpfile, (void));
char * _EXFUN(tmpnam, (char *));
int _EXFUN(fclose, (FILE *));
@@ -162,7 +157,6 @@ int _EXFUN(sscanf, (const char *, const char *, ...));
int _EXFUN(vfprintf, (FILE *, const char *, __VALIST));
int _EXFUN(vprintf, (const char *, __VALIST));
int _EXFUN(vsprintf, (char *, const char *, __VALIST));
-int _EXFUN(vsnprintf, (char *, size_t, const char *, __VALIST));
int _EXFUN(fgetc, (FILE *));
char * _EXFUN(fgets, (char *, int, FILE *));
int _EXFUN(fputc, (int, FILE *));
@@ -188,13 +182,22 @@ void _EXFUN(perror, (const char *));
#ifndef _REENT_ONLY
FILE * _EXFUN(fopen, (const char *_name, const char *_type));
int _EXFUN(sprintf, (char *, const char *, ...));
-int _EXFUN(snprintf, (char *, size_t, const char *, ...));
+int _EXFUN(remove, (const char *));
+int _EXFUN(rename, (const char *, const char *));
#endif
#ifndef __STRICT_ANSI__
int _EXFUN(vfiprintf, (FILE *, const char *, __VALIST));
int _EXFUN(iprintf, (const char *, ...));
int _EXFUN(fiprintf, (FILE *, const char *, ...));
int _EXFUN(siprintf, (char *, const char *, ...));
+char * _EXFUN(tempnam, (const char *, const char *));
+int _EXFUN(vsnprintf, (char *, size_t, const char *, __VALIST));
+int _EXFUN(vfscanf, (FILE *, const char *, __VALIST));
+int _EXFUN(vscanf, (const char *, __VALIST));
+int _EXFUN(vsscanf, (const char *, const char *, __VALIST));
+#ifndef _REENT_ONLY
+int _EXFUN(snprintf, (char *, size_t, const char *, ...));
+#endif
#endif
/*
@@ -220,6 +223,7 @@ int _EXFUN(setlinebuf, (FILE *));
FILE * _EXFUN(_fdopen_r, (struct _reent *, int, const char *));
FILE * _EXFUN(_fopen_r, (struct _reent *, const char *, const char *));
+int _EXFUN(_fscanf_r, (struct _reent *, FILE *, const char *, ...));
int _EXFUN(_getchar_r, (struct _reent *));
char * _EXFUN(_gets_r, (struct _reent *, char *));
int _EXFUN(_iprintf_r, (struct _reent *, const char *, ...));
@@ -235,6 +239,7 @@ int _EXFUN(_rename_r, (struct _reent *,
int _EXFUN(_scanf_r, (struct _reent *, const char *, ...));
int _EXFUN(_sprintf_r, (struct _reent *, char *, const char *, ...));
int _EXFUN(_snprintf_r, (struct _reent *, char *, size_t, const char *, ...));
+int _EXFUN(_sscanf_r, (struct _reent *, const char *, const char *, ...));
char * _EXFUN(_tempnam_r, (struct _reent *, const char *, const char *));
FILE * _EXFUN(_tmpfile_r, (struct _reent *));
char * _EXFUN(_tmpnam_r, (struct _reent *, char *));
@@ -242,6 +247,9 @@ int _EXFUN(_vfprintf_r, (struct _reent *, FILE *, const char *, __VALIST));
int _EXFUN(_vprintf_r, (struct _reent *, const char *, __VALIST));
int _EXFUN(_vsprintf_r, (struct _reent *, char *, const char *, __VALIST));
int _EXFUN(_vsnprintf_r, (struct _reent *, char *, size_t, const char *, __VALIST));
+int _EXFUN(_vfscanf_r, (struct _reent *, FILE *, const char *, __VALIST));
+int _EXFUN(_vscanf_r, (struct _reent *, const char *, __VALIST));
+int _EXFUN(_vsscanf_r, (struct _reent *, const char *, const char *, __VALIST));
/*
* Routines internal to the implementation.
diff --git a/newlib/libc/include/stdlib.h b/newlib/libc/include/stdlib.h
index b055108..20549f4 100644
--- a/newlib/libc/include/stdlib.h
+++ b/newlib/libc/include/stdlib.h
@@ -93,6 +93,7 @@ double _EXFUN(strtod,(const char *__n, char **_end_PTR));
float _EXFUN(strtodf,(const char *__n, char **_end_PTR));
#endif
long _EXFUN(strtol,(const char *__n, char **_end_PTR, int __base));
+long _EXFUN(_strtol_r,(struct _reent *,const char *__n, char **_end_PTR, int __base));
unsigned long _EXFUN(strtoul,(const char *_n_PTR, char **_end_PTR, int __base));
unsigned long _EXFUN(_strtoul_r,(struct _reent *,const char *_n_PTR, char **_end_PTR, int __base));
int _EXFUN(system,(const char *__string));
diff --git a/newlib/libc/stdio/Makefile.am b/newlib/libc/stdio/Makefile.am
index 8461d4a..fd7a586 100644
--- a/newlib/libc/stdio/Makefile.am
+++ b/newlib/libc/stdio/Makefile.am
@@ -65,8 +65,10 @@ lib_a_SOURCES = \
vfprintf.c \
vfscanf.c \
vprintf.c \
+ vscanf.c \
vsnprintf.c \
vsprintf.c \
+ vsscanf.c \
wbuf.c \
wsetup.c
@@ -117,7 +119,8 @@ CHEWOUT_FILES = \
sscanf.def \
tmpfile.def \
tmpnam.def \
- vfprintf.def
+ vfprintf.def \
+ vfscanf.def
SUFFIXES = .def
@@ -161,5 +164,7 @@ ungetc.o: local.h
vfiprintf.o: local.h
vfprintf.o: local.h
vfscanf.o: local.h floatio.h
+vscanf.o: local.h
+vsscanf.o: local.h
wbuf.o: local.h fvwrite.h
wsetup.o: local.h
diff --git a/newlib/libc/stdio/Makefile.in b/newlib/libc/stdio/Makefile.in
index 2f487a1..f034323 100644
--- a/newlib/libc/stdio/Makefile.in
+++ b/newlib/libc/stdio/Makefile.in
@@ -118,7 +118,7 @@ lib_a_SOURCES = \
getc.c \
getchar.c \
gets.c \
- getw.c \
+ getw.c \
iprintf.c \
makebuf.c \
mktemp.c \
@@ -127,7 +127,7 @@ lib_a_SOURCES = \
putc.c \
putchar.c \
puts.c \
- putw.c \
+ putw.c \
refill.c \
remove.c \
rename.c \
@@ -147,8 +147,10 @@ lib_a_SOURCES = \
vfprintf.c \
vfscanf.c \
vprintf.c \
+ vscanf.c \
vsnprintf.c \
vsprintf.c \
+ vsscanf.c \
wbuf.c \
wsetup.c
@@ -197,7 +199,8 @@ CHEWOUT_FILES = \
sscanf.def \
tmpfile.def \
tmpnam.def \
- vfprintf.def
+ vfprintf.def \
+ vfscanf.def
SUFFIXES = .def
@@ -220,11 +223,12 @@ lib_a_DEPENDENCIES = vfiprintf.o
lib_a_OBJECTS = clearerr.o fclose.o fdopen.o feof.o ferror.o fflush.o \
fgetc.o fgetpos.o fgets.o fileno.o findfp.o fiprintf.o flags.o fopen.o \
fprintf.o fputc.o fputs.o fread.o freopen.o fscanf.o fseek.o fsetpos.o \
-ftell.o fvwrite.o fwalk.o fwrite.o getc.o getchar.o gets.o getw.o iprintf.o \
-makebuf.o mktemp.o perror.o printf.o putc.o putchar.o puts.o putw.o refill.o \
-remove.o rename.o rewind.o rget.o scanf.o setbuf.o setvbuf.o siprintf.o \
-snprintf.o sprintf.o sscanf.o stdio.o tmpfile.o tmpnam.o ungetc.o \
-vfprintf.o vfscanf.o vprintf.o vsnprintf.o vsprintf.o wbuf.o wsetup.o
+ftell.o fvwrite.o fwalk.o fwrite.o getc.o getchar.o gets.o getw.o \
+iprintf.o makebuf.o mktemp.o perror.o printf.o putc.o putchar.o puts.o \
+putw.o refill.o remove.o rename.o rewind.o rget.o scanf.o setbuf.o \
+setvbuf.o siprintf.o snprintf.o sprintf.o sscanf.o stdio.o tmpfile.o \
+tmpnam.o ungetc.o vfprintf.o vfscanf.o vprintf.o vscanf.o vsnprintf.o \
+vsprintf.o vsscanf.o wbuf.o wsetup.o
CFLAGS = @CFLAGS@
COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
CCLD = $(CC)
@@ -234,7 +238,7 @@ DIST_COMMON = Makefile.am Makefile.in
DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST)
-TAR = tar
+TAR = gtar
GZIP_ENV = --best
SOURCES = $(lib_a_SOURCES)
OBJECTS = $(lib_a_OBJECTS)
@@ -320,7 +324,7 @@ distdir: $(DISTFILES)
@for file in $(DISTFILES); do \
if test -f $$file; then d=.; else d=$(srcdir); fi; \
if test -d $$d/$$file; then \
- cp -pr $$/$$file $(distdir)/$$file; \
+ cp -pr $$d/$$file $(distdir)/$$file; \
else \
test -f $(distdir)/$$file \
|| ln $$d/$$file $(distdir)/$$file 2> /dev/null \
@@ -437,6 +441,8 @@ ungetc.o: local.h
vfiprintf.o: local.h
vfprintf.o: local.h
vfscanf.o: local.h floatio.h
+vscanf.o: local.h
+vsscanf.o: local.h
wbuf.o: local.h fvwrite.h
wsetup.o: local.h
diff --git a/newlib/libc/stdio/fscanf.c b/newlib/libc/stdio/fscanf.c
index 8980410..92fc4ea 100644
--- a/newlib/libc/stdio/fscanf.c
+++ b/newlib/libc/stdio/fscanf.c
@@ -19,42 +19,61 @@
#include <stdio.h>
#ifdef _HAVE_STDC
-
#include <stdarg.h>
+#else
+#include <varargs.h>
+#endif
-extern int __svfscanf ();
+#include "local.h"
+
+#ifndef _REENT_ONLY
int
-fscanf (FILE * fp, const char *fmt, ...)
+#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);
- ret = __svfscanf (fp, fmt, ap);
+#else
+ va_start (ap);
+#endif
+ ret = __svfscanf_r (_REENT, fp, fmt, ap);
va_end (ap);
return ret;
}
-#else
-
-#include <varargs.h>
-
-extern int __svfscanf ();
+#endif /* !_REENT_ONLY */
int
-fscanf (fp, fmt, va_alist)
+#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);
- ret = __svfscanf (fp, fmt, ap);
+#endif
+ ret = __svfscanf_r (ptr, fp, fmt, ap);
va_end (ap);
- return ret;
+ return (ret);
}
-#endif
diff --git a/newlib/libc/stdio/local.h b/newlib/libc/stdio/local.h
index dfe5e79..8b55503 100644
--- a/newlib/libc/stdio/local.h
+++ b/newlib/libc/stdio/local.h
@@ -27,7 +27,7 @@
#include <reent.h>
#include <unistd.h>
-extern int _EXFUN(__svfscanf,(FILE *, _CONST char *,va_list));
+extern int _EXFUN(__svfscanf_r,(struct _reent *,FILE *, _CONST char *,va_list));
extern FILE *_EXFUN(__sfp,(struct _reent *));
extern int _EXFUN(__sflags,(struct _reent *,_CONST char*, int*));
extern int _EXFUN(__srefill,(FILE *));
diff --git a/newlib/libc/stdio/scanf.c b/newlib/libc/stdio/scanf.c
index 0a48189..5dd14fd 100644
--- a/newlib/libc/stdio/scanf.c
+++ b/newlib/libc/stdio/scanf.c
@@ -25,6 +25,8 @@
#include <varargs.h>
#endif
+#include "local.h"
+
#ifndef _REENT_ONLY
int
@@ -44,12 +46,12 @@ scanf (fmt, va_alist)
#else
va_start (ap);
#endif
- ret = __svfscanf (_stdin_r (_REENT), fmt, ap);
+ ret = __svfscanf_r (_REENT, _stdin_r (_REENT), fmt, ap);
va_end (ap);
return ret;
}
-#endif
+#endif /* !_REENT_ONLY */
int
#ifdef _HAVE_STDC
@@ -69,7 +71,9 @@ _scanf_r (ptr, fmt, va_alist)
#else
va_start (ap);
#endif
- ret = __svfscanf (_stdin_r (ptr), fmt, ap);
+ ret = __svfscanf_r (ptr, _stdin_r (ptr), fmt, ap);
va_end (ap);
return (ret);
}
+
+
diff --git a/newlib/libc/stdio/sscanf.c b/newlib/libc/stdio/sscanf.c
index 5a403de..7cf897c 100644
--- a/newlib/libc/stdio/sscanf.c
+++ b/newlib/libc/stdio/sscanf.c
@@ -35,6 +35,11 @@ ANSI_SYNOPSIS
int sscanf(const char *<[str]>, const char *<[format]>
[, <[arg]>, ...]);
+ int _scanf_r(struct _reent *<[ptr]>, const char *<[format]> [, <[arg]>, ...]);
+ int _fscanf_r(struct _reent *<[ptr]>, FILE *<[fd]>, const char *<[format]> [, <[arg]>, ...]);
+ int _sscanf_r(struct _reent *<[ptr]>, const char *<[str]>, const char *<[format]>
+ [, <[arg]>, ...]);
+
TRAD_SYNOPSIS
#include <stdio.h>
@@ -50,6 +55,20 @@ TRAD_SYNOPSIS
char *<[str]>;
char *<[format]>;
+ int _scanf_r(<[ptr]>, <[format]> [, <[arg]>, ...])
+ struct _reent *<[ptr]>;
+ char *<[format]>;
+
+ int _fscanf_r(<[ptr]>, <[fd]>, <[format]> [, <[arg]>, ...]);
+ struct _reent *<[ptr]>;
+ FILE *<[fd]>;
+ char *<[format]>;
+
+ int _sscanf_r(<[ptr]>, <[str]>, <[format]> [, <[arg]>, ...]);
+ struct _reent *<[ptr]>;
+ char *<[str]>;
+ char *<[format]>;
+
DESCRIPTION
<<scanf>> scans a series of input fields from standard input,
@@ -74,6 +93,10 @@ DESCRIPTION
source of input: <<fscanf>> reads from a file, and <<sscanf>>
from a string.
+ The routines <<_scanf_r>>, <<_fscanf_r>>, and <<_sscanf_r>> are reentrant
+ versions of <<scanf>>, <<fscanf>>, and <<sscanf>> that take an additional
+ first argument pointing to a reentrancy structure.
+
The string at <<*<[format]>>> is a character sequence composed
of zero or more directives. Directives are composed of
one or more whitespace characters, non-whitespace characters,
@@ -353,6 +376,8 @@ eofread (cookie, buf, len)
return 0;
}
+#ifndef _REENT_ONLY
+
#ifdef _HAVE_STDC
int
_DEFUN (sscanf, (str, fmt), _CONST char *str _AND _CONST char *fmt _DOTS)
@@ -380,7 +405,42 @@ sscanf (str, fmt, va_alist)
#else
va_start (ap);
#endif
- ret = __svfscanf (&f, fmt, ap);
+ ret = __svfscanf_r (_REENT, &f, fmt, ap);
+ va_end (ap);
+ return ret;
+}
+
+#endif /* !_REENT_ONLY */
+
+#ifdef _HAVE_STDC
+int
+_DEFUN (_sscanf_r, (ptr, str, fmt), struct _reent *ptr _AND _CONST char *str _AND _CONST char *fmt _DOTS)
+#else
+int
+_sscanf_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;
+ f._bf._base = f._p = (unsigned char *) str;
+ f._bf._size = f._r = strlen (str);
+ f._read = eofread;
+ f._ub._base = NULL;
+ f._lb._base = NULL;
+ f._data = _REENT;
+#ifdef _HAVE_STDC
+ va_start (ap, fmt);
+#else
+ va_start (ap);
+#endif
+ ret = __svfscanf_r (ptr, &f, fmt, ap);
va_end (ap);
return ret;
}
diff --git a/newlib/libc/stdio/vfscanf.c b/newlib/libc/stdio/vfscanf.c
index 623e744..fad6e91 100644
--- a/newlib/libc/stdio/vfscanf.c
+++ b/newlib/libc/stdio/vfscanf.c
@@ -1,6 +1,91 @@
-/* No user fns here. Pesch 15apr92. */
-
/*
+FUNCTION
+<<vscanf>>, <<vfscanf>>, <<vsscanf>>---format argument list
+
+INDEX
+ vscanf
+INDEX
+ vfscanf
+INDEX
+ vsscanf
+
+ANSI_SYNOPSIS
+ #include <stdio.h>
+ #include <stdarg.h>
+ 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(void *<[reent]>, const char *<[fmt]>,
+ va_list <[list]>);
+ int _vfscanf_r(void *<[reent]>, FILE *<[fp]>, const char *<[fmt]>,
+ va_list <[list]>);
+ int _vsscanf_r(void *<[reent]>, const char *<[str]>, const char *<[fmt]>,
+ va_list <[list]>);
+
+TRAD_SYNOPSIS
+ #include <stdio.h>
+ #include <varargs.h>
+ 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]>)
+ char *<[reent]>;
+ char *<[fmt]>;
+ va_list <[list]>;
+
+ int _vfscanf_r( <[reent]>, <[fp]>, <[fmt]>, <[list]>)
+ char *<[reent]>;
+ FILE *<[fp]>;
+ char *<[fmt]>;
+ va_list <[list]>;
+
+ int _vsscanf_r( <[reent]>, <[str]>, <[fmt]>, <[list]>)
+ char *<[reent]>;
+ char *<[str]>;
+ char *<[fmt]>;
+ va_list <[list]>;
+
+DESCRIPTION
+<<vscanf>>, <<vfscanf>>, and <<vsscanf>> are (respectively) variants
+of <<scanf>>, <<fscanf>>, and <<sscanf>>. They differ only in
+allowing their caller to pass the variable argument list as a
+<<va_list>> object (initialized by <<va_start>>) rather than
+directly accepting a variable number of arguments.
+
+RETURNS
+The return values are consistent with the corresponding functions:
+<<vscanf>> returns the number of input fields successfully scanned,
+converted, and stored; the return value does not include scanned
+fields which were not stored.
+
+If <<vscanf>> attempts to read at end-of-file, the return value
+is <<EOF>>.
+
+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:
+*/
+
+/*-
* Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
*
@@ -104,12 +189,47 @@ extern _LONG_DOUBLE _strtold _PARAMS((char *s, char **sptr));
#define BufferEmpty (fp->_r <= 0 && __srefill(fp))
+#ifndef _REENT_ONLY
+
+int
+_DEFUN (vfscanf, (fp, fmt, ap),
+ register FILE *fp _AND
+ _CONST char *fmt _AND
+ va_list ap)
+{
+ CHECK_INIT(fp);
+ return __svfscanf_r (fp->_data, fp, fmt, ap);
+}
+
int
__svfscanf (fp, fmt0, ap)
register FILE *fp;
char _CONST *fmt0;
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)
+{
+ return __svfscanf_r (data, fp, fmt, ap);
+}
+
+
+int
+__svfscanf_r (rptr, fp, fmt0, ap)
+ struct _reent *rptr;
+ register FILE *fp;
+ char _CONST *fmt0;
+ 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 */
@@ -149,7 +269,7 @@ __svfscanf (fp, fmt0, ap)
#ifndef MB_CAPABLE
wc = *fmt;
#else
- nbytes = _mbtowc_r (_REENT, &wc, fmt, MB_CUR_MAX, &state);
+ nbytes = _mbtowc_r (rptr, &wc, fmt, MB_CUR_MAX, &state);
#endif
fmt += nbytes;
if (wc == 0)
@@ -235,13 +355,13 @@ __svfscanf (fp, fmt0, ap)
/* FALLTHROUGH */
case 'd':
c = CT_INT;
- ccfn = (u_long (*)())strtol;
+ ccfn = (u_long (*)())_strtol_r;
base = 10;
break;
case 'i':
c = CT_INT;
- ccfn = (u_long (*)())strtol;
+ ccfn = (u_long (*)())_strtol_r;
base = 0;
break;
@@ -250,13 +370,13 @@ __svfscanf (fp, fmt0, ap)
/* FALLTHROUGH */
case 'o':
c = CT_INT;
- ccfn = strtoul;
+ ccfn = _strtoul_r;
base = 8;
break;
case 'u':
c = CT_INT;
- ccfn = strtoul;
+ ccfn = _strtoul_r;
base = 10;
break;
@@ -264,7 +384,7 @@ __svfscanf (fp, fmt0, ap)
case 'x':
flags |= PFXOK; /* enable 0x prefixing */
c = CT_INT;
- ccfn = strtoul;
+ ccfn = _strtoul_r;
base = 16;
break;
@@ -298,7 +418,7 @@ __svfscanf (fp, fmt0, ap)
case 'p': /* pointer format is like hex */
flags |= POINTER | PFXOK;
c = CT_INT;
- ccfn = strtoul;
+ ccfn = _strtoul_r;
base = 16;
break;
@@ -332,7 +452,7 @@ __svfscanf (fp, fmt0, ap)
if (isupper (c))
flags |= LONG;
c = CT_INT;
- ccfn = (u_long (*)())strtol;
+ ccfn = (u_long (*)())_strtol_r;
base = 10;
break;
}
@@ -663,7 +783,7 @@ __svfscanf (fp, fmt0, ap)
u_long res;
*p = 0;
- res = (*ccfn) (buf, (char **) NULL, base);
+ res = (*ccfn) (rptr, buf, (char **) NULL, base);
if (flags & POINTER)
*(va_arg (ap, _PTR *)) = (_PTR) (unsigned _POINTER_INT) res;
else if (flags & SHORT)
@@ -835,7 +955,7 @@ __svfscanf (fp, fmt0, ap)
exp_start = p;
}
else if (exp_adjust)
- new_exp = atol (exp_start + 1) - exp_adjust;
+ new_exp = _strtol_r (rptr, (exp_start + 1), NULL, 10) - exp_adjust;
if (exp_adjust)
{
@@ -846,7 +966,7 @@ __svfscanf (fp, fmt0, ap)
sprintf (exp_start, "e%ld", new_exp);
}
#ifdef _NO_LONGDBL
- res = atof (buf);
+ res = _strtod_r (rptr, buf, NULL);
#else /* !_NO_LONGDBL */
res = _strtold (buf, NULL);
#endif /* !_NO_LONGDBL */
diff --git a/newlib/libc/stdio/vscanf.c b/newlib/libc/stdio/vscanf.c
new file mode 100644
index 0000000..59c6373
--- /dev/null
+++ b/newlib/libc/stdio/vscanf.c
@@ -0,0 +1,54 @@
+/*-
+ * 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 <stdio.h>
+#include "local.h"
+
+#ifdef _HAVE_STDC
+#include <stdarg.h>
+#else
+#include <varargs.h>
+#endif
+
+/*
+ * vscanf
+ */
+
+#ifndef _REENT_ONLY
+
+int
+_DEFUN (vscanf, (fmt, ap),
+ _CONST char *fmt _AND
+ va_list ap)
+{
+ 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)
+{
+ return __svfscanf_r (ptr, _stdin_r (ptr), fmt, ap);
+}
+
diff --git a/newlib/libc/stdio/vsscanf.c b/newlib/libc/stdio/vsscanf.c
new file mode 100644
index 0000000..5ac6d09
--- /dev/null
+++ b/newlib/libc/stdio/vsscanf.c
@@ -0,0 +1,76 @@
+/*
+ * 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 <reent.h>
+#include <stdio.h>
+#include <string.h>
+#ifdef _HAVE_STDC
+#include <stdarg.h>
+#else
+#include <varargs.h>
+#endif
+#include "local.h"
+
+static
+_READ_WRITE_RETURN_TYPE
+eofread1 (cookie, buf, len)
+ _PTR cookie;
+ char *buf;
+ int len;
+{
+ return 0;
+}
+
+/*
+ * 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;
+ f._bf._base = f._p = (unsigned char *) str;
+ f._bf._size = f._r = strlen (str);
+ f._read = eofread1;
+ f._ub._base = NULL;
+ f._lb._base = NULL;
+ f._data = ptr;
+ return __svfscanf_r (ptr, &f, fmt, ap);
+}
+
diff --git a/newlib/libc/stdlib/strtod.c b/newlib/libc/stdlib/strtod.c
index a314d5b..c16d75d 100644
--- a/newlib/libc/stdlib/strtod.c
+++ b/newlib/libc/stdlib/strtod.c
@@ -725,7 +725,7 @@ _DEFUN (strtodf, (s00, se),
_CONST char *s00 _AND
char **se)
{
- return strtod (s00, se);
+ return _strtod_r (_REENT, s00, se);
}
#endif