emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master 9a34591 3/4: Use a better buffer size in emacs_perr


From: Paul Eggert
Subject: [Emacs-diffs] master 9a34591 3/4: Use a better buffer size in emacs_perror
Date: Sat, 13 Jul 2019 19:53:27 -0400 (EDT)

branch: master
commit 9a34591ddd5ef481af5bad1fd0b76c39fce4e8e3
Author: Paul Eggert <address@hidden>
Commit: Paul Eggert <address@hidden>

    Use a better buffer size in emacs_perror
    
    * src/sysdep.c (emacs_perror): Since the buffer is for avoiding
    interleaving, size it via PIPE_BUF not BUFSIZ.
    * src/sysstdio.h (PIPE_BUF): Provide a default.
---
 src/sysdep.c   | 4 ++--
 src/sysstdio.h | 5 +++++
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/src/sysdep.c b/src/sysdep.c
index 4c3d546..9301405 100644
--- a/src/sysdep.c
+++ b/src/sysdep.c
@@ -2711,10 +2711,10 @@ emacs_perror (char const *message)
                         ? 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];
+  char buf[min (PIPE_BUF, MAX_ALLOCA)];
   int nbytes = snprintf (buf, sizeof buf, "%s: %s: %s\n",
                         command, message, error_string);
-  if (0 <= nbytes && nbytes < BUFSIZ)
+  if (0 <= nbytes && nbytes < sizeof buf)
     emacs_write (STDERR_FILENO, buf, nbytes);
   else
     {
diff --git a/src/sysstdio.h b/src/sysstdio.h
index 5303e8a..637f5fd 100644
--- a/src/sysstdio.h
+++ b/src/sysstdio.h
@@ -21,6 +21,7 @@ along with GNU Emacs.  If not, see 
<https://www.gnu.org/licenses/>.  */
 #define EMACS_SYSSTDIO_H
 
 #include <fcntl.h>
+#include <limits.h>
 #include <stdio.h>
 #include "unlocked-io.h"
 
@@ -38,4 +39,8 @@ extern void close_output_streams (void);
 # define FOPEN_TEXT ""
 #endif
 
+#ifndef PIPE_BUF
+ #define PIPE_BUF MAX_ALLOCA
+#endif
+
 #endif /* EMACS_SYSSTDIO_H */



reply via email to

[Prev in Thread] Current Thread [Next in Thread]