MCPcopy Create free account
hub / github.com/coreutils/coreutils / next_file

Function next_file

src/expand-common.c:348–389  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

346 Return NULL if there are no more input files. */
347
348extern FILE *
349next_file (FILE *fp)
350{
351 static char *prev_file;
352 char *file;
353
354 if (fp)
355 {
356 int err = errno;
357 if (!ferror (fp))
358 err = 0;
359 if (streq (prev_file, "-"))
360 clearerr (fp); /* Also clear EOF. */
361 else if (fclose (fp) != 0)
362 err = errno;
363 if (err)
364 {
365 error (0, err, "%s", quotef (prev_file));
366 exit_status = EXIT_FAILURE;
367 }
368 }
369
370 while ((file = *file_list++) != NULL)
371 {
372 if (streq (file, "-"))
373 {
374 have_read_stdin = true;
375 fp = stdin;
376 }
377 else
378 fp = fopen (file, "r");
379 if (fp)
380 {
381 prev_file = file;
382 fadvise (fp, FADVISE_SEQUENTIAL);
383 return fp;
384 }
385 error (0, errno, "%s", quotef (file));
386 exit_status = EXIT_FAILURE;
387 }
388 return NULL;
389}
390
391/* Close standard input if we have read from it. */
392extern void

Callers 2

expandFunction · 0.85
unexpandFunction · 0.85

Calls 1

fadviseFunction · 0.85

Tested by

no test coverage detected