www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/05/28/23:22:38

Xref: news2.mv.net comp.os.msdos.djgpp:4314
From: Broeker AT PROBLEM_WITH_INEWS_DOMAIN_FILE (Hans-Bernhard Broeker)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: djgpp 2.0 fscanf bug??
Date: 28 May 1996 14:11:26 GMT
Organization: RWTH -Aachen / Rechnerbetrieb Informatik
Lines: 62
Message-ID: <4of1ie$cp0@news.rwth-aachen.de>
References: <199605271815 DOT OAA07597 AT fcshome DOT stoneham DOT ma DOT us>
NNTP-Posting-Host: axpcl3.physik.rwth-aachen.de
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019