+2021-11-09 Paul Eggert <eggert@cs.ucla.edu>
+
+ exclude: yield proper errno on failure
+ * lib/exclude.c (add_exclude_file): Do not assume that fclose
+ preserves errno on success.
+
2021-11-07 Paul Eggert <eggert@cs.ucla.edu>
regex: break regcomp.c link with glibc
/* Use ADD_FUNC to append to EX the patterns in FILE_NAME, each with
OPTIONS. LINE_END terminates each pattern in the file. If
LINE_END is a space character, ignore trailing spaces and empty
- lines in FP. Return -1 on failure, 0 on success. */
+ lines in FP. Return -1 (setting errno) on failure, 0 on success. */
int
add_exclude_fp (void (*add_func) (struct exclude *, char const *, int, void *),
struct exclude *ex, char const *file_name, int options,
char line_end)
{
- bool use_stdin = file_name[0] == '-' && !file_name[1];
- FILE *in;
- int rc = 0;
+ if (strcmp (file_name, "-") == 0)
+ return add_exclude_fp (call_addfn, ex, stdin, options, line_end, add_func);
- if (use_stdin)
- in = stdin;
- else if (! (in = fopen (file_name, "re")))
+ FILE *in = fopen (file_name, "re");
+ if (!in)
return -1;
-
- rc = add_exclude_fp (call_addfn, ex, in, options, line_end, &add_func);
-
- if (!use_stdin && fclose (in) != 0)
- rc = -1;
-
+ int rc = add_exclude_fp (call_addfn, ex, in, options, line_end, add_func);
+ int e = errno;
+ if (fclose (in) != 0)
+ return -1;
+ errno = e;
return rc;
}