mirror of
https://https.git.savannah.gnu.org/git/patch.git
synced 2026-01-27 01:44:34 +00:00
Prefer strerror to perror
* src/patch.c (putline): Move from here ... * src/util.c: ... to here, and make it extern. * src/pch.c (there_is_another_patch): * src/util.c (pfatal): Use putline with strerror rather than attempting to work around old perror bugs. This also works better in the unlikely case where the program name length does not fit in int.
This commit is contained in:
parent
6cb321aff4
commit
248ef134f8
13
src/patch.c
13
src/patch.c
@ -1321,19 +1321,6 @@ print_unidiff_range (FILE *fp, lin start, lin count)
|
||||
}
|
||||
}
|
||||
|
||||
/* Output to FP a line containing the concatenation of the remaining
|
||||
string arguments. A null pointer terminates the string args. */
|
||||
static void
|
||||
putline (FILE *fp, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start (ap, fp);
|
||||
for (char *arg; (arg = va_arg (ap, char *)); )
|
||||
fputs (arg, fp);
|
||||
va_end (ap);
|
||||
putc ('\n', fp);
|
||||
}
|
||||
|
||||
static void
|
||||
print_header_line (FILE *fp, const char *tag, bool reverse)
|
||||
{
|
||||
|
||||
@ -297,10 +297,11 @@ there_is_another_patch (bool need_header, mode_t *file_type)
|
||||
inerrno = stat_file (inname, &instat);
|
||||
if (inerrno)
|
||||
{
|
||||
perror (inname);
|
||||
fputs (inname, stderr);
|
||||
putline (stderr, ": ", strerror (inerrno), nullptr);
|
||||
fflush (stderr);
|
||||
free (inname);
|
||||
inname = 0;
|
||||
inname = nullptr;
|
||||
}
|
||||
else
|
||||
invc = -1;
|
||||
|
||||
17
src/util.c
17
src/util.c
@ -992,6 +992,19 @@ write_fatal (void)
|
||||
pfatal ("write error");
|
||||
}
|
||||
|
||||
/* Output to FP a line containing the concatenation of the remaining
|
||||
string arguments. A null pointer terminates the string args. */
|
||||
void
|
||||
putline (FILE *fp, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start (ap, fp);
|
||||
for (char *arg; (arg = va_arg (ap, char *)); )
|
||||
fputs (arg, fp);
|
||||
va_end (ap);
|
||||
putc ('\n', fp);
|
||||
}
|
||||
|
||||
/* Say something from patch, something from the system, then silence . . . */
|
||||
|
||||
void
|
||||
@ -1004,9 +1017,7 @@ pfatal (char const *format, ...)
|
||||
va_start (args, format);
|
||||
vfprintf (stderr, format, args);
|
||||
va_end (args);
|
||||
fflush (stderr); /* perror bypasses stdio on some hosts. */
|
||||
errno = errnum;
|
||||
perror (" ");
|
||||
putline (stderr, " : ", strerror (errnum), nullptr);
|
||||
fflush (stderr);
|
||||
fatal_exit (0);
|
||||
}
|
||||
|
||||
@ -64,6 +64,7 @@ void read_fatal (void) __attribute__ ((noreturn));
|
||||
void remove_prefix (char *, size_t);
|
||||
void removedirs (char const *);
|
||||
void write_fatal (void) __attribute__ ((noreturn));
|
||||
void putline (FILE *, ...);
|
||||
void insert_file_id (struct stat const *, enum file_id_type);
|
||||
enum file_id_type lookup_file_id (struct stat const *);
|
||||
void set_queued_output (struct stat const *, bool);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user