This is the mail archive of the newlib@sources.redhat.com mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: vfscanf in newlib


Christopher Faylor wrote:
> 
> On Fri, Apr 20, 2001 at 01:25:07PM -0400, J. Johnston wrote:
> >> Since the cygwin folks are about to release a new official kernel (1.3.0
> >> this weekend) I'd like to get these changes into newlib quickly.  Other
> >> than the tests promised above, what else do I need to do to facilitate
> >> that?
> >>
> >
> >You should try out the new patch.  The new patch adds a few new _r
> >routines that should also be added to Cygwin which alters the Cygwin
> >portion of your patch.
> 
> Chuck,
> If you can submit the appropriate cygwin changes, I'll definitely get them
> into 1.3.0.
> 

As discussed, I have attached the new patch.  I moved stuff around in stdio.h
because there were multiple sections using the same #ifdef.  There were also
some routines that were not properly under the non-strict ANSI flag.

-- Jeff J.
Index: libc/include/stdio.h
===================================================================
RCS file: /cvs/src/src/newlib/libc/include/stdio.h,v
retrieving revision 1.7
diff -u -r1.7 stdio.h
--- libc/include/stdio.h	2001/02/09 00:32:43	1.7
+++ libc/include/stdio.h	2001/04/20 19:03:48
@@ -142,11 +142,6 @@
 #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(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 @@
 #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 @@
 
 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(_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(_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.
Index: libc/include/stdlib.h
===================================================================
RCS file: /cvs/src/src/newlib/libc/include/stdlib.h,v
retrieving revision 1.8
diff -u -r1.8 stdlib.h
--- libc/include/stdlib.h	2001/02/15 02:04:53	1.8
+++ libc/include/stdlib.h	2001/04/20 19:03:48
@@ -93,6 +93,7 @@
 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));
Index: libc/stdio/Makefile.am
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdio/Makefile.am,v
retrieving revision 1.2
diff -u -r1.2 Makefile.am
--- libc/stdio/Makefile.am	2000/03/08 03:42:25	1.2
+++ libc/stdio/Makefile.am	2001/04/20 19:03:48
@@ -65,8 +65,10 @@
 	vfprintf.c 			\
 	vfscanf.c 			\
 	vprintf.c 			\
+	vscanf.c			\
 	vsnprintf.c			\
 	vsprintf.c 			\
+	vsscanf.c			\
 	wbuf.c 				\
 	wsetup.c 
 
@@ -117,7 +119,8 @@
 	sscanf.def		\
 	tmpfile.def		\
 	tmpnam.def		\
-	vfprintf.def
+	vfprintf.def		\
+	vfscanf.def
 
 SUFFIXES = .def
 
@@ -161,5 +164,7 @@
 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
Index: libc/stdio/Makefile.in
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdio/Makefile.in,v
retrieving revision 1.2
diff -u -r1.2 Makefile.in
--- libc/stdio/Makefile.in	2000/03/08 03:42:25	1.2
+++ libc/stdio/Makefile.in	2001/04/20 19:03:48
@@ -118,7 +118,7 @@
 	getc.c 				\
 	getchar.c 			\
 	gets.c 				\
-	getw.c 				\
+	getw.c				\
 	iprintf.c 			\
 	makebuf.c			\
 	mktemp.c 			\
@@ -127,7 +127,7 @@
 	putc.c 				\
 	putchar.c 			\
 	puts.c 				\
-	putw.c 				\
+	putw.c				\
 	refill.c 			\
 	remove.c 			\
 	rename.c 			\
@@ -147,8 +147,10 @@
 	vfprintf.c 			\
 	vfscanf.c 			\
 	vprintf.c 			\
+	vscanf.c			\
 	vsnprintf.c			\
 	vsprintf.c 			\
+	vsscanf.c			\
 	wbuf.c 				\
 	wsetup.c 
 
@@ -197,7 +199,8 @@
 	sscanf.def		\
 	tmpfile.def		\
 	tmpnam.def		\
-	vfprintf.def
+	vfprintf.def		\
+	vfscanf.def
 
 
 SUFFIXES = .def
@@ -220,11 +223,12 @@
 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 @@
 
 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 @@
 	@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 @@
 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
 
