summaryrefslogtreecommitdiffstats
path: root/newlib/libc/stdio/sscanf.c
diff options
context:
space:
mode:
Diffstat (limited to 'newlib/libc/stdio/sscanf.c')
-rw-r--r--newlib/libc/stdio/sscanf.c62
1 files changed, 61 insertions, 1 deletions
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;
}