--- ray/src/common/fgetword.c 2003/02/25 02:47:21 2.3 +++ ray/src/common/fgetword.c 2005/10/12 03:37:54 2.6 @@ -1,34 +1,38 @@ #ifndef lint -static const char RCSid[] = "$Id: fgetword.c,v 2.3 2003/02/25 02:47:21 greg Exp $"; +static const char RCSid[] = "$Id: fgetword.c,v 2.6 2005/10/12 03:37:54 greg Exp $"; #endif /* * Read white space separated words from stream * - * External symbols declared in standard.h + * External symbols declared in rtio.h */ #include "copyright.h" -#include +#include "rtio.h" #include char * -fgetword(s, n, fp) /* get (quoted) word up to n-1 characters */ -char *s; -int n; -register FILE *fp; +fgetword( /* get (quoted) word up to n-1 characters */ + char *s, + int n, + register FILE *fp +) { int quote = '\0'; register char *cp; register int c; + /* sanity checks */ + if ((s == NULL) | (n <= 0)) + return(NULL); /* skip initial white space */ do c = getc(fp); while (isspace(c)); /* check for quote */ - if ((c == '"' | c == '\'')) { + if ((c == '"') | (c == '\'')) { quote = c; c = getc(fp); } @@ -44,7 +48,7 @@ register FILE *fp; c = getc(fp); } while (c != EOF && !(quote ? c==quote : isspace(c))); *cp = '\0'; - if ((c != EOF & !quote)) /* replace space */ + if ((c != EOF) & (!quote)) /* replace space */ ungetc(c, fp); return(s); }