Index: libc/stdio/fscanf.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdio/fscanf.c,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 fscanf.c
--- libc/stdio/fscanf.c	2000/02/17 19:39:47	1.1.1.1
+++ libc/stdio/fscanf.c	2001/04/20 19:03:48
@@ -19,42 +19,61 @@
 #include <stdio.h>
 
 #ifdef _HAVE_STDC
-
 #include <stdarg.h>
+#else
+#include <varargs.h>
+#endif
+
+#include "local.h"
 
-extern int __svfscanf ();
+#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
Index: libc/stdio/local.h
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdio/local.h,v
retrieving revision 1.3
diff -u -r1.3 local.h
--- libc/stdio/local.h	2001/03/06 01:04:43	1.3
+++ libc/stdio/local.h	2001/04/20 19:03:48
@@ -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 *));
Index: libc/stdio/scanf.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdio/scanf.c,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 scanf.c
--- libc/stdio/scanf.c	2000/02/17 19:39:47	1.1.1.1
+++ libc/stdio/scanf.c	2001/04/20 19:03:48
@@ -25,6 +25,8 @@
 #include <varargs.h>
 #endif
 
+#include "local.h"
+
 #ifndef _REENT_ONLY
 
 int
@@ -44,12 +46,12 @@
 #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 @@
 #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);
 }
+
+
Index: libc/stdio/sscanf.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdio/sscanf.c,v
retrieving revision 1.2
diff -u -r1.2 sscanf.c
--- libc/stdio/sscanf.c	2001/03/06 01:04:43	1.2
+++ libc/stdio/sscanf.c	2001/04/20 19:03:48
@@ -35,7 +35,12 @@
         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 @@
 	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 @@
         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 @@
   return 0;
 }
 
+#ifndef _REENT_ONLY 
+
 #ifdef _HAVE_STDC
 int 
 _DEFUN (sscanf, (str, fmt), _CONST char *str _AND _CONST char *fmt _DOTS)
@@ -379,8 +404,43 @@
   va_start (ap, fmt);
 #else
   va_start (ap);
+#endif
+  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 (&f, fmt, ap);
+  ret = __svfscanf_r (ptr, &f, fmt, ap);
   va_end (ap);
   return ret;
 }
Index: libc/stdio/vfscanf.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdio/vfscanf.c,v
retrieving revision 1.6
diff -u -r1.6 vfscanf.c
--- libc/stdio/vfscanf.c	2000/12/07 00:17:20	1.6
+++ libc/stdio/vfscanf.c	2001/04/20 19:03:48
@@ -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 @@
 
 #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 @@
 #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 @@
 	  /* 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 @@
 	  /* 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 @@
 	case 'x':
 	  flags |= PFXOK;	/* enable 0x prefixing */
 	  c = CT_INT;
-	  ccfn = strtoul;
+	  ccfn = _strtoul_r;
 	  base = 16;
 	  break;
 
@@ -298,7 +418,7 @@
 	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 @@
 	  if (isupper (c))
 	    flags |= LONG;
 	  c = CT_INT;
-	  ccfn = (u_long (*)())strtol;
+	  ccfn = (u_long (*)())_strtol_r;
 	  base = 10;
 	  break;
 	}
@@ -663,7 +783,7 @@
 	      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 @@
 		  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 @@
                  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 */
Index: libc/stdio/vscanf.c
===================================================================
RCS file: vscanf.c
diff -N vscanf.c
--- libc/stdio/vscanf.c	Tue May  5 13:32:27 1998
+++ libc/stdio/vscanf.c	Fri Apr 20 12:03:48 2001
@@ -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);
+}
+
Index: libc/stdio/vsscanf.c
===================================================================
RCS file: vsscanf.c
diff -N vsscanf.c
--- libc/stdio/vsscanf.c	Tue May  5 13:32:27 1998
+++ libc/stdio/vsscanf.c	Fri Apr 20 12:03:48 2001
@@ -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);    
+}
+
Index: libc/stdlib/strtod.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdlib/strtod.c,v
retrieving revision 1.2
diff -u -r1.2 strtod.c
--- libc/stdlib/strtod.c	2000/04/17 17:10:17	1.2
+++ libc/stdlib/strtod.c	2001/04/20 19:03:48
@@ -725,7 +725,7 @@
 	_CONST char *s00 _AND
 	char **se)
 {
-  return strtod (s00, se);
+  return _strtod_r (_REENT, s00, se);
 }
 
 #endif

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]