>From 6adaa706cbf4da6c45782b5107a6a3fa423c8487 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Tue, 2 Jul 2019 23:44:12 -0700 Subject: [PATCH 4/4] Simplify emacs_perror * src/sysdep.c (emacs_perror): Simplify by using errprintf. --- src/sysdep.c | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/src/sysdep.c b/src/sysdep.c index cf7699d43e..640d4908e1 100644 --- a/src/sysdep.c +++ b/src/sysdep.c @@ -2701,7 +2701,7 @@ emacs_write_quit (int fd, void const *buf, ptrdiff_t nbyte) } /* Write a diagnostic to standard error that contains MESSAGE and a - string derived from errno. Preserve errno. Do not buffer stderr. + string derived from errno. Preserve errno. Flush the output. Do not process quits or pending signals if interrupted. */ void emacs_perror (char const *message) @@ -2710,22 +2710,7 @@ emacs_perror (char const *message) char const *error_string = emacs_strerror (err); char const *command = (initial_argv && initial_argv[0] ? initial_argv[0] : "emacs"); - /* Write it out all at once, if it's short; this is less likely to - be interleaved with other output. */ - char buf[BUFSIZ]; - int nbytes = snprintf (buf, sizeof buf, "%s: %s: %s\n", - command, message, error_string); - if (0 <= nbytes && nbytes < BUFSIZ) - emacs_write (STDERR_FILENO, buf, nbytes); - else - { - emacs_write (STDERR_FILENO, command, strlen (command)); - emacs_write (STDERR_FILENO, ": ", 2); - emacs_write (STDERR_FILENO, message, strlen (message)); - emacs_write (STDERR_FILENO, ": ", 2); - emacs_write (STDERR_FILENO, error_string, strlen (error_string)); - emacs_write (STDERR_FILENO, "\n", 1); - } + errprintf ("%s: %s: %s\n", command, message, error_string); errno = err; } -- 2.21.0