summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdio/vfscanf.c
diff options
context:
space:
mode:
authorjkh <jkh@FreeBSD.org>1997-07-01 17:46:39 +0000
committerjkh <jkh@FreeBSD.org>1997-07-01 17:46:39 +0000
commita10c1a2949114029b4375969b9303841d9a19235 (patch)
treeca58c56ab4c33f1b97d602941a9c28e56b3ea16c /lib/libc/stdio/vfscanf.c
parenta89fad600560806a4dbb474ecb82abf640cd4cdb (diff)
downloadFreeBSD-src-a10c1a2949114029b4375969b9303841d9a19235.zip
FreeBSD-src-a10c1a2949114029b4375969b9303841d9a19235.tar.gz
Add 64 bit int support to scanf()
PR: 2080 Submitted by: David Dawes <dawes@rf900.physics.usyd.edu.au>
Diffstat (limited to 'lib/libc/stdio/vfscanf.c')
-rw-r--r--lib/libc/stdio/vfscanf.c37
1 files changed, 23 insertions, 14 deletions
diff --git a/lib/libc/stdio/vfscanf.c b/lib/libc/stdio/vfscanf.c
index 14d7a3b..0df3720 100644
--- a/lib/libc/stdio/vfscanf.c
+++ b/lib/libc/stdio/vfscanf.c
@@ -39,7 +39,7 @@
static char sccsid[] = "@(#)vfscanf.c 8.1 (Berkeley) 6/4/93";
#endif
static const char rcsid[] =
- "$Id: vfscanf.c,v 1.9 1997/04/04 18:28:38 ache Exp $";
+ "$Id: vfscanf.c,v 1.10 1997/04/04 19:07:02 ache Exp $";
#endif /* LIBC_SCCS and not lint */
#include <stdio.h>
@@ -69,6 +69,7 @@ static const char rcsid[] =
#define SUPPRESS 0x08 /* suppress assignment */
#define POINTER 0x10 /* weird %p pointer (`fake hex') */
#define NOSKIP 0x20 /* do not skip blanks */
+#define QUAD 0x400
/*
* The following are used in numeric conversions only:
@@ -90,7 +91,7 @@ static const char rcsid[] =
#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_INT 3 /* integer, i.e., strtoq or strtouq */
#define CT_FLOAT 4 /* floating, i.e., strtod */
#define u_char unsigned char
@@ -117,8 +118,8 @@ __svfscanf(fp, fmt0, ap)
int nassigned; /* number of fields assigned */
int nconversions; /* number of conversions */
int nread; /* number of characters consumed from fp */
- int base; /* base argument to strtol/strtoul */
- u_long (*ccfn)(); /* conversion function (strtol/strtoul) */
+ int base; /* base argument to strtoq/strtouq */
+ u_quad_t(*ccfn)(); /* conversion function (strtoq/strtouq) */
char ccltab[256]; /* character class table for %[...] */
char buf[BUF]; /* buffer for numeric conversions */
@@ -171,6 +172,9 @@ literal:
case 'l':
flags |= LONG;
goto again;
+ case 'q':
+ flags |= QUAD;
+ goto again;
case 'L':
flags |= LONGDBL;
goto again;
@@ -195,13 +199,13 @@ literal:
/* FALLTHROUGH */
case 'd':
c = CT_INT;
- ccfn = (u_long (*)())strtol;
+ ccfn = (u_quad_t (*)())strtoq;
base = 10;
break;
case 'i':
c = CT_INT;
- ccfn = (u_long (*)())strtol;
+ ccfn = (u_quad_t (*)())strtoq;
base = 0;
break;
@@ -210,13 +214,13 @@ literal:
/* FALLTHROUGH */
case 'o':
c = CT_INT;
- ccfn = strtoul;
+ ccfn = strtouq;
base = 8;
break;
case 'u':
c = CT_INT;
- ccfn = strtoul;
+ ccfn = strtouq;
base = 10;
break;
@@ -226,7 +230,7 @@ literal:
case 'x':
flags |= PFXOK; /* enable 0x prefixing */
c = CT_INT;
- ccfn = strtoul;
+ ccfn = strtouq;
base = 16;
break;
@@ -258,7 +262,7 @@ literal:
case 'p': /* pointer format is like hex */
flags |= POINTER | PFXOK;
c = CT_INT;
- ccfn = strtoul;
+ ccfn = strtouq;
base = 16;
break;
@@ -270,6 +274,8 @@ literal:
*va_arg(ap, short *) = nread;
else if (flags & LONG)
*va_arg(ap, long *) = nread;
+ else if (flags & QUAD)
+ *va_arg(ap, quad_t *) = nread;
else
*va_arg(ap, int *) = nread;
continue;
@@ -284,7 +290,7 @@ literal:
if (isupper(c))
flags |= LONG;
c = CT_INT;
- ccfn = (u_long (*)())strtol;
+ ccfn = (u_quad_t (*)())strtoq;
base = 10;
break;
}
@@ -429,7 +435,7 @@ literal:
continue;
case CT_INT:
- /* scan an integer as if by strtol/strtoul */
+ /* scan an integer as if by strtoq/strtouq */
#ifdef hardway
if (width == 0 || width > sizeof(buf) - 1)
width = sizeof(buf) - 1;
@@ -547,16 +553,19 @@ literal:
(void) ungetc(c, fp);
}
if ((flags & SUPPRESS) == 0) {
- u_long res;
+ u_quad_t res;
*p = 0;
res = (*ccfn)(buf, (char **)NULL, base);
if (flags & POINTER)
- *va_arg(ap, void **) = (void *)res;
+ *va_arg(ap, void **) =
+ (void *)(u_long)res;
else if (flags & SHORT)
*va_arg(ap, short *) = res;
else if (flags & LONG)
*va_arg(ap, long *) = res;
+ else if (flags & QUAD)
+ *va_arg(ap, quad_t *) = res;
else
*va_arg(ap, int *) = res;
nassigned++;
OpenPOWER on IntegriCloud