diff options
| author | Paul Eggert | 2019-07-13 12:31:41 -0700 |
|---|---|---|
| committer | Paul Eggert | 2019-07-13 16:53:21 -0700 |
| commit | 9a34591ddd5ef481af5bad1fd0b76c39fce4e8e3 (patch) | |
| tree | c5f2b9c885ab9ee375dea5f980bd7bccb388a2ee /src | |
| parent | 1178f98f2c0973dd1f8a66cbb4de20c0d7af3271 (diff) | |
| download | emacs-9a34591ddd5ef481af5bad1fd0b76c39fce4e8e3.tar.gz emacs-9a34591ddd5ef481af5bad1fd0b76c39fce4e8e3.zip | |
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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/sysdep.c | 4 | ||||
| -rw-r--r-- | src/sysstdio.h | 5 |
2 files changed, 7 insertions, 2 deletions
diff --git a/src/sysdep.c b/src/sysdep.c index 4c3d546962c..9301405943b 100644 --- a/src/sysdep.c +++ b/src/sysdep.c | |||
| @@ -2711,10 +2711,10 @@ emacs_perror (char const *message) | |||
| 2711 | ? initial_argv[0] : "emacs"); | 2711 | ? initial_argv[0] : "emacs"); |
| 2712 | /* Write it out all at once, if it's short; this is less likely to | 2712 | /* Write it out all at once, if it's short; this is less likely to |
| 2713 | be interleaved with other output. */ | 2713 | be interleaved with other output. */ |
| 2714 | char buf[BUFSIZ]; | 2714 | char buf[min (PIPE_BUF, MAX_ALLOCA)]; |
| 2715 | int nbytes = snprintf (buf, sizeof buf, "%s: %s: %s\n", | 2715 | int nbytes = snprintf (buf, sizeof buf, "%s: %s: %s\n", |
| 2716 | command, message, error_string); | 2716 | command, message, error_string); |
| 2717 | if (0 <= nbytes && nbytes < BUFSIZ) | 2717 | if (0 <= nbytes && nbytes < sizeof buf) |
| 2718 | emacs_write (STDERR_FILENO, buf, nbytes); | 2718 | emacs_write (STDERR_FILENO, buf, nbytes); |
| 2719 | else | 2719 | else |
| 2720 | { | 2720 | { |
diff --git a/src/sysstdio.h b/src/sysstdio.h index 5303e8a15b2..637f5fdfa6d 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/>. */ | |||
| 21 | #define EMACS_SYSSTDIO_H | 21 | #define EMACS_SYSSTDIO_H |
| 22 | 22 | ||
| 23 | #include <fcntl.h> | 23 | #include <fcntl.h> |
| 24 | #include <limits.h> | ||
| 24 | #include <stdio.h> | 25 | #include <stdio.h> |
| 25 | #include "unlocked-io.h" | 26 | #include "unlocked-io.h" |
| 26 | 27 | ||
| @@ -38,4 +39,8 @@ extern void close_output_streams (void); | |||
| 38 | # define FOPEN_TEXT "" | 39 | # define FOPEN_TEXT "" |
| 39 | #endif | 40 | #endif |
| 40 | 41 | ||
| 42 | #ifndef PIPE_BUF | ||
| 43 | #define PIPE_BUF MAX_ALLOCA | ||
| 44 | #endif | ||
| 45 | |||
| 41 | #endif /* EMACS_SYSSTDIO_H */ | 46 | #endif /* EMACS_SYSSTDIO_H */ |