aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert2019-07-08 17:50:39 -0700
committerPaul Eggert2019-07-08 17:50:39 -0700
commitf8ab90839fe64b2ec8b398a50e8fb4f33e8e95e1 (patch)
treec3909d7ae6d78c78cc9e293c20cd764f49931bc2 /src
parent7b70efb740a04517e2764b0986c6e92305c1dd3e (diff)
downloademacs-f8ab90839fe64b2ec8b398a50e8fb4f33e8e95e1.tar.gz
emacs-f8ab90839fe64b2ec8b398a50e8fb4f33e8e95e1.zip
Use fewer locks when accessing stdio
* src/alloc.c, src/bidi.c, src/emacs-module.c, src/pdumper.c: * src/regex-emacs.c, src/unexhp9k800.c, src/unexmacosx.c: * src/widget.c, src/xdisp.c, src/xselect.c, src/xterm.c: Include sysstdio.h instead of stdio.h, to avoid locking stdio streams in many cases. * src/alloc.c (test_setjmp): * src/bidi.c (bidi_dump_cached_states): * src/cm.c (calccost): * src/dispnew.c (init_display_interactive): * src/emacs.c (main): * src/image.c (convert_mono_to_color_image): * src/minibuf.c (read_minibuf_noninteractive): * src/nsfont.m (ns_descriptor_to_entity) (ns_dump_glyphstring): * src/nsterm.h (NSTRACE_MSG_NO_DASHES): * src/nsterm.m (ns_mouse_position) (sendEvent:, keyDown:, performDragOperation:): * src/pdumper.c (dump_fingerprint, print_paths_to_root_1): * src/print.c (debug_print): * src/regex-emacs.c (debug_putchar, print_fastmap) (print_partial_compiled_pattern, print_compiled_pattern) (print_double_string, regex_compile): * src/term.c (vfatal): * src/unexhp9k800.c (read_header): * src/unexmacosx.c (unexec_error): * src/widget.c (EmacsFrameInitialize): * src/xdisp.c (message_to_stderr, vmessage, dump_glyph_row) (Fdump_glyph_matrix, Fdump_frame_glyph_matrix, dump_glyph_string): * src/xfaces.c (Fdump_colors, Fdump_face): * src/xselect.c (x_clipboard_manager_error_2): * src/xterm.c (x_initialize): * src/xwidget.c (WEBKIT_FN_INIT): Prefer unlocked calls like fputs to locked calls like fprintf. * src/charset.c (read_hex): * src/cm.c (cmputc, cmcheckmagic): * src/dispnew.c (update_frame, update_frame_with_menu) (update_frame_1, Fsend_string_to_terminal, Fding) (bitch_at_user): * src/emacs.c (main, Fdump_emacs): * src/emacs-module.c (module_abort): * src/fileio.c (Fdo_auto_save): * src/image.c (slurp_file) (png_read_from_file, png_load_body, our_stdio_fill_input_buffer): * src/keyboard.c (record_char, kbd_buffer_get_event) (handle_interrupt): * src/lread.c (readbyte_from_stdio, read1): * src/minibuf.c (read_minibuf_noninteractive): * src/print.c (printchar_to_stream, strout) (Fredirect_debugging_output): * src/sysdep.c (reset_sys_modes, close_output_streams) (procfs_ttyname, procfs_get_total_memory): * src/term.c (tty_ring_bell, tty_send_additional_strings) (tty_set_terminal_modes, tty_reset_terminal_modes) (tty_update_end, tty_clear_end_of_line, tty_write_glyphs) (tty_write_glyphs_with_face, tty_insert_glyphs) (tty_menu_activate): * src/xfaces.c (Fx_load_color_file): Simplify by using ordinary calls like putc to explicitly-unlocked calls like putc_unlocked, since the ordinary calls are now unlocked anyway. * src/emacs.c (main, Fdump_emacs): * src/pdumper.c (Fdump_emacs_portable): Coalesce adjacent printfs. * src/nsterm.h: Include sysstdio.h as this file’s macros rely on it. * src/regex-emacs.c (print_compiled_pattern): Omit redundant fflush. * src/sysstdio.h: Include unlocked-io.h. (clearerr_unlocked, feof_unlocked, ferror_unlocked) (fflush_unlocked, fgets_unlocked, fputc_unlocked) (fputs_unlocked, fread_unlocked, fwrite_unlocked) (getc_unlocked, getchar_unlocked, putc_unlocked) (putchar_unlocked): Remove these macros; now done by unlocked-io.h. * src/xwidget.c: Include sysstdio.h.
Diffstat (limited to 'src')
-rw-r--r--src/alloc.c6
-rw-r--r--src/bidi.c12
-rw-r--r--src/charset.c10
-rw-r--r--src/cm.c16
-rw-r--r--src/dispnew.c30
-rw-r--r--src/emacs-module.c4
-rw-r--r--src/emacs.c76
-rw-r--r--src/fileio.c14
-rw-r--r--src/image.c11
-rw-r--r--src/keyboard.c17
-rw-r--r--src/lread.c7
-rw-r--r--src/minibuf.c10
-rw-r--r--src/nsfont.m13
-rw-r--r--src/nsterm.h3
-rw-r--r--src/nsterm.m8
-rw-r--r--src/pdumper.c16
-rw-r--r--src/print.c12
-rw-r--r--src/regex-emacs.c65
-rw-r--r--src/sysdep.c12
-rw-r--r--src/sysstdio.h42
-rw-r--r--src/term.c46
-rw-r--r--src/unexhp9k800.c4
-rw-r--r--src/unexmacosx.c6
-rw-r--r--src/widget.c5
-rw-r--r--src/xdisp.c29
-rw-r--r--src/xfaces.c20
-rw-r--r--src/xselect.c9
-rw-r--r--src/xterm.c6
-rw-r--r--src/xwidget.c4
29 files changed, 231 insertions, 282 deletions
diff --git a/src/alloc.c b/src/alloc.c
index 64aaa8acdfa..90817da5974 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -22,7 +22,6 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
22 22
23#include <errno.h> 23#include <errno.h>
24#include <stdint.h> 24#include <stdint.h>
25#include <stdio.h>
26#include <stdlib.h> 25#include <stdlib.h>
27#include <limits.h> /* For CHAR_BIT. */ 26#include <limits.h> /* For CHAR_BIT. */
28#include <signal.h> /* For SIGABRT, SIGDANGER. */ 27#include <signal.h> /* For SIGABRT, SIGDANGER. */
@@ -38,6 +37,7 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
38#include "ptr-bounds.h" 37#include "ptr-bounds.h"
39#include "puresize.h" 38#include "puresize.h"
40#include "sheap.h" 39#include "sheap.h"
40#include "sysstdio.h"
41#include "systime.h" 41#include "systime.h"
42#include "character.h" 42#include "character.h"
43#include "buffer.h" 43#include "buffer.h"
@@ -4813,10 +4813,10 @@ test_setjmp (void)
4813 taking place, or the setjmp just didn't save the register. */ 4813 taking place, or the setjmp just didn't save the register. */
4814 4814
4815 if (x == 1) 4815 if (x == 1)
4816 fprintf (stderr, SETJMP_WILL_LIKELY_WORK); 4816 fputs (SETJMP_WILL_LIKELY_WORK, stderr);
4817 else 4817 else
4818 { 4818 {
4819 fprintf (stderr, SETJMP_WILL_NOT_WORK); 4819 fputs (SETJMP_WILL_NOT_WORK, stderr);
4820 exit (1); 4820 exit (1);
4821 } 4821 }
4822 } 4822 }
diff --git a/src/bidi.c b/src/bidi.c
index c530d49c107..1430d223313 100644
--- a/src/bidi.c
+++ b/src/bidi.c
@@ -238,13 +238,13 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
238 necessary. */ 238 necessary. */
239 239
240#include <config.h> 240#include <config.h>
241#include <stdio.h>
242 241
243#include "lisp.h" 242#include "lisp.h"
244#include "character.h" 243#include "character.h"
245#include "buffer.h" 244#include "buffer.h"
246#include "dispextern.h" 245#include "dispextern.h"
247#include "region-cache.h" 246#include "region-cache.h"
247#include "sysstdio.h"
248 248
249static bool bidi_initialized = 0; 249static bool bidi_initialized = 0;
250 250
@@ -3586,7 +3586,7 @@ bidi_dump_cached_states (void)
3586 3586
3587 if (bidi_cache_idx == 0) 3587 if (bidi_cache_idx == 0)
3588 { 3588 {
3589 fprintf (stderr, "The cache is empty.\n"); 3589 fputs ("The cache is empty.\n", stderr);
3590 return; 3590 return;
3591 } 3591 }
3592 fprintf (stderr, "Total of %"pD"d state%s in cache:\n", 3592 fprintf (stderr, "Total of %"pD"d state%s in cache:\n",
@@ -3597,13 +3597,11 @@ bidi_dump_cached_states (void)
3597 fputs ("ch ", stderr); 3597 fputs ("ch ", stderr);
3598 for (i = 0; i < bidi_cache_idx; i++) 3598 for (i = 0; i < bidi_cache_idx; i++)
3599 fprintf (stderr, "%*c", ndigits, bidi_cache[i].ch); 3599 fprintf (stderr, "%*c", ndigits, bidi_cache[i].ch);
3600 fputs ("\n", stderr); 3600 fputs ("\nlvl ", stderr);
3601 fputs ("lvl ", stderr);
3602 for (i = 0; i < bidi_cache_idx; i++) 3601 for (i = 0; i < bidi_cache_idx; i++)
3603 fprintf (stderr, "%*d", ndigits, bidi_cache[i].resolved_level); 3602 fprintf (stderr, "%*d", ndigits, bidi_cache[i].resolved_level);
3604 fputs ("\n", stderr); 3603 fputs ("\npos ", stderr);
3605 fputs ("pos ", stderr);
3606 for (i = 0; i < bidi_cache_idx; i++) 3604 for (i = 0; i < bidi_cache_idx; i++)
3607 fprintf (stderr, "%*"pD"d", ndigits, bidi_cache[i].charpos); 3605 fprintf (stderr, "%*"pD"d", ndigits, bidi_cache[i].charpos);
3608 fputs ("\n", stderr); 3606 putc ('\n', stderr);
3609} 3607}
diff --git a/src/charset.c b/src/charset.c
index c0700f972ee..85535e8bff1 100644
--- a/src/charset.c
+++ b/src/charset.c
@@ -415,23 +415,23 @@ load_charset_map (struct charset *charset, struct charset_map_entries *entries,
415static unsigned 415static unsigned
416read_hex (FILE *fp, int lookahead, int *terminator, bool *overflow) 416read_hex (FILE *fp, int lookahead, int *terminator, bool *overflow)
417{ 417{
418 int c = lookahead < 0 ? getc_unlocked (fp) : lookahead; 418 int c = lookahead < 0 ? getc (fp) : lookahead;
419 419
420 while (true) 420 while (true)
421 { 421 {
422 if (c == '#') 422 if (c == '#')
423 do 423 do
424 c = getc_unlocked (fp); 424 c = getc (fp);
425 while (0 <= c && c != '\n'); 425 while (0 <= c && c != '\n');
426 else if (c == '0') 426 else if (c == '0')
427 { 427 {
428 c = getc_unlocked (fp); 428 c = getc (fp);
429 if (c < 0 || c == 'x') 429 if (c < 0 || c == 'x')
430 break; 430 break;
431 } 431 }
432 if (c < 0) 432 if (c < 0)
433 break; 433 break;
434 c = getc_unlocked (fp); 434 c = getc (fp);
435 } 435 }
436 436
437 unsigned n = 0; 437 unsigned n = 0;
@@ -440,7 +440,7 @@ read_hex (FILE *fp, int lookahead, int *terminator, bool *overflow)
440 if (0 <= c) 440 if (0 <= c)
441 while (true) 441 while (true)
442 { 442 {
443 c = getc_unlocked (fp); 443 c = getc (fp);
444 int digit = char_hexdigit (c); 444 int digit = char_hexdigit (c);
445 if (digit < 0) 445 if (digit < 0)
446 break; 446 break;
diff --git a/src/cm.c b/src/cm.c
index 71cc94759fb..e09216a854b 100644
--- a/src/cm.c
+++ b/src/cm.c
@@ -45,8 +45,8 @@ int
45cmputc (int c) 45cmputc (int c)
46{ 46{
47 if (current_tty->termscript) 47 if (current_tty->termscript)
48 putc_unlocked (c & 0177, current_tty->termscript); 48 putc (c & 0177, current_tty->termscript);
49 putc_unlocked (c & 0177, current_tty->output); 49 putc (c & 0177, current_tty->output);
50 return c; 50 return c;
51} 51}
52 52
@@ -117,11 +117,11 @@ cmcheckmagic (struct tty_display_info *tty)
117 if (!MagicWrap (tty) || curY (tty) >= FrameRows (tty) - 1) 117 if (!MagicWrap (tty) || curY (tty) >= FrameRows (tty) - 1)
118 emacs_abort (); 118 emacs_abort ();
119 if (tty->termscript) 119 if (tty->termscript)
120 putc_unlocked ('\r', tty->termscript); 120 putc ('\r', tty->termscript);
121 putc_unlocked ('\r', tty->output); 121 putc ('\r', tty->output);
122 if (tty->termscript) 122 if (tty->termscript)
123 putc_unlocked ('\n', tty->termscript); 123 putc ('\n', tty->termscript);
124 putc_unlocked ('\n', tty->output); 124 putc ('\n', tty->output);
125 curX (tty) = 0; 125 curX (tty) = 0;
126 curY (tty)++; 126 curY (tty)++;
127 } 127 }
@@ -205,7 +205,7 @@ calccost (struct tty_display_info *tty,
205 p = tty->Wcm->cm_down, c = tty->Wcm->cc_down; 205 p = tty->Wcm->cm_down, c = tty->Wcm->cc_down;
206 if (c == BIG) { /* caint get thar from here */ 206 if (c == BIG) { /* caint get thar from here */
207 if (doit) 207 if (doit)
208 printf ("OOPS"); 208 fputs ("OOPS", stdout);
209 return c; 209 return c;
210 } 210 }
211 totalcost = c * deltay; 211 totalcost = c * deltay;
@@ -288,7 +288,7 @@ dodelta:
288 if (c == BIG) { /* caint get thar from here */ 288 if (c == BIG) { /* caint get thar from here */
289fail: 289fail:
290 if (doit) 290 if (doit)
291 printf ("OOPS"); 291 fputs ("OOPS", stdout);
292 return BIG; 292 return BIG;
293 } 293 }
294 totalcost += c * deltax; 294 totalcost += c * deltax;
diff --git a/src/dispnew.c b/src/dispnew.c
index 956f3ea3573..0131b63767b 100644
--- a/src/dispnew.c
+++ b/src/dispnew.c
@@ -3126,9 +3126,9 @@ update_frame (struct frame *f, bool force_p, bool inhibit_hairy_id_p)
3126 if (FRAME_TERMCAP_P (f) || FRAME_MSDOS_P (f)) 3126 if (FRAME_TERMCAP_P (f) || FRAME_MSDOS_P (f))
3127 { 3127 {
3128 if (FRAME_TTY (f)->termscript) 3128 if (FRAME_TTY (f)->termscript)
3129 fflush_unlocked (FRAME_TTY (f)->termscript); 3129 fflush (FRAME_TTY (f)->termscript);
3130 if (FRAME_TERMCAP_P (f)) 3130 if (FRAME_TERMCAP_P (f))
3131 fflush_unlocked (FRAME_TTY (f)->output); 3131 fflush (FRAME_TTY (f)->output);
3132 } 3132 }
3133 3133
3134 /* Check window matrices for lost pointers. */ 3134 /* Check window matrices for lost pointers. */
@@ -3181,8 +3181,8 @@ update_frame_with_menu (struct frame *f, int row, int col)
3181 update_end (f); 3181 update_end (f);
3182 3182
3183 if (FRAME_TTY (f)->termscript) 3183 if (FRAME_TTY (f)->termscript)
3184 fflush_unlocked (FRAME_TTY (f)->termscript); 3184 fflush (FRAME_TTY (f)->termscript);
3185 fflush_unlocked (FRAME_TTY (f)->output); 3185 fflush (FRAME_TTY (f)->output);
3186 /* Check window matrices for lost pointers. */ 3186 /* Check window matrices for lost pointers. */
3187#if GLYPH_DEBUG 3187#if GLYPH_DEBUG
3188#if 0 3188#if 0
@@ -4621,7 +4621,7 @@ update_frame_1 (struct frame *f, bool force_p, bool inhibit_id_p,
4621 ptrdiff_t outq = __fpending (display_output); 4621 ptrdiff_t outq = __fpending (display_output);
4622 if (outq > 900 4622 if (outq > 900
4623 || (outq > 20 && ((i - 1) % preempt_count == 0))) 4623 || (outq > 20 && ((i - 1) % preempt_count == 0)))
4624 fflush_unlocked (display_output); 4624 fflush (display_output);
4625 } 4625 }
4626 } 4626 }
4627 4627
@@ -5745,13 +5745,13 @@ when TERMINAL is nil. */)
5745 5745
5746 if (tty->termscript) 5746 if (tty->termscript)
5747 { 5747 {
5748 fwrite_unlocked (SDATA (string), 1, SBYTES (string), tty->termscript); 5748 fwrite (SDATA (string), 1, SBYTES (string), tty->termscript);
5749 fflush_unlocked (tty->termscript); 5749 fflush (tty->termscript);
5750 } 5750 }
5751 out = tty->output; 5751 out = tty->output;
5752 } 5752 }
5753 fwrite_unlocked (SDATA (string), 1, SBYTES (string), out); 5753 fwrite (SDATA (string), 1, SBYTES (string), out);
5754 fflush_unlocked (out); 5754 fflush (out);
5755 unblock_input (); 5755 unblock_input ();
5756 return Qnil; 5756 return Qnil;
5757} 5757}
@@ -5766,7 +5766,7 @@ terminate any keyboard macro currently executing. */)
5766 if (!NILP (arg)) 5766 if (!NILP (arg))
5767 { 5767 {
5768 if (noninteractive) 5768 if (noninteractive)
5769 putchar_unlocked (07); 5769 putchar (07);
5770 else 5770 else
5771 ring_bell (XFRAME (selected_frame)); 5771 ring_bell (XFRAME (selected_frame));
5772 } 5772 }
@@ -5780,7 +5780,7 @@ void
5780bitch_at_user (void) 5780bitch_at_user (void)
5781{ 5781{
5782 if (noninteractive) 5782 if (noninteractive)
5783 putchar_unlocked (07); 5783 putchar (07);
5784 else if (!INTERACTIVE) /* Stop executing a keyboard macro. */ 5784 else if (!INTERACTIVE) /* Stop executing a keyboard macro. */
5785 { 5785 {
5786 const char *msg 5786 const char *msg
@@ -6205,12 +6205,14 @@ init_display_interactive (void)
6205#endif 6205#endif
6206 if (!terminal_type) 6206 if (!terminal_type)
6207 { 6207 {
6208 char const *msg
6209 = "Please set the environment variable TERM; see 'tset'.\n";
6208#ifdef HAVE_WINDOW_SYSTEM 6210#ifdef HAVE_WINDOW_SYSTEM
6209 if (! inhibit_window_system) 6211 if (! inhibit_window_system)
6210 fprintf (stderr, "Please set the environment variable DISPLAY or TERM (see 'tset').\n"); 6212 msg = ("Please set the environment variable DISPLAY or TERM; "
6211 else 6213 "see 'tset'.\n");
6212#endif /* HAVE_WINDOW_SYSTEM */ 6214#endif /* HAVE_WINDOW_SYSTEM */
6213 fprintf (stderr, "Please set the environment variable TERM; see 'tset'.\n"); 6215 fputs (msg, stderr);
6214 exit (1); 6216 exit (1);
6215 } 6217 }
6216 6218
diff --git a/src/emacs-module.c b/src/emacs-module.c
index c856663d2ff..8c09ea6bb6c 100644
--- a/src/emacs-module.c
+++ b/src/emacs-module.c
@@ -81,7 +81,6 @@ To add a new module function, proceed as follows:
81#include <stdarg.h> 81#include <stdarg.h>
82#include <stddef.h> 82#include <stddef.h>
83#include <stdint.h> 83#include <stdint.h>
84#include <stdio.h>
85#include <stdlib.h> 84#include <stdlib.h>
86#include <time.h> 85#include <time.h>
87 86
@@ -91,6 +90,7 @@ To add a new module function, proceed as follows:
91#include "coding.h" 90#include "coding.h"
92#include "keyboard.h" 91#include "keyboard.h"
93#include "syssignal.h" 92#include "syssignal.h"
93#include "sysstdio.h"
94#include "thread.h" 94#include "thread.h"
95 95
96#include <intprops.h> 96#include <intprops.h>
@@ -1304,7 +1304,7 @@ module_abort (const char *format, ...)
1304 va_start (args, format); 1304 va_start (args, format);
1305 vfprintf (stderr, format, args); 1305 vfprintf (stderr, format, args);
1306 va_end (args); 1306 va_end (args);
1307 fputc ('\n', stderr); 1307 putc ('\n', stderr);
1308 fflush (NULL); 1308 fflush (NULL);
1309 emacs_abort (); 1309 emacs_abort ();
1310} 1310}
diff --git a/src/emacs.c b/src/emacs.c
index 0f03dd656d3..9c93748a0f5 100644
--- a/src/emacs.c
+++ b/src/emacs.c
@@ -1125,12 +1125,12 @@ main (int argc, char **argv)
1125 tem2 = Fsymbol_value (intern_c_string ("emacs-copyright")); 1125 tem2 = Fsymbol_value (intern_c_string ("emacs-copyright"));
1126 if (!STRINGP (tem)) 1126 if (!STRINGP (tem))
1127 { 1127 {
1128 fprintf (stderr, "Invalid value of 'emacs-version'\n"); 1128 fputs ("Invalid value of 'emacs-version'\n", stderr);
1129 exit (1); 1129 exit (1);
1130 } 1130 }
1131 if (!STRINGP (tem2)) 1131 if (!STRINGP (tem2))
1132 { 1132 {
1133 fprintf (stderr, "Invalid value of 'emacs-copyright'\n"); 1133 fputs ("Invalid value of 'emacs-copyright'\n", stderr);
1134 exit (1); 1134 exit (1);
1135 } 1135 }
1136 else 1136 else
@@ -1144,13 +1144,14 @@ main (int argc, char **argv)
1144 version = emacs_version; 1144 version = emacs_version;
1145 copyright = emacs_copyright; 1145 copyright = emacs_copyright;
1146 } 1146 }
1147 printf ("%s %s\n", PACKAGE_NAME, version); 1147 printf (("%s %s\n"
1148 printf ("%s\n", copyright); 1148 "%s\n"
1149 printf ("%s comes with ABSOLUTELY NO WARRANTY.\n", PACKAGE_NAME); 1149 "%s comes with ABSOLUTELY NO WARRANTY.\n"
1150 printf ("You may redistribute copies of %s\n", PACKAGE_NAME); 1150 "You may redistribute copies of %s\n"
1151 printf ("under the terms of the GNU General Public License.\n"); 1151 "under the terms of the GNU General Public License.\n"
1152 printf ("For more information about these matters, "); 1152 "For more information about these matters, "
1153 printf ("see the file named COPYING.\n"); 1153 "see the file named COPYING.\n"),
1154 PACKAGE_NAME, version, copyright, PACKAGE_NAME, PACKAGE_NAME);
1154 exit (0); 1155 exit (0);
1155 } 1156 }
1156 1157
@@ -1246,7 +1247,7 @@ main (int argc, char **argv)
1246 } 1247 }
1247#endif /* HAVE_SETRLIMIT and RLIMIT_STACK and not CYGWIN */ 1248#endif /* HAVE_SETRLIMIT and RLIMIT_STACK and not CYGWIN */
1248 1249
1249 clearerr_unlocked (stdin); 1250 clearerr (stdin);
1250 1251
1251 emacs_backtrace (-1); 1252 emacs_backtrace (-1);
1252 1253
@@ -1344,7 +1345,7 @@ main (int argc, char **argv)
1344 int i; 1345 int i;
1345 printf ("Usage: %s [OPTION-OR-FILENAME]...\n", argv[0]); 1346 printf ("Usage: %s [OPTION-OR-FILENAME]...\n", argv[0]);
1346 for (i = 0; i < ARRAYELTS (usage_message); i++) 1347 for (i = 0; i < ARRAYELTS (usage_message); i++)
1347 fputs_unlocked (usage_message[i], stdout); 1348 fputs (usage_message[i], stdout);
1348 exit (0); 1349 exit (0);
1349 } 1350 }
1350 1351
@@ -1402,7 +1403,7 @@ main (int argc, char **argv)
1402 before exiting. */ 1403 before exiting. */
1403 if (emacs_pipe (daemon_pipe) != 0) 1404 if (emacs_pipe (daemon_pipe) != 0)
1404 { 1405 {
1405 fprintf (stderr, "Cannot pipe!\n"); 1406 fputs ("Cannot pipe!\n", stderr);
1406 exit (1); 1407 exit (1);
1407 } 1408 }
1408 } /* daemon_type == 2 */ 1409 } /* daemon_type == 2 */
@@ -1412,10 +1413,10 @@ main (int argc, char **argv)
1412 int systemd_socket = sd_listen_fds (1); 1413 int systemd_socket = sd_listen_fds (1);
1413 1414
1414 if (systemd_socket > 1) 1415 if (systemd_socket > 1)
1415 fprintf (stderr, 1416 fputs (("\n"
1416 ("\n" 1417 "Warning: systemd passed more than one socket to Emacs.\n"
1417 "Warning: systemd passed more than one socket to Emacs.\n" 1418 "Try 'Accept=false' in the Emacs socket unit file.\n"),
1418 "Try 'Accept=false' in the Emacs socket unit file.\n")); 1419 stderr);
1419 else if (systemd_socket == 1 1420 else if (systemd_socket == 1
1420 && (0 < sd_is_socket (SD_LISTEN_FDS_START, 1421 && (0 < sd_is_socket (SD_LISTEN_FDS_START,
1421 AF_UNSPEC, SOCK_STREAM, 1))) 1422 AF_UNSPEC, SOCK_STREAM, 1)))
@@ -1423,9 +1424,10 @@ main (int argc, char **argv)
1423#endif /* HAVE_LIBSYSTEMD */ 1424#endif /* HAVE_LIBSYSTEMD */
1424 1425
1425#ifdef USE_GTK 1426#ifdef USE_GTK
1426 fprintf (stderr, "\nWarning: due to a long standing Gtk+ bug\nhttps://gitlab.gnome.org/GNOME/gtk/issues/221\n\ 1427 fputs ("\nWarning: due to a long standing Gtk+ bug\nhttps://gitlab.gnome.org/GNOME/gtk/issues/221\n\
1427Emacs might crash when run in daemon mode and the X11 connection is unexpectedly lost.\n\ 1428Emacs might crash when run in daemon mode and the X11 connection is unexpectedly lost.\n\
1428Using an Emacs configured with --with-x-toolkit=lucid does not have this problem.\n"); 1429Using an Emacs configured with --with-x-toolkit=lucid does not have this problem.\n",
1430 stderr);
1429#endif /* USE_GTK */ 1431#endif /* USE_GTK */
1430 1432
1431 if (daemon_type == 2) 1433 if (daemon_type == 2)
@@ -1457,12 +1459,12 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem
1457 1459
1458 if (retval < 0) 1460 if (retval < 0)
1459 { 1461 {
1460 fprintf (stderr, "Error reading status from child\n"); 1462 fputs ("Error reading status from child\n", stderr);
1461 exit (1); 1463 exit (1);
1462 } 1464 }
1463 else if (retval == 0) 1465 else if (retval == 0)
1464 { 1466 {
1465 fprintf (stderr, "Error: server did not start correctly\n"); 1467 fputs ("Error: server did not start correctly\n", stderr);
1466 exit (1); 1468 exit (1);
1467 } 1469 }
1468 1470
@@ -1488,7 +1490,7 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem
1488 1490
1489 if (! (0 <= fdStrlen && fdStrlen < sizeof fdStr)) 1491 if (! (0 <= fdStrlen && fdStrlen < sizeof fdStr))
1490 { 1492 {
1491 fprintf (stderr, "daemon: child name too long\n"); 1493 fputs ("daemon: child name too long\n", stderr);
1492 exit (EXIT_CANNOT_INVOKE); 1494 exit (EXIT_CANNOT_INVOKE);
1493 } 1495 }
1494 1496
@@ -1504,10 +1506,11 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem
1504 /* In exec'd: parse special dname into pipe and name info. */ 1506 /* In exec'd: parse special dname into pipe and name info. */
1505 if (!dname_arg || !*dname_arg || strnlen (dname_arg, 71) == 71 1507 if (!dname_arg || !*dname_arg || strnlen (dname_arg, 71) == 71
1506 || !strchr (dname_arg, '\n')) 1508 || !strchr (dname_arg, '\n'))
1507 { 1509 {
1508 fprintf (stderr, "emacs daemon: daemon name absent or too long\n"); 1510 fputs ("emacs daemon: daemon name absent or too long\n",
1509 exit (EXIT_CANNOT_INVOKE); 1511 stderr);
1510 } 1512 exit (EXIT_CANNOT_INVOKE);
1513 }
1511 dname_arg2[0] = '\0'; 1514 dname_arg2[0] = '\0';
1512 sscanf (dname_arg, "\n%d,%d\n%s", &(daemon_pipe[0]), &(daemon_pipe[1]), 1515 sscanf (dname_arg, "\n%d,%d\n%s", &(daemon_pipe[0]), &(daemon_pipe[1]),
1513 dname_arg2); 1516 dname_arg2);
@@ -1531,7 +1534,7 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem
1531 exit (1); 1534 exit (1);
1532 } 1535 }
1533#else /* MSDOS */ 1536#else /* MSDOS */
1534 fprintf (stderr, "This platform does not support daemon mode.\n"); 1537 fputs ("This platform does not support daemon mode.\n", stderr);
1535 exit (1); 1538 exit (1);
1536#endif /* MSDOS */ 1539#endif /* MSDOS */
1537 if (dname_arg) 1540 if (dname_arg)
@@ -2545,16 +2548,15 @@ You must run Emacs in batch mode in order to dump it. */)
2545# define MAX_HEAP_BSS_DIFF (1024 * 1024) 2548# define MAX_HEAP_BSS_DIFF (1024 * 1024)
2546 2549
2547 if (heap_bss_diff > MAX_HEAP_BSS_DIFF) 2550 if (heap_bss_diff > MAX_HEAP_BSS_DIFF)
2548 { 2551 fprintf (stderr,
2549 fprintf (stderr, "**************************************************\n"); 2552 ("**************************************************\n"
2550 fprintf (stderr, "Warning: Your system has a gap between BSS and the\n"); 2553 "Warning: Your system has a gap between BSS and the\n"
2551 fprintf (stderr, ("heap (%"PRIuMAX" bytes). " 2554 "heap (%"PRIuMAX" bytes). This usually means that exec-shield\n"
2552 "This usually means that exec-shield\n"), 2555 "or something similar is in effect. The dump may\n"
2553 heap_bss_diff); 2556 "fail because of this. See the section about\n"
2554 fprintf (stderr, "or something similar is in effect. The dump may\n"); 2557 "exec-shield in etc/PROBLEMS for more information.\n"
2555 fprintf (stderr, "fail because of this. See the section about\n"); 2558 "**************************************************\n"),
2556 fprintf (stderr, "exec-shield in etc/PROBLEMS for more information.\n"); 2559 heap_bss_diff);
2557 fprintf (stderr, "**************************************************\n");
2558 } 2560 }
2559# endif 2561# endif
2560 2562
@@ -2591,7 +2593,7 @@ You must run Emacs in batch mode in order to dump it. */)
2591 } 2593 }
2592# endif 2594# endif
2593 2595
2594 fflush_unlocked (stdout); 2596 fflush (stdout);
2595 /* Tell malloc where start of impure now is. */ 2597 /* Tell malloc where start of impure now is. */
2596 /* Also arrange for warnings when nearly out of space. */ 2598 /* Also arrange for warnings when nearly out of space. */
2597# if !defined SYSTEM_MALLOC && !defined HYBRID_MALLOC && !defined WINDOWSNT 2599# if !defined SYSTEM_MALLOC && !defined HYBRID_MALLOC && !defined WINDOWSNT
diff --git a/src/fileio.c b/src/fileio.c
index 8f23a305a52..cce49c43b2e 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -5787,12 +5787,12 @@ A non-nil CURRENT-ONLY argument means save only current buffer. */)
5787 { 5787 {
5788 block_input (); 5788 block_input ();
5789 if (!NILP (BVAR (b, filename))) 5789 if (!NILP (BVAR (b, filename)))
5790 fwrite_unlocked (SDATA (BVAR (b, filename)), 1, 5790 fwrite (SDATA (BVAR (b, filename)), 1,
5791 SBYTES (BVAR (b, filename)), stream); 5791 SBYTES (BVAR (b, filename)), stream);
5792 putc_unlocked ('\n', stream); 5792 putc ('\n', stream);
5793 fwrite_unlocked (SDATA (BVAR (b, auto_save_file_name)), 1, 5793 fwrite (SDATA (BVAR (b, auto_save_file_name)), 1,
5794 SBYTES (BVAR (b, auto_save_file_name)), stream); 5794 SBYTES (BVAR (b, auto_save_file_name)), stream);
5795 putc_unlocked ('\n', stream); 5795 putc ('\n', stream);
5796 unblock_input (); 5796 unblock_input ();
5797 } 5797 }
5798 5798
@@ -5987,7 +5987,7 @@ effect except for flushing STREAM's data. */)
5987 5987
5988 binmode = NILP (mode) ? O_TEXT : O_BINARY; 5988 binmode = NILP (mode) ? O_TEXT : O_BINARY;
5989 if (fp != stdin) 5989 if (fp != stdin)
5990 fflush_unlocked (fp); 5990 fflush (fp);
5991 5991
5992 return (set_binary_mode (fileno (fp), binmode) == O_BINARY) ? Qt : Qnil; 5992 return (set_binary_mode (fileno (fp), binmode) == O_BINARY) ? Qt : Qnil;
5993} 5993}
diff --git a/src/image.c b/src/image.c
index b4b6c1bac1c..e898a7364a8 100644
--- a/src/image.c
+++ b/src/image.c
@@ -2991,7 +2991,7 @@ slurp_file (int fd, ptrdiff_t *size)
2991 This can happen if the file grows as we read it. */ 2991 This can happen if the file grows as we read it. */
2992 ptrdiff_t buflen = st.st_size; 2992 ptrdiff_t buflen = st.st_size;
2993 buf = xmalloc (buflen + 1); 2993 buf = xmalloc (buflen + 1);
2994 if (fread_unlocked (buf, 1, buflen + 1, fp) == buflen) 2994 if (fread (buf, 1, buflen + 1, fp) == buflen)
2995 *size = buflen; 2995 *size = buflen;
2996 else 2996 else
2997 { 2997 {
@@ -3338,7 +3338,7 @@ convert_mono_to_color_image (struct frame *f, struct image *img,
3338 DeleteDC (new_img_dc); 3338 DeleteDC (new_img_dc);
3339 DeleteObject (img->pixmap); 3339 DeleteObject (img->pixmap);
3340 if (new_pixmap == 0) 3340 if (new_pixmap == 0)
3341 fprintf (stderr, "Failed to convert image to color.\n"); 3341 fputs ("Failed to convert image to color.\n", stderr);
3342 else 3342 else
3343 img->pixmap = new_pixmap; 3343 img->pixmap = new_pixmap;
3344} 3344}
@@ -6427,7 +6427,7 @@ png_read_from_file (png_structp png_ptr, png_bytep data, png_size_t length)
6427{ 6427{
6428 FILE *fp = png_get_io_ptr (png_ptr); 6428 FILE *fp = png_get_io_ptr (png_ptr);
6429 6429
6430 if (fread_unlocked (data, 1, length, fp) < length) 6430 if (fread (data, 1, length, fp) < length)
6431 png_error (png_ptr, "Read error"); 6431 png_error (png_ptr, "Read error");
6432} 6432}
6433 6433
@@ -6490,7 +6490,7 @@ png_load_body (struct frame *f, struct image *img, struct png_load_context *c)
6490 } 6490 }
6491 6491
6492 /* Check PNG signature. */ 6492 /* Check PNG signature. */
6493 if (fread_unlocked (sig, 1, sizeof sig, fp) != sizeof sig 6493 if (fread (sig, 1, sizeof sig, fp) != sizeof sig
6494 || png_sig_cmp (sig, 0, sizeof sig)) 6494 || png_sig_cmp (sig, 0, sizeof sig))
6495 { 6495 {
6496 fclose (fp); 6496 fclose (fp);
@@ -7100,8 +7100,7 @@ our_stdio_fill_input_buffer (j_decompress_ptr cinfo)
7100 { 7100 {
7101 ptrdiff_t bytes; 7101 ptrdiff_t bytes;
7102 7102
7103 bytes = fread_unlocked (src->buffer, 1, JPEG_STDIO_BUFFER_SIZE, 7103 bytes = fread (src->buffer, 1, JPEG_STDIO_BUFFER_SIZE, src->file);
7104 src->file);
7105 if (bytes > 0) 7104 if (bytes > 0)
7106 src->mgr.bytes_in_buffer = bytes; 7105 src->mgr.bytes_in_buffer = bytes;
7107 else 7106 else
diff --git a/src/keyboard.c b/src/keyboard.c
index 56916e0cb4e..c47eecab9fb 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -3311,7 +3311,7 @@ record_char (Lisp_Object c)
3311 if (FIXNUMP (c)) 3311 if (FIXNUMP (c))
3312 { 3312 {
3313 if (XUFIXNUM (c) < 0x100) 3313 if (XUFIXNUM (c) < 0x100)
3314 putc_unlocked (XUFIXNUM (c), dribble); 3314 putc (XUFIXNUM (c), dribble);
3315 else 3315 else
3316 fprintf (dribble, " 0x%"pI"x", XUFIXNUM (c)); 3316 fprintf (dribble, " 0x%"pI"x", XUFIXNUM (c));
3317 } 3317 }
@@ -3324,15 +3324,14 @@ record_char (Lisp_Object c)
3324 3324
3325 if (SYMBOLP (dribblee)) 3325 if (SYMBOLP (dribblee))
3326 { 3326 {
3327 putc_unlocked ('<', dribble); 3327 putc ('<', dribble);
3328 fwrite_unlocked (SDATA (SYMBOL_NAME (dribblee)), sizeof (char), 3328 fwrite (SDATA (SYMBOL_NAME (dribblee)), sizeof (char),
3329 SBYTES (SYMBOL_NAME (dribblee)), 3329 SBYTES (SYMBOL_NAME (dribblee)), dribble);
3330 dribble); 3330 putc ('>', dribble);
3331 putc_unlocked ('>', dribble);
3332 } 3331 }
3333 } 3332 }
3334 3333
3335 fflush_unlocked (dribble); 3334 fflush (dribble);
3336 unblock_input (); 3335 unblock_input ();
3337 } 3336 }
3338} 3337}
@@ -3769,7 +3768,7 @@ kbd_buffer_get_event (KBOARD **kbp,
3769 detaching from the terminal. */ 3768 detaching from the terminal. */
3770 || (IS_DAEMON && DAEMON_RUNNING)) 3769 || (IS_DAEMON && DAEMON_RUNNING))
3771 { 3770 {
3772 int c = getchar_unlocked (); 3771 int c = getchar ();
3773 XSETINT (obj, c); 3772 XSETINT (obj, c);
3774 *kbp = current_kboard; 3773 *kbp = current_kboard;
3775 return obj; 3774 return obj;
@@ -10394,7 +10393,7 @@ handle_interrupt (bool in_signal_handler)
10394 sigemptyset (&blocked); 10393 sigemptyset (&blocked);
10395 sigaddset (&blocked, SIGINT); 10394 sigaddset (&blocked, SIGINT);
10396 pthread_sigmask (SIG_BLOCK, &blocked, 0); 10395 pthread_sigmask (SIG_BLOCK, &blocked, 0);
10397 fflush_unlocked (stdout); 10396 fflush (stdout);
10398 } 10397 }
10399 10398
10400 reset_all_sys_modes (); 10399 reset_all_sys_modes ();
diff --git a/src/lread.c b/src/lread.c
index 27529c3d630..e06eafcf6cf 100644
--- a/src/lread.c
+++ b/src/lread.c
@@ -490,13 +490,12 @@ readbyte_from_stdio (void)
490 block_input (); 490 block_input ();
491 491
492 /* Interrupted reads have been observed while reading over the network. */ 492 /* Interrupted reads have been observed while reading over the network. */
493 while ((c = getc_unlocked (instream)) == EOF && errno == EINTR 493 while ((c = getc (instream)) == EOF && errno == EINTR && ferror (instream))
494 && ferror_unlocked (instream))
495 { 494 {
496 unblock_input (); 495 unblock_input ();
497 maybe_quit (); 496 maybe_quit ();
498 block_input (); 497 block_input ();
499 clearerr_unlocked (instream); 498 clearerr (instream);
500 } 499 }
501 500
502 unblock_input (); 501 unblock_input ();
@@ -3063,7 +3062,7 @@ read1 (Lisp_Object readcharfun, int *pch, bool first_in_list)
3063 = c = infile->buf[--infile->lookahead]; 3062 = c = infile->buf[--infile->lookahead];
3064 block_input (); 3063 block_input ();
3065 for (; i < nskip && 0 <= c; i++) 3064 for (; i < nskip && 0 <= c; i++)
3066 saved_doc_string[i] = c = getc_unlocked (instream); 3065 saved_doc_string[i] = c = getc (instream);
3067 unblock_input (); 3066 unblock_input ();
3068 3067
3069 saved_doc_string_length = i; 3068 saved_doc_string_length = i;
diff --git a/src/minibuf.c b/src/minibuf.c
index d932dbe8e20..d9a6e15b05d 100644
--- a/src/minibuf.c
+++ b/src/minibuf.c
@@ -206,15 +206,15 @@ read_minibuf_noninteractive (Lisp_Object prompt, bool expflag,
206 suppress_echo_on_tty (STDIN_FILENO); 206 suppress_echo_on_tty (STDIN_FILENO);
207 } 207 }
208 208
209 fwrite_unlocked (SDATA (prompt), 1, SBYTES (prompt), stdout); 209 fwrite (SDATA (prompt), 1, SBYTES (prompt), stdout);
210 fflush_unlocked (stdout); 210 fflush (stdout);
211 211
212 val = Qnil; 212 val = Qnil;
213 size = 100; 213 size = 100;
214 len = 0; 214 len = 0;
215 line = xmalloc (size); 215 line = xmalloc (size);
216 216
217 while ((c = getchar_unlocked ()) != '\n' && c != '\r') 217 while ((c = getchar ()) != '\n' && c != '\r')
218 { 218 {
219 if (c == EOF) 219 if (c == EOF)
220 { 220 {
@@ -224,7 +224,7 @@ read_minibuf_noninteractive (Lisp_Object prompt, bool expflag,
224 else 224 else
225 { 225 {
226 if (hide_char) 226 if (hide_char)
227 fprintf (stdout, "%c", hide_char); 227 putchar (hide_char);
228 if (len == size) 228 if (len == size)
229 line = xpalloc (line, &size, 1, -1, sizeof *line); 229 line = xpalloc (line, &size, 1, -1, sizeof *line);
230 line[len++] = c; 230 line[len++] = c;
@@ -234,7 +234,7 @@ read_minibuf_noninteractive (Lisp_Object prompt, bool expflag,
234 /* Reset tty. */ 234 /* Reset tty. */
235 if (hide_char) 235 if (hide_char)
236 { 236 {
237 fprintf (stdout, "\n"); 237 putc ('\n', stdout);
238 if (etty_valid) 238 if (etty_valid)
239 { 239 {
240 emacs_set_tty (STDIN_FILENO, &etty, 0); 240 emacs_set_tty (STDIN_FILENO, &etty, 0);
diff --git a/src/nsfont.m b/src/nsfont.m
index eca97ab86cc..e22a954e63f 100644
--- a/src/nsfont.m
+++ b/src/nsfont.m
@@ -212,7 +212,7 @@ ns_descriptor_to_entity (NSFontDescriptor *desc,
212 212
213 if (NSFONT_TRACE) 213 if (NSFONT_TRACE)
214 { 214 {
215 fprintf (stderr, "created font_entity:\n "); 215 fputs ("created font_entity:\n ", stderr);
216 debug_print (font_entity); 216 debug_print (font_entity);
217 } 217 }
218 218
@@ -1472,16 +1472,13 @@ ns_dump_glyphstring (struct glyph_string *s)
1472{ 1472{
1473 int i; 1473 int i;
1474 1474
1475 fprintf (stderr, "Glyph string len = %d at (%d, %d) overhang (%d, %d)," 1475 fprintf (stderr, ("Glyph string len = %d at (%d, %d) overhang (%d, %d),"
1476"overlap = %d, bg_filled = %d:", 1476 "overlap = %d, bg_filled = %d:"),
1477 s->nchars, s->x, s->y, s->left_overhang, s->right_overhang, 1477 s->nchars, s->x, s->y, s->left_overhang, s->right_overhang,
1478 s->row->overlapping_p, s->background_filled_p); 1478 s->row->overlapping_p, s->background_filled_p);
1479 for (i =0; i<s->nchars; i++) 1479 for (i =0; i<s->nchars; i++)
1480 { 1480 putc (s->first_glyph[i].u.ch, stderr);
1481 int c = s->first_glyph[i].u.ch; 1481 putc ('\n', stderr);
1482 fprintf (stderr, "%c", c);
1483 }
1484 fprintf (stderr, "\n");
1485} 1482}
1486 1483
1487static void syms_of_nsfont_for_pdumper (void); 1484static void syms_of_nsfont_for_pdumper (void);
diff --git a/src/nsterm.h b/src/nsterm.h
index 567f462ec69..9773eb3e662 100644
--- a/src/nsterm.h
+++ b/src/nsterm.h
@@ -23,6 +23,7 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
23#include "character.h" 23#include "character.h"
24#include "font.h" 24#include "font.h"
25#include "sysselect.h" 25#include "sysselect.h"
26#include "sysstdio.h"
26 27
27#ifdef HAVE_NS 28#ifdef HAVE_NS
28#ifdef __OBJC__ 29#ifdef __OBJC__
@@ -180,7 +181,7 @@ char const * nstrace_fullscreen_type_name (int);
180 __FILE__, __LINE__, nstrace_num++, \ 181 __FILE__, __LINE__, nstrace_num++, \
181 2*nstrace_depth, " | | | | | | | | | | | | | | | .."); \ 182 2*nstrace_depth, " | | | | | | | | | | | | | | | .."); \
182 fprintf (stderr, __VA_ARGS__); \ 183 fprintf (stderr, __VA_ARGS__); \
183 fprintf (stderr, "\n"); \ 184 putc ('\n', stderr); \
184 } \ 185 } \
185 } \ 186 } \
186 while(0) 187 while(0)
diff --git a/src/nsterm.m b/src/nsterm.m
index bc1c7860aac..02331826d9b 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -2466,7 +2466,7 @@ ns_mouse_position (struct frame **fp, int insist, Lisp_Object *bar_window,
2466 2466
2467 if (*fp == NULL) 2467 if (*fp == NULL)
2468 { 2468 {
2469 fprintf (stderr, "Warning: ns_mouse_position () called with null *fp.\n"); 2469 fputs ("Warning: ns_mouse_position () called with null *fp.\n", stderr);
2470 return; 2470 return;
2471 } 2471 }
2472 2472
@@ -5613,7 +5613,7 @@ ns_term_shutdown (int sig)
5613 5613
5614 if (type == NSEventTypeCursorUpdate && window == nil) 5614 if (type == NSEventTypeCursorUpdate && window == nil)
5615 { 5615 {
5616 fprintf (stderr, "Dropping external cursor update event.\n"); 5616 fputs ("Dropping external cursor update event.\n", stderr);
5617 return; 5617 return;
5618 } 5618 }
5619 5619
@@ -6333,7 +6333,7 @@ not_in_argv (NSString *arg)
6333 https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/EventOverview/HandlingKeyEvents/HandlingKeyEvents.html. */ 6333 https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/EventOverview/HandlingKeyEvents/HandlingKeyEvents.html. */
6334 6334
6335 if (NS_KEYLOG && !processingCompose) 6335 if (NS_KEYLOG && !processingCompose)
6336 fprintf (stderr, "keyDown: Begin compose sequence.\n"); 6336 fputs ("keyDown: Begin compose sequence.\n", stderr);
6337 6337
6338 /* FIXME: interpretKeyEvents doesn’t seem to send insertText if ⌘ is 6338 /* FIXME: interpretKeyEvents doesn’t seem to send insertText if ⌘ is
6339 used as shift-like modifier, at least on El Capitan. Mask it 6339 used as shift-like modifier, at least on El Capitan. Mask it
@@ -8291,7 +8291,7 @@ not_in_argv (NSString *arg)
8291 } 8291 }
8292 else 8292 else
8293 { 8293 {
8294 fprintf (stderr, "Invalid data type in dragging pasteboard\n"); 8294 fputs ("Invalid data type in dragging pasteboard\n", stderr);
8295 return NO; 8295 return NO;
8296 } 8296 }
8297 8297
diff --git a/src/pdumper.c b/src/pdumper.c
index c00f8a0af54..8b630d221b1 100644
--- a/src/pdumper.c
+++ b/src/pdumper.c
@@ -23,7 +23,6 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
23#include <math.h> 23#include <math.h>
24#include <stdarg.h> 24#include <stdarg.h>
25#include <stdint.h> 25#include <stdint.h>
26#include <stdio.h>
27#include <stdlib.h> 26#include <stdlib.h>
28#include <sys/mman.h> 27#include <sys/mman.h>
29#include <sys/param.h> 28#include <sys/param.h>
@@ -42,6 +41,7 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
42#include "lisp.h" 41#include "lisp.h"
43#include "pdumper.h" 42#include "pdumper.h"
44#include "window.h" 43#include "window.h"
44#include "sysstdio.h"
45#include "systime.h" 45#include "systime.h"
46#include "thread.h" 46#include "thread.h"
47#include "bignum.h" 47#include "bignum.h"
@@ -329,7 +329,7 @@ dump_fingerprint (const char *label, unsigned char const *xfingerprint)
329 fprintf (stderr, "%s: ", label); 329 fprintf (stderr, "%s: ", label);
330 for (int i = 0; i < 32; ++i) 330 for (int i = 0; i < 32; ++i)
331 fprintf (stderr, "%02x", (unsigned) xfingerprint[i]); 331 fprintf (stderr, "%02x", (unsigned) xfingerprint[i]);
332 fprintf (stderr, "\n"); 332 putc ('\n', stderr);
333} 333}
334 334
335/* Format of an Emacs portable dump file. All offsets are relative to 335/* Format of an Emacs portable dump file. All offsets are relative to
@@ -1404,9 +1404,9 @@ print_paths_to_root_1 (struct dump_context *ctx,
1404 referrers = XCDR (referrers); 1404 referrers = XCDR (referrers);
1405 Lisp_Object repr = Fprin1_to_string (referrer, Qnil); 1405 Lisp_Object repr = Fprin1_to_string (referrer, Qnil);
1406 for (int i = 0; i < level; ++i) 1406 for (int i = 0; i < level; ++i)
1407 fputc (' ', stderr); 1407 putc (' ', stderr);
1408 fwrite (SDATA (repr), 1, SBYTES (repr), stderr); 1408 fwrite (SDATA (repr), 1, SBYTES (repr), stderr);
1409 fputc ('\n', stderr); 1409 putc ('\n', stderr);
1410 print_paths_to_root_1 (ctx, referrer, level + 1); 1410 print_paths_to_root_1 (ctx, referrer, level + 1);
1411 } 1411 }
1412} 1412}
@@ -4226,14 +4226,14 @@ types. */)
4226 dump_seek (ctx, 0); 4226 dump_seek (ctx, 0);
4227 dump_write (ctx, &ctx->header, sizeof (ctx->header)); 4227 dump_write (ctx, &ctx->header, sizeof (ctx->header));
4228 4228
4229 fprintf (stderr, "Dump complete\n");
4230 fprintf (stderr, 4229 fprintf (stderr,
4231 "Byte counts: header=%lu hot=%lu discardable=%lu cold=%lu\n", 4230 ("Dump complete\n"
4231 "Byte counts: header=%lu hot=%lu discardable=%lu cold=%lu\n"
4232 "Reloc counts: hot=%u discardable=%u\n"),
4232 (unsigned long) (header_end - header_start), 4233 (unsigned long) (header_end - header_start),
4233 (unsigned long) (hot_end - hot_start), 4234 (unsigned long) (hot_end - hot_start),
4234 (unsigned long) (discardable_end - ctx->header.discardable_start), 4235 (unsigned long) (discardable_end - ctx->header.discardable_start),
4235 (unsigned long) (cold_end - ctx->header.cold_start)); 4236 (unsigned long) (cold_end - ctx->header.cold_start),
4236 fprintf (stderr, "Reloc counts: hot=%u discardable=%u\n",
4237 number_hot_relocations, 4237 number_hot_relocations,
4238 number_discardable_relocations); 4238 number_discardable_relocations);
4239 4239
diff --git a/src/print.c b/src/print.c
index dc44b1e89e0..6623244c598 100644
--- a/src/print.c
+++ b/src/print.c
@@ -233,7 +233,7 @@ printchar_to_stream (unsigned int ch, FILE *stream)
233 { 233 {
234 if (ASCII_CHAR_P (ch)) 234 if (ASCII_CHAR_P (ch))
235 { 235 {
236 putc_unlocked (ch, stream); 236 putc (ch, stream);
237#ifdef WINDOWSNT 237#ifdef WINDOWSNT
238 /* Send the output to a debugger (nothing happens if there 238 /* Send the output to a debugger (nothing happens if there
239 isn't one). */ 239 isn't one). */
@@ -251,7 +251,7 @@ printchar_to_stream (unsigned int ch, FILE *stream)
251 if (encode_p) 251 if (encode_p)
252 encoded_ch = code_convert_string_norecord (encoded_ch, 252 encoded_ch = code_convert_string_norecord (encoded_ch,
253 coding_system, true); 253 coding_system, true);
254 fwrite_unlocked (SSDATA (encoded_ch), 1, SBYTES (encoded_ch), stream); 254 fwrite (SSDATA (encoded_ch), 1, SBYTES (encoded_ch), stream);
255#ifdef WINDOWSNT 255#ifdef WINDOWSNT
256 if (print_output_debug_flag && stream == stderr) 256 if (print_output_debug_flag && stream == stderr)
257 OutputDebugString (SSDATA (encoded_ch)); 257 OutputDebugString (SSDATA (encoded_ch));
@@ -303,7 +303,7 @@ printchar (unsigned int ch, Lisp_Object fun)
303 if (DISP_TABLE_P (Vstandard_display_table)) 303 if (DISP_TABLE_P (Vstandard_display_table))
304 printchar_to_stream (ch, stdout); 304 printchar_to_stream (ch, stdout);
305 else 305 else
306 fwrite_unlocked (str, 1, len, stdout); 306 fwrite (str, 1, len, stdout);
307 noninteractive_need_newline = 1; 307 noninteractive_need_newline = 1;
308 } 308 }
309 else 309 else
@@ -374,7 +374,7 @@ strout (const char *ptr, ptrdiff_t size, ptrdiff_t size_byte,
374 } 374 }
375 } 375 }
376 else 376 else
377 fwrite_unlocked (ptr, 1, size_byte, stdout); 377 fwrite (ptr, 1, size_byte, stdout);
378 378
379 noninteractive_need_newline = 1; 379 noninteractive_need_newline = 1;
380 } 380 }
@@ -825,7 +825,7 @@ append to existing target file. */)
825 report_file_error ("Cannot open debugging output stream", file); 825 report_file_error ("Cannot open debugging output stream", file);
826 } 826 }
827 827
828 fflush_unlocked (stderr); 828 fflush (stderr);
829 if (dup2 (fd, STDERR_FILENO) < 0) 829 if (dup2 (fd, STDERR_FILENO) < 0)
830 report_file_error ("dup2", file); 830 report_file_error ("dup2", file);
831 if (fd != stderr_dup) 831 if (fd != stderr_dup)
@@ -840,7 +840,7 @@ void
840debug_print (Lisp_Object arg) 840debug_print (Lisp_Object arg)
841{ 841{
842 Fprin1 (arg, Qexternal_debugging_output); 842 Fprin1 (arg, Qexternal_debugging_output);
843 fprintf (stderr, "\r\n"); 843 fputs ("\r\n", stderr);
844} 844}
845 845
846void safe_debug_print (Lisp_Object) EXTERNALLY_VISIBLE; 846void safe_debug_print (Lisp_Object) EXTERNALLY_VISIBLE;
diff --git a/src/regex-emacs.c b/src/regex-emacs.c
index ac9f91dacbc..bf2ad072f56 100644
--- a/src/regex-emacs.c
+++ b/src/regex-emacs.c
@@ -436,7 +436,7 @@ extract_number_and_incr (re_char **source)
436#ifdef REGEX_EMACS_DEBUG 436#ifdef REGEX_EMACS_DEBUG
437 437
438/* Use standard I/O for debugging. */ 438/* Use standard I/O for debugging. */
439# include <stdio.h> 439# include "sysstdio.h"
440 440
441static int regex_emacs_debug = -100000; 441static int regex_emacs_debug = -100000;
442 442
@@ -453,7 +453,7 @@ static void
453debug_putchar (int c) 453debug_putchar (int c)
454{ 454{
455 if (c >= 32 && c <= 126) 455 if (c >= 32 && c <= 126)
456 fputc (c, stderr); 456 putc (c, stderr);
457 else 457 else
458 { 458 {
459 unsigned int uc = c; 459 unsigned int uc = c;
@@ -482,12 +482,12 @@ print_fastmap (char *fastmap)
482 } 482 }
483 if (was_a_range) 483 if (was_a_range)
484 { 484 {
485 fprintf (stderr, "-"); 485 debug_putchar ('-');
486 debug_putchar (i - 1); 486 debug_putchar (i - 1);
487 } 487 }
488 } 488 }
489 } 489 }
490 fputc ('\n', stderr); 490 putc ('\n', stderr);
491} 491}
492 492
493 493
@@ -503,7 +503,7 @@ print_partial_compiled_pattern (re_char *start, re_char *end)
503 503
504 if (start == NULL) 504 if (start == NULL)
505 { 505 {
506 fprintf (stderr, "(null)\n"); 506 fputs ("(null)\n", stderr);
507 return; 507 return;
508 } 508 }
509 509
@@ -515,11 +515,11 @@ print_partial_compiled_pattern (re_char *start, re_char *end)
515 switch ((re_opcode_t) *p++) 515 switch ((re_opcode_t) *p++)
516 { 516 {
517 case no_op: 517 case no_op:
518 fprintf (stderr, "/no_op"); 518 fputs ("/no_op", stderr);
519 break; 519 break;
520 520
521 case succeed: 521 case succeed:
522 fprintf (stderr, "/succeed"); 522 fputs ("/succeed", stderr);
523 break; 523 break;
524 524
525 case exactn: 525 case exactn:
@@ -527,7 +527,7 @@ print_partial_compiled_pattern (re_char *start, re_char *end)
527 fprintf (stderr, "/exactn/%d", mcnt); 527 fprintf (stderr, "/exactn/%d", mcnt);
528 do 528 do
529 { 529 {
530 fprintf (stderr, "/"); 530 debug_putchar ('/');
531 debug_putchar (*p++); 531 debug_putchar (*p++);
532 } 532 }
533 while (--mcnt); 533 while (--mcnt);
@@ -546,7 +546,7 @@ print_partial_compiled_pattern (re_char *start, re_char *end)
546 break; 546 break;
547 547
548 case anychar: 548 case anychar:
549 fprintf (stderr, "/anychar"); 549 fputs ("/anychar", stderr);
550 break; 550 break;
551 551
552 case charset: 552 case charset:
@@ -561,7 +561,7 @@ print_partial_compiled_pattern (re_char *start, re_char *end)
561 (re_opcode_t) *(p - 1) == charset_not ? "^" : ""); 561 (re_opcode_t) *(p - 1) == charset_not ? "^" : "");
562 562
563 if (p + *p >= pend) 563 if (p + *p >= pend)
564 fprintf (stderr, " !extends past end of pattern! "); 564 fputs (" !extends past end of pattern! ", stderr);
565 565
566 for (c = 0; c < 256; c++) 566 for (c = 0; c < 256; c++)
567 if (c / 8 < length 567 if (c / 8 < length
@@ -570,7 +570,7 @@ print_partial_compiled_pattern (re_char *start, re_char *end)
570 /* Are we starting a range? */ 570 /* Are we starting a range? */
571 if (last + 1 == c && ! in_range) 571 if (last + 1 == c && ! in_range)
572 { 572 {
573 fprintf (stderr, "-"); 573 debug_putchar ('-');
574 in_range = true; 574 in_range = true;
575 } 575 }
576 /* Have we broken a range? */ 576 /* Have we broken a range? */
@@ -589,14 +589,14 @@ print_partial_compiled_pattern (re_char *start, re_char *end)
589 if (in_range) 589 if (in_range)
590 debug_putchar (last); 590 debug_putchar (last);
591 591
592 fprintf (stderr, "]"); 592 debug_putchar (']');
593 593
594 p += 1 + length; 594 p += 1 + length;
595 595
596 if (has_range_table) 596 if (has_range_table)
597 { 597 {
598 int count; 598 int count;
599 fprintf (stderr, "has-range-table"); 599 fputs ("has-range-table", stderr);
600 600
601 /* ??? Should print the range table; for now, just skip it. */ 601 /* ??? Should print the range table; for now, just skip it. */
602 p += 2; /* skip range table bits */ 602 p += 2; /* skip range table bits */
@@ -607,11 +607,11 @@ print_partial_compiled_pattern (re_char *start, re_char *end)
607 break; 607 break;
608 608
609 case begline: 609 case begline:
610 fprintf (stderr, "/begline"); 610 fputs ("/begline", stderr);
611 break; 611 break;
612 612
613 case endline: 613 case endline:
614 fprintf (stderr, "/endline"); 614 fputs ("/endline", stderr);
615 break; 615 break;
616 616
617 case on_failure_jump: 617 case on_failure_jump:
@@ -670,70 +670,70 @@ print_partial_compiled_pattern (re_char *start, re_char *end)
670 break; 670 break;
671 671
672 case wordbound: 672 case wordbound:
673 fprintf (stderr, "/wordbound"); 673 fputs ("/wordbound", stderr);
674 break; 674 break;
675 675
676 case notwordbound: 676 case notwordbound:
677 fprintf (stderr, "/notwordbound"); 677 fputs ("/notwordbound", stderr);
678 break; 678 break;
679 679
680 case wordbeg: 680 case wordbeg:
681 fprintf (stderr, "/wordbeg"); 681 fputs ("/wordbeg", stderr);
682 break; 682 break;
683 683
684 case wordend: 684 case wordend:
685 fprintf (stderr, "/wordend"); 685 fputs ("/wordend", stderr);
686 break; 686 break;
687 687
688 case symbeg: 688 case symbeg:
689 fprintf (stderr, "/symbeg"); 689 fputs ("/symbeg", stderr);
690 break; 690 break;
691 691
692 case symend: 692 case symend:
693 fprintf (stderr, "/symend"); 693 fputs ("/symend", stderr);
694 break; 694 break;
695 695
696 case syntaxspec: 696 case syntaxspec:
697 fprintf (stderr, "/syntaxspec"); 697 fputs ("/syntaxspec", stderr);
698 mcnt = *p++; 698 mcnt = *p++;
699 fprintf (stderr, "/%d", mcnt); 699 fprintf (stderr, "/%d", mcnt);
700 break; 700 break;
701 701
702 case notsyntaxspec: 702 case notsyntaxspec:
703 fprintf (stderr, "/notsyntaxspec"); 703 fputs ("/notsyntaxspec", stderr);
704 mcnt = *p++; 704 mcnt = *p++;
705 fprintf (stderr, "/%d", mcnt); 705 fprintf (stderr, "/%d", mcnt);
706 break; 706 break;
707 707
708 case at_dot: 708 case at_dot:
709 fprintf (stderr, "/at_dot"); 709 fputs ("/at_dot", stderr);
710 break; 710 break;
711 711
712 case categoryspec: 712 case categoryspec:
713 fprintf (stderr, "/categoryspec"); 713 fputs ("/categoryspec", stderr);
714 mcnt = *p++; 714 mcnt = *p++;
715 fprintf (stderr, "/%d", mcnt); 715 fprintf (stderr, "/%d", mcnt);
716 break; 716 break;
717 717
718 case notcategoryspec: 718 case notcategoryspec:
719 fprintf (stderr, "/notcategoryspec"); 719 fputs ("/notcategoryspec", stderr);
720 mcnt = *p++; 720 mcnt = *p++;
721 fprintf (stderr, "/%d", mcnt); 721 fprintf (stderr, "/%d", mcnt);
722 break; 722 break;
723 723
724 case begbuf: 724 case begbuf:
725 fprintf (stderr, "/begbuf"); 725 fputs ("/begbuf", stderr);
726 break; 726 break;
727 727
728 case endbuf: 728 case endbuf:
729 fprintf (stderr, "/endbuf"); 729 fputs ("/endbuf", stderr);
730 break; 730 break;
731 731
732 default: 732 default:
733 fprintf (stderr, "?%d", *(p-1)); 733 fprintf (stderr, "?%d", *(p-1));
734 } 734 }
735 735
736 fprintf (stderr, "\n"); 736 putc ('\n', stderr);
737 } 737 }
738 738
739 fprintf (stderr, "%td:\tend of pattern.\n", p - start); 739 fprintf (stderr, "%td:\tend of pattern.\n", p - start);
@@ -751,14 +751,13 @@ print_compiled_pattern (struct re_pattern_buffer *bufp)
751 751
752 if (bufp->fastmap_accurate && bufp->fastmap) 752 if (bufp->fastmap_accurate && bufp->fastmap)
753 { 753 {
754 fprintf (stderr, "fastmap: "); 754 fputs ("fastmap: ", stderr);
755 print_fastmap (bufp->fastmap); 755 print_fastmap (bufp->fastmap);
756 } 756 }
757 757
758 fprintf (stderr, "re_nsub: %td\t", bufp->re_nsub); 758 fprintf (stderr, "re_nsub: %td\t", bufp->re_nsub);
759 fprintf (stderr, "regs_alloc: %d\t", bufp->regs_allocated); 759 fprintf (stderr, "regs_alloc: %d\t", bufp->regs_allocated);
760 fprintf (stderr, "can_be_null: %d\n", bufp->can_be_null); 760 fprintf (stderr, "can_be_null: %d\n", bufp->can_be_null);
761 fflush (stderr);
762 /* Perhaps we should print the translate table? */ 761 /* Perhaps we should print the translate table? */
763} 762}
764 763
@@ -768,7 +767,7 @@ print_double_string (re_char *where, re_char *string1, ptrdiff_t size1,
768 re_char *string2, ptrdiff_t size2) 767 re_char *string2, ptrdiff_t size2)
769{ 768{
770 if (where == NULL) 769 if (where == NULL)
771 fprintf (stderr, "(null)"); 770 fputs ("(null)", stderr);
772 else 771 else
773 { 772 {
774 int i; 773 int i;
@@ -1751,7 +1750,7 @@ regex_compile (re_char *pattern, ptrdiff_t size,
1751 { 1750 {
1752 for (ptrdiff_t debug_count = 0; debug_count < size; debug_count++) 1751 for (ptrdiff_t debug_count = 0; debug_count < size; debug_count++)
1753 debug_putchar (pattern[debug_count]); 1752 debug_putchar (pattern[debug_count]);
1754 fputc ('\n', stderr); 1753 putc ('\n', stderr);
1755 } 1754 }
1756#endif 1755#endif
1757 1756
diff --git a/src/sysdep.c b/src/sysdep.c
index c7d7eefc2ab..99d3ee60698 100644
--- a/src/sysdep.c
+++ b/src/sysdep.c
@@ -1472,7 +1472,7 @@ reset_sys_modes (struct tty_display_info *tty_out)
1472{ 1472{
1473 if (noninteractive) 1473 if (noninteractive)
1474 { 1474 {
1475 fflush_unlocked (stdout); 1475 fflush (stdout);
1476 return; 1476 return;
1477 } 1477 }
1478 if (!tty_out->term_initted) 1478 if (!tty_out->term_initted)
@@ -1495,11 +1495,11 @@ reset_sys_modes (struct tty_display_info *tty_out)
1495 tty_turn_off_insert (tty_out); 1495 tty_turn_off_insert (tty_out);
1496 1496
1497 for (int i = cursorX (tty_out); i < FrameCols (tty_out) - 1; i++) 1497 for (int i = cursorX (tty_out); i < FrameCols (tty_out) - 1; i++)
1498 fputc_unlocked (' ', tty_out->output); 1498 putc (' ', tty_out->output);
1499 } 1499 }
1500 1500
1501 cmgoto (tty_out, FrameRows (tty_out) - 1, 0); 1501 cmgoto (tty_out, FrameRows (tty_out) - 1, 0);
1502 fflush_unlocked (tty_out->output); 1502 fflush (tty_out->output);
1503 1503
1504 if (tty_out->terminal->reset_terminal_modes_hook) 1504 if (tty_out->terminal->reset_terminal_modes_hook)
1505 tty_out->terminal->reset_terminal_modes_hook (tty_out->terminal); 1505 tty_out->terminal->reset_terminal_modes_hook (tty_out->terminal);
@@ -2783,7 +2783,7 @@ close_output_streams (void)
2783 /* Do not close stderr if addresses are being sanitized, as the 2783 /* Do not close stderr if addresses are being sanitized, as the
2784 sanitizer might report to stderr after this function is invoked. */ 2784 sanitizer might report to stderr after this function is invoked. */
2785 if (ADDRESS_SANITIZER 2785 if (ADDRESS_SANITIZER
2786 ? fflush_unlocked (stderr) != 0 || ferror (stderr) 2786 ? fflush (stderr) != 0 || ferror (stderr)
2787 : close_stream (stderr) != 0) 2787 : close_stream (stderr) != 0)
2788 _exit (EXIT_FAILURE); 2788 _exit (EXIT_FAILURE);
2789} 2789}
@@ -3184,7 +3184,7 @@ procfs_ttyname (int rdev)
3184 char minor[25]; /* 2 32-bit numbers + dash */ 3184 char minor[25]; /* 2 32-bit numbers + dash */
3185 char *endp; 3185 char *endp;
3186 3186
3187 for (; !feof_unlocked (fdev) && !ferror_unlocked (fdev); name[0] = 0) 3187 for (; !feof (fdev) && !ferror (fdev); name[0] = 0)
3188 { 3188 {
3189 if (fscanf (fdev, "%*s %s %u %s %*s\n", name, &major, minor) >= 3 3189 if (fscanf (fdev, "%*s %s %u %s %*s\n", name, &major, minor) >= 3
3190 && major == MAJOR (rdev)) 3190 && major == MAJOR (rdev))
@@ -3234,7 +3234,7 @@ procfs_get_total_memory (void)
3234 break; 3234 break;
3235 3235
3236 case 0: 3236 case 0:
3237 while ((c = getc_unlocked (fmem)) != EOF && c != '\n') 3237 while ((c = getc (fmem)) != EOF && c != '\n')
3238 continue; 3238 continue;
3239 done = c == EOF; 3239 done = c == EOF;
3240 break; 3240 break;
diff --git a/src/sysstdio.h b/src/sysstdio.h
index a2364c4e1fb..68ae043fe33 100644
--- a/src/sysstdio.h
+++ b/src/sysstdio.h
@@ -22,6 +22,7 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
22 22
23#include <fcntl.h> 23#include <fcntl.h>
24#include <stdio.h> 24#include <stdio.h>
25#include "unlocked-io.h"
25 26
26extern FILE *emacs_fopen (char const *, char const *); 27extern FILE *emacs_fopen (char const *, char const *);
27extern void close_output_streams (void); 28extern void close_output_streams (void);
@@ -34,45 +35,4 @@ extern void close_output_streams (void);
34# define FOPEN_TEXT "" 35# define FOPEN_TEXT ""
35#endif 36#endif
36 37
37/* These are compatible with unlocked-io.h, if both files are included. */
38#if !HAVE_DECL_CLEARERR_UNLOCKED
39# define clearerr_unlocked(x) clearerr (x)
40#endif
41#if !HAVE_DECL_FEOF_UNLOCKED
42# define feof_unlocked(x) feof (x)
43#endif
44#if !HAVE_DECL_FERROR_UNLOCKED
45# define ferror_unlocked(x) ferror (x)
46#endif
47#if !HAVE_DECL_FFLUSH_UNLOCKED
48# define fflush_unlocked(x) fflush (x)
49#endif
50#if !HAVE_DECL_FGETS_UNLOCKED
51# define fgets_unlocked(x,y,z) fgets (x,y,z)
52#endif
53#if !HAVE_DECL_FPUTC_UNLOCKED
54# define fputc_unlocked(x,y) fputc (x,y)
55#endif
56#if !HAVE_DECL_FPUTS_UNLOCKED
57# define fputs_unlocked(x,y) fputs (x,y)
58#endif
59#if !HAVE_DECL_FREAD_UNLOCKED
60# define fread_unlocked(w,x,y,z) fread (w,x,y,z)
61#endif
62#if !HAVE_DECL_FWRITE_UNLOCKED
63# define fwrite_unlocked(w,x,y,z) fwrite (w,x,y,z)
64#endif
65#if !HAVE_DECL_GETC_UNLOCKED
66# define getc_unlocked(x) getc (x)
67#endif
68#if !HAVE_DECL_GETCHAR_UNLOCKED
69# define getchar_unlocked() getchar ()
70#endif
71#if !HAVE_DECL_PUTC_UNLOCKED
72# define putc_unlocked(x,y) putc (x,y)
73#endif
74#if !HAVE_DECL_PUTCHAR_UNLOCKED
75# define putchar_unlocked(x) putchar (x)
76#endif
77
78#endif /* EMACS_SYSSTDIO_H */ 38#endif /* EMACS_SYSSTDIO_H */
diff --git a/src/term.c b/src/term.c
index 8b5a710d80a..b058d8bdad0 100644
--- a/src/term.c
+++ b/src/term.c
@@ -145,7 +145,7 @@ tty_ring_bell (struct frame *f)
145 OUTPUT (tty, (tty->TS_visible_bell && visible_bell 145 OUTPUT (tty, (tty->TS_visible_bell && visible_bell
146 ? tty->TS_visible_bell 146 ? tty->TS_visible_bell
147 : tty->TS_bell)); 147 : tty->TS_bell));
148 fflush_unlocked (tty->output); 148 fflush (tty->output);
149 } 149 }
150} 150}
151 151
@@ -170,10 +170,9 @@ tty_send_additional_strings (struct terminal *terminal, Lisp_Object sym)
170 Lisp_Object string = XCAR (extra_codes); 170 Lisp_Object string = XCAR (extra_codes);
171 if (STRINGP (string)) 171 if (STRINGP (string))
172 { 172 {
173 fwrite_unlocked (SDATA (string), 1, SBYTES (string), tty->output); 173 fwrite (SDATA (string), 1, SBYTES (string), tty->output);
174 if (tty->termscript) 174 if (tty->termscript)
175 fwrite_unlocked (SDATA (string), 1, SBYTES (string), 175 fwrite (SDATA (string), 1, SBYTES (string), tty->termscript);
176 tty->termscript);
177 } 176 }
178 } 177 }
179} 178}
@@ -201,7 +200,7 @@ tty_set_terminal_modes (struct terminal *terminal)
201 OUTPUT_IF (tty, tty->TS_keypad_mode); 200 OUTPUT_IF (tty, tty->TS_keypad_mode);
202 losecursor (tty); 201 losecursor (tty);
203 tty_send_additional_strings (terminal, Qtty_mode_set_strings); 202 tty_send_additional_strings (terminal, Qtty_mode_set_strings);
204 fflush_unlocked (tty->output); 203 fflush (tty->output);
205 } 204 }
206} 205}
207 206
@@ -224,7 +223,7 @@ tty_reset_terminal_modes (struct terminal *terminal)
224 /* Output raw CR so kernel can track the cursor hpos. */ 223 /* Output raw CR so kernel can track the cursor hpos. */
225 current_tty = tty; 224 current_tty = tty;
226 cmputc ('\r'); 225 cmputc ('\r');
227 fflush_unlocked (tty->output); 226 fflush (tty->output);
228 } 227 }
229} 228}
230 229
@@ -239,7 +238,7 @@ tty_update_end (struct frame *f)
239 tty_show_cursor (tty); 238 tty_show_cursor (tty);
240 tty_turn_off_insert (tty); 239 tty_turn_off_insert (tty);
241 tty_background_highlight (tty); 240 tty_background_highlight (tty);
242 fflush_unlocked (tty->output); 241 fflush (tty->output);
243} 242}
244 243
245/* The implementation of set_terminal_window for termcap frames. */ 244/* The implementation of set_terminal_window for termcap frames. */
@@ -501,8 +500,8 @@ tty_clear_end_of_line (struct frame *f, int first_unused_hpos)
501 for (i = curX (tty); i < first_unused_hpos; i++) 500 for (i = curX (tty); i < first_unused_hpos; i++)
502 { 501 {
503 if (tty->termscript) 502 if (tty->termscript)
504 fputc_unlocked (' ', tty->termscript); 503 putc (' ', tty->termscript);
505 fputc_unlocked (' ', tty->output); 504 putc (' ', tty->output);
506 } 505 }
507 cmplus (tty, first_unused_hpos - curX (tty)); 506 cmplus (tty, first_unused_hpos - curX (tty));
508 } 507 }
@@ -775,11 +774,10 @@ tty_write_glyphs (struct frame *f, struct glyph *string, int len)
775 if (coding->produced > 0) 774 if (coding->produced > 0)
776 { 775 {
777 block_input (); 776 block_input ();
778 fwrite_unlocked (conversion_buffer, 1, coding->produced, tty->output); 777 fwrite (conversion_buffer, 1, coding->produced, tty->output);
779 clearerr_unlocked (tty->output); 778 clearerr (tty->output);
780 if (tty->termscript) 779 if (tty->termscript)
781 fwrite_unlocked (conversion_buffer, 1, coding->produced, 780 fwrite (conversion_buffer, 1, coding->produced, tty->termscript);
782 tty->termscript);
783 unblock_input (); 781 unblock_input ();
784 } 782 }
785 string += n; 783 string += n;
@@ -836,11 +834,10 @@ tty_write_glyphs_with_face (register struct frame *f, register struct glyph *str
836 if (coding->produced > 0) 834 if (coding->produced > 0)
837 { 835 {
838 block_input (); 836 block_input ();
839 fwrite_unlocked (conversion_buffer, 1, coding->produced, tty->output); 837 fwrite (conversion_buffer, 1, coding->produced, tty->output);
840 clearerr_unlocked (tty->output); 838 clearerr (tty->output);
841 if (tty->termscript) 839 if (tty->termscript)
842 fwrite_unlocked (conversion_buffer, 1, coding->produced, 840 fwrite (conversion_buffer, 1, coding->produced, tty->termscript);
843 tty->termscript);
844 unblock_input (); 841 unblock_input ();
845 } 842 }
846 843
@@ -922,11 +919,10 @@ tty_insert_glyphs (struct frame *f, struct glyph *start, int len)
922 if (coding->produced > 0) 919 if (coding->produced > 0)
923 { 920 {
924 block_input (); 921 block_input ();
925 fwrite_unlocked (conversion_buffer, 1, coding->produced, tty->output); 922 fwrite (conversion_buffer, 1, coding->produced, tty->output);
926 clearerr_unlocked (tty->output); 923 clearerr (tty->output);
927 if (tty->termscript) 924 if (tty->termscript)
928 fwrite_unlocked (conversion_buffer, 1, coding->produced, 925 fwrite (conversion_buffer, 1, coding->produced, tty->termscript);
929 tty->termscript);
930 unblock_input (); 926 unblock_input ();
931 } 927 }
932 928
@@ -3331,7 +3327,7 @@ tty_menu_activate (tty_menu *menu, int *pane, int *selidx,
3331 which calls tty_show_cursor. Re-hide it, so it doesn't show 3327 which calls tty_show_cursor. Re-hide it, so it doesn't show
3332 through the menus. */ 3328 through the menus. */
3333 tty_hide_cursor (tty); 3329 tty_hide_cursor (tty);
3334 fflush_unlocked (tty->output); 3330 fflush (tty->output);
3335 } 3331 }
3336 3332
3337 sf->mouse_moved = 0; 3333 sf->mouse_moved = 0;
@@ -3339,7 +3335,7 @@ tty_menu_activate (tty_menu *menu, int *pane, int *selidx,
3339 while (statecount--) 3335 while (statecount--)
3340 free_saved_screen (state[statecount].screen_behind); 3336 free_saved_screen (state[statecount].screen_behind);
3341 tty_show_cursor (tty); /* Turn cursor back on. */ 3337 tty_show_cursor (tty); /* Turn cursor back on. */
3342 fflush_unlocked (tty->output); 3338 fflush (tty->output);
3343 3339
3344/* Clean up any mouse events that are waiting inside Emacs event queue. 3340/* Clean up any mouse events that are waiting inside Emacs event queue.
3345 These events are likely to be generated before the menu was even 3341 These events are likely to be generated before the menu was even
@@ -4398,10 +4394,10 @@ use the Bourne shell command 'TERM=...; export TERM' (C-shell:\n\
4398static void 4394static void
4399vfatal (const char *str, va_list ap) 4395vfatal (const char *str, va_list ap)
4400{ 4396{
4401 fprintf (stderr, "emacs: "); 4397 fputs ("emacs: ", stderr);
4402 vfprintf (stderr, str, ap); 4398 vfprintf (stderr, str, ap);
4403 if (! (str[0] && str[strlen (str) - 1] == '\n')) 4399 if (! (str[0] && str[strlen (str) - 1] == '\n'))
4404 fprintf (stderr, "\n"); 4400 putc ('\n', stderr);
4405 exit (1); 4401 exit (1);
4406} 4402}
4407 4403
diff --git a/src/unexhp9k800.c b/src/unexhp9k800.c
index cbf1835b9ee..d2943eb18c9 100644
--- a/src/unexhp9k800.c
+++ b/src/unexhp9k800.c
@@ -52,8 +52,8 @@
52#include <config.h> 52#include <config.h>
53#include "unexec.h" 53#include "unexec.h"
54#include "lisp.h" 54#include "lisp.h"
55#include "sysstdio.h"
55 56
56#include <stdio.h>
57#include <fcntl.h> 57#include <fcntl.h>
58#include <errno.h> 58#include <errno.h>
59#include <a.out.h> 59#include <a.out.h>
@@ -167,7 +167,7 @@ read_header (int file, struct header *hdr, struct som_exec_auxhdr *auxhdr)
167 if (hdr->a_magic != EXEC_MAGIC && hdr->a_magic != SHARE_MAGIC 167 if (hdr->a_magic != EXEC_MAGIC && hdr->a_magic != SHARE_MAGIC
168 && hdr->a_magic != DEMAND_MAGIC) 168 && hdr->a_magic != DEMAND_MAGIC)
169 { 169 {
170 fprintf (stderr, "a.out file doesn't have valid magic number\n"); 170 fputs ("a.out file doesn't have valid magic number\n", stderr);
171 exit (1); 171 exit (1);
172 } 172 }
173 173
diff --git a/src/unexmacosx.c b/src/unexmacosx.c
index a94c0cccb6b..5f52cedb2b7 100644
--- a/src/unexmacosx.c
+++ b/src/unexmacosx.c
@@ -97,9 +97,9 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
97 97
98#include "unexec.h" 98#include "unexec.h"
99#include "lisp.h" 99#include "lisp.h"
100#include "sysstdio.h"
100 101
101#include <errno.h> 102#include <errno.h>
102#include <stdio.h>
103#include <fcntl.h> 103#include <fcntl.h>
104#include <stdarg.h> 104#include <stdarg.h>
105#include <stdint.h> 105#include <stdint.h>
@@ -303,9 +303,9 @@ unexec_error (const char *format, ...)
303 va_list ap; 303 va_list ap;
304 304
305 va_start (ap, format); 305 va_start (ap, format);
306 fprintf (stderr, "unexec: "); 306 fputs ("unexec: ", stderr);
307 vfprintf (stderr, format, ap); 307 vfprintf (stderr, format, ap);
308 fprintf (stderr, "\n"); 308 putc ('\n', stderr);
309 va_end (ap); 309 va_end (ap);
310 exit (1); 310 exit (1);
311} 311}
diff --git a/src/widget.c b/src/widget.c
index e662dd3ecdf..c3d396ddab0 100644
--- a/src/widget.c
+++ b/src/widget.c
@@ -31,10 +31,10 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
31#include <config.h> 31#include <config.h>
32#include "widget.h" 32#include "widget.h"
33 33
34#include <stdio.h>
35#include <stdlib.h> 34#include <stdlib.h>
36 35
37#include "lisp.h" 36#include "lisp.h"
37#include "sysstdio.h"
38#include "xterm.h" 38#include "xterm.h"
39#include "frame.h" 39#include "frame.h"
40 40
@@ -364,8 +364,7 @@ EmacsFrameInitialize (Widget request, Widget new, ArgList dum1, Cardinal *dum2)
364 364
365 if (!ew->emacs_frame.frame) 365 if (!ew->emacs_frame.frame)
366 { 366 {
367 fprintf (stderr, 367 fputs ("can't create an emacs frame widget without a frame\n", stderr);
368 "can't create an emacs frame widget without a frame\n");
369 exit (1); 368 exit (1);
370 } 369 }
371 370
diff --git a/src/xdisp.c b/src/xdisp.c
index 75cc97df1c0..2711e54382d 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -302,7 +302,6 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
302 buffer_posn_from_coords in dispnew.c for how this is handled. */ 302 buffer_posn_from_coords in dispnew.c for how this is handled. */
303 303
304#include <config.h> 304#include <config.h>
305#include <stdio.h>
306#include <stdlib.h> 305#include <stdlib.h>
307#include <limits.h> 306#include <limits.h>
308#include <math.h> 307#include <math.h>
@@ -311,6 +310,7 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
311#include "atimer.h" 310#include "atimer.h"
312#include "composite.h" 311#include "composite.h"
313#include "keyboard.h" 312#include "keyboard.h"
313#include "sysstdio.h"
314#include "systime.h" 314#include "systime.h"
315#include "frame.h" 315#include "frame.h"
316#include "window.h" 316#include "window.h"
@@ -10714,7 +10714,7 @@ message_to_stderr (Lisp_Object m)
10714 if (noninteractive_need_newline) 10714 if (noninteractive_need_newline)
10715 { 10715 {
10716 noninteractive_need_newline = false; 10716 noninteractive_need_newline = false;
10717 fputc ('\n', stderr); 10717 putc ('\n', stderr);
10718 } 10718 }
10719 if (STRINGP (m)) 10719 if (STRINGP (m))
10720 { 10720 {
@@ -10728,7 +10728,7 @@ message_to_stderr (Lisp_Object m)
10728 else 10728 else
10729 s = m; 10729 s = m;
10730 10730
10731 /* We want to write this out with a single fwrite call so that 10731 /* We want to write this out with a single call so that
10732 output doesn't interleave with other processes writing to 10732 output doesn't interleave with other processes writing to
10733 stderr at the same time. */ 10733 stderr at the same time. */
10734 { 10734 {
@@ -10742,9 +10742,7 @@ message_to_stderr (Lisp_Object m)
10742 } 10742 }
10743 } 10743 }
10744 else if (!cursor_in_echo_area) 10744 else if (!cursor_in_echo_area)
10745 fputc ('\n', stderr); 10745 putc ('\n', stderr);
10746
10747 fflush (stderr);
10748} 10746}
10749 10747
10750/* The non-logging version of message3. 10748/* The non-logging version of message3.
@@ -10889,11 +10887,11 @@ vmessage (const char *m, va_list ap)
10889 if (m) 10887 if (m)
10890 { 10888 {
10891 if (noninteractive_need_newline) 10889 if (noninteractive_need_newline)
10892 fputc ('\n', stderr); 10890 putc ('\n', stderr);
10893 noninteractive_need_newline = false; 10891 noninteractive_need_newline = false;
10894 vfprintf (stderr, m, ap); 10892 vfprintf (stderr, m, ap);
10895 if (!cursor_in_echo_area) 10893 if (!cursor_in_echo_area)
10896 fputc ('\n', stderr); 10894 putc ('\n', stderr);
10897 fflush (stderr); 10895 fflush (stderr);
10898 } 10896 }
10899 } 10897 }
@@ -19648,9 +19646,9 @@ dump_glyph_row (struct glyph_row *row, int vpos, int glyphs)
19648{ 19646{
19649 if (glyphs != 1) 19647 if (glyphs != 1)
19650 { 19648 {
19651 fprintf (stderr, "Row Start End Used oE><\\CTZFesm X Y W H V A P\n"); 19649 fputs (("Row Start End Used oE><\\CTZFesm X Y W H V A P\n"
19652 fprintf (stderr, "==============================================================================\n"); 19650 "==============================================================================\n"),
19653 19651 stderr);
19654 fprintf (stderr, "%3d %9"pD"d %9"pD"d %4d %1.1d%1.1d%1.1d%1.1d\ 19652 fprintf (stderr, "%3d %9"pD"d %9"pD"d %4d %1.1d%1.1d%1.1d%1.1d\
19655%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n", 19653%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
19656 vpos, 19654 vpos,
@@ -19701,7 +19699,8 @@ dump_glyph_row (struct glyph_row *row, int vpos, int glyphs)
19701 ++glyph_end; 19699 ++glyph_end;
19702 19700
19703 if (glyph < glyph_end) 19701 if (glyph < glyph_end)
19704 fprintf (stderr, " Glyph# Type Pos O W Code C Face LR\n"); 19702 fputs (" Glyph# Type Pos O W Code C Face LR\n",
19703 stderr);
19705 19704
19706 for (; glyph < glyph_end; ++glyph) 19705 for (; glyph < glyph_end; ++glyph)
19707 dump_glyph (row, glyph, area); 19706 dump_glyph (row, glyph, area);
@@ -19761,7 +19760,7 @@ with numeric argument, its value is passed as the GLYPHS flag. */)
19761 BUF_PT (buffer), BUF_BEGV (buffer), BUF_ZV (buffer)); 19760 BUF_PT (buffer), BUF_BEGV (buffer), BUF_ZV (buffer));
19762 fprintf (stderr, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n", 19761 fprintf (stderr, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
19763 w->cursor.x, w->cursor.y, w->cursor.hpos, w->cursor.vpos); 19762 w->cursor.x, w->cursor.y, w->cursor.hpos, w->cursor.vpos);
19764 fprintf (stderr, "=============================================\n"); 19763 fputs ("=============================================\n", stderr);
19765 dump_glyph_matrix (w->current_matrix, 19764 dump_glyph_matrix (w->current_matrix,
19766 TYPE_RANGED_FIXNUMP (int, glyphs) ? XFIXNUM (glyphs) : 0); 19765 TYPE_RANGED_FIXNUMP (int, glyphs) ? XFIXNUM (glyphs) : 0);
19767 return Qnil; 19766 return Qnil;
@@ -19778,7 +19777,7 @@ Only text-mode frames have frame glyph matrices. */)
19778 if (f->current_matrix) 19777 if (f->current_matrix)
19779 dump_glyph_matrix (f->current_matrix, 1); 19778 dump_glyph_matrix (f->current_matrix, 1);
19780 else 19779 else
19781 fprintf (stderr, "*** This frame doesn't have a frame glyph matrix ***\n"); 19780 fputs ("*** This frame doesn't have a frame glyph matrix ***\n", stderr);
19782 return Qnil; 19781 return Qnil;
19783} 19782}
19784 19783
@@ -25974,7 +25973,7 @@ extern void dump_glyph_string (struct glyph_string *) EXTERNALLY_VISIBLE;
25974void 25973void
25975dump_glyph_string (struct glyph_string *s) 25974dump_glyph_string (struct glyph_string *s)
25976{ 25975{
25977 fprintf (stderr, "glyph string\n"); 25976 fputs ("glyph string\n", stderr);
25978 fprintf (stderr, " x, y, w, h = %d, %d, %d, %d\n", 25977 fprintf (stderr, " x, y, w, h = %d, %d, %d, %d\n",
25979 s->x, s->y, s->width, s->height); 25978 s->x, s->y, s->width, s->height);
25980 fprintf (stderr, " ybase = %d\n", s->ybase); 25979 fprintf (stderr, " ybase = %d\n", s->ybase);
diff --git a/src/xfaces.c b/src/xfaces.c
index d9e66eaf2d1..c3cae7e2a68 100644
--- a/src/xfaces.c
+++ b/src/xfaces.c
@@ -418,21 +418,18 @@ DEFUN ("dump-colors", Fdump_colors, Sdump_colors, 0, 0, 0,
418{ 418{
419 int i, n; 419 int i, n;
420 420
421 fputc ('\n', stderr); 421 putc ('\n', stderr);
422 422
423 for (i = n = 0; i < ARRAYELTS (color_count); ++i) 423 for (i = n = 0; i < ARRAYELTS (color_count); ++i)
424 if (color_count[i]) 424 if (color_count[i])
425 { 425 {
426 fprintf (stderr, "%3d: %5d", i, color_count[i]); 426 fprintf (stderr, "%3d: %5d", i, color_count[i]);
427 ++n; 427 ++n;
428 if (n % 5 == 0) 428 putc (n % 5 == 0 ? '\n' : '\t', stderr);
429 fputc ('\n', stderr);
430 else
431 fputc ('\t', stderr);
432 } 429 }
433 430
434 if (n % 5 != 0) 431 if (n % 5 != 0)
435 fputc ('\n', stderr); 432 putc ('\n', stderr);
436 return Qnil; 433 return Qnil;
437} 434}
438 435
@@ -6363,7 +6360,7 @@ where R,G,B are numbers between 0 and 255 and name is an arbitrary string. */)
6363 int red, green, blue; 6360 int red, green, blue;
6364 int num; 6361 int num;
6365 6362
6366 while (fgets_unlocked (buf, sizeof (buf), fp) != NULL) { 6363 while (fgets (buf, sizeof (buf), fp) != NULL)
6367 if (sscanf (buf, "%d %d %d %n", &red, &green, &blue, &num) == 3) 6364 if (sscanf (buf, "%d %d %d %n", &red, &green, &blue, &num) == 3)
6368 { 6365 {
6369#ifdef HAVE_NTGUI 6366#ifdef HAVE_NTGUI
@@ -6377,7 +6374,6 @@ where R,G,B are numbers between 0 and 255 and name is an arbitrary string. */)
6377 cmap = Fcons (Fcons (make_string (name, len), make_fixnum (color)), 6374 cmap = Fcons (Fcons (make_string (name, len), make_fixnum (color)),
6378 cmap); 6375 cmap);
6379 } 6376 }
6380 }
6381 fclose (fp); 6377 fclose (fp);
6382 } 6378 }
6383 unblock_input (); 6379 unblock_input ();
@@ -6429,14 +6425,14 @@ DEFUN ("dump-face", Fdump_face, Sdump_face, 0, 1, 0, doc: /* */)
6429 { 6425 {
6430 int i; 6426 int i;
6431 6427
6432 fprintf (stderr, "font selection order: "); 6428 fputs ("font selection order: ", stderr);
6433 for (i = 0; i < ARRAYELTS (font_sort_order); ++i) 6429 for (i = 0; i < ARRAYELTS (font_sort_order); ++i)
6434 fprintf (stderr, "%d ", font_sort_order[i]); 6430 fprintf (stderr, "%d ", font_sort_order[i]);
6435 fprintf (stderr, "\n"); 6431 putc ('\n', stderr);
6436 6432
6437 fprintf (stderr, "alternative fonts: "); 6433 fputs ("alternative fonts: ", stderr);
6438 debug_print (Vface_alternative_font_family_alist); 6434 debug_print (Vface_alternative_font_family_alist);
6439 fprintf (stderr, "\n"); 6435 putc ('\n', stderr);
6440 6436
6441 for (i = 0; i < FRAME_FACE_CACHE (SELECTED_FRAME ())->used; ++i) 6437 for (i = 0; i < FRAME_FACE_CACHE (SELECTED_FRAME ())->used; ++i)
6442 Fdump_face (make_fixnum (i)); 6438 Fdump_face (make_fixnum (i));
diff --git a/src/xselect.c b/src/xselect.c
index ed68e4b1a6d..d74f064a1c7 100644
--- a/src/xselect.c
+++ b/src/xselect.c
@@ -21,7 +21,6 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
21 21
22#include <config.h> 22#include <config.h>
23#include <limits.h> 23#include <limits.h>
24#include <stdio.h> /* TRACE_SELECTION needs this. */
25 24
26#ifdef HAVE_SYS_TYPES_H 25#ifdef HAVE_SYS_TYPES_H
27#include <sys/types.h> 26#include <sys/types.h>
@@ -33,6 +32,7 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
33#include "xterm.h" /* for all of the X includes */ 32#include "xterm.h" /* for all of the X includes */
34#include "frame.h" /* Need this to get the X window of selected_frame */ 33#include "frame.h" /* Need this to get the X window of selected_frame */
35#include "blockinput.h" 34#include "blockinput.h"
35#include "sysstdio.h" /* TRACE_SELECTION needs this. */
36#include "termhooks.h" 36#include "termhooks.h"
37#include "keyboard.h" 37#include "keyboard.h"
38#include "pdumper.h" 38#include "pdumper.h"
@@ -2172,9 +2172,10 @@ If the problem persists, set `%s' to nil.");
2172static Lisp_Object 2172static Lisp_Object
2173x_clipboard_manager_error_2 (Lisp_Object err) 2173x_clipboard_manager_error_2 (Lisp_Object err)
2174{ 2174{
2175 fprintf (stderr, "Error saving to X clipboard manager.\n\ 2175 fputs (("Error saving to X clipboard manager.\n"
2176If the problem persists, set '%s' \ 2176 "If the problem persists,"
2177to nil.\n", "x-select-enable-clipboard-manager"); 2177 " set 'x-select-enable-clipboard-manager' to nil.\n"),
2178 stderr);
2178 return Qnil; 2179 return Qnil;
2179} 2180}
2180 2181
diff --git a/src/xterm.c b/src/xterm.c
index 38bc17de973..c96aa74a7a6 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -21,12 +21,12 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
21/* Xt features made by Fred Pierresteguy. */ 21/* Xt features made by Fred Pierresteguy. */
22 22
23#include <config.h> 23#include <config.h>
24#include <stdio.h>
25#include <stdlib.h> 24#include <stdlib.h>
26#include <math.h> 25#include <math.h>
27 26
28#include "lisp.h" 27#include "lisp.h"
29#include "blockinput.h" 28#include "blockinput.h"
29#include "sysstdio.h"
30 30
31/* This may include sys/types.h, and that somehow loses 31/* This may include sys/types.h, and that somehow loses
32 if this is not done before the other system files. */ 32 if this is not done before the other system files. */
@@ -13441,8 +13441,8 @@ x_initialize (void)
13441#if THREADS_ENABLED 13441#if THREADS_ENABLED
13442 /* This must be called before any other Xlib routines. */ 13442 /* This must be called before any other Xlib routines. */
13443 if (XInitThreads () == 0) 13443 if (XInitThreads () == 0)
13444 fprintf (stderr, 13444 fputs ("Warning: An error occurred initializing X11 thread support!\n",
13445 "Warning: An error occurred initializing X11 thread support!\n"); 13445 stderr);
13446#endif 13446#endif
13447 13447
13448#ifdef USE_X_TOOLKIT 13448#ifdef USE_X_TOOLKIT
diff --git a/src/xwidget.c b/src/xwidget.c
index 2486a2d4da8..121510ebac0 100644
--- a/src/xwidget.c
+++ b/src/xwidget.c
@@ -26,6 +26,7 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
26#include "frame.h" 26#include "frame.h"
27#include "keyboard.h" 27#include "keyboard.h"
28#include "gtkutil.h" 28#include "gtkutil.h"
29#include "sysstdio.h"
29 30
30#include <webkit2/webkit2.h> 31#include <webkit2/webkit2.h>
31#include <JavaScriptCore/JavaScript.h> 32#include <JavaScriptCore/JavaScript.h>
@@ -690,7 +691,8 @@ x_draw_xwidget_glyph_string (struct glyph_string *s)
690 struct xwidget *xw = XXWIDGET (xwidget); \ 691 struct xwidget *xw = XXWIDGET (xwidget); \
691 if (!xw->widget_osr || !WEBKIT_IS_WEB_VIEW (xw->widget_osr)) \ 692 if (!xw->widget_osr || !WEBKIT_IS_WEB_VIEW (xw->widget_osr)) \
692 { \ 693 { \
693 printf ("ERROR xw->widget_osr does not hold a webkit instance\n"); \ 694 fputs ("ERROR xw->widget_osr does not hold a webkit instance\n", \
695 stdout); \
694 return Qnil; \ 696 return Qnil; \
695 } 697 }
696 698