summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdio/vfscanf.c
diff options
context:
space:
mode:
authorbde <bde@FreeBSD.org>1997-03-03 17:53:02 +0000
committerbde <bde@FreeBSD.org>1997-03-03 17:53:02 +0000
commit6c38eceeb9c3076678e4763e02440823894d2323 (patch)
treea621c42376035aa4fe3fa97ce3a63d1c3d653577 /lib/libc/stdio/vfscanf.c
parent1b71c44ec90a9cb3eb6ad56c2ac634eba72f6085 (diff)
downloadFreeBSD-src-6c38eceeb9c3076678e4763e02440823894d2323.zip
FreeBSD-src-6c38eceeb9c3076678e4763e02440823894d2323.tar.gz
Fixed handling of input failure by the scanf family.
- 0 was returned instead of EOF when an input failure occured while skipping white-space after 0 assignments. This fixes PR2606. The diagnosis in PR2606 is wrong. - EOF was returned instead of 0 when an input failure occurred after zero assignments and nonzero suppressed assignments. - EOF was spelled -1. This should be in 2.2.
Diffstat (limited to 'lib/libc/stdio/vfscanf.c')
-rw-r--r--lib/libc/stdio/vfscanf.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/lib/libc/stdio/vfscanf.c b/lib/libc/stdio/vfscanf.c
index b39f789..54cf776 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$";
+ "$Id: vfscanf.c,v 1.7 1997/02/22 15:02:41 peter Exp $";
#endif /* LIBC_SCCS and not lint */
#include <stdio.h>
@@ -115,6 +115,7 @@ __svfscanf(fp, fmt0, ap)
register int flags; /* flags as defined above */
register char *p0; /* saves original value of p when necessary */
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) */
@@ -126,6 +127,7 @@ __svfscanf(fp, fmt0, ap)
{ 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };
nassigned = 0;
+ nconversions = 0;
nread = 0;
base = 0; /* XXX just to keep gcc happy */
ccfn = NULL; /* XXX just to keep gcc happy */
@@ -136,7 +138,7 @@ __svfscanf(fp, fmt0, ap)
if (isspace(c)) {
for (;;) {
if (fp->_r <= 0 && __srefill(fp))
- return (nassigned);
+ goto input_failure;
if (!isspace(*fp->_p))
break;
nread++, fp->_r--, fp->_p++;
@@ -261,6 +263,7 @@ literal:
break;
case 'n':
+ nconversions++;
if (flags & SUPPRESS) /* ??? */
continue;
if (flags & SHORT)
@@ -349,6 +352,7 @@ literal:
nread += r;
nassigned++;
}
+ nconversions++;
break;
case CT_CCL:
@@ -390,6 +394,7 @@ literal:
nassigned++;
}
nread += n;
+ nconversions++;
break;
case CT_STRING:
@@ -420,6 +425,7 @@ literal:
nread += p - p0;
nassigned++;
}
+ nconversions++;
continue;
case CT_INT:
@@ -556,6 +562,7 @@ literal:
nassigned++;
}
nread += p - buf;
+ nconversions++;
break;
#ifdef FLOATING_POINT
@@ -647,12 +654,13 @@ literal:
nassigned++;
}
nread += p - buf;
+ nconversions++;
break;
#endif /* FLOATING_POINT */
}
}
input_failure:
- return (nassigned ? nassigned : -1);
+ return (nconversions != 0 ? nassigned : EOF);
match_failure:
return (nassigned);
}
OpenPOWER on IntegriCloud