- fgets(linebuf, sizeof(linebuf), fi);
- token = strtok(linebuf, " ");
- if (token && strncmp(token, "CD", 2) != 0 && strcmp(token, "CATALOG") != 0) {
- fclose(fi);
- return -1;
+ if (fgets(linebuf, sizeof(linebuf), fi) != NULL) {
+ token = strtok(linebuf, " ");
+ if (token && strncmp(token, "CD", 2) != 0 && strcmp(token, "CATALOG") != 0) {
+ fclose(fi);
+ return -1;
+ }