problem in sun fscanf()/doscan() known?

Christopher Lott cml at cis.ohio-state.edu
Fri Feb 3 11:37:27 AEST 1989


Hi sun folks,

I have run into an apparent problem with fscanf() [really doscan() ?] in
SunOS 3.5.1 and would like to know if it is known to you, sun, or both.
If known to sun, could you please tell me the appropriate service/bug
number?

fscanf() seems to fail when using the string matching features (brackets)
to scan for a string when that string is null (absent).  This piece of
code derives loosely from atrun.c, the program which reads files queued by
the at command.  It scans for the magic header text, followed by the data,
followed by "any character that is not a newline" followed by the newline.
Well, if the newline follows the data immediately, the following code
breaks.


#include <stdio.h>

main(argc, argv)
     int argc;
     char **argv;
{
  FILE *infile;
  int t, bad;
  char owner[256], jobname[256], shell[256], mailvar[256];

  if (argc < 2) {
    printf ("usage: %s filename\n", *argv);
    exit (0);
  }

  *owner = *jobname = *shell = *mailvar = NULL;

  if ( (infile = fopen (argv[1], "r")) != NULL) {

    t = fscanf(infile,"# owner: %127s%*[^\n]\n",owner);
    if (t != 1) printf ("t=%d\n", t);

    t = fscanf(infile,"# jobname: %127s%*[^\n]\n",jobname);
    if (t != 1) printf ("t=%d\n", t);

    t = fscanf(infile,"# shell: %5s%*[^\n]\n",shell);
    if (t != 1) printf ("t=%d\n", t);

    t = fscanf(infile,"# notify by mail: %3s%*[^\n]\n",mailvar);
    if (t != 1) printf ("t=%d\n", t);
  }
  else {
    perror (argv[1]);
  }

  printf ("read %s\n", owner);
  printf ("read %s\n", jobname);
  printf ("read %s\n", shell);
  printf ("read %s\n", mailvar);

  exit (0);

}

/* sample input follows:
 * first line is one that starts with pound sign

# owner: cml
# jobname: ./test_script
# shell: sh
# notify by mail: no

followed by more cruft...

* end of sample input
*/

This piece of code compiles and runs nicely on our pyramid.

The code will work if the '%*[^\n]' bits are removed from each line.

I have reported this problem directly to bugs at sun.com.  I just want to
know if anyone else has seen it.  Please mail to me; I'll summarize back
to spots if the response seems high.

thanks.

chris...
--------
cml at cis.ohio-state.edu        Computer Science Dept, OSU          614-292-1826
 or:  ...!{att,pyramid,killer}!osu-cis!cml		<standard disclaimers>

[[ Sun will tell you that it is a bug with the 3.5 version of atrun, and
that it is "fixed" (actually, completely rewritten) in 4.x.  See Sun-Spots
volume 6 issue 225.  The construct "%*[^\n]\n" as used by atrun is meant
to gobble up any blank lines that may exist.  But the scanf documentation
states that at least one character must match the %[...] construct in
order for it to succeed.  So the fault lies with atrun, not with _doscan.
--wnl ]]



More information about the Comp.sys.sun mailing list