Fix to hex dump program posted yesterday
dlnash at ut-ngp.UUCP
dlnash at ut-ngp.UUCP
Fri Jan 30 03:22:06 AEST 1987
Due to a slight problem in the way I handle files in the hex dump program
I posted yesterday, you can get a core dump if you try to dump more than
one file and the first one does not exist. The problem comes from trying
to freopen() a NULL file pointer. What follows is a new version of the
nextfile() function in hd.c. It is not in a shell archive, just
cut it off and put it into the hd.c source in place of the old nextfile().
Sorry for the inconvienence.
Don Nash
-------------------------cut here for nextfile.c-------------------------
FILE *nextfile(argc, argv)
int argc;
CHAR *argv[];
/*
This function steps through the files on the command line opening
each file in turn. It returns the FILE * for the file it opens.
*/
{
static int fn = 0; /* keeps track of which argv[] is in use */
static FILE *filep = (FILE *)NULL;
addr = 0l; /* reset addr to zero */
if (argc < 2) { /* if no args, use stdin */
if (++fn == 1) { /* only do this part once */
titlep = (CHAR *)NULL; /* set titlep */
page(); /* start a new page */
return(stdin); /* return stdin */
} /* if */
else
return(NULL); /* no more, so return NULL */
} /* if */
loop:
if (++fn < argc) { /* if still more args to go */
if (filep != NULL) /* close any open file */
fclose(filep);
#if MSDOS
filep = fopen(argv[fn], "rb"); /* open next file */
#else
filep = fopen(argv[fn], "r"); /* open next file */
#endif
titlep = argv[fn]; /* set titlep */
page(); /* start a new page */
if (filep == NULL) { /* check for bad filename */
printf("Cannot open file %s\n", argv[fn]);
goto loop;
} /* if */
return(filep); /* return file pointer */
} /* if */
return(NULL); /* no more files, return NULL */
} /* nextfile */
-------------------------end of nextfile.c-------------------------
More information about the Comp.sources.unix
mailing list