diff options
Diffstat (limited to 'newlib/libc/stdio')
-rw-r--r-- | newlib/libc/stdio/Makefile.am | 7 | ||||
-rw-r--r-- | newlib/libc/stdio/Makefile.in | 26 | ||||
-rw-r--r-- | newlib/libc/stdio/fscanf.c | 45 | ||||
-rw-r--r-- | newlib/libc/stdio/local.h | 2 | ||||
-rw-r--r-- | newlib/libc/stdio/scanf.c | 10 | ||||
-rw-r--r-- | newlib/libc/stdio/sscanf.c | 62 | ||||
-rw-r--r-- | newlib/libc/stdio/vfscanf.c | 146 | ||||
-rw-r--r-- | newlib/libc/stdio/vscanf.c | 54 | ||||
-rw-r--r-- | newlib/libc/stdio/vsscanf.c | 76 |
9 files changed, 386 insertions, 42 deletions
diff --git a/newlib/libc/stdio/Makefile.am b/newlib/libc/stdio/Makefile.am index 8461d4ace..fd7a586b4 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 2f487a19f..f0343239e 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 8980410d3..92fc4ea7e 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 dfe5e796e..8b55503c8 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 0a4818934..5dd14fde4 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 5a403de5c..7cf897c5b 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 623e744b9..fad6e91ab 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 000000000..59c63738a --- /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 000000000..5ac6d098f --- /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); +} + |