Mail Archives: djgpp/1996/05/28/23:22:38
fredex AT fcshome DOT stoneham DOT ma DOT us wrote:
> > >That's exactly my point (perhaps I didn't explain it well enough)-- on
> > >DJGPP's fscanf it DOESN'T return zero, and DOESN'T exit the loop. This
> > >code is written with the
> > >expectation that when fscanf tries to convert that MSH it'll fail
> > >because it's not an integer, then return zero so the inner loop will be
> > >exited. But on DJGPP it returns 4.
To all it may concern: Yes, this *is* a DJGPP library bug, and it's a
known one (DJ's bug tracker, number 68). Some time ago (March/April,
mainly), Alexander Lukyanov and I solved it. The problem is in the
helper function _doscan(), that does all the 'real' work for the scanf
family. My fix in the bug tracker isn't really correct, so here's the
latest version I have brought to this university account (may be not
the very latest one, but should be correct nevertheless). I'll also
update the bug tracker version, I think. If you prefer Alexander's
posted version, you'll have to search DJ's mail/newsgroup archives
on the Web for the subject word 'doscan'.
You'll need to rebuild doscan.o at least, and put it into libc.a to
replace the previous version, for this patch to be really of use.
(And, of course, you'll need the library sources).
OK, here it is (fix for file src/libc/ansi/stdio/doscan.c):
--- dosc_v2.c Wed Jan 24 04:31:46 1996
+++ dosc_hbb.c Thu Apr 11 10:40:50 1996
@@ -101,13 +101,14 @@
if (ch == '\0')
return(-1);
if (_innum(ptr, ch, len, size, iop, scan_getc, scan_ungetc,
- &fileended) && ptr)
- nmatch++;
-/* breaks %n */
-/* if (fileended) {
- return(nmatch? nmatch: -1);
- } */
- break;
+ &fileended)) { /* HBB: returns true on successful match */
+ if (ptr)
+ nmatch++; /* HBB: successful match, and no 'dummy' "%*" spec */
+ break; /* HBB: success, so go on scanning */
+ } else if (fileended && !nmatch)
+ return(-1); /* HBB: input failure before any successful match, requests EOF-return */
+ else
+ return(nmatch); /* HBB: 'normal' failure (matching ~, or input ~ after some successful match(es) */
case ' ':
case '\n':
case '\t':
@@ -129,7 +130,7 @@
if (ch1 != EOF) nchars++;
if (ch1 != ch) {
if (ch1==EOF)
- return(-1);
+ return(nmatch?nmatch:-1); /* HBB: only return -1 if *no* success at all */
scan_ungetc(ch1, iop);
nchars--;
return(nmatch);
Have fun with it
Hans-Bernhard Broeker (Aachen, Germany)
- Raw text -