aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert1999-10-19 07:25:11 +0000
committerPaul Eggert1999-10-19 07:25:11 +0000
commit68c45bf06516ed4650eb7f9f617742d84750600a (patch)
tree8eed6fd2d1f6112b2bea449f86397ad0447836ab /src
parent0f0912e6442b71ed549b625bfc694581787da97e (diff)
downloademacs-68c45bf06516ed4650eb7f9f617742d84750600a.tar.gz
emacs-68c45bf06516ed4650eb7f9f617742d84750600a.zip
Add support for large files, 64-bit Solaris, system locale codings.
* Makefile.in (emacs): Set the LC_ALL environment variable to "C" when dumping, so that the dumped Emacs doesn't have stray locale info. (dired.o): Depend on systime.h. (editfns.o): Depend on coding.h. * alloc.c, buffer.c, callproc.c, ccl.c, charset.c, coding.c, data.c, dispnew.c, editfns.c, emacs.c, filelock.c, floatfns.c, hftctl.c, keyboard.c, process.c, sysdep.c, unexelf.c, unexhp9k800.c, unexsunos4.c, vmsfns.c, vmsgmalloc.c, w32faces.c, w32menu.c, w32term.c, w32xfns.c, xfaces.c, xfns.c, xmenu.c, xterm.c: Include <config.h> before any system include files. * alloc.c, buffer.c, ccl.c, data.c, editfns.c, emacs.c, eval.c, fileio.c, filelock.c, frame.c, insdel.c, keymap.c, lread.c, m/alpha.h, print.c, search.c, sysdep.c, xdisp.c, xfaces.c, xfns.c, xmenu.c, xterm.c: Do not include <stdlib.h>, as <config.h> does this now. * callproc.c (Fcall_process): Synchronize messages locale before invoking strerror. Decode resulting string with locale-coding-system. * coding.c (Vlocale_coding_system): New var. (syms_of_coding): Adjust to above change. (emacs_strerror): New function. * coding.h (emacs_strerror, Vlocale_coding_system): New decls. * config.in (HAVE_STDIO_EXT_H, HAVE_TM_GMTOFF, HAVE___FPENDING, HAVE_FTELLO, HAVE_GETLOADAVG, HAVE_MBLEN, HAVE_MBRLEN, HAVE_STRSIGNAL): New macros. (BITS_PER_LONG): Default to 64 if _LP64 is defined. <stdlib.h>: Include if HAVE_STDLIB_H is defined and NOT_C_CODE isn't. * dired.c: Include "systime.h". (Ffile_attributes): Do not cast s.st_size to int; this loses information if int is 32 bits but st_size and EMACS_INT are larger. Treat large device numbers like large inode numbers. * dispnew.c (PENDING_OUTPUT_COUNT): Use __fpending if available. * editfns.c: Include coding.h. (emacs_strftime): Remove decl. (emacs_strftimeu): New decl. (emacs_memftimeu): Renamed from emacs_memftime; new arg UT. Use emacs_strftimeu instead of emacs_strftime. (Fformat_time_string): Convert format string using Vlocale_coding_system, and convert result back. Synchronize time locale before invoking lower level function. Invoke emacs_memftimeu, passing ut, instead of emacs_memftime. * emacs.c: Include <locale.h> if HAVE_SETLOCALE is defined. (Vmessages_locale, Vprevious_messages_locale, Vtime_locale, Vprevious_time_locale): New variables. (main): Invoke setlocale early, so that initial error messages are localized properly. But skip locale-setting if LC_ALL is "C". Fix up locale when it's safe to do so. (fixup_locale): Moved here from xterm.c. (synchronize_locale, synchronize_time_locale, synchronize_messages_locale): New functions. (syms_of_emacs): Accommodate above changes. * fileio.c (report_file_error): Convert strerror output according to Vlocale_coding_system. (Finsert_file_contents): Check for arithmetic overflow in computations that depend on file size. Report IO errors with emacs_strerror, not strerror. * fns.c (Fgethash): Declare dflt parameter. * gmalloc.c: Do not define const to nothing if HAVE_CONFIG_H is defined; that's config.h's job. * lisp.h (EMACS_INT, BITS_PER_EMACS_INT, EMACS_UINT): If _LP64, default these values to long, BITS_PER_LONG, and unsigned long. (VALBITS, MARKBIT, XINT): Do not assume 32-bit EMACS_INT. (PNTR_COMPARISON_TYPE): Default to EMACS_UINT, not to unsigned int. (code_convert_string_norecord, fixup_locale, synchronize_messages_locale, synchronize_time_locale, emacs_open, emacs_close, emacs_read, emacs_write): New decls. All Emacs callers of open, close, read, write changed to use emacs_open, emacs_close, emacs_read, emacs_write. * lread.c (file_offset, file_tell): New macros. All uses of ftell changed to file_tell. (saved_doc_string_position, prev_saved_doc_string_position): Now of type file_offset. (init_lread): Do not fix locale here; fixup_locale now does this. * m/amdahl.h, s/usg5-4.h: (NSIG): Remove. (NSIG_MINIMUM): New macro. * m/cydra5.h, m/dpx2.h, m/mips.h, m/pfa50.h, m/sps7.h, m/stride.h, m/ustation.h, s/gnu-linux.h, s/hpux.h, s/iris3-5.h, s/iris3-6.h, s/umips.h, s/usg5-4.h: (SIGIO): Do not undef. (BROKEN_SIGIO): New macro. * m/ustation.h: (SIGTSTP): Do not undef. (BROKEN_SIGTSTP): New macro. * s/gnu-linux.h: (SIGPOLL, SIGURG): Do not undef. (BROKEN_SIGPOLL, BROKEN_SIGURG): New macros. * s/ptx4.h: (SIGINFO): Do not undef. (BROKEN_SIGINFO): New macros. * m/delta.h, s/ptx.h, s/template.h: Doc fix. * mktime.c, strftime.c: Update to glibc 2.1.2 version, with some Emacs-related changes merged. * print.c (float_to_string): Prepend "-" to representation of a NaN if the NaN is negative. * process.c (sys_siglist): Omit if HAVE_STRSIGNAL. (wait_reading_process_input): Use emacs_strerror, not strerror. * process.c (status_message, sigchld_handler): Synchronize locale, then use strsignal istead of sys_siglist. * w32proc.c (sys_wait): Likewise. * s/aix3-1.h, s/bsd4-1.h, s/dgux.h, s/gnu-linux.h, s/hiuxmpp.h, s/hpux.h, s/iris3-5.h, s/iris3-6.h, s/irix3-3.h, s/osf1.h, s/rtu.h, s/sunos4-1.h, s/unipl5-0.h, s/unipl5-2.h, s/usg5-0.h, s/usg5-2-2.h, s/usg5-2.h, s/usg5-3.h, s/xenix.h: (open, close, read, write, INTERRUPTIBLE_OPEN, INTERRUPTIBLE_CLOSE, INTERRUPTIBLE_IO): Remove. * s/sol2-5.h (_LARGEFILE_SOURCE, _FILE_OFFSET_BITS): New macros. * sysdep.c (sys_read, sys_write, read, write, sys_close, close, sys_open, open): Remove. (emacs_open, emacs_close, emacs_read, emacs_write): Always define; the old INTERRUPTIBLE_OPEN, INTERRUPTIBLE_CLOSE, and INTERRUPTIBLE_IO macros are no longer used. (emacs_open): Renamed from sys_open. Merge BSD4_1 version. (emacs_close): Renamed from sys_close. (emacs_read): Renamed from sys_read. (emacs_write): Renamed from sys_write. (sys_siglist): Do not declare if HAVE_STRSIGNAL. (dup2): Do not print error on failure; the real dup2 doesn't. (strsignal): New function, defined if !HAVE_STRSIGNAL. * syssignal.h (SIGINFO): Undef if defined and if BROKEN_SIGINFO is defined. (SIGIO, SIGPOLL, SIGTSTP, SIGURG): Likewise. (NSIG): If less than NSIG_MINIMUM, define to NSIG_MINIMUM. (strsignal): Declare if !HAVE_STRSIGNAL. * unexelf.c (ElfBitsW, ELFSIZE, ElfExpandBitsW): New macros. (ElfW): Define in terms of ElfExpandBitsW. * w32proc.c (sys_siglist): Remove decl. * xdisp.c (decode_mode_spec): 3rd arg is int, not char, to comply with ANSI C. (display_string): Declare face_string_pos arg. * xfns.c (Fx_show_tip): Declare timeout param. * xterm.c: No need to include locale.h. (x_alloc_lighter_color, x_setup_relief_color): Pass arg as double, not float, for compatibility with ANSI C. (fixup_locale): Move to emacs.c. (x_term_init): Do not setlocale or fixup locale; the main program does this now.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog176
-rw-r--r--src/Makefile.in11
-rw-r--r--src/alloc.c10
-rw-r--r--src/buffer.c5
-rw-r--r--src/callproc.c97
-rw-r--r--src/ccl.c10
-rw-r--r--src/charset.c5
-rw-r--r--src/coding.c31
-rw-r--r--src/coding.h4
-rw-r--r--src/config.in23
-rw-r--r--src/data.c6
-rw-r--r--src/dired.c15
-rw-r--r--src/dispnew.c8
-rw-r--r--src/doc.c20
-rw-r--r--src/editfns.c45
-rw-r--r--src/emacs.c113
-rw-r--r--src/eval.c6
-rw-r--r--src/fileio.c108
-rw-r--r--src/filelock.c9
-rw-r--r--src/floatfns.c5
-rw-r--r--src/fns.c2
-rw-r--r--src/frame.c5
-rw-r--r--src/gmalloc.c4
-rw-r--r--src/hftctl.c8
-rw-r--r--src/insdel.c5
-rw-r--r--src/keyboard.c8
-rw-r--r--src/keymap.c5
-rw-r--r--src/lisp.h35
-rw-r--r--src/lread.c37
-rw-r--r--src/mktime.c159
-rw-r--r--src/msdos.c8
-rw-r--r--src/print.c16
-rw-r--r--src/process.c108
-rw-r--r--src/search.c5
-rw-r--r--src/sound.c18
-rw-r--r--src/strftime.c219
-rw-r--r--src/sunfns.c4
-rw-r--r--src/sysdep.c129
-rw-r--r--src/syssignal.h30
-rw-r--r--src/unexelf.c28
-rw-r--r--src/unexhp9k800.c8
-rw-r--r--src/unexsunos4.c13
-rw-r--r--src/vmsfns.c4
-rw-r--r--src/vmsgmalloc.c10
-rw-r--r--src/w32faces.c4
-rw-r--r--src/w32menu.c5
-rw-r--r--src/w32proc.c18
-rw-r--r--src/w32term.c4
-rw-r--r--src/w32xfns.c4
-rw-r--r--src/xdisp.c9
-rw-r--r--src/xfaces.c3
-rw-r--r--src/xfns.c10
-rw-r--r--src/xmenu.c8
-rw-r--r--src/xterm.c48
54 files changed, 1003 insertions, 685 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index bafec6aff21..25171792180 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,179 @@
11999-10-19 Paul Eggert <eggert@twinsun.com>
2
3 Add support for large files, 64-bit Solaris, system locale codings.
4
5 * Makefile.in (emacs): Set the LC_ALL environment variable to "C"
6 when dumping, so that the dumped Emacs doesn't have stray locale info.
7 (dired.o): Depend on systime.h.
8 (editfns.o): Depend on coding.h.
9
10 * alloc.c, buffer.c, callproc.c, ccl.c, charset.c, coding.c, data.c,
11 dispnew.c, editfns.c, emacs.c, filelock.c, floatfns.c, hftctl.c,
12 keyboard.c, process.c, sysdep.c, unexelf.c, unexhp9k800.c,
13 unexsunos4.c, vmsfns.c, vmsgmalloc.c, w32faces.c, w32menu.c, w32term.c,
14 w32xfns.c, xfaces.c, xfns.c, xmenu.c, xterm.c:
15 Include <config.h> before any system include files.
16
17 * alloc.c, buffer.c, ccl.c, data.c, editfns.c, emacs.c, eval.c,
18 fileio.c, filelock.c, frame.c, insdel.c, keymap.c, lread.c,
19 m/alpha.h, print.c, search.c, sysdep.c, xdisp.c, xfaces.c, xfns.c,
20 xmenu.c, xterm.c:
21 Do not include <stdlib.h>, as <config.h> does this now.
22
23 * callproc.c (Fcall_process):
24 Synchronize messages locale before invoking strerror.
25 Decode resulting string with locale-coding-system.
26
27 * coding.c (Vlocale_coding_system): New var.
28 (syms_of_coding): Adjust to above change.
29 (emacs_strerror): New function.
30
31 * coding.h (emacs_strerror, Vlocale_coding_system): New decls.
32
33 * config.in (HAVE_STDIO_EXT_H, HAVE_TM_GMTOFF, HAVE___FPENDING,
34 HAVE_FTELLO, HAVE_GETLOADAVG, HAVE_MBLEN, HAVE_MBRLEN,
35 HAVE_STRSIGNAL): New macros.
36 (BITS_PER_LONG): Default to 64 if _LP64 is defined.
37 <stdlib.h>: Include if HAVE_STDLIB_H is defined and NOT_C_CODE isn't.
38
39 * dired.c: Include "systime.h".
40 (Ffile_attributes): Do not cast s.st_size to int; this loses
41 information if int is 32 bits but st_size and EMACS_INT are larger.
42 Treat large device numbers like large inode numbers.
43
44 * dispnew.c (PENDING_OUTPUT_COUNT): Use __fpending if available.
45
46 * editfns.c: Include coding.h.
47 (emacs_strftime): Remove decl.
48 (emacs_strftimeu): New decl.
49 (emacs_memftimeu): Renamed from emacs_memftime; new arg UT.
50 Use emacs_strftimeu instead of emacs_strftime.
51 (Fformat_time_string): Convert format string using
52 Vlocale_coding_system, and convert result back. Synchronize time
53 locale before invoking lower level function. Invoke
54 emacs_memftimeu, passing ut, instead of emacs_memftime.
55
56 * emacs.c: Include <locale.h> if HAVE_SETLOCALE is defined.
57 (Vmessages_locale, Vprevious_messages_locale, Vtime_locale,
58 Vprevious_time_locale): New variables.
59 (main): Invoke setlocale early, so that initial error messages are
60 localized properly. But skip locale-setting if LC_ALL is "C".
61 Fix up locale when it's safe to do so.
62 (fixup_locale): Moved here from xterm.c.
63 (synchronize_locale, synchronize_time_locale,
64 synchronize_messages_locale): New functions.
65 (syms_of_emacs): Accommodate above changes.
66
67 * fileio.c (report_file_error): Convert strerror output according
68 to Vlocale_coding_system.
69 (Finsert_file_contents): Check for arithmetic overflow in
70 computations that depend on file size. Report IO errors
71 with emacs_strerror, not strerror.
72
73 * fns.c (Fgethash): Declare dflt parameter.
74
75 * gmalloc.c: Do not define const to nothing if HAVE_CONFIG_H
76 is defined; that's config.h's job.
77
78 * lisp.h (EMACS_INT, BITS_PER_EMACS_INT, EMACS_UINT): If _LP64,
79 default these values to long, BITS_PER_LONG, and unsigned long.
80 (VALBITS, MARKBIT, XINT): Do not assume 32-bit EMACS_INT.
81 (PNTR_COMPARISON_TYPE): Default to EMACS_UINT, not to unsigned int.
82 (code_convert_string_norecord, fixup_locale,
83 synchronize_messages_locale, synchronize_time_locale,
84 emacs_open, emacs_close, emacs_read, emacs_write): New decls.
85 All Emacs callers of open, close, read, write changed to use
86 emacs_open, emacs_close, emacs_read, emacs_write.
87
88 * lread.c (file_offset, file_tell): New macros. All uses of ftell
89 changed to file_tell.
90 (saved_doc_string_position, prev_saved_doc_string_position): Now
91 of type file_offset.
92 (init_lread): Do not fix locale here; fixup_locale now does this.
93
94 * m/amdahl.h, s/usg5-4.h:
95 (NSIG): Remove.
96 (NSIG_MINIMUM): New macro.
97
98 * m/cydra5.h, m/dpx2.h, m/mips.h, m/pfa50.h, m/sps7.h, m/stride.h,
99 m/ustation.h, s/gnu-linux.h, s/hpux.h, s/iris3-5.h, s/iris3-6.h,
100 s/umips.h, s/usg5-4.h:
101 (SIGIO): Do not undef.
102 (BROKEN_SIGIO): New macro.
103
104 * m/ustation.h:
105 (SIGTSTP): Do not undef.
106 (BROKEN_SIGTSTP): New macro.
107
108 * s/gnu-linux.h:
109 (SIGPOLL, SIGURG): Do not undef.
110 (BROKEN_SIGPOLL, BROKEN_SIGURG): New macros.
111
112 * s/ptx4.h:
113 (SIGINFO): Do not undef.
114 (BROKEN_SIGINFO): New macros.
115
116 * m/delta.h, s/ptx.h, s/template.h: Doc fix.
117
118 * mktime.c, strftime.c: Update to glibc 2.1.2 version, with
119 some Emacs-related changes merged.
120
121 * print.c (float_to_string): Prepend "-" to representation of a
122 NaN if the NaN is negative.
123
124 * process.c (sys_siglist): Omit if HAVE_STRSIGNAL.
125 (wait_reading_process_input): Use emacs_strerror, not strerror.
126
127 * process.c (status_message, sigchld_handler): Synchronize locale,
128 then use strsignal istead of sys_siglist.
129 * w32proc.c (sys_wait): Likewise.
130
131 * s/aix3-1.h, s/bsd4-1.h, s/dgux.h, s/gnu-linux.h, s/hiuxmpp.h,
132 s/hpux.h, s/iris3-5.h, s/iris3-6.h, s/irix3-3.h, s/osf1.h, s/rtu.h,
133 s/sunos4-1.h, s/unipl5-0.h, s/unipl5-2.h, s/usg5-0.h, s/usg5-2-2.h,
134 s/usg5-2.h, s/usg5-3.h, s/xenix.h:
135 (open, close, read, write, INTERRUPTIBLE_OPEN,
136 INTERRUPTIBLE_CLOSE, INTERRUPTIBLE_IO): Remove.
137
138 * s/sol2-5.h (_LARGEFILE_SOURCE, _FILE_OFFSET_BITS): New macros.
139
140 * sysdep.c (sys_read, sys_write, read, write, sys_close, close,
141 sys_open, open): Remove.
142 (emacs_open, emacs_close, emacs_read, emacs_write): Always define;
143 the old INTERRUPTIBLE_OPEN, INTERRUPTIBLE_CLOSE, and INTERRUPTIBLE_IO
144 macros are no longer used.
145 (emacs_open): Renamed from sys_open. Merge BSD4_1 version.
146 (emacs_close): Renamed from sys_close.
147 (emacs_read): Renamed from sys_read.
148 (emacs_write): Renamed from sys_write.
149 (sys_siglist): Do not declare if HAVE_STRSIGNAL.
150 (dup2): Do not print error on failure; the real dup2 doesn't.
151 (strsignal): New function, defined if !HAVE_STRSIGNAL.
152
153 * syssignal.h (SIGINFO): Undef if defined and if BROKEN_SIGINFO
154 is defined.
155 (SIGIO, SIGPOLL, SIGTSTP, SIGURG): Likewise.
156 (NSIG): If less than NSIG_MINIMUM, define to NSIG_MINIMUM.
157 (strsignal): Declare if !HAVE_STRSIGNAL.
158
159 * unexelf.c (ElfBitsW, ELFSIZE, ElfExpandBitsW): New macros.
160 (ElfW): Define in terms of ElfExpandBitsW.
161
162 * w32proc.c (sys_siglist): Remove decl.
163
164 * xdisp.c (decode_mode_spec): 3rd arg is int, not char, to comply
165 with ANSI C.
166 (display_string): Declare face_string_pos arg.
167
168 * xfns.c (Fx_show_tip): Declare timeout param.
169
170 * xterm.c: No need to include locale.h.
171 (x_alloc_lighter_color, x_setup_relief_color):
172 Pass arg as double, not float, for compatibility with ANSI C.
173 (fixup_locale): Move to emacs.c.
174 (x_term_init): Do not setlocale or fixup locale; the main program
175 does this now.
176
11999-10-18 Dave Love <fx@gnu.org> 1771999-10-18 Dave Love <fx@gnu.org>
2 178
3 * doc.c (Fdocumentation_property): Gcpro `tem'. 179 * doc.c (Fdocumentation_property): Gcpro `tem'.
diff --git a/src/Makefile.in b/src/Makefile.in
index b5403c2f352..509a1bf0585 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -1,5 +1,5 @@
1# Makefile for GNU Emacs. 1# Makefile for GNU Emacs.
2# Copyright (C) 1985, 87, 88, 93, 94, 95 Free Software Foundation, Inc. 2# Copyright (C) 1985, 87, 88, 93, 94, 95, 1999 Free Software Foundation, Inc.
3 3
4# This file is part of GNU Emacs. 4# This file is part of GNU Emacs.
5 5
@@ -856,9 +856,9 @@ emacs: temacs ${etc}DOC ${lisp}
856 ln temacs emacs 856 ln temacs emacs
857#else 857#else
858#ifdef HAVE_SHM 858#ifdef HAVE_SHM
859 ./temacs -nl -batch -l loadup dump 859 LC_ALL=C ./temacs -nl -batch -l loadup dump
860#else /* ! defined (HAVE_SHM) */ 860#else /* ! defined (HAVE_SHM) */
861 ./temacs -batch -l loadup dump 861 LC_ALL=C ./temacs -batch -l loadup dump
862#endif /* ! defined (HAVE_SHM) */ 862#endif /* ! defined (HAVE_SHM) */
863#endif /* ! defined (CANNOT_DUMP) */ 863#endif /* ! defined (CANNOT_DUMP) */
864 -./emacs -q -batch -f list-load-path-shadows 864 -./emacs -q -batch -f list-load-path-shadows
@@ -1057,7 +1057,8 @@ cmds.o: cmds.c syntax.h buffer.h charset.h commands.h window.h $(config_h) \
1057pre-crt0.o: pre-crt0.c 1057pre-crt0.o: pre-crt0.c
1058ecrt0.o: ecrt0.c $(config_h) 1058ecrt0.o: ecrt0.c $(config_h)
1059 CRT0_COMPILE ${srcdir}/ecrt0.c 1059 CRT0_COMPILE ${srcdir}/ecrt0.c
1060dired.o: dired.c commands.h buffer.h $(config_h) charset.h coding.h regex.h 1060dired.o: dired.c commands.h buffer.h $(config_h) charset.h coding.h regex.h \
1061 systime.h
1061dispnew.o: dispnew.c commands.h frame.h window.h buffer.h dispextern.h \ 1062dispnew.o: dispnew.c commands.h frame.h window.h buffer.h dispextern.h \
1062 termchar.h termopts.h termhooks.h cm.h disptab.h systty.h systime.h \ 1063 termchar.h termopts.h termhooks.h cm.h disptab.h systty.h systime.h \
1063 xterm.h blockinput.h charset.h msdos.h $(config_h) 1064 xterm.h blockinput.h charset.h msdos.h $(config_h)
@@ -1065,7 +1066,7 @@ doc.o: doc.c $(config_h) epaths.h buffer.h keyboard.h
1065doprnt.o: doprnt.c charset.h $(config_h) 1066doprnt.o: doprnt.c charset.h $(config_h)
1066dosfns.o: buffer.h termchar.h termhooks.h frame.h msdos.h dosfns.h $(config_h) 1067dosfns.o: buffer.h termchar.h termhooks.h frame.h msdos.h dosfns.h $(config_h)
1067editfns.o: editfns.c window.h buffer.h systime.h INTERVAL_SRC charset.h \ 1068editfns.o: editfns.c window.h buffer.h systime.h INTERVAL_SRC charset.h \
1068 $(config_h) 1069 coding.h $(config_h)
1069emacs.o: emacs.c commands.h systty.h syssignal.h blockinput.h process.h \ 1070emacs.o: emacs.c commands.h systty.h syssignal.h blockinput.h process.h \
1070 termhooks.h buffer.h INTERVAL_SRC $(config_h) 1071 termhooks.h buffer.h INTERVAL_SRC $(config_h)
1071fileio.o: fileio.c window.h buffer.h systime.h INTERVAL_SRC charset.h \ 1072fileio.o: fileio.c window.h buffer.h systime.h INTERVAL_SRC charset.h \
diff --git a/src/alloc.c b/src/alloc.c
index 7120cae26b6..0e3ad2dbf9e 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -1,5 +1,5 @@
1/* Storage allocation and gc for GNU Emacs Lisp interpreter. 1/* Storage allocation and gc for GNU Emacs Lisp interpreter.
2 Copyright (C) 1985, 86, 88, 93, 94, 95, 97, 1998 2 Copyright (C) 1985, 86, 88, 93, 94, 95, 97, 98, 1999
3 Free Software Foundation, Inc. 3 Free Software Foundation, Inc.
4 4
5This file is part of GNU Emacs. 5This file is part of GNU Emacs.
@@ -19,14 +19,10 @@ along with GNU Emacs; see the file COPYING. If not, write to
19the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20Boston, MA 02111-1307, USA. */ 20Boston, MA 02111-1307, USA. */
21 21
22/* Note that this declares bzero on OSF/1. How dumb. */
23#include <signal.h>
24
25#include <config.h> 22#include <config.h>
26 23
27#ifdef STDC_HEADERS 24/* Note that this declares bzero on OSF/1. How dumb. */
28#include <stdlib.h> 25#include <signal.h>
29#endif
30 26
31#include "lisp.h" 27#include "lisp.h"
32#include "intervals.h" 28#include "intervals.h"
diff --git a/src/buffer.c b/src/buffer.c
index 6ab4200b750..59f4bcc4789 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -19,6 +19,7 @@ along with GNU Emacs; see the file COPYING. If not, write to
19the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20Boston, MA 02111-1307, USA. */ 20Boston, MA 02111-1307, USA. */
21 21
22#include <config.h>
22 23
23#include <sys/types.h> 24#include <sys/types.h>
24#include <sys/stat.h> 25#include <sys/stat.h>
@@ -32,10 +33,6 @@ extern int errno;
32#define MAXPATHLEN 1024 33#define MAXPATHLEN 1024
33#endif /* not MAXPATHLEN */ 34#endif /* not MAXPATHLEN */
34 35
35#include <config.h>
36#ifdef STDC_HEADERS
37#include <stdlib.h>
38#endif
39#ifdef HAVE_UNISTD_H 36#ifdef HAVE_UNISTD_H
40#include <unistd.h> 37#include <unistd.h>
41#endif 38#endif
diff --git a/src/callproc.c b/src/callproc.c
index de6856b5068..5ea59bf4629 100644
--- a/src/callproc.c
+++ b/src/callproc.c
@@ -1,5 +1,5 @@
1/* Synchronous subprocess invocation for GNU Emacs. 1/* Synchronous subprocess invocation for GNU Emacs.
2 Copyright (C) 1985, 86, 87, 88, 93, 94, 95 Free Software Foundation, Inc. 2 Copyright (C) 1985, 86,87,88,93,94,95, 1999 Free Software Foundation, Inc.
3 3
4This file is part of GNU Emacs. 4This file is part of GNU Emacs.
5 5
@@ -19,10 +19,9 @@ the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19Boston, MA 02111-1307, USA. */ 19Boston, MA 02111-1307, USA. */
20 20
21 21
22#include <config.h>
22#include <signal.h> 23#include <signal.h>
23#include <errno.h> 24#include <errno.h>
24
25#include <config.h>
26#include <stdio.h> 25#include <stdio.h>
27 26
28extern int errno; 27extern int errno;
@@ -134,7 +133,7 @@ static Lisp_Object
134call_process_kill (fdpid) 133call_process_kill (fdpid)
135 Lisp_Object fdpid; 134 Lisp_Object fdpid;
136{ 135{
137 close (XFASTINT (Fcar (fdpid))); 136 emacs_close (XFASTINT (Fcar (fdpid)));
138 EMACS_KILLPG (XFASTINT (Fcdr (fdpid)), SIGKILL); 137 EMACS_KILLPG (XFASTINT (Fcdr (fdpid)), SIGKILL);
139 synch_process_alive = 0; 138 synch_process_alive = 0;
140 return Qnil; 139 return Qnil;
@@ -148,7 +147,7 @@ call_process_cleanup (fdpid)
148 /* for MSDOS fdpid is really (fd . tempfile) */ 147 /* for MSDOS fdpid is really (fd . tempfile) */
149 register Lisp_Object file; 148 register Lisp_Object file;
150 file = Fcdr (fdpid); 149 file = Fcdr (fdpid);
151 close (XFASTINT (Fcar (fdpid))); 150 emacs_close (XFASTINT (Fcar (fdpid)));
152 if (strcmp (XSTRING (file)-> data, NULL_DEVICE) != 0) 151 if (strcmp (XSTRING (file)-> data, NULL_DEVICE) != 0)
153 unlink (XSTRING (file)->data); 152 unlink (XSTRING (file)->data);
154#else /* not MSDOS and not macintosh */ 153#else /* not MSDOS and not macintosh */
@@ -156,7 +155,7 @@ call_process_cleanup (fdpid)
156 155
157 if (call_process_exited) 156 if (call_process_exited)
158 { 157 {
159 close (XFASTINT (Fcar (fdpid))); 158 emacs_close (XFASTINT (Fcar (fdpid)));
160 return Qnil; 159 return Qnil;
161 } 160 }
162 161
@@ -173,7 +172,7 @@ call_process_cleanup (fdpid)
173 message1 ("Waiting for process to die...done"); 172 message1 ("Waiting for process to die...done");
174 } 173 }
175 synch_process_alive = 0; 174 synch_process_alive = 0;
176 close (XFASTINT (Fcar (fdpid))); 175 emacs_close (XFASTINT (Fcar (fdpid)));
177#endif /* not MSDOS */ 176#endif /* not MSDOS */
178 return Qnil; 177 return Qnil;
179} 178}
@@ -359,7 +358,7 @@ If you quit, the process is killed with SIGINT, or SIGKILL if you quit again.")
359 358
360 display = nargs >= 4 ? args[3] : Qnil; 359 display = nargs >= 4 ? args[3] : Qnil;
361 360
362 filefd = open (XSTRING (infile)->data, O_RDONLY, 0); 361 filefd = emacs_open (XSTRING (infile)->data, O_RDONLY, 0);
363 if (filefd < 0) 362 if (filefd < 0)
364 { 363 {
365 report_file_error ("Opening process input file", Fcons (infile, Qnil)); 364 report_file_error ("Opening process input file", Fcons (infile, Qnil));
@@ -374,7 +373,7 @@ If you quit, the process is killed with SIGINT, or SIGKILL if you quit again.")
374 } 373 }
375 if (NILP (path)) 374 if (NILP (path))
376 { 375 {
377 close (filefd); 376 emacs_close (filefd);
378 report_file_error ("Searching for program", Fcons (args[0], Qnil)); 377 report_file_error ("Searching for program", Fcons (args[0], Qnil));
379 } 378 }
380 new_argv[0] = XSTRING (path)->data; 379 new_argv[0] = XSTRING (path)->data;
@@ -436,7 +435,7 @@ If you quit, the process is killed with SIGINT, or SIGKILL if you quit again.")
436 outfilefd = creat (tempfile, S_IREAD | S_IWRITE); 435 outfilefd = creat (tempfile, S_IREAD | S_IWRITE);
437 if (outfilefd < 0) 436 if (outfilefd < 0)
438 { 437 {
439 close (filefd); 438 emacs_close (filefd);
440 report_file_error ("Opening process output file", 439 report_file_error ("Opening process output file",
441 Fcons (build_string (tempfile), Qnil)); 440 Fcons (build_string (tempfile), Qnil));
442 } 441 }
@@ -465,7 +464,7 @@ If you quit, the process is killed with SIGINT, or SIGKILL if you quit again.")
465#endif /* macintosh */ 464#endif /* macintosh */
466 465
467 if (INTEGERP (buffer)) 466 if (INTEGERP (buffer))
468 fd[1] = open (NULL_DEVICE, O_WRONLY), fd[0] = -1; 467 fd[1] = emacs_open (NULL_DEVICE, O_WRONLY, 0), fd[0] = -1;
469 else 468 else
470 { 469 {
471#ifndef MSDOS 470#ifndef MSDOS
@@ -500,13 +499,13 @@ If you quit, the process is killed with SIGINT, or SIGKILL if you quit again.")
500 synch_process_retcode = 0; 499 synch_process_retcode = 0;
501 500
502 if (NILP (error_file)) 501 if (NILP (error_file))
503 fd_error = open (NULL_DEVICE, O_WRONLY); 502 fd_error = emacs_open (NULL_DEVICE, O_WRONLY, 0);
504 else if (STRINGP (error_file)) 503 else if (STRINGP (error_file))
505 { 504 {
506#ifdef DOS_NT 505#ifdef DOS_NT
507 fd_error = open (XSTRING (error_file)->data, 506 fd_error = emacs_open (XSTRING (error_file)->data,
508 O_WRONLY | O_TRUNC | O_CREAT | O_TEXT, 507 O_WRONLY | O_TRUNC | O_CREAT | O_TEXT,
509 S_IREAD | S_IWRITE); 508 S_IREAD | S_IWRITE);
510#else /* not DOS_NT */ 509#else /* not DOS_NT */
511 fd_error = creat (XSTRING (error_file)->data, 0666); 510 fd_error = creat (XSTRING (error_file)->data, 0666);
512#endif /* not DOS_NT */ 511#endif /* not DOS_NT */
@@ -514,11 +513,11 @@ If you quit, the process is killed with SIGINT, or SIGKILL if you quit again.")
514 513
515 if (fd_error < 0) 514 if (fd_error < 0)
516 { 515 {
517 close (filefd); 516 emacs_close (filefd);
518 if (fd[0] != filefd) 517 if (fd[0] != filefd)
519 close (fd[0]); 518 emacs_close (fd[0]);
520 if (fd1 >= 0) 519 if (fd1 >= 0)
521 close (fd1); 520 emacs_close (fd1);
522#ifdef MSDOS 521#ifdef MSDOS
523 unlink (tempfile); 522 unlink (tempfile);
524#endif 523#endif
@@ -560,7 +559,10 @@ If you quit, the process is killed with SIGINT, or SIGKILL if you quit again.")
560 synch_process_alive = 0; 559 synch_process_alive = 0;
561 synch_process_retcode = pid; 560 synch_process_retcode = pid;
562 if (synch_process_retcode < 0) /* means it couldn't be exec'ed */ 561 if (synch_process_retcode < 0) /* means it couldn't be exec'ed */
563 synch_process_death = strerror (errno); 562 {
563 synchronize_messages_locale ();
564 synch_process_death = strerror (errno);
565 }
564 566
565 /* Since CRLF is converted to LF within `decode_coding', we can 567 /* Since CRLF is converted to LF within `decode_coding', we can
566 always open a file with binary mode. */ 568 always open a file with binary mode. */
@@ -585,19 +587,22 @@ If you quit, the process is killed with SIGINT, or SIGKILL if you quit again.")
585 synch_process_alive = 0; 587 synch_process_alive = 0;
586 synch_process_retcode = pid; 588 synch_process_retcode = pid;
587 if (synch_process_retcode < 0) /* means it couldn't be exec'ed */ 589 if (synch_process_retcode < 0) /* means it couldn't be exec'ed */
588 synch_process_death = strerror (errno); 590 {
591 synchronize_messages_locale ();
592 synch_process_death = strerror (errno);
593 }
589 594
590 close (outfilefd); 595 emacs_close (outfilefd);
591 if (fd_error != outfilefd) 596 if (fd_error != outfilefd)
592 close (fd_error); 597 emacs_close (fd_error);
593 fd1 = -1; /* No harm in closing that one! */ 598 fd1 = -1; /* No harm in closing that one! */
594 /* Since CRLF is converted to LF within `decode_coding', we can 599 /* Since CRLF is converted to LF within `decode_coding', we can
595 always open a file with binary mode. */ 600 always open a file with binary mode. */
596 fd[0] = open (tempfile, O_BINARY); 601 fd[0] = emacs_open (tempfile, O_RDONLY | O_BINARY, 0);
597 if (fd[0] < 0) 602 if (fd[0] < 0)
598 { 603 {
599 unlink (tempfile); 604 unlink (tempfile);
600 close (filefd); 605 emacs_close (filefd);
601 report_file_error ("Cannot re-open temporary file", Qnil); 606 report_file_error ("Cannot re-open temporary file", Qnil);
602 } 607 }
603#else /* not MSDOS */ 608#else /* not MSDOS */
@@ -610,7 +615,7 @@ If you quit, the process is killed with SIGINT, or SIGKILL if you quit again.")
610 if (pid == 0) 615 if (pid == 0)
611 { 616 {
612 if (fd[0] >= 0) 617 if (fd[0] >= 0)
613 close (fd[0]); 618 emacs_close (fd[0]);
614#ifdef HAVE_SETSID 619#ifdef HAVE_SETSID
615 setsid (); 620 setsid ();
616#endif 621#endif
@@ -626,7 +631,7 @@ If you quit, the process is killed with SIGINT, or SIGKILL if you quit again.")
626 631
627 /* The MSDOS case did this already. */ 632 /* The MSDOS case did this already. */
628 if (fd_error >= 0) 633 if (fd_error >= 0)
629 close (fd_error); 634 emacs_close (fd_error);
630#endif /* not MSDOS */ 635#endif /* not MSDOS */
631#endif /* not macintosh */ 636#endif /* not macintosh */
632 637
@@ -634,22 +639,22 @@ If you quit, the process is killed with SIGINT, or SIGKILL if you quit again.")
634 639
635 /* Close most of our fd's, but not fd[0] 640 /* Close most of our fd's, but not fd[0]
636 since we will use that to read input from. */ 641 since we will use that to read input from. */
637 close (filefd); 642 emacs_close (filefd);
638 if (fd1 >= 0 && fd1 != fd_error) 643 if (fd1 >= 0 && fd1 != fd_error)
639 close (fd1); 644 emacs_close (fd1);
640 } 645 }
641 646
642 if (pid < 0) 647 if (pid < 0)
643 { 648 {
644 if (fd[0] >= 0) 649 if (fd[0] >= 0)
645 close (fd[0]); 650 emacs_close (fd[0]);
646 report_file_error ("Doing vfork", Qnil); 651 report_file_error ("Doing vfork", Qnil);
647 } 652 }
648 653
649 if (INTEGERP (buffer)) 654 if (INTEGERP (buffer))
650 { 655 {
651 if (fd[0] >= 0) 656 if (fd[0] >= 0)
652 close (fd[0]); 657 emacs_close (fd[0]);
653#ifndef subprocesses 658#ifndef subprocesses
654 /* If Emacs has been built with asynchronous subprocess support, 659 /* If Emacs has been built with asynchronous subprocess support,
655 we don't need to do this, I think because it will then have 660 we don't need to do this, I think because it will then have
@@ -737,7 +742,8 @@ If you quit, the process is killed with SIGINT, or SIGKILL if you quit again.")
737 nread = carryover; 742 nread = carryover;
738 while (nread < bufsize - 1024) 743 while (nread < bufsize - 1024)
739 { 744 {
740 int this_read = read (fd[0], bufptr + nread, bufsize - nread); 745 int this_read = emacs_read (fd[0], bufptr + nread,
746 bufsize - nread);
741 747
742 if (this_read < 0) 748 if (this_read < 0)
743 goto give_up; 749 goto give_up;
@@ -849,7 +855,8 @@ If you quit, the process is killed with SIGINT, or SIGKILL if you quit again.")
849 unbind_to (count, Qnil); 855 unbind_to (count, Qnil);
850 856
851 if (synch_process_death) 857 if (synch_process_death)
852 return build_string (synch_process_death); 858 return code_convert_string_norecord (build_string (synch_process_death),
859 Vlocale_coding_system, 0);
853 return make_number (synch_process_retcode); 860 return make_number (synch_process_retcode);
854} 861}
855#endif 862#endif
@@ -1163,16 +1170,16 @@ child_setup (in, out, err, new_argv, set_pgrp, current_dir)
1163 } 1170 }
1164 1171
1165#ifndef MSDOS 1172#ifndef MSDOS
1166 close (0); 1173 emacs_close (0);
1167 close (1); 1174 emacs_close (1);
1168 close (2); 1175 emacs_close (2);
1169 1176
1170 dup2 (in, 0); 1177 dup2 (in, 0);
1171 dup2 (out, 1); 1178 dup2 (out, 1);
1172 dup2 (err, 2); 1179 dup2 (err, 2);
1173 close (in); 1180 emacs_close (in);
1174 close (out); 1181 emacs_close (out);
1175 close (err); 1182 emacs_close (err);
1176#endif /* not MSDOS */ 1183#endif /* not MSDOS */
1177#endif /* not WINDOWSNT */ 1184#endif /* not WINDOWSNT */
1178 1185
@@ -1212,9 +1219,9 @@ child_setup (in, out, err, new_argv, set_pgrp, current_dir)
1212 environ = env; 1219 environ = env;
1213 execvp (new_argv[0], new_argv); 1220 execvp (new_argv[0], new_argv);
1214 1221
1215 write (1, "Can't exec program: ", 20); 1222 emacs_write (1, "Can't exec program: ", 20);
1216 write (1, new_argv[0], strlen (new_argv[0])); 1223 emacs_write (1, new_argv[0], strlen (new_argv[0]));
1217 write (1, "\n", 1); 1224 emacs_write (1, "\n", 1);
1218 _exit (1); 1225 _exit (1);
1219#endif /* not WINDOWSNT */ 1226#endif /* not WINDOWSNT */
1220#endif /* not MSDOS */ 1227#endif /* not MSDOS */
@@ -1236,15 +1243,15 @@ relocate_fd (fd, minfd)
1236 char *message1 = "Error while setting up child: "; 1243 char *message1 = "Error while setting up child: ";
1237 char *errmessage = strerror (errno); 1244 char *errmessage = strerror (errno);
1238 char *message2 = "\n"; 1245 char *message2 = "\n";
1239 write (2, message1, strlen (message1)); 1246 emacs_write (2, message1, strlen (message1));
1240 write (2, errmessage, strlen (errmessage)); 1247 emacs_write (2, errmessage, strlen (errmessage));
1241 write (2, message2, strlen (message2)); 1248 emacs_write (2, message2, strlen (message2));
1242 _exit (1); 1249 _exit (1);
1243 } 1250 }
1244 /* Note that we hold the original FD open while we recurse, 1251 /* Note that we hold the original FD open while we recurse,
1245 to guarantee we'll get a new FD if we need it. */ 1252 to guarantee we'll get a new FD if we need it. */
1246 new = relocate_fd (new, minfd); 1253 new = relocate_fd (new, minfd);
1247 close (fd); 1254 emacs_close (fd);
1248 return new; 1255 return new;
1249 } 1256 }
1250} 1257}
diff --git a/src/ccl.c b/src/ccl.c
index fb9fbf60e4a..6a6876df7c8 100644
--- a/src/ccl.c
+++ b/src/ccl.c
@@ -19,16 +19,14 @@ along with GNU Emacs; see the file COPYING. If not, write to
19the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20Boston, MA 02111-1307, USA. */ 20Boston, MA 02111-1307, USA. */
21 21
22#include <stdio.h>
23
24#ifdef emacs 22#ifdef emacs
25
26#include <config.h> 23#include <config.h>
27
28#ifdef STDC_HEADERS
29#include <stdlib.h>
30#endif 24#endif
31 25
26#include <stdio.h>
27
28#ifdef emacs
29
32#include "lisp.h" 30#include "lisp.h"
33#include "charset.h" 31#include "charset.h"
34#include "ccl.h" 32#include "ccl.h"
diff --git a/src/charset.c b/src/charset.c
index 61fdcf66ef5..fefb2380de4 100644
--- a/src/charset.c
+++ b/src/charset.c
@@ -22,12 +22,15 @@ Boston, MA 02111-1307, USA. */
22/* At first, see the document in `charset.h' to understand the code in 22/* At first, see the document in `charset.h' to understand the code in
23 this file. */ 23 this file. */
24 24
25#ifdef emacs
26#include <config.h>
27#endif
28
25#include <stdio.h> 29#include <stdio.h>
26 30
27#ifdef emacs 31#ifdef emacs
28 32
29#include <sys/types.h> 33#include <sys/types.h>
30#include <config.h>
31#include "lisp.h" 34#include "lisp.h"
32#include "buffer.h" 35#include "buffer.h"
33#include "charset.h" 36#include "charset.h"
diff --git a/src/coding.c b/src/coding.c
index 4bf0b2aea81..1e75be5ab6f 100644
--- a/src/coding.c
+++ b/src/coding.c
@@ -268,11 +268,14 @@ encode_coding_XXX (coding, source, destination, src_bytes, dst_bytes)
268 268
269/*** 1. Preamble ***/ 269/*** 1. Preamble ***/
270 270
271#ifdef emacs
272#include <config.h>
273#endif
274
271#include <stdio.h> 275#include <stdio.h>
272 276
273#ifdef emacs 277#ifdef emacs
274 278
275#include <config.h>
276#include "lisp.h" 279#include "lisp.h"
277#include "buffer.h" 280#include "buffer.h"
278#include "charset.h" 281#include "charset.h"
@@ -357,6 +360,8 @@ Lisp_Object Vfile_coding_system_alist;
357Lisp_Object Vprocess_coding_system_alist; 360Lisp_Object Vprocess_coding_system_alist;
358Lisp_Object Vnetwork_coding_system_alist; 361Lisp_Object Vnetwork_coding_system_alist;
359 362
363Lisp_Object Vlocale_coding_system;
364
360#endif /* emacs */ 365#endif /* emacs */
361 366
362Lisp_Object Qcoding_category, Qcoding_category_index; 367Lisp_Object Qcoding_category, Qcoding_category_index;
@@ -5786,6 +5791,10 @@ or a cons of coding systems which are used as above.\n\
5786See also the function `find-operation-coding-system'."); 5791See also the function `find-operation-coding-system'.");
5787 Vnetwork_coding_system_alist = Qnil; 5792 Vnetwork_coding_system_alist = Qnil;
5788 5793
5794 DEFVAR_LISP ("locale-coding-system", &Vlocale_coding_system,
5795 "Coding system to use with system messages.");
5796 Vlocale_coding_system = Qnil;
5797
5789 DEFVAR_LISP ("eol-mnemonic-unix", &eol_mnemonic_unix, 5798 DEFVAR_LISP ("eol-mnemonic-unix", &eol_mnemonic_unix,
5790 "*String displayed in mode line for UNIX-like (LF) end-of-line format."); 5799 "*String displayed in mode line for UNIX-like (LF) end-of-line format.");
5791 eol_mnemonic_unix = build_string (":"); 5800 eol_mnemonic_unix = build_string (":");
@@ -5853,4 +5862,24 @@ The default value is `select-safe-coding-system' (which see).");
5853 5862
5854} 5863}
5855 5864
5865char *
5866emacs_strerror (error_number)
5867 int error_number;
5868{
5869 char *str;
5870
5871 synchronize_messages_locale ();
5872 str = strerror (error_number);
5873
5874 if (! NILP (Vlocale_coding_system))
5875 {
5876 Lisp_Object dec = code_convert_string_norecord (build_string (str),
5877 Vlocale_coding_system,
5878 0);
5879 str = (char *) XSTRING (dec)->data;
5880 }
5881
5882 return str;
5883}
5884
5856#endif /* emacs */ 5885#endif /* emacs */
diff --git a/src/coding.h b/src/coding.h
index 7bbfdbd6621..5ef9f2a08ca 100644
--- a/src/coding.h
+++ b/src/coding.h
@@ -551,12 +551,16 @@ extern Lisp_Object Qfile_coding_system;
551extern Lisp_Object Qcall_process, Qcall_process_region, Qprocess_argument; 551extern Lisp_Object Qcall_process, Qcall_process_region, Qprocess_argument;
552extern Lisp_Object Qstart_process, Qopen_network_stream; 552extern Lisp_Object Qstart_process, Qopen_network_stream;
553 553
554extern char *emacs_strerror P_ ((int));
555
554/* Coding-system for reading files and receiving data from process. */ 556/* Coding-system for reading files and receiving data from process. */
555extern Lisp_Object Vcoding_system_for_read; 557extern Lisp_Object Vcoding_system_for_read;
556/* Coding-system for writing files and sending data to process. */ 558/* Coding-system for writing files and sending data to process. */
557extern Lisp_Object Vcoding_system_for_write; 559extern Lisp_Object Vcoding_system_for_write;
558/* Coding-system actually used in the latest I/O. */ 560/* Coding-system actually used in the latest I/O. */
559extern Lisp_Object Vlast_coding_system_used; 561extern Lisp_Object Vlast_coding_system_used;
562/* Coding-system to use with system messages (e.g. strerror). */
563extern Lisp_Object Vlocale_coding_system;
560 564
561/* If non-zero, process buffer inherits the coding system used to decode 565/* If non-zero, process buffer inherits the coding system used to decode
562 the subprocess output. */ 566 the subprocess output. */
diff --git a/src/config.in b/src/config.in
index 6d1b2342f87..abf084ce735 100644
--- a/src/config.in
+++ b/src/config.in
@@ -1,5 +1,5 @@
1/* GNU Emacs site configuration template file. -*- C -*- 1/* GNU Emacs site configuration template file. -*- C -*-
2 Copyright (C) 1988, 1993, 1994 Free Software Foundation, Inc. 2 Copyright (C) 1988, 1993, 1994, 1999 Free Software Foundation, Inc.
3 3
4This file is part of GNU Emacs. 4This file is part of GNU Emacs.
5 5
@@ -166,10 +166,11 @@ Boston, MA 02111-1307, USA. */
166#undef HAVE_TERMIOS_H 166#undef HAVE_TERMIOS_H
167#undef HAVE_LIMITS_H 167#undef HAVE_LIMITS_H
168#undef HAVE_STRING_H 168#undef HAVE_STRING_H
169#undef STDC_HEADERS
170#undef TIME_WITH_SYS_TIME
171#undef HAVE_STDLIB_H 169#undef HAVE_STDLIB_H
172#undef HAVE_TERMCAP_H 170#undef HAVE_TERMCAP_H
171#undef HAVE_STDIO_EXT_H
172#undef STDC_HEADERS
173#undef TIME_WITH_SYS_TIME
173 174
174#undef HAVE_LIBDNET 175#undef HAVE_LIBDNET
175#undef HAVE_LIBPTHREADS 176#undef HAVE_LIBPTHREADS
@@ -226,6 +227,7 @@ Boston, MA 02111-1307, USA. */
226#undef TM_IN_SYS_TIME 227#undef TM_IN_SYS_TIME
227#undef HAVE_TM_ZONE 228#undef HAVE_TM_ZONE
228#undef HAVE_TZNAME 229#undef HAVE_TZNAME
230#undef HAVE_TM_GMTOFF
229 231
230#undef const 232#undef const
231 233
@@ -270,6 +272,12 @@ Boston, MA 02111-1307, USA. */
270#undef HAVE_SHUTDOWN 272#undef HAVE_SHUTDOWN
271#undef HAVE_STRFTIME 273#undef HAVE_STRFTIME
272#undef HAVE_GETADDRINFO 274#undef HAVE_GETADDRINFO
275#undef HAVE___FPENDING
276#undef HAVE_FTELLO
277#undef HAVE_GETLOADAVG
278#undef HAVE_MBLEN
279#undef HAVE_MBRLEN
280#undef HAVE_STRSIGNAL
273 281
274#undef LOCALTIME_CACHE 282#undef LOCALTIME_CACHE
275#undef HAVE_INET_SOCKETS 283#undef HAVE_INET_SOCKETS
@@ -447,12 +455,19 @@ extern char *getenv ();
447#endif 455#endif
448 456
449#ifndef BITS_PER_LONG 457#ifndef BITS_PER_LONG
458#ifdef _LP64
459#define BITS_PER_LONG 64
460#else
450#define BITS_PER_LONG 32 461#define BITS_PER_LONG 32
451#endif 462#endif
463#endif
452 464
453/* Don't include <string.h> during configure. */ 465/* Don't include "string.h" or <stdlib.h> in non-C code. */
454#ifndef NOT_C_CODE 466#ifndef NOT_C_CODE
455#ifdef HAVE_STRING_H 467#ifdef HAVE_STRING_H
456#include "string.h" 468#include "string.h"
457#endif 469#endif
470#ifdef HAVE_STDLIB_H
471#include <stdlib.h>
472#endif
458#endif 473#endif
diff --git a/src/data.c b/src/data.c
index 2c7e2298a50..ff361c87f01 100644
--- a/src/data.c
+++ b/src/data.c
@@ -1,5 +1,5 @@
1/* Primitive operations on Lisp data types for GNU Emacs Lisp interpreter. 1/* Primitive operations on Lisp data types for GNU Emacs Lisp interpreter.
2 Copyright (C) 1985,86,88,93,94,95,97, 1998 Free Software Foundation, Inc. 2 Copyright (C) 1985,86,88,93,94,95,97,98, 1999 Free Software Foundation, Inc.
3 3
4This file is part of GNU Emacs. 4This file is part of GNU Emacs.
5 5
@@ -19,9 +19,8 @@ the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19Boston, MA 02111-1307, USA. */ 19Boston, MA 02111-1307, USA. */
20 20
21 21
22#include <signal.h>
23
24#include <config.h> 22#include <config.h>
23#include <signal.h>
25#include <stdio.h> 24#include <stdio.h>
26#include "lisp.h" 25#include "lisp.h"
27#include "puresize.h" 26#include "puresize.h"
@@ -38,7 +37,6 @@ Boston, MA 02111-1307, USA. */
38#ifdef LISP_FLOAT_TYPE 37#ifdef LISP_FLOAT_TYPE
39 38
40#ifdef STDC_HEADERS 39#ifdef STDC_HEADERS
41#include <stdlib.h>
42#include <float.h> 40#include <float.h>
43#endif 41#endif
44 42
diff --git a/src/dired.c b/src/dired.c
index d9c2ab0f865..ca762c360dc 100644
--- a/src/dired.c
+++ b/src/dired.c
@@ -1,5 +1,5 @@
1/* Lisp functions for making directory listings. 1/* Lisp functions for making directory listings.
2 Copyright (C) 1985, 1986, 1993, 1994 Free Software Foundation, Inc. 2 Copyright (C) 1985, 1986, 1993, 1994, 1999 Free Software Foundation, Inc.
3 3
4This file is part of GNU Emacs. 4This file is part of GNU Emacs.
5 5
@@ -25,6 +25,8 @@ Boston, MA 02111-1307, USA. */
25#include <sys/types.h> 25#include <sys/types.h>
26#include <sys/stat.h> 26#include <sys/stat.h>
27 27
28#include "systime.h"
29
28#ifdef VMS 30#ifdef VMS
29#include <string.h> 31#include <string.h>
30#include <rms.h> 32#include <rms.h>
@@ -790,7 +792,7 @@ If file does not exist, returns nil.")
790 values[4] = make_time (s.st_atime); 792 values[4] = make_time (s.st_atime);
791 values[5] = make_time (s.st_mtime); 793 values[5] = make_time (s.st_mtime);
792 values[6] = make_time (s.st_ctime); 794 values[6] = make_time (s.st_ctime);
793 values[7] = make_number ((int) s.st_size); 795 values[7] = make_number (s.st_size);
794 /* If the size is out of range for an integer, return a float. */ 796 /* If the size is out of range for an integer, return a float. */
795 if (XINT (values[7]) != s.st_size) 797 if (XINT (values[7]) != s.st_size)
796 values[7] = make_float ((double)s.st_size); 798 values[7] = make_float ((double)s.st_size);
@@ -822,7 +824,14 @@ If file does not exist, returns nil.")
822 else 824 else
823 /* But keep the most common cases as integers. */ 825 /* But keep the most common cases as integers. */
824 values[10] = make_number (s.st_ino); 826 values[10] = make_number (s.st_ino);
825 values[11] = make_number (s.st_dev); 827
828 /* Likewise for device. */
829 if (s.st_dev & (((EMACS_INT) (-1)) << VALBITS))
830 values[11] = Fcons (make_number (s.st_dev >> 16),
831 make_number (s.st_dev & 0xffff));
832 else
833 values[11] = make_number (s.st_dev);
834
826 return Flist (sizeof(values) / sizeof(values[0]), values); 835 return Flist (sizeof(values) / sizeof(values[0]), values);
827} 836}
828 837
diff --git a/src/dispnew.c b/src/dispnew.c
index 54facf43aa2..a92ee9159d1 100644
--- a/src/dispnew.c
+++ b/src/dispnew.c
@@ -1,5 +1,5 @@
1/* Updating of data structures for redisplay. 1/* Updating of data structures for redisplay.
2 Copyright (C) 1985, 86, 87, 88, 93, 94, 95, 97, 1998 2 Copyright (C) 1985, 86, 87, 88, 93, 94, 95, 97, 98, 1999
3 Free Software Foundation, Inc. 3 Free Software Foundation, Inc.
4 4
5This file is part of GNU Emacs. 5This file is part of GNU Emacs.
@@ -19,8 +19,8 @@ along with GNU Emacs; see the file COPYING. If not, write to
19the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20Boston, MA 02111-1307, USA. */ 20Boston, MA 02111-1307, USA. */
21 21
22#include <signal.h>
23#include <config.h> 22#include <config.h>
23#include <signal.h>
24#include <stdio.h> 24#include <stdio.h>
25#include <ctype.h> 25#include <ctype.h>
26 26
@@ -91,6 +91,10 @@ Boston, MA 02111-1307, USA. */
91#define PENDING_OUTPUT_COUNT(FILE) ((FILE)->__bufp - (FILE)->__buffer) 91#define PENDING_OUTPUT_COUNT(FILE) ((FILE)->__bufp - (FILE)->__buffer)
92#endif 92#endif
93#else /* not __GNU_LIBRARY__ */ 93#else /* not __GNU_LIBRARY__ */
94#if !defined (PENDING_OUTPUT_COUNT) && HAVE_STDIO_EXT_H && HAVE___FPENDING
95#include <stdio_ext.h>
96#define PENDING_OUTPUT_COUNT(FILE) __fpending (FILE)
97#endif
94#ifndef PENDING_OUTPUT_COUNT 98#ifndef PENDING_OUTPUT_COUNT
95#define PENDING_OUTPUT_COUNT(FILE) ((FILE)->_ptr - (FILE)->_base) 99#define PENDING_OUTPUT_COUNT(FILE) ((FILE)->_ptr - (FILE)->_base)
96#endif 100#endif
diff --git a/src/doc.c b/src/doc.c
index 7590054201a..43785510597 100644
--- a/src/doc.c
+++ b/src/doc.c
@@ -1,5 +1,5 @@
1/* Record indices of function doc strings stored in a file. 1/* Record indices of function doc strings stored in a file.
2 Copyright (C) 1985, 86, 93, 94, 95, 97, 1998 Free Software Foundation, Inc. 2 Copyright (C) 1985, 86,93,94,95,97,98, 1999 Free Software Foundation, Inc.
3 3
4This file is part of GNU Emacs. 4This file is part of GNU Emacs.
5 5
@@ -161,7 +161,7 @@ get_doc_string (filepos, unibyte, definition)
161 name = (char *) XSTRING (file)->data; 161 name = (char *) XSTRING (file)->data;
162 } 162 }
163 163
164 fd = open (name, O_RDONLY, 0); 164 fd = emacs_open (name, O_RDONLY, 0);
165 if (fd < 0) 165 if (fd < 0)
166 { 166 {
167#ifndef CANNOT_DUMP 167#ifndef CANNOT_DUMP
@@ -173,7 +173,7 @@ get_doc_string (filepos, unibyte, definition)
173 strcat (name, XSTRING (file)->data); 173 strcat (name, XSTRING (file)->data);
174 munge_doc_file_name (name); 174 munge_doc_file_name (name);
175 175
176 fd = open (name, O_RDONLY, 0); 176 fd = emacs_open (name, O_RDONLY, 0);
177 } 177 }
178#endif 178#endif
179 if (fd < 0) 179 if (fd < 0)
@@ -184,7 +184,7 @@ get_doc_string (filepos, unibyte, definition)
184 offset = position % (8 * 1024); 184 offset = position % (8 * 1024);
185 if (0 > lseek (fd, position - offset, 0)) 185 if (0 > lseek (fd, position - offset, 0))
186 { 186 {
187 close (fd); 187 emacs_close (fd);
188 error ("Position %ld out of range in doc string file \"%s\"", 188 error ("Position %ld out of range in doc string file \"%s\"",
189 position, name); 189 position, name);
190 } 190 }
@@ -216,10 +216,10 @@ get_doc_string (filepos, unibyte, definition)
216 If we read the same block last time, maybe skip this? */ 216 If we read the same block last time, maybe skip this? */
217 if (space_left > 1024 * 8) 217 if (space_left > 1024 * 8)
218 space_left = 1024 * 8; 218 space_left = 1024 * 8;
219 nread = read (fd, p, space_left); 219 nread = emacs_read (fd, p, space_left);
220 if (nread < 0) 220 if (nread < 0)
221 { 221 {
222 close (fd); 222 emacs_close (fd);
223 error ("Read error on documentation file"); 223 error ("Read error on documentation file");
224 } 224 }
225 p[nread] = 0; 225 p[nread] = 0;
@@ -237,7 +237,7 @@ get_doc_string (filepos, unibyte, definition)
237 } 237 }
238 p += nread; 238 p += nread;
239 } 239 }
240 close (fd); 240 emacs_close (fd);
241 241
242 /* Scan the text and perform quoting with ^A (char code 1). 242 /* Scan the text and perform quoting with ^A (char code 1).
243 ^A^A becomes ^A, ^A0 becomes a null char, and ^A_ becomes a ^_. */ 243 ^A^A becomes ^A, ^A0 becomes a null char, and ^A_ becomes a ^_. */
@@ -507,7 +507,7 @@ when doc strings are referred to later in the dumped Emacs.")
507#endif /* VMS4_4 */ 507#endif /* VMS4_4 */
508#endif /* VMS */ 508#endif /* VMS */
509 509
510 fd = open (name, O_RDONLY, 0); 510 fd = emacs_open (name, O_RDONLY, 0);
511 if (fd < 0) 511 if (fd < 0)
512 report_file_error ("Opening doc string file", 512 report_file_error ("Opening doc string file",
513 Fcons (build_string (name), Qnil)); 513 Fcons (build_string (name), Qnil));
@@ -517,7 +517,7 @@ when doc strings are referred to later in the dumped Emacs.")
517 while (1) 517 while (1)
518 { 518 {
519 if (filled < 512) 519 if (filled < 512)
520 filled += read (fd, &buf[filled], sizeof buf - 1 - filled); 520 filled += emacs_read (fd, &buf[filled], sizeof buf - 1 - filled);
521 if (!filled) 521 if (!filled)
522 break; 522 break;
523 523
@@ -557,7 +557,7 @@ when doc strings are referred to later in the dumped Emacs.")
557 filled -= end - buf; 557 filled -= end - buf;
558 bcopy (end, buf, filled); 558 bcopy (end, buf, filled);
559 } 559 }
560 close (fd); 560 emacs_close (fd);
561 return Qnil; 561 return Qnil;
562} 562}
563 563
diff --git a/src/editfns.c b/src/editfns.c
index a9c2b5f5855..ae710dbff76 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -19,9 +19,8 @@ the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19Boston, MA 02111-1307, USA. */ 19Boston, MA 02111-1307, USA. */
20 20
21 21
22#include <sys/types.h>
23
24#include <config.h> 22#include <config.h>
23#include <sys/types.h>
25 24
26#ifdef VMS 25#ifdef VMS
27#include "vms-pwd.h" 26#include "vms-pwd.h"
@@ -29,10 +28,6 @@ Boston, MA 02111-1307, USA. */
29#include <pwd.h> 28#include <pwd.h>
30#endif 29#endif
31 30
32#ifdef STDC_HEADERS
33#include <stdlib.h>
34#endif
35
36#ifdef HAVE_UNISTD_H 31#ifdef HAVE_UNISTD_H
37#include <unistd.h> 32#include <unistd.h>
38#endif 33#endif
@@ -41,6 +36,7 @@ Boston, MA 02111-1307, USA. */
41#include "intervals.h" 36#include "intervals.h"
42#include "buffer.h" 37#include "buffer.h"
43#include "charset.h" 38#include "charset.h"
39#include "coding.h"
44#include "window.h" 40#include "window.h"
45 41
46#include "systime.h" 42#include "systime.h"
@@ -57,7 +53,7 @@ extern Lisp_Object make_time ();
57extern void insert_from_buffer (); 53extern void insert_from_buffer ();
58static int tm_diff (); 54static int tm_diff ();
59static void update_buffer_properties (); 55static void update_buffer_properties ();
60size_t emacs_strftime (); 56size_t emacs_strftimeu ();
61void set_time_zone_rule (); 57void set_time_zone_rule ();
62 58
63Lisp_Object Vbuffer_access_fontify_functions; 59Lisp_Object Vbuffer_access_fontify_functions;
@@ -1174,27 +1170,29 @@ lisp_time_argument (specified_time, result)
1174 1170
1175/* Write information into buffer S of size MAXSIZE, according to the 1171/* Write information into buffer S of size MAXSIZE, according to the
1176 FORMAT of length FORMAT_LEN, using time information taken from *TP. 1172 FORMAT of length FORMAT_LEN, using time information taken from *TP.
1173 Default to Universal Time if UT is nonzero, local time otherwise.
1177 Return the number of bytes written, not including the terminating 1174 Return the number of bytes written, not including the terminating
1178 '\0'. If S is NULL, nothing will be written anywhere; so to 1175 '\0'. If S is NULL, nothing will be written anywhere; so to
1179 determine how many bytes would be written, use NULL for S and 1176 determine how many bytes would be written, use NULL for S and
1180 ((size_t) -1) for MAXSIZE. 1177 ((size_t) -1) for MAXSIZE.
1181 1178
1182 This function behaves like emacs_strftime, except it allows null 1179 This function behaves like emacs_strftimeu, except it allows null
1183 bytes in FORMAT. */ 1180 bytes in FORMAT. */
1184static size_t 1181static size_t
1185emacs_memftime (s, maxsize, format, format_len, tp) 1182emacs_memftimeu (s, maxsize, format, format_len, tp, ut)
1186 char *s; 1183 char *s;
1187 size_t maxsize; 1184 size_t maxsize;
1188 const char *format; 1185 const char *format;
1189 size_t format_len; 1186 size_t format_len;
1190 const struct tm *tp; 1187 const struct tm *tp;
1188 int ut;
1191{ 1189{
1192 size_t total = 0; 1190 size_t total = 0;
1193 1191
1194 /* Loop through all the null-terminated strings in the format 1192 /* Loop through all the null-terminated strings in the format
1195 argument. Normally there's just one null-terminated string, but 1193 argument. Normally there's just one null-terminated string, but
1196 there can be arbitrarily many, concatenated together, if the 1194 there can be arbitrarily many, concatenated together, if the
1197 format contains '\0' bytes. emacs_strftime stops at the first 1195 format contains '\0' bytes. emacs_strftimeu stops at the first
1198 '\0' byte so we must invoke it separately for each such string. */ 1196 '\0' byte so we must invoke it separately for each such string. */
1199 for (;;) 1197 for (;;)
1200 { 1198 {
@@ -1204,7 +1202,7 @@ emacs_memftime (s, maxsize, format, format_len, tp)
1204 if (s) 1202 if (s)
1205 s[0] = '\1'; 1203 s[0] = '\1';
1206 1204
1207 result = emacs_strftime (s, maxsize, format, tp); 1205 result = emacs_strftimeu (s, maxsize, format, tp, ut);
1208 1206
1209 if (s) 1207 if (s)
1210 { 1208 {
@@ -1283,36 +1281,43 @@ DEFUN ("format-time-string", Fformat_time_string, Sformat_time_string, 1, 3, 0,
1283 time_t value; 1281 time_t value;
1284 int size; 1282 int size;
1285 struct tm *tm; 1283 struct tm *tm;
1284 int ut = ! NILP (universal);
1286 1285
1287 CHECK_STRING (format_string, 1); 1286 CHECK_STRING (format_string, 1);
1288 1287
1289 if (! lisp_time_argument (time, &value)) 1288 if (! lisp_time_argument (time, &value))
1290 error ("Invalid time specification"); 1289 error ("Invalid time specification");
1291 1290
1291 format_string = code_convert_string_norecord (format_string,
1292 Vlocale_coding_system, 1);
1293
1292 /* This is probably enough. */ 1294 /* This is probably enough. */
1293 size = STRING_BYTES (XSTRING (format_string)) * 6 + 50; 1295 size = STRING_BYTES (XSTRING (format_string)) * 6 + 50;
1294 1296
1295 tm = NILP (universal) ? localtime (&value) : gmtime (&value); 1297 tm = ut ? gmtime (&value) : localtime (&value);
1296 if (! tm) 1298 if (! tm)
1297 error ("Specified time is not representable"); 1299 error ("Specified time is not representable");
1298 1300
1301 synchronize_time_locale ();
1302
1299 while (1) 1303 while (1)
1300 { 1304 {
1301 char *buf = (char *) alloca (size + 1); 1305 char *buf = (char *) alloca (size + 1);
1302 int result; 1306 int result;
1303 1307
1304 buf[0] = '\1'; 1308 buf[0] = '\1';
1305 result = emacs_memftime (buf, size, XSTRING (format_string)->data, 1309 result = emacs_memftimeu (buf, size, XSTRING (format_string)->data,
1306 STRING_BYTES (XSTRING (format_string)), 1310 STRING_BYTES (XSTRING (format_string)),
1307 tm); 1311 tm, ut);
1308 if ((result > 0 && result < size) || (result == 0 && buf[0] == '\0')) 1312 if ((result > 0 && result < size) || (result == 0 && buf[0] == '\0'))
1309 return make_string (buf, result); 1313 return code_convert_string_norecord (make_string (buf, result),
1314 Vlocale_coding_system, 0);
1310 1315
1311 /* If buffer was too small, make it bigger and try again. */ 1316 /* If buffer was too small, make it bigger and try again. */
1312 result = emacs_memftime (NULL, (size_t) -1, 1317 result = emacs_memftimeu (NULL, (size_t) -1,
1313 XSTRING (format_string)->data, 1318 XSTRING (format_string)->data,
1314 STRING_BYTES (XSTRING (format_string)), 1319 STRING_BYTES (XSTRING (format_string)),
1315 tm); 1320 tm, ut);
1316 size = result + 1; 1321 size = result + 1;
1317 } 1322 }
1318} 1323}
diff --git a/src/emacs.c b/src/emacs.c
index 8d105289a95..4a52e2ee8d4 100644
--- a/src/emacs.c
+++ b/src/emacs.c
@@ -1,5 +1,5 @@
1/* Fully extensible Emacs, running on Unix, intended for GNU. 1/* Fully extensible Emacs, running on Unix, intended for GNU.
2 Copyright (C) 1985,86,87,93,94,95,97,1998 Free Software Foundation, Inc. 2 Copyright (C) 1985,86,87,93,94,95,97,98,1999 Free Software Foundation, Inc.
3 3
4This file is part of GNU Emacs. 4This file is part of GNU Emacs.
5 5
@@ -19,10 +19,9 @@ the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19Boston, MA 02111-1307, USA. */ 19Boston, MA 02111-1307, USA. */
20 20
21 21
22#include <config.h>
22#include <signal.h> 23#include <signal.h>
23#include <errno.h> 24#include <errno.h>
24
25#include <config.h>
26#include <stdio.h> 25#include <stdio.h>
27 26
28#include <sys/types.h> 27#include <sys/types.h>
@@ -40,10 +39,6 @@ Boston, MA 02111-1307, USA. */
40#include <sys/ioctl.h> 39#include <sys/ioctl.h>
41#endif 40#endif
42 41
43#ifdef STDC_HEADERS
44#include <stdlib.h>
45#endif
46
47#include "lisp.h" 42#include "lisp.h"
48#include "commands.h" 43#include "commands.h"
49#include "intervals.h" 44#include "intervals.h"
@@ -56,6 +51,10 @@ Boston, MA 02111-1307, USA. */
56#include "termhooks.h" 51#include "termhooks.h"
57#include "keyboard.h" 52#include "keyboard.h"
58 53
54#ifdef HAVE_SETLOCALE
55#include <locale.h>
56#endif
57
59#ifdef HAVE_SETRLIMIT 58#ifdef HAVE_SETRLIMIT
60#include <sys/time.h> 59#include <sys/time.h>
61#include <sys/resource.h> 60#include <sys/resource.h>
@@ -128,6 +127,12 @@ Lisp_Object Vsystem_configuration_options;
128 127
129Lisp_Object Qfile_name_handler_alist; 128Lisp_Object Qfile_name_handler_alist;
130 129
130/* Current and previous system locales for messages and time. */
131Lisp_Object Vmessages_locale;
132Lisp_Object Vprevious_messages_locale;
133Lisp_Object Vtime_locale;
134Lisp_Object Vprevious_time_locale;
135
131/* If non-zero, emacs should not attempt to use an window-specific code, 136/* If non-zero, emacs should not attempt to use an window-specific code,
132 but instead should use the virtual terminal under which it was started */ 137 but instead should use the virtual terminal under which it was started */
133int inhibit_window_system; 138int inhibit_window_system;
@@ -602,6 +607,7 @@ main (argc, argv, envp)
602 char **envp; 607 char **envp;
603{ 608{
604 char stack_bottom_variable; 609 char stack_bottom_variable;
610 int do_initial_setlocale;
605 int skip_args = 0; 611 int skip_args = 0;
606 extern int errno; 612 extern int errno;
607 extern int sys_nerr; 613 extern int sys_nerr;
@@ -785,6 +791,20 @@ main (argc, argv, envp)
785 setuid (getuid ()); 791 setuid (getuid ());
786#endif /* SET_EMACS_PRIORITY */ 792#endif /* SET_EMACS_PRIORITY */
787 793
794 /* Skip initial setlocale if LC_ALL is "C", as it's not needed in that case.
795 The build procedure uses this while dumping, to ensure that the
796 dumped Emacs does not have its system locale tables initialized,
797 as that might cause screwups when the dumped Emacs starts up. */
798 {
799 char *lc_all = getenv ("LC_ALL");
800 do_initial_setlocale = ! lc_all || strcmp (lc_all, "C");
801 }
802
803 /* Set locale now, so that initial error messages are localized properly.
804 fixup_locale must wait until later, since it builds strings. */
805 if (do_initial_setlocale)
806 setlocale (LC_ALL, "");
807
788#ifdef EXTRA_INITIALIZE 808#ifdef EXTRA_INITIALIZE
789 EXTRA_INITIALIZE; 809 EXTRA_INITIALIZE;
790#endif 810#endif
@@ -798,9 +818,9 @@ main (argc, argv, envp)
798 if (argmatch (argv, argc, "-t", "--terminal", 4, &term, &skip_args)) 818 if (argmatch (argv, argc, "-t", "--terminal", 4, &term, &skip_args))
799 { 819 {
800 int result; 820 int result;
801 close (0); 821 emacs_close (0);
802 close (1); 822 emacs_close (1);
803 result = open (term, O_RDWR, 2 ); 823 result = emacs_open (term, O_RDWR, 0);
804 if (result < 0) 824 if (result < 0)
805 { 825 {
806 char *errstring = strerror (errno); 826 char *errstring = strerror (errno);
@@ -994,6 +1014,14 @@ the Bugs section of the Emacs manual or the file BUGS.\n", argv[0]);
994 } 1014 }
995 1015
996 init_alloc (); 1016 init_alloc ();
1017
1018 if (do_initial_setlocale)
1019 {
1020 fixup_locale ();
1021 Vmessages_locale = Vprevious_messages_locale;
1022 Vtime_locale = Vprevious_time_locale;
1023 }
1024
997 init_eval (); 1025 init_eval ();
998 init_coding (); 1026 init_coding ();
999 init_data (); 1027 init_data ();
@@ -1859,6 +1887,55 @@ You must run Emacs in batch mode in order to dump it.")
1859 1887
1860#endif /* not CANNOT_DUMP */ 1888#endif /* not CANNOT_DUMP */
1861 1889
1890#if HAVE_SETLOCALE
1891/* Recover from setlocale (LC_ALL, ""). */
1892void
1893fixup_locale ()
1894{
1895 char *l;
1896
1897 /* The Emacs Lisp reader needs LC_NUMERIC to be "C",
1898 so that numbers are read and printed properly for Emacs Lisp. */
1899 setlocale (LC_NUMERIC, "C");
1900
1901#ifdef LC_MESSAGES
1902 l = setlocale (LC_MESSAGES, (char *) 0);
1903 Vprevious_messages_locale = l ? build_string (l) : Qnil;
1904#endif
1905 l = setlocale (LC_TIME, (char *) 0);
1906 Vprevious_time_locale = l ? build_string (l) : Qnil;
1907}
1908
1909static void
1910synchronize_locale (category, plocale, desired_locale)
1911 int category;
1912 Lisp_Object *plocale;
1913 Lisp_Object desired_locale;
1914{
1915 if (STRINGP (desired_locale)
1916 && (NILP (*plocale) || NILP (Fstring_equal (*plocale, desired_locale)))
1917 && setlocale (category, XSTRING (desired_locale)->data))
1918 *plocale = desired_locale;
1919}
1920
1921/* Set system time locale to match Vtime_locale, if possible. */
1922void
1923synchronize_time_locale ()
1924{
1925 synchronize_locale (LC_TIME, &Vprevious_time_locale, Vtime_locale);
1926}
1927
1928/* Set system messages locale to match Vmessages_locale, if possible. */
1929void
1930synchronize_messages_locale ()
1931{
1932#ifdef LC_MESSAGES
1933 synchronize_locale (LC_MESSAGES, &Vprevious_messages_locale,
1934 Vmessages_locale);
1935#endif
1936}
1937#endif /* HAVE_SETLOCALE */
1938
1862#ifndef SEPCHAR 1939#ifndef SEPCHAR
1863#define SEPCHAR ':' 1940#define SEPCHAR ':'
1864#endif 1941#endif
@@ -2003,4 +2080,20 @@ This is non-nil when we can't find those directories in their standard\n\
2003installed locations, but we can find them\n\ 2080installed locations, but we can find them\n\
2004near where the Emacs executable was found."); 2081near where the Emacs executable was found.");
2005 Vinstallation_directory = Qnil; 2082 Vinstallation_directory = Qnil;
2083
2084 DEFVAR_LISP ("messages-locale", &Vmessages_locale,
2085 "System locale for messages.");
2086 Vmessages_locale = Qnil;
2087
2088 DEFVAR_LISP ("previous-messages-locale", &Vprevious_messages_locale,
2089 "Most recently used system locale for messages.");
2090 Vprevious_messages_locale = Qnil;
2091
2092 DEFVAR_LISP ("time-locale", &Vtime_locale,
2093 "System locale for time.");
2094 Vtime_locale = Qnil;
2095
2096 DEFVAR_LISP ("previous-time-locale", &Vprevious_time_locale,
2097 "Most recently used system locale for time.");
2098 Vprevious_time_locale = Qnil;
2006} 2099}
diff --git a/src/eval.c b/src/eval.c
index c879ecb7ec4..59150df232a 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -1,5 +1,5 @@
1/* Evaluator for GNU Emacs Lisp interpreter. 1/* Evaluator for GNU Emacs Lisp interpreter.
2 Copyright (C) 1985, 1986, 1987, 1993, 1994, 1995 Free Software Foundation, Inc. 2 Copyright (C) 1985, 86, 87, 93, 94, 95, 1999 Free Software Foundation, Inc.
3 3
4This file is part of GNU Emacs. 4This file is part of GNU Emacs.
5 5
@@ -21,10 +21,6 @@ Boston, MA 02111-1307, USA. */
21 21
22#include <config.h> 22#include <config.h>
23 23
24#ifdef STDC_HEADERS
25#include <stdlib.h>
26#endif
27
28#include "lisp.h" 24#include "lisp.h"
29#include "blockinput.h" 25#include "blockinput.h"
30 26
diff --git a/src/fileio.c b/src/fileio.c
index 39927008d57..5a00649d79e 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -1,5 +1,5 @@
1/* File IO for GNU Emacs. 1/* File IO for GNU Emacs.
2 Copyright (C) 1985,86,87,88,93,94,95,96,97,1998 Free Software Foundation, Inc. 2 Copyright (C) 1985,86,87,88,93,94,95,96,97,98,1999 Free Software Foundation, Inc.
3 3
4This file is part of GNU Emacs. 4This file is part of GNU Emacs.
5 5
@@ -32,10 +32,6 @@ Boston, MA 02111-1307, USA. */
32#include <unistd.h> 32#include <unistd.h>
33#endif 33#endif
34 34
35#ifdef STDC_HEADERS
36#include <stdlib.h>
37#endif
38
39#if !defined (S_ISLNK) && defined (S_IFLNK) 35#if !defined (S_ISLNK) && defined (S_IFLNK)
40# define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK) 36# define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
41#endif 37#endif
@@ -253,7 +249,10 @@ report_file_error (string, data)
253 Lisp_Object errstring; 249 Lisp_Object errstring;
254 int errorno = errno; 250 int errorno = errno;
255 251
256 errstring = build_string (strerror (errno)); 252 synchronize_messages_locale ();
253 errstring = code_convert_string_norecord (build_string (strerror (errorno)),
254 Vlocale_coding_system, 0);
255
257 while (1) 256 while (1)
258 switch (errorno) 257 switch (errorno)
259 { 258 {
@@ -275,7 +274,7 @@ Lisp_Object
275close_file_unwind (fd) 274close_file_unwind (fd)
276 Lisp_Object fd; 275 Lisp_Object fd;
277{ 276{
278 close (XFASTINT (fd)); 277 emacs_close (XFASTINT (fd));
279 return Qnil; 278 return Qnil;
280} 279}
281 280
@@ -2287,7 +2286,7 @@ A prefix arg makes KEEP-TIME non-nil.")
2287 else if (stat (XSTRING (encoded_newname)->data, &out_st) < 0) 2286 else if (stat (XSTRING (encoded_newname)->data, &out_st) < 0)
2288 out_st.st_mode = 0; 2287 out_st.st_mode = 0;
2289 2288
2290 ifd = open (XSTRING (encoded_file)->data, O_RDONLY); 2289 ifd = emacs_open (XSTRING (encoded_file)->data, O_RDONLY, 0);
2291 if (ifd < 0) 2290 if (ifd < 0)
2292 report_file_error ("Opening input file", Fcons (file, Qnil)); 2291 report_file_error ("Opening input file", Fcons (file, Qnil));
2293 2292
@@ -2339,13 +2338,13 @@ A prefix arg makes KEEP-TIME non-nil.")
2339 2338
2340 immediate_quit = 1; 2339 immediate_quit = 1;
2341 QUIT; 2340 QUIT;
2342 while ((n = read (ifd, buf, sizeof buf)) > 0) 2341 while ((n = emacs_read (ifd, buf, sizeof buf)) > 0)
2343 if (write (ofd, buf, n) != n) 2342 if (emacs_write (ofd, buf, n) != n)
2344 report_file_error ("I/O error", Fcons (newname, Qnil)); 2343 report_file_error ("I/O error", Fcons (newname, Qnil));
2345 immediate_quit = 0; 2344 immediate_quit = 0;
2346 2345
2347 /* Closing the output clobbers the file times on some systems. */ 2346 /* Closing the output clobbers the file times on some systems. */
2348 if (close (ofd) < 0) 2347 if (emacs_close (ofd) < 0)
2349 report_file_error ("I/O error", Fcons (newname, Qnil)); 2348 report_file_error ("I/O error", Fcons (newname, Qnil));
2350 2349
2351 if (input_file_statable_p) 2350 if (input_file_statable_p)
@@ -2375,7 +2374,7 @@ A prefix arg makes KEEP-TIME non-nil.")
2375#endif /* MSDOS */ 2374#endif /* MSDOS */
2376 } 2375 }
2377 2376
2378 close (ifd); 2377 emacs_close (ifd);
2379 2378
2380 /* Discard the unwind protects. */ 2379 /* Discard the unwind protects. */
2381 specpdl_ptr = specpdl + count; 2380 specpdl_ptr = specpdl + count;
@@ -2914,10 +2913,10 @@ See also `file-exists-p' and `file-attributes'.")
2914 if (S_ISFIFO (statbuf.st_mode)) 2913 if (S_ISFIFO (statbuf.st_mode))
2915 flags |= O_NONBLOCK; 2914 flags |= O_NONBLOCK;
2916#endif 2915#endif
2917 desc = open (XSTRING (absname)->data, flags); 2916 desc = emacs_open (XSTRING (absname)->data, flags, 0);
2918 if (desc < 0) 2917 if (desc < 0)
2919 return Qnil; 2918 return Qnil;
2920 close (desc); 2919 emacs_close (desc);
2921 return Qt; 2920 return Qt;
2922#endif /* not DOS_NT */ 2921#endif /* not DOS_NT */
2923} 2922}
@@ -2983,10 +2982,10 @@ If there is no error, we return nil.")
2983 2982
2984 encoded_filename = ENCODE_FILE (filename); 2983 encoded_filename = ENCODE_FILE (filename);
2985 2984
2986 fd = open (XSTRING (encoded_filename)->data, O_RDONLY); 2985 fd = emacs_open (XSTRING (encoded_filename)->data, O_RDONLY, 0);
2987 if (fd < 0) 2986 if (fd < 0)
2988 report_file_error (XSTRING (string)->data, Fcons (filename, Qnil)); 2987 report_file_error (XSTRING (string)->data, Fcons (filename, Qnil));
2989 close (fd); 2988 emacs_close (fd);
2990 2989
2991 return Qnil; 2990 return Qnil;
2992} 2991}
@@ -3403,12 +3402,12 @@ actually used.")
3403#ifndef APOLLO 3402#ifndef APOLLO
3404 if (stat (XSTRING (filename)->data, &st) < 0) 3403 if (stat (XSTRING (filename)->data, &st) < 0)
3405#else 3404#else
3406 if ((fd = open (XSTRING (filename)->data, O_RDONLY)) < 0 3405 if ((fd = emacs_open (XSTRING (filename)->data, O_RDONLY, 0)) < 0
3407 || fstat (fd, &st) < 0) 3406 || fstat (fd, &st) < 0)
3408#endif /* not APOLLO */ 3407#endif /* not APOLLO */
3409#endif /* WINDOWSNT */ 3408#endif /* WINDOWSNT */
3410 { 3409 {
3411 if (fd >= 0) close (fd); 3410 if (fd >= 0) emacs_close (fd);
3412 badopen: 3411 badopen:
3413 if (NILP (visit)) 3412 if (NILP (visit))
3414 report_file_error ("Opening input file", Fcons (orig_filename, Qnil)); 3413 report_file_error ("Opening input file", Fcons (orig_filename, Qnil));
@@ -3438,7 +3437,7 @@ actually used.")
3438#endif 3437#endif
3439 3438
3440 if (fd < 0) 3439 if (fd < 0)
3441 if ((fd = open (XSTRING (filename)->data, O_RDONLY)) < 0) 3440 if ((fd = emacs_open (XSTRING (filename)->data, O_RDONLY, 0)) < 0)
3442 goto badopen; 3441 goto badopen;
3443 3442
3444 /* Replacement should preserve point as it preserves markers. */ 3443 /* Replacement should preserve point as it preserves markers. */
@@ -3470,7 +3469,13 @@ actually used.")
3470 if (! not_regular) 3469 if (! not_regular)
3471 { 3470 {
3472 XSETINT (end, st.st_size); 3471 XSETINT (end, st.st_size);
3473 if (XINT (end) != st.st_size) 3472
3473 /* Arithmetic overflow can occur if an Emacs integer cannot
3474 represent the file size, or if the calculations below
3475 overflow. The calculations below double the file size
3476 twice, so check that it can be multiplied by 4 safely. */
3477 if (XINT (end) != st.st_size
3478 || ((int) st.st_size * 4) / 4 != st.st_size)
3474 error ("Maximum buffer size exceeded"); 3479 error ("Maximum buffer size exceeded");
3475 } 3480 }
3476 } 3481 }
@@ -3503,22 +3508,22 @@ actually used.")
3503 int how_many, nread; 3508 int how_many, nread;
3504 3509
3505 if (st.st_size <= (1024 * 4)) 3510 if (st.st_size <= (1024 * 4))
3506 nread = read (fd, read_buf, 1024 * 4); 3511 nread = emacs_read (fd, read_buf, 1024 * 4);
3507 else 3512 else
3508 { 3513 {
3509 nread = read (fd, read_buf, 1024); 3514 nread = emacs_read (fd, read_buf, 1024);
3510 if (nread >= 0) 3515 if (nread >= 0)
3511 { 3516 {
3512 if (lseek (fd, st.st_size - (1024 * 3), 0) < 0) 3517 if (lseek (fd, st.st_size - (1024 * 3), 0) < 0)
3513 report_file_error ("Setting file position", 3518 report_file_error ("Setting file position",
3514 Fcons (orig_filename, Qnil)); 3519 Fcons (orig_filename, Qnil));
3515 nread += read (fd, read_buf + nread, 1024 * 3); 3520 nread += emacs_read (fd, read_buf + nread, 1024 * 3);
3516 } 3521 }
3517 } 3522 }
3518 3523
3519 if (nread < 0) 3524 if (nread < 0)
3520 error ("IO error reading %s: %s", 3525 error ("IO error reading %s: %s",
3521 XSTRING (orig_filename)->data, strerror (errno)); 3526 XSTRING (orig_filename)->data, emacs_strerror (errno));
3522 else if (nread > 0) 3527 else if (nread > 0)
3523 { 3528 {
3524 int count = specpdl_ptr - specpdl; 3529 int count = specpdl_ptr - specpdl;
@@ -3618,10 +3623,10 @@ actually used.")
3618 { 3623 {
3619 int nread, bufpos; 3624 int nread, bufpos;
3620 3625
3621 nread = read (fd, buffer, sizeof buffer); 3626 nread = emacs_read (fd, buffer, sizeof buffer);
3622 if (nread < 0) 3627 if (nread < 0)
3623 error ("IO error reading %s: %s", 3628 error ("IO error reading %s: %s",
3624 XSTRING (orig_filename)->data, strerror (errno)); 3629 XSTRING (orig_filename)->data, emacs_strerror (errno));
3625 else if (nread == 0) 3630 else if (nread == 0)
3626 break; 3631 break;
3627 3632
@@ -3660,7 +3665,7 @@ actually used.")
3660 there's no need to replace anything. */ 3665 there's no need to replace anything. */
3661 if (same_at_start - BEGV_BYTE == XINT (end)) 3666 if (same_at_start - BEGV_BYTE == XINT (end))
3662 { 3667 {
3663 close (fd); 3668 emacs_close (fd);
3664 specpdl_ptr--; 3669 specpdl_ptr--;
3665 /* Truncate the buffer to the size of the file. */ 3670 /* Truncate the buffer to the size of the file. */
3666 del_range_1 (same_at_start, same_at_end, 0); 3671 del_range_1 (same_at_start, same_at_end, 0);
@@ -3689,10 +3694,10 @@ actually used.")
3689 total_read = 0; 3694 total_read = 0;
3690 while (total_read < trial) 3695 while (total_read < trial)
3691 { 3696 {
3692 nread = read (fd, buffer + total_read, trial - total_read); 3697 nread = emacs_read (fd, buffer + total_read, trial - total_read);
3693 if (nread <= 0) 3698 if (nread <= 0)
3694 error ("IO error reading %s: %s", 3699 error ("IO error reading %s: %s",
3695 XSTRING (orig_filename)->data, strerror (errno)); 3700 XSTRING (orig_filename)->data, emacs_strerror (errno));
3696 total_read += nread; 3701 total_read += nread;
3697 } 3702 }
3698 /* Scan this bufferful from the end, comparing with 3703 /* Scan this bufferful from the end, comparing with
@@ -3809,7 +3814,7 @@ actually used.")
3809 /* Allow quitting out of the actual I/O. */ 3814 /* Allow quitting out of the actual I/O. */
3810 immediate_quit = 1; 3815 immediate_quit = 1;
3811 QUIT; 3816 QUIT;
3812 this = read (fd, destination, trytry); 3817 this = emacs_read (fd, destination, trytry);
3813 immediate_quit = 0; 3818 immediate_quit = 0;
3814 3819
3815 if (this < 0 || this + unprocessed == 0) 3820 if (this < 0 || this + unprocessed == 0)
@@ -3862,7 +3867,7 @@ actually used.")
3862 3867
3863 if (how_much == -1) 3868 if (how_much == -1)
3864 error ("IO error reading %s: %s", 3869 error ("IO error reading %s: %s",
3865 XSTRING (orig_filename)->data, strerror (errno)); 3870 XSTRING (orig_filename)->data, emacs_strerror (errno));
3866 else if (how_much == -2) 3871 else if (how_much == -2)
3867 error ("maximum buffer size exceeded"); 3872 error ("maximum buffer size exceeded");
3868 } 3873 }
@@ -3881,7 +3886,7 @@ actually used.")
3881 if (bufpos == inserted) 3886 if (bufpos == inserted)
3882 { 3887 {
3883 xfree (conversion_buffer); 3888 xfree (conversion_buffer);
3884 close (fd); 3889 emacs_close (fd);
3885 specpdl_ptr--; 3890 specpdl_ptr--;
3886 /* Truncate the buffer to the size of the file. */ 3891 /* Truncate the buffer to the size of the file. */
3887 del_range_byte (same_at_start, same_at_end, 0); 3892 del_range_byte (same_at_start, same_at_end, 0);
@@ -3946,7 +3951,7 @@ actually used.")
3946 inserted = PT - temp; 3951 inserted = PT - temp;
3947 3952
3948 free (conversion_buffer); 3953 free (conversion_buffer);
3949 close (fd); 3954 emacs_close (fd);
3950 specpdl_ptr--; 3955 specpdl_ptr--;
3951 3956
3952 goto handled; 3957 goto handled;
@@ -4003,7 +4008,8 @@ actually used.")
4003 /* Allow quitting out of the actual I/O. */ 4008 /* Allow quitting out of the actual I/O. */
4004 immediate_quit = 1; 4009 immediate_quit = 1;
4005 QUIT; 4010 QUIT;
4006 this = read (fd, BYTE_POS_ADDR (PT_BYTE + inserted - 1) + 1, trytry); 4011 this = emacs_read (fd, BYTE_POS_ADDR (PT_BYTE + inserted - 1) + 1,
4012 trytry);
4007 immediate_quit = 0; 4013 immediate_quit = 0;
4008 4014
4009 if (this <= 0) 4015 if (this <= 0)
@@ -4034,14 +4040,14 @@ actually used.")
4034 /* Put an anchor to ensure multi-byte form ends at gap. */ 4040 /* Put an anchor to ensure multi-byte form ends at gap. */
4035 *GPT_ADDR = 0; 4041 *GPT_ADDR = 0;
4036 4042
4037 close (fd); 4043 emacs_close (fd);
4038 4044
4039 /* Discard the unwind protect for closing the file. */ 4045 /* Discard the unwind protect for closing the file. */
4040 specpdl_ptr--; 4046 specpdl_ptr--;
4041 4047
4042 if (how_much < 0) 4048 if (how_much < 0)
4043 error ("IO error reading %s: %s", 4049 error ("IO error reading %s: %s",
4044 XSTRING (orig_filename)->data, strerror (errno)); 4050 XSTRING (orig_filename)->data, emacs_strerror (errno));
4045 4051
4046 if (! coding_system_decided) 4052 if (! coding_system_decided)
4047 { 4053 {
@@ -4496,9 +4502,9 @@ This does code conversion according to the value of\n\
4496 desc = -1; 4502 desc = -1;
4497 if (!NILP (append)) 4503 if (!NILP (append))
4498#ifdef DOS_NT 4504#ifdef DOS_NT
4499 desc = open (fn, O_WRONLY | buffer_file_type); 4505 desc = emacs_open (fn, O_WRONLY | buffer_file_type, 0);
4500#else /* not DOS_NT */ 4506#else /* not DOS_NT */
4501 desc = open (fn, O_WRONLY); 4507 desc = emacs_open (fn, O_WRONLY, 0);
4502#endif /* not DOS_NT */ 4508#endif /* not DOS_NT */
4503 4509
4504 if (desc < 0 && (NILP (append) || errno == ENOENT)) 4510 if (desc < 0 && (NILP (append) || errno == ENOENT))
@@ -4506,7 +4512,7 @@ This does code conversion according to the value of\n\
4506 if (auto_saving) /* Overwrite any previous version of autosave file */ 4512 if (auto_saving) /* Overwrite any previous version of autosave file */
4507 { 4513 {
4508 vms_truncate (fn); /* if fn exists, truncate to zero length */ 4514 vms_truncate (fn); /* if fn exists, truncate to zero length */
4509 desc = open (fn, O_RDWR); 4515 desc = emacs_open (fn, O_RDWR, 0);
4510 if (desc < 0) 4516 if (desc < 0)
4511 desc = creat_copy_attrs (STRINGP (current_buffer->filename) 4517 desc = creat_copy_attrs (STRINGP (current_buffer->filename)
4512 ? XSTRING (current_buffer->filename)->data : 0, 4518 ? XSTRING (current_buffer->filename)->data : 0,
@@ -4539,7 +4545,7 @@ This does code conversion according to the value of\n\
4539 /* We can't make a new version; 4545 /* We can't make a new version;
4540 try to truncate and rewrite existing version if any. */ 4546 try to truncate and rewrite existing version if any. */
4541 vms_truncate (fn); 4547 vms_truncate (fn);
4542 desc = open (fn, O_RDWR); 4548 desc = emacs_open (fn, O_RDWR, 0);
4543 } 4549 }
4544#endif 4550#endif
4545 } 4551 }
@@ -4549,14 +4555,14 @@ This does code conversion according to the value of\n\
4549 } 4555 }
4550#else /* not VMS */ 4556#else /* not VMS */
4551#ifdef DOS_NT 4557#ifdef DOS_NT
4552 desc = open (fn, 4558 desc = emacs_open (fn,
4553 O_WRONLY | O_TRUNC | O_CREAT | buffer_file_type 4559 O_WRONLY | O_TRUNC | O_CREAT | buffer_file_type
4554 | (mustbenew == Qexcl ? O_EXCL : 0), 4560 | (mustbenew == Qexcl ? O_EXCL : 0),
4555 S_IREAD | S_IWRITE); 4561 S_IREAD | S_IWRITE);
4556#else /* not DOS_NT */ 4562#else /* not DOS_NT */
4557 desc = open (fn, O_WRONLY | O_TRUNC | O_CREAT 4563 desc = emacs_open (fn, O_WRONLY | O_TRUNC | O_CREAT
4558 | (mustbenew == Qexcl ? O_EXCL : 0), 4564 | (mustbenew == Qexcl ? O_EXCL : 0),
4559 auto_saving ? auto_save_mode_bits : 0666); 4565 auto_saving ? auto_save_mode_bits : 0666);
4560#endif /* not DOS_NT */ 4566#endif /* not DOS_NT */
4561#endif /* not VMS */ 4567#endif /* not VMS */
4562 4568
@@ -4701,7 +4707,7 @@ This does code conversion according to the value of\n\
4701#endif 4707#endif
4702 4708
4703 /* NFS can report a write failure now. */ 4709 /* NFS can report a write failure now. */
4704 if (close (desc) < 0) 4710 if (emacs_close (desc) < 0)
4705 failure = 1, save_errno = errno; 4711 failure = 1, save_errno = errno;
4706 4712
4707#ifdef VMS 4713#ifdef VMS
@@ -4735,7 +4741,7 @@ This does code conversion according to the value of\n\
4735 4741
4736 if (failure) 4742 if (failure)
4737 error ("IO error writing %s: %s", XSTRING (filename)->data, 4743 error ("IO error writing %s: %s", XSTRING (filename)->data,
4738 strerror (save_errno)); 4744 emacs_strerror (save_errno));
4739 4745
4740 if (visiting) 4746 if (visiting)
4741 { 4747 {
@@ -4927,14 +4933,14 @@ e_write (desc, addr, nbytes, coding)
4927 nbytes -= coding->consumed, addr += coding->consumed; 4933 nbytes -= coding->consumed, addr += coding->consumed;
4928 if (coding->produced > 0) 4934 if (coding->produced > 0)
4929 { 4935 {
4930 coding->produced -= write (desc, buf, coding->produced); 4936 coding->produced -= emacs_write (desc, buf, coding->produced);
4931 if (coding->produced) return -1; 4937 if (coding->produced) return -1;
4932 } 4938 }
4933 if (result == CODING_FINISH_INSUFFICIENT_SRC) 4939 if (result == CODING_FINISH_INSUFFICIENT_SRC)
4934 { 4940 {
4935 /* The source text ends by an incomplete multibyte form. 4941 /* The source text ends by an incomplete multibyte form.
4936 There's no way other than write it out as is. */ 4942 There's no way other than write it out as is. */
4937 nbytes -= write (desc, addr, nbytes); 4943 nbytes -= emacs_write (desc, addr, nbytes);
4938 if (nbytes) return -1; 4944 if (nbytes) return -1;
4939 } 4945 }
4940 if (nbytes <= 0) 4946 if (nbytes <= 0)
diff --git a/src/filelock.c b/src/filelock.c
index c08a8a41f59..66f347b479c 100644
--- a/src/filelock.c
+++ b/src/filelock.c
@@ -19,14 +19,11 @@ the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19Boston, MA 02111-1307, USA. */ 19Boston, MA 02111-1307, USA. */
20 20
21 21
22#include <config.h>
22#include <sys/types.h> 23#include <sys/types.h>
23#include <sys/stat.h> 24#include <sys/stat.h>
24#include <signal.h> 25#include <signal.h>
25#include <config.h>
26#include <stdio.h> 26#include <stdio.h>
27#ifdef HAVE_STDLIB_H
28#include <stdlib.h>
29#endif
30 27
31#ifdef VMS 28#ifdef VMS
32#include "vms-pwd.h" 29#include "vms-pwd.h"
@@ -255,11 +252,11 @@ get_boot_time_1 (filename, newest)
255 { 252 {
256 /* On some versions of IRIX, opening a nonexistent file name 253 /* On some versions of IRIX, opening a nonexistent file name
257 is likely to crash in the utmp routines. */ 254 is likely to crash in the utmp routines. */
258 desc = open (filename, O_RDONLY); 255 desc = emacs_open (filename, O_RDONLY, 0);
259 if (desc < 0) 256 if (desc < 0)
260 return; 257 return;
261 258
262 close (desc); 259 emacs_close (desc);
263 260
264 utmpname (filename); 261 utmpname (filename);
265 } 262 }
diff --git a/src/floatfns.c b/src/floatfns.c
index b989591cc81..ebe1b7de43c 100644
--- a/src/floatfns.c
+++ b/src/floatfns.c
@@ -1,5 +1,5 @@
1/* Primitive operations on floating point for GNU Emacs Lisp interpreter. 1/* Primitive operations on floating point for GNU Emacs Lisp interpreter.
2 Copyright (C) 1988, 1993, 1994 Free Software Foundation, Inc. 2 Copyright (C) 1988, 1993, 1994, 1999 Free Software Foundation, Inc.
3 3
4This file is part of GNU Emacs. 4This file is part of GNU Emacs.
5 5
@@ -44,9 +44,8 @@ Boston, MA 02111-1307, USA. */
44 a domain error occurs.) 44 a domain error occurs.)
45 */ 45 */
46 46
47#include <signal.h>
48
49#include <config.h> 47#include <config.h>
48#include <signal.h>
50#include "lisp.h" 49#include "lisp.h"
51#include "syssignal.h" 50#include "syssignal.h"
52 51
diff --git a/src/fns.c b/src/fns.c
index 887e8f8c867..e5c3a2be428 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -4404,7 +4404,7 @@ DEFUN ("gethash", Fgethash, Sgethash, 2, 3, 0,
4404 "Look up KEY in TABLE and return its associated value.\n\ 4404 "Look up KEY in TABLE and return its associated value.\n\
4405If KEY is not found, return DFLT which defaults to nil.") 4405If KEY is not found, return DFLT which defaults to nil.")
4406 (key, table, dflt) 4406 (key, table, dflt)
4407 Lisp_Object key, table; 4407 Lisp_Object key, table, dflt;
4408{ 4408{
4409 struct Lisp_Hash_Table *h = check_hash_table (table); 4409 struct Lisp_Hash_Table *h = check_hash_table (table);
4410 int i = hash_lookup (h, key, NULL); 4410 int i = hash_lookup (h, key, NULL);
diff --git a/src/frame.c b/src/frame.c
index 2e2c7e50cd5..e5f80fdea16 100644
--- a/src/frame.c
+++ b/src/frame.c
@@ -1,5 +1,5 @@
1/* Generic frame functions. 1/* Generic frame functions.
2 Copyright (C) 1993, 1994, 1995, 1997 Free Software Foundation. 2 Copyright (C) 1993, 1994, 1995, 1997, 1999 Free Software Foundation.
3 3
4This file is part of GNU Emacs. 4This file is part of GNU Emacs.
5 5
@@ -21,9 +21,6 @@ Boston, MA 02111-1307, USA. */
21#include <config.h> 21#include <config.h>
22 22
23#include <stdio.h> 23#include <stdio.h>
24#ifdef HAVE_STDLIB_H
25#include <stdlib.h>
26#endif
27#include "lisp.h" 24#include "lisp.h"
28#include "charset.h" 25#include "charset.h"
29#ifdef HAVE_X_WINDOWS 26#ifdef HAVE_X_WINDOWS
diff --git a/src/gmalloc.c b/src/gmalloc.c
index 4f132391c7a..b291903fa50 100644
--- a/src/gmalloc.c
+++ b/src/gmalloc.c
@@ -5,7 +5,7 @@
5/* The malloc headers and source files from the C library follow here. */ 5/* The malloc headers and source files from the C library follow here. */
6 6
7/* Declarations for `malloc' and friends. 7/* Declarations for `malloc' and friends.
8 Copyright 1990, 91, 92, 93, 95, 96 Free Software Foundation, Inc. 8 Copyright 1990, 91, 92, 93, 95, 96, 99 Free Software Foundation, Inc.
9 Written May 1989 by Mike Haertel. 9 Written May 1989 by Mike Haertel.
10 10
11This library is free software; you can redistribute it and/or 11This library is free software; you can redistribute it and/or
@@ -44,8 +44,10 @@ Cambridge, MA 02139, USA.
44#else /* Not C++ or ANSI C. */ 44#else /* Not C++ or ANSI C. */
45#undef PP 45#undef PP
46#define PP(args) () 46#define PP(args) ()
47#ifndef HAVE_CONFIG_H
47#undef const 48#undef const
48#define const 49#define const
50#endif
49#undef __ptr_t 51#undef __ptr_t
50#define __ptr_t char * 52#define __ptr_t char *
51#endif /* C++ or ANSI C. */ 53#endif /* C++ or ANSI C. */
diff --git a/src/hftctl.c b/src/hftctl.c
index 5fe816abbb5..8a264a70a27 100644
--- a/src/hftctl.c
+++ b/src/hftctl.c
@@ -41,11 +41,9 @@
41/* */ 41/* */
42/***************************************************************/ 42/***************************************************************/
43 43
44#include <config.h>
44#include <sys/signal.h> 45#include <sys/signal.h>
45#include <errno.h> 46#include <errno.h>
46
47#include <config.h>
48
49#include <stdio.h> 47#include <stdio.h>
50#include <fcntl.h> 48#include <fcntl.h>
51#include <setjmp.h> 49#include <setjmp.h>
@@ -102,7 +100,7 @@ static struct hfctlack ACK =
102 /* read a buffer */ 100 /* read a buffer */
103#define RD_BUF(f,p,l) \ 101#define RD_BUF(f,p,l) \
104 while ((l)) \ 102 while ((l)) \
105 if ((j = read((f),(p),(l))) < 0) \ 103 if ((j = emacs_read (f, p, l)) < 0) \
106 if (errno != EINTR) return (-1); \ 104 if (errno != EINTR) return (-1); \
107 else continue; \ 105 else continue; \
108 else { (l) -= j; (p) += j; } 106 else { (l) -= j; (p) += j; }
@@ -333,7 +331,7 @@ WR_REQ (fd, request, cmdlen, cmd, resplen)
333 } 331 }
334 332
335 /* write request to terminal */ 333 /* write request to terminal */
336 if (write(fd,p.c,size) == -1) return (-1); 334 if (emacs_write (fd, p.c, size) == -1) return (-1);
337 if (p.req != &req) /* free if allocated */ 335 if (p.req != &req) /* free if allocated */
338 xfree (p.c); 336 xfree (p.c);
339 return (0); 337 return (0);
diff --git a/src/insdel.c b/src/insdel.c
index b4f6ac5a5a2..6a4aa46d993 100644
--- a/src/insdel.c
+++ b/src/insdel.c
@@ -1,5 +1,5 @@
1/* Buffer insertion/deletion and gap motion for GNU Emacs. 1/* Buffer insertion/deletion and gap motion for GNU Emacs.
2 Copyright (C) 1985, 86, 93, 94, 95, 97, 1998 Free Software Foundation, Inc. 2 Copyright (C) 1985, 86,93,94,95,97,98, 1999 Free Software Foundation, Inc.
3 3
4This file is part of GNU Emacs. 4This file is part of GNU Emacs.
5 5
@@ -20,9 +20,6 @@ Boston, MA 02111-1307, USA. */
20 20
21 21
22#include <config.h> 22#include <config.h>
23#ifdef HAVE_STDLIB_H
24#include <stdlib.h>
25#endif
26#include "lisp.h" 23#include "lisp.h"
27#include "intervals.h" 24#include "intervals.h"
28#include "buffer.h" 25#include "buffer.h"
diff --git a/src/keyboard.c b/src/keyboard.c
index 93f5ebbf2c1..ab331cadcbe 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -1,5 +1,5 @@
1/* Keyboard and mouse input; editor command loop. 1/* Keyboard and mouse input; editor command loop.
2 Copyright (C) 1985,86,87,88,89,93,94,95,96,97 Free Software Foundation, Inc. 2 Copyright (C) 1985,86,87,88,89,93,94,95,96,97,99 Free Software Foundation, Inc.
3 3
4This file is part of GNU Emacs. 4This file is part of GNU Emacs.
5 5
@@ -18,10 +18,8 @@ along with GNU Emacs; see the file COPYING. If not, write to
18the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19Boston, MA 02111-1307, USA. */ 19Boston, MA 02111-1307, USA. */
20 20
21/* Allow config.h to undefine symbols found here. */
22#include <signal.h>
23
24#include <config.h> 21#include <config.h>
22#include <signal.h>
25#include <stdio.h> 23#include <stdio.h>
26#include "termchar.h" 24#include "termchar.h"
27#include "termopts.h" 25#include "termopts.h"
@@ -5572,7 +5570,7 @@ read_avail_input (expected)
5572 cbuf[0] = dos_keyread (); 5570 cbuf[0] = dos_keyread ();
5573 nread = 1; 5571 nread = 1;
5574#else 5572#else
5575 nread = read (input_fd, cbuf, n_to_read); 5573 nread = emacs_read (input_fd, cbuf, n_to_read);
5576#endif 5574#endif
5577 /* POSIX infers that processes which are not in the session leader's 5575 /* POSIX infers that processes which are not in the session leader's
5578 process group won't get SIGHUP's at logout time. BSDI adheres to 5576 process group won't get SIGHUP's at logout time. BSDI adheres to
diff --git a/src/keymap.c b/src/keymap.c
index e20e4fd79a9..b4a1083ed50 100644
--- a/src/keymap.c
+++ b/src/keymap.c
@@ -1,5 +1,5 @@
1/* Manipulation of keymaps 1/* Manipulation of keymaps
2 Copyright (C) 1985, 86,87,88,93,94,95,98 Free Software Foundation, Inc. 2 Copyright (C) 1985, 86,87,88,93,94,95,98,99 Free Software Foundation, Inc.
3 3
4This file is part of GNU Emacs. 4This file is part of GNU Emacs.
5 5
@@ -21,9 +21,6 @@ Boston, MA 02111-1307, USA. */
21 21
22#include <config.h> 22#include <config.h>
23#include <stdio.h> 23#include <stdio.h>
24#ifdef STDC_HEADERS
25#include <stdlib.h>
26#endif
27#undef NULL 24#undef NULL
28#include "lisp.h" 25#include "lisp.h"
29#include "commands.h" 26#include "commands.h"
diff --git a/src/lisp.h b/src/lisp.h
index d40a1298307..e624523d35d 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -1,5 +1,5 @@
1/* Fundamental definitions for GNU Emacs Lisp interpreter. 1/* Fundamental definitions for GNU Emacs Lisp interpreter.
2 Copyright (C) 1985,86,87,93,94,95,97,1998 Free Software Foundation, Inc. 2 Copyright (C) 1985,86,87,93,94,95,97,98,1999 Free Software Foundation, Inc.
3 3
4This file is part of GNU Emacs. 4This file is part of GNU Emacs.
5 5
@@ -27,6 +27,15 @@ Boston, MA 02111-1307, USA. */
27 27
28 28
29/* These are default choices for the types to use. */ 29/* These are default choices for the types to use. */
30#ifdef _LP64
31#ifndef EMACS_INT
32#define EMACS_INT long
33#define BITS_PER_EMACS_INT BITS_PER_LONG
34#endif
35#ifndef EMACS_UINT
36#define EMACS_UINT unsigned long
37#endif
38#else /* not _LP64 */
30#ifndef EMACS_INT 39#ifndef EMACS_INT
31#define EMACS_INT int 40#define EMACS_INT int
32#define BITS_PER_EMACS_INT BITS_PER_INT 41#define BITS_PER_EMACS_INT BITS_PER_INT
@@ -34,6 +43,7 @@ Boston, MA 02111-1307, USA. */
34#ifndef EMACS_UINT 43#ifndef EMACS_UINT
35#define EMACS_UINT unsigned int 44#define EMACS_UINT unsigned int
36#endif 45#endif
46#endif
37 47
38/* Define the fundamental Lisp data structures. */ 48/* Define the fundamental Lisp data structures. */
39 49
@@ -98,7 +108,7 @@ enum Lisp_Misc_Type
98 108
99/* These values are overridden by the m- file on some machines. */ 109/* These values are overridden by the m- file on some machines. */
100#ifndef VALBITS 110#ifndef VALBITS
101#define VALBITS 28 111#define VALBITS (BITS_PER_EMACS_INT - 4)
102#endif 112#endif
103 113
104#ifndef GCTYPEBITS 114#ifndef GCTYPEBITS
@@ -212,7 +222,7 @@ Lisp_Object;
212 rather than being part of a string block. */ 222 rather than being part of a string block. */
213 223
214#ifndef MARKBIT 224#ifndef MARKBIT
215#define MARKBIT ((int) ((unsigned int) 1 << (VALBITS + GCTYPEBITS))) 225#define MARKBIT ((EMACS_INT) ((EMACS_UINT) 1 << (VALBITS + GCTYPEBITS)))
216#endif /*MARKBIT */ 226#endif /*MARKBIT */
217 227
218/* In the size word of a vector, this bit means the vector has been marked. 228/* In the size word of a vector, this bit means the vector has been marked.
@@ -278,7 +288,7 @@ enum pvec_type
278/* Extract the value of a Lisp_Object as a signed integer. */ 288/* Extract the value of a Lisp_Object as a signed integer. */
279 289
280#ifndef XINT /* Some machines need to do this differently. */ 290#ifndef XINT /* Some machines need to do this differently. */
281#define XINT(a) (((a) << (BITS_PER_INT-VALBITS)) >> (BITS_PER_INT-VALBITS)) 291#define XINT(a) (((a) << (BITS_PER_EMACS_INT-VALBITS)) >> (BITS_PER_EMACS_INT-VALBITS))
282#endif 292#endif
283 293
284/* Extract the value as an unsigned integer. This is a basis 294/* Extract the value as an unsigned integer. This is a basis
@@ -1332,7 +1342,7 @@ typedef unsigned char UCHAR;
1332 1342
1333/* Cast pointers to this type to compare them. Some machines want int. */ 1343/* Cast pointers to this type to compare them. Some machines want int. */
1334#ifndef PNTR_COMPARISON_TYPE 1344#ifndef PNTR_COMPARISON_TYPE
1335#define PNTR_COMPARISON_TYPE unsigned int 1345#define PNTR_COMPARISON_TYPE EMACS_UINT
1336#endif 1346#endif
1337 1347
1338/* Define a built-in function for calling from Lisp. 1348/* Define a built-in function for calling from Lisp.
@@ -1765,6 +1775,7 @@ EXFUN (Ffind_operation_coding_system, MANY);
1765EXFUN (Fencode_coding_string, 3); 1775EXFUN (Fencode_coding_string, 3);
1766EXFUN (Fdecode_coding_string, 3); 1776EXFUN (Fdecode_coding_string, 3);
1767extern Lisp_Object detect_coding_system P_ ((unsigned char *, int, int)); 1777extern Lisp_Object detect_coding_system P_ ((unsigned char *, int, int));
1778Lisp_Object code_convert_string_norecord P_ ((Lisp_Object, Lisp_Object, int));
1768extern void init_coding P_ ((void)); 1779extern void init_coding P_ ((void));
1769extern void init_coding_once P_ ((void)); 1780extern void init_coding_once P_ ((void));
1770extern void syms_of_coding P_ ((void)); 1781extern void syms_of_coding P_ ((void));
@@ -2506,6 +2517,16 @@ extern Lisp_Object decode_env_path P_ ((char *, char *));
2506extern Lisp_Object Vinvocation_name, Vinvocation_directory; 2517extern Lisp_Object Vinvocation_name, Vinvocation_directory;
2507extern Lisp_Object Vinstallation_directory; 2518extern Lisp_Object Vinstallation_directory;
2508EXFUN (Fkill_emacs, 1); 2519EXFUN (Fkill_emacs, 1);
2520#if HAVE_SETLOCALE
2521void fixup_locale P_ ((void));
2522void synchronize_messages_locale P_ ((void));
2523void synchronize_time_locale P_ ((void));
2524#else
2525#define setlocale(category, locale)
2526#define fixup_locale()
2527#define synchronize_messages_locale()
2528#define synchronize_time_locale()
2529#endif
2509void shut_down_emacs P_ ((int, int, Lisp_Object)); 2530void shut_down_emacs P_ ((int, int, Lisp_Object));
2510/* Nonzero means don't do interactive redisplay and don't change tty modes */ 2531/* Nonzero means don't do interactive redisplay and don't change tty modes */
2511extern int noninteractive; 2532extern int noninteractive;
@@ -2627,6 +2648,10 @@ extern int set_window_size P_ ((int, int, int));
2627extern void create_process P_ ((Lisp_Object, char **, Lisp_Object)); 2648extern void create_process P_ ((Lisp_Object, char **, Lisp_Object));
2628extern int tabs_safe_p P_ ((void)); 2649extern int tabs_safe_p P_ ((void));
2629extern void init_baud_rate P_ ((void)); 2650extern void init_baud_rate P_ ((void));
2651extern int emacs_open P_ ((char *, int, int));
2652extern int emacs_close P_ ((int));
2653extern int emacs_read P_ ((int, char *, unsigned int));
2654extern int emacs_write P_ ((int, char *, unsigned int));
2630 2655
2631/* defined in filelock.c */ 2656/* defined in filelock.c */
2632EXFUN (Funlock_buffer, 0); 2657EXFUN (Funlock_buffer, 0);
diff --git a/src/lread.c b/src/lread.c
index c14554f5b31..e08b4ddcdca 100644
--- a/src/lread.c
+++ b/src/lread.c
@@ -1,5 +1,5 @@
1/* Lisp parsing and input streams. 1/* Lisp parsing and input streams.
2 Copyright (C) 1985, 86, 87, 88, 89, 93, 94, 95, 97, 1998 2 Copyright (C) 1985, 86, 87, 88, 89, 93, 94, 95, 97, 98, 1999
3 Free Software Foundation, Inc. 3 Free Software Foundation, Inc.
4 4
5This file is part of GNU Emacs. 5This file is part of GNU Emacs.
@@ -58,10 +58,6 @@ Boston, MA 02111-1307, USA. */
58#endif 58#endif
59 59
60#ifdef LISP_FLOAT_TYPE 60#ifdef LISP_FLOAT_TYPE
61#ifdef STDC_HEADERS
62#include <stdlib.h>
63#endif
64
65#include <math.h> 61#include <math.h>
66#endif /* LISP_FLOAT_TYPE */ 62#endif /* LISP_FLOAT_TYPE */
67 63
@@ -73,6 +69,14 @@ Boston, MA 02111-1307, USA. */
73#define O_RDONLY 0 69#define O_RDONLY 0
74#endif 70#endif
75 71
72#ifdef HAVE_FTELLO
73#define file_offset off_t
74#define file_tell ftello
75#else
76#define file_offset long
77#define file_tell ftell
78#endif
79
76extern int errno; 80extern int errno;
77 81
78Lisp_Object Qread_char, Qget_file_char, Qstandard_input, Qcurrent_load_list; 82Lisp_Object Qread_char, Qget_file_char, Qstandard_input, Qcurrent_load_list;
@@ -156,7 +160,7 @@ static int saved_doc_string_size;
156/* Length of actual data in saved_doc_string. */ 160/* Length of actual data in saved_doc_string. */
157static int saved_doc_string_length; 161static int saved_doc_string_length;
158/* This is the file position that string came from. */ 162/* This is the file position that string came from. */
159static int saved_doc_string_position; 163static file_offset saved_doc_string_position;
160 164
161/* This contains the previous string skipped with #@. 165/* This contains the previous string skipped with #@.
162 We copy it from saved_doc_string when a new string 166 We copy it from saved_doc_string when a new string
@@ -167,7 +171,7 @@ static int prev_saved_doc_string_size;
167/* Length of actual data in prev_saved_doc_string. */ 171/* Length of actual data in prev_saved_doc_string. */
168static int prev_saved_doc_string_length; 172static int prev_saved_doc_string_length;
169/* This is the file position that string came from. */ 173/* This is the file position that string came from. */
170static int prev_saved_doc_string_position; 174static file_offset prev_saved_doc_string_position;
171 175
172/* Nonzero means inside a new-style backquote 176/* Nonzero means inside a new-style backquote
173 with no surrounding parentheses. 177 with no surrounding parentheses.
@@ -714,7 +718,7 @@ Return t if file exists.")
714 if (!NILP (Vload_source_file_function)) 718 if (!NILP (Vload_source_file_function))
715 { 719 {
716 if (fd != 0) 720 if (fd != 0)
717 close (fd); 721 emacs_close (fd);
718 return call4 (Vload_source_file_function, found, file, 722 return call4 (Vload_source_file_function, found, file,
719 NILP (noerror) ? Qnil : Qt, 723 NILP (noerror) ? Qnil : Qt,
720 NILP (nomessage) ? Qnil : Qt); 724 NILP (nomessage) ? Qnil : Qt);
@@ -722,14 +726,14 @@ Return t if file exists.")
722 } 726 }
723 727
724#ifdef WINDOWSNT 728#ifdef WINDOWSNT
725 close (fd); 729 emacs_close (fd);
726 stream = fopen ((char *) XSTRING (found)->data, fmode); 730 stream = fopen ((char *) XSTRING (found)->data, fmode);
727#else /* not WINDOWSNT */ 731#else /* not WINDOWSNT */
728 stream = fdopen (fd, fmode); 732 stream = fdopen (fd, fmode);
729#endif /* not WINDOWSNT */ 733#endif /* not WINDOWSNT */
730 if (stream == 0) 734 if (stream == 0)
731 { 735 {
732 close (fd); 736 emacs_close (fd);
733 error ("Failure to create stdio stream for %s", XSTRING (file)->data); 737 error ("Failure to create stdio stream for %s", XSTRING (file)->data);
734 } 738 }
735 739
@@ -817,7 +821,7 @@ close_load_descs ()
817#ifndef WINDOWSNT 821#ifndef WINDOWSNT
818 Lisp_Object tail; 822 Lisp_Object tail;
819 for (tail = load_descriptor_list; !NILP (tail); tail = XCDR (tail)) 823 for (tail = load_descriptor_list; !NILP (tail); tail = XCDR (tail))
820 close (XFASTINT (XCAR (tail))); 824 emacs_close (XFASTINT (XCAR (tail)));
821#endif 825#endif
822} 826}
823 827
@@ -966,7 +970,7 @@ openp (path, str, suffix, storeptr, exec_only)
966 if (exec_only) 970 if (exec_only)
967 fd = (access (fn, X_OK) == 0) ? 1 : -1; 971 fd = (access (fn, X_OK) == 0) ? 1 : -1;
968 else 972 else
969 fd = open (fn, O_RDONLY, 0); 973 fd = emacs_open (fn, O_RDONLY, 0);
970 974
971 if (fd >= 0) 975 if (fd >= 0)
972 { 976 {
@@ -1751,7 +1755,7 @@ read1 (readcharfun, pch, first_in_list)
1751 { 1755 {
1752 char *temp = saved_doc_string; 1756 char *temp = saved_doc_string;
1753 int temp_size = saved_doc_string_size; 1757 int temp_size = saved_doc_string_size;
1754 int temp_pos = saved_doc_string_position; 1758 file_offset temp_pos = saved_doc_string_position;
1755 int temp_len = saved_doc_string_length; 1759 int temp_len = saved_doc_string_length;
1756 1760
1757 saved_doc_string = prev_saved_doc_string; 1761 saved_doc_string = prev_saved_doc_string;
@@ -1777,7 +1781,7 @@ read1 (readcharfun, pch, first_in_list)
1777 saved_doc_string_size); 1781 saved_doc_string_size);
1778 } 1782 }
1779 1783
1780 saved_doc_string_position = ftell (instream); 1784 saved_doc_string_position = file_tell (instream);
1781 1785
1782 /* Copy that many characters into saved_doc_string. */ 1786 /* Copy that many characters into saved_doc_string. */
1783 for (i = 0; i < nskip && c >= 0; i++) 1787 for (i = 0; i < nskip && c >= 0; i++)
@@ -3129,11 +3133,6 @@ init_lread ()
3129 char *normal; 3133 char *normal;
3130 int turn_off_warning = 0; 3134 int turn_off_warning = 0;
3131 3135
3132#ifdef HAVE_SETLOCALE
3133 /* Make sure numbers are parsed as we expect. */
3134 setlocale (LC_NUMERIC, "C");
3135#endif /* HAVE_SETLOCALE */
3136
3137 /* Compute the default load-path. */ 3136 /* Compute the default load-path. */
3138#ifdef CANNOT_DUMP 3137#ifdef CANNOT_DUMP
3139 normal = PATH_LOADSEARCH; 3138 normal = PATH_LOADSEARCH;
diff --git a/src/mktime.c b/src/mktime.c
index de5b47ddeff..3b3330eea06 100644
--- a/src/mktime.c
+++ b/src/mktime.c
@@ -1,4 +1,5 @@
1/* Copyright (C) 1993, 94, 95, 96, 97, 98 Free Software Foundation, Inc. 1/* Convert a `struct tm' to a time_t value.
2 Copyright (C) 1993, 94, 95, 96, 97, 98, 99 Free Software Foundation, Inc.
2 Contributed by Paul Eggert (eggert@twinsun.com). 3 Contributed by Paul Eggert (eggert@twinsun.com).
3 4
4 NOTE: The canonical source of this file is maintained with the GNU C Library. 5 NOTE: The canonical source of this file is maintained with the GNU C Library.
@@ -27,14 +28,8 @@
27# include <config.h> 28# include <config.h>
28#endif 29#endif
29 30
30/* Some systems need this in order to declare localtime_r properly. */
31#ifndef _REENTRANT
32# define _REENTRANT 1
33#endif
34
35#ifdef _LIBC 31#ifdef _LIBC
36# define HAVE_LIMITS_H 1 32# define HAVE_LIMITS_H 1
37# define HAVE_LOCALTIME_R 1
38# define STDC_HEADERS 1 33# define STDC_HEADERS 1
39#endif 34#endif
40 35
@@ -62,7 +57,7 @@
62#endif /* DEBUG */ 57#endif /* DEBUG */
63 58
64#ifndef __P 59#ifndef __P
65# if defined (__GNUC__) || (defined (__STDC__) && __STDC__) 60# if defined __GNUC__ || (defined __STDC__ && __STDC__)
66# define __P(args) args 61# define __P(args) args
67# else 62# else
68# define __P(args) () 63# define __P(args) ()
@@ -114,26 +109,15 @@ const unsigned short int __mon_yday[2][13] =
114 { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 } 109 { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 }
115 }; 110 };
116 111
117static struct tm *ranged_convert __P ((struct tm *(*) __P ((const time_t *,
118 struct tm *)),
119 time_t *, struct tm *));
120static time_t ydhms_tm_diff __P ((int, int, int, int, int, const struct tm *));
121time_t __mktime_internal __P ((struct tm *,
122 struct tm *(*) (const time_t *, struct tm *),
123 time_t *));
124
125 112
126#ifdef _LIBC 113#ifdef _LIBC
127# define localtime_r __localtime_r 114# define my_mktime_localtime_r __localtime_r
128#else 115#else
129# if ! HAVE_LOCALTIME_R && ! defined localtime_r 116/* If we're a mktime substitute in a GNU program, then prefer
130/* Approximate localtime_r as best we can in its absence. */ 117 localtime to localtime_r, since many localtime_r implementations
131# define localtime_r my_mktime_localtime_r 118 are buggy. */
132static struct tm *localtime_r __P ((const time_t *, struct tm *));
133static struct tm * 119static struct tm *
134localtime_r (t, tp) 120my_mktime_localtime_r (const time_t *t, struct tm *tp)
135 const time_t *t;
136 struct tm *tp;
137{ 121{
138 struct tm *l = localtime (t); 122 struct tm *l = localtime (t);
139 if (! l) 123 if (! l)
@@ -141,7 +125,6 @@ localtime_r (t, tp)
141 *tp = *l; 125 *tp = *l;
142 return tp; 126 return tp;
143} 127}
144# endif /* ! HAVE_LOCALTIME_R && ! defined (localtime_r) */
145#endif /* ! _LIBC */ 128#endif /* ! _LIBC */
146 129
147 130
@@ -152,9 +135,8 @@ localtime_r (t, tp)
152 If TP is null, return a nonzero value. 135 If TP is null, return a nonzero value.
153 If overflow occurs, yield the low order bits of the correct answer. */ 136 If overflow occurs, yield the low order bits of the correct answer. */
154static time_t 137static time_t
155ydhms_tm_diff (year, yday, hour, min, sec, tp) 138ydhms_tm_diff (int year, int yday, int hour, int min, int sec,
156 int year, yday, hour, min, sec; 139 const struct tm *tp)
157 const struct tm *tp;
158{ 140{
159 if (!tp) 141 if (!tp)
160 return 1; 142 return 1;
@@ -181,32 +163,12 @@ ydhms_tm_diff (year, yday, hour, min, sec, tp)
181 } 163 }
182} 164}
183 165
184
185static time_t localtime_offset;
186
187/* Convert *TP to a time_t value. */
188time_t
189mktime (tp)
190 struct tm *tp;
191{
192#ifdef _LIBC
193 /* POSIX.1 8.1.1 requires that whenever mktime() is called, the
194 time zone names contained in the external variable `tzname' shall
195 be set as if the tzset() function had been called. */
196 __tzset ();
197#endif
198
199 return __mktime_internal (tp, localtime_r, &localtime_offset);
200}
201
202/* Use CONVERT to convert *T to a broken down time in *TP. 166/* Use CONVERT to convert *T to a broken down time in *TP.
203 If *T is out of range for conversion, adjust it so that 167 If *T is out of range for conversion, adjust it so that
204 it is the nearest in-range value and then convert that. */ 168 it is the nearest in-range value and then convert that. */
205static struct tm * 169static struct tm *
206ranged_convert (convert, t, tp) 170ranged_convert (struct tm *(*convert) (const time_t *, struct tm *),
207 struct tm *(*convert) __P ((const time_t *, struct tm *)); 171 time_t *t, struct tm *tp)
208 time_t *t;
209 struct tm *tp;
210{ 172{
211 struct tm *r; 173 struct tm *r;
212 174
@@ -253,19 +215,18 @@ ranged_convert (convert, t, tp)
253 compared to what the result would be for UTC without leap seconds. 215 compared to what the result would be for UTC without leap seconds.
254 If *OFFSET's guess is correct, only one CONVERT call is needed. */ 216 If *OFFSET's guess is correct, only one CONVERT call is needed. */
255time_t 217time_t
256__mktime_internal (tp, convert, offset) 218__mktime_internal (struct tm *tp,
257 struct tm *tp; 219 struct tm *(*convert) (const time_t *, struct tm *),
258 struct tm *(*convert) __P ((const time_t *, struct tm *)); 220 time_t *offset)
259 time_t *offset;
260{ 221{
261 time_t t, dt, t0; 222 time_t t, dt, t0, t1, t2;
262 struct tm tm; 223 struct tm tm;
263 224
264 /* The maximum number of probes (calls to CONVERT) should be enough 225 /* The maximum number of probes (calls to CONVERT) should be enough
265 to handle any combinations of time zone rule changes, solar time, 226 to handle any combinations of time zone rule changes, solar time,
266 and leap seconds. POSIX.1 prohibits leap seconds, but some hosts 227 leap seconds, and oscillations around a spring-forward gap.
267 have them anyway. */ 228 POSIX.1 prohibits leap seconds, but some hosts have them anyway. */
268 int remaining_probes = 4; 229 int remaining_probes = 6;
269 230
270 /* Time requested. Copy it in case CONVERT modifies *TP; this can 231 /* Time requested. Copy it in case CONVERT modifies *TP; this can
271 occur if TP is localtime's returned value and CONVERT is localtime. */ 232 occur if TP is localtime's returned value and CONVERT is localtime. */
@@ -311,36 +272,52 @@ __mktime_internal (tp, convert, offset)
311 tm.tm_yday = tm.tm_hour = tm.tm_min = tm.tm_sec = 0; 272 tm.tm_yday = tm.tm_hour = tm.tm_min = tm.tm_sec = 0;
312 t0 = ydhms_tm_diff (year, yday, hour, min, sec, &tm); 273 t0 = ydhms_tm_diff (year, yday, hour, min, sec, &tm);
313 274
314 for (t = t0 + *offset; 275 for (t = t1 = t2 = t0 + *offset;
315 (dt = ydhms_tm_diff (year, yday, hour, min, sec, 276 (dt = ydhms_tm_diff (year, yday, hour, min, sec,
316 ranged_convert (convert, &t, &tm))); 277 ranged_convert (convert, &t, &tm)));
317 t += dt) 278 t1 = t2, t2 = t, t += dt)
318 if (--remaining_probes == 0) 279 if (t == t1 && t != t2
280 && (isdst < 0 || tm.tm_isdst < 0
281 || (isdst != 0) != (tm.tm_isdst != 0)))
282 /* We can't possibly find a match, as we are oscillating
283 between two values. The requested time probably falls
284 within a spring-forward gap of size DT. Follow the common
285 practice in this case, which is to return a time that is DT
286 away from the requested time, preferring a time whose
287 tm_isdst differs from the requested value. In practice,
288 this is more useful than returning -1. */
289 break;
290 else if (--remaining_probes == 0)
319 return -1; 291 return -1;
320 292
321 /* Check whether tm.tm_isdst has the requested value, if any. */ 293 /* If we have a match, check whether tm.tm_isdst has the requested
322 if (0 <= isdst && 0 <= tm.tm_isdst) 294 value, if any. */
295 if (dt == 0 && isdst != tm.tm_isdst && 0 <= isdst && 0 <= tm.tm_isdst)
323 { 296 {
324 int dst_diff = (isdst != 0) - (tm.tm_isdst != 0); 297 /* tm.tm_isdst has the wrong value. Look for a neighboring
325 if (dst_diff) 298 time with the right value, and use its UTC offset.
299 Heuristic: probe the previous three calendar quarters (approximately),
300 looking for the desired isdst. This isn't perfect,
301 but it's good enough in practice. */
302 int quarter = 7889238; /* seconds per average 1/4 Gregorian year */
303 int i;
304
305 /* If we're too close to the time_t limit, look in future quarters. */
306 if (t < TIME_T_MIN + 3 * quarter)
307 quarter = -quarter;
308
309 for (i = 1; i <= 3; i++)
326 { 310 {
327 /* Move two hours in the direction indicated by the disagreement, 311 time_t ot = t - i * quarter;
328 probe some more, and switch to a new time if found. 312 struct tm otm;
329 The largest known fallback due to daylight savings is two hours: 313 ranged_convert (convert, &ot, &otm);
330 once, in Newfoundland, 1988-10-30 02:00 -> 00:00. */ 314 if (otm.tm_isdst == isdst)
331 time_t ot = t - 2 * 60 * 60 * dst_diff;
332 while (--remaining_probes != 0)
333 { 315 {
334 struct tm otm; 316 /* We found the desired tm_isdst.
335 if (! (dt = ydhms_tm_diff (year, yday, hour, min, sec, 317 Extrapolate back to the desired time. */
336 ranged_convert (convert, &ot, &otm)))) 318 t = ot + ydhms_tm_diff (year, yday, hour, min, sec, &otm);
337 { 319 ranged_convert (convert, &t, &tm);
338 t = ot; 320 break;
339 tm = otm;
340 break;
341 }
342 if ((ot += dt) == t)
343 break; /* Avoid a redundant probe. */
344 } 321 }
345 } 322 }
346 } 323 }
@@ -386,6 +363,24 @@ __mktime_internal (tp, convert, offset)
386 return t; 363 return t;
387} 364}
388 365
366
367static time_t localtime_offset;
368
369/* Convert *TP to a time_t value. */
370time_t
371mktime (tp)
372 struct tm *tp;
373{
374#ifdef _LIBC
375 /* POSIX.1 8.1.1 requires that whenever mktime() is called, the
376 time zone names contained in the external variable `tzname' shall
377 be set as if the tzset() function had been called. */
378 __tzset ();
379#endif
380
381 return __mktime_internal (tp, my_mktime_localtime_r, &localtime_offset);
382}
383
389#ifdef weak_alias 384#ifdef weak_alias
390weak_alias (mktime, timelocal) 385weak_alias (mktime, timelocal)
391#endif 386#endif
@@ -530,6 +525,6 @@ main (argc, argv)
530 525
531/* 526/*
532Local Variables: 527Local Variables:
533compile-command: "gcc -DDEBUG -D__EXTENSIONS__ -DHAVE_LIMITS_H -DHAVE_LOCALTIME_R -DSTDC_HEADERS -Wall -W -O -g mktime.c -o mktime" 528compile-command: "gcc -DDEBUG -DHAVE_LIMITS_H -DSTDC_HEADERS -Wall -W -O -g mktime.c -o mktime"
534End: 529End:
535*/ 530*/
diff --git a/src/msdos.c b/src/msdos.c
index 1cea4af486c..7b8d74da31f 100644
--- a/src/msdos.c
+++ b/src/msdos.c
@@ -1,5 +1,5 @@
1/* MS-DOS specific C utilities. -*- coding: raw-text -*- 1/* MS-DOS specific C utilities. -*- coding: raw-text -*-
2 Copyright (C) 1993, 1994, 1995, 1996, 1997 Free Software Foundation, Inc. 2 Copyright (C) 1993, 94, 95, 96, 97, 1999 Free Software Foundation, Inc.
3 3
4This file is part of GNU Emacs. 4This file is part of GNU Emacs.
5 5
@@ -3654,9 +3654,9 @@ run_msdos_command (argv, working_dir, tempin, tempout, temperr, envv)
3654 dup2 (inbak, 0); 3654 dup2 (inbak, 0);
3655 dup2 (outbak, 1); 3655 dup2 (outbak, 1);
3656 dup2 (errbak, 2); 3656 dup2 (errbak, 2);
3657 close (inbak); 3657 emacs_close (inbak);
3658 close (outbak); 3658 emacs_close (outbak);
3659 close (errbak); 3659 emacs_close (errbak);
3660 3660
3661 dos_ttraw (); 3661 dos_ttraw ();
3662 if (have_mouse > 0) 3662 if (have_mouse > 0)
diff --git a/src/print.c b/src/print.c
index 163c23cb8be..ad45035c7ac 100644
--- a/src/print.c
+++ b/src/print.c
@@ -1,5 +1,5 @@
1/* Lisp object printing and output streams. 1/* Lisp object printing and output streams.
2 Copyright (C) 1985, 86, 88, 93, 94, 95, 97, 1998 2 Copyright (C) 1985, 86, 88, 93, 94, 95, 97, 98, 1999
3 Free Software Foundation, Inc. 3 Free Software Foundation, Inc.
4 4
5This file is part of GNU Emacs. 5This file is part of GNU Emacs.
@@ -60,7 +60,6 @@ Lisp_Object Vfloat_output_format, Qfloat_output_format;
60 60
61#if STDC_HEADERS 61#if STDC_HEADERS
62#include <float.h> 62#include <float.h>
63#include <stdlib.h>
64#endif 63#endif
65 64
66/* Default to values appropriate for IEEE floating point. */ 65/* Default to values appropriate for IEEE floating point. */
@@ -960,6 +959,19 @@ float_to_string (buf, data)
960 /* Check for NaN in a way that won't fail if there are no NaNs. */ 959 /* Check for NaN in a way that won't fail if there are no NaNs. */
961 if (! (data * 0.0 >= 0.0)) 960 if (! (data * 0.0 >= 0.0))
962 { 961 {
962 /* Prepend "-" if the NaN's sign bit is negative.
963 The sign bit of a double is the bit that is 1 in -0.0. */
964 int i;
965 union { double d; char c[sizeof (double)]; } u_data, u_minus_zero;
966 u_data.d = data;
967 u_minus_zero.d = - 0.0;
968 for (i = 0; i < sizeof (double); i++)
969 if (u_data.c[i] & u_minus_zero.c[i])
970 {
971 *buf++ = '-';
972 break;
973 }
974
963 strcpy (buf, "0.0e+NaN"); 975 strcpy (buf, "0.0e+NaN");
964 return; 976 return;
965 } 977 }
diff --git a/src/process.c b/src/process.c
index d2804763e3d..144e69af7c6 100644
--- a/src/process.c
+++ b/src/process.c
@@ -1,5 +1,5 @@
1/* Asynchronous subprocess control for GNU Emacs. 1/* Asynchronous subprocess control for GNU Emacs.
2 Copyright (C) 1985, 86, 87, 88, 93, 94, 95, 96, 1998 2 Copyright (C) 1985, 86, 87, 88, 93, 94, 95, 96, 98, 1999
3 Free Software Foundation, Inc. 3 Free Software Foundation, Inc.
4 4
5This file is part of GNU Emacs. 5This file is part of GNU Emacs.
@@ -20,10 +20,10 @@ the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20Boston, MA 02111-1307, USA. */ 20Boston, MA 02111-1307, USA. */
21 21
22 22
23#include <signal.h>
24
25#include <config.h> 23#include <config.h>
26 24
25#include <signal.h>
26
27/* This file is split into two parts by the following preprocessor 27/* This file is split into two parts by the following preprocessor
28 conditional. The 'then' clause contains all of the support for 28 conditional. The 'then' clause contains all of the support for
29 asynchronous subprocesses. The 'else' clause contains stub 29 asynchronous subprocesses. The 'else' clause contains stub
@@ -155,6 +155,7 @@ extern char *sys_errlist[];
155extern int h_errno; 155extern int h_errno;
156#endif 156#endif
157 157
158#ifndef HAVE_STRSIGNAL
158#ifndef SYS_SIGLIST_DECLARED 159#ifndef SYS_SIGLIST_DECLARED
159#ifndef VMS 160#ifndef VMS
160#ifndef BSD4_1 161#ifndef BSD4_1
@@ -196,6 +197,7 @@ char *sys_siglist[] =
196#endif 197#endif
197#endif /* VMS */ 198#endif /* VMS */
198#endif /* ! SYS_SIGLIST_DECLARED */ 199#endif /* ! SYS_SIGLIST_DECLARED */
200#endif /* ! HAVE_STRSIGNAL */
199 201
200/* t means use pty, nil means use a pipe, 202/* t means use pty, nil means use a pipe,
201 maybe other values to come. */ 203 maybe other values to come. */
@@ -357,16 +359,9 @@ status_message (status)
357 359
358 if (EQ (symbol, Qsignal) || EQ (symbol, Qstop)) 360 if (EQ (symbol, Qsignal) || EQ (symbol, Qstop))
359 { 361 {
360 char *signame = 0; 362 char *signame;
361 if (code < NSIG) 363 synchronize_messages_locale ();
362 { 364 signame = strsignal (code);
363#ifndef VMS
364 /* Cast to suppress warning if the table has const char *. */
365 signame = (char *) sys_siglist[code];
366#else
367 signame = sys_errlist[code];
368#endif
369 }
370 if (signame == 0) 365 if (signame == 0)
371 signame = "unknown"; 366 signame = "unknown";
372 string = build_string (signame); 367 string = build_string (signame);
@@ -426,7 +421,7 @@ allocate_pty ()
426#else /* no PTY_OPEN */ 421#else /* no PTY_OPEN */
427#ifdef IRIS 422#ifdef IRIS
428 /* Unusual IRIS code */ 423 /* Unusual IRIS code */
429 *ptyv = open ("/dev/ptc", O_RDWR | O_NDELAY, 0); 424 *ptyv = emacs_open ("/dev/ptc", O_RDWR | O_NDELAY, 0);
430 if (fd < 0) 425 if (fd < 0)
431 return -1; 426 return -1;
432 if (fstat (fd, &stb) < 0) 427 if (fstat (fd, &stb) < 0)
@@ -441,9 +436,9 @@ allocate_pty ()
441 else 436 else
442 failed_count = 0; 437 failed_count = 0;
443#ifdef O_NONBLOCK 438#ifdef O_NONBLOCK
444 fd = open (pty_name, O_RDWR | O_NONBLOCK, 0); 439 fd = emacs_open (pty_name, O_RDWR | O_NONBLOCK, 0);
445#else 440#else
446 fd = open (pty_name, O_RDWR | O_NDELAY, 0); 441 fd = emacs_open (pty_name, O_RDWR | O_NDELAY, 0);
447#endif 442#endif
448#endif /* not IRIS */ 443#endif /* not IRIS */
449#endif /* no PTY_OPEN */ 444#endif /* no PTY_OPEN */
@@ -460,7 +455,7 @@ allocate_pty ()
460#ifndef UNIPLUS 455#ifndef UNIPLUS
461 if (access (pty_name, 6) != 0) 456 if (access (pty_name, 6) != 0)
462 { 457 {
463 close (fd); 458 emacs_close (fd);
464#if !defined(IRIS) && !defined(__sgi) 459#if !defined(IRIS) && !defined(__sgi)
465 continue; 460 continue;
466#else 461#else
@@ -1361,9 +1356,9 @@ create_process (process, new_argv, current_dir)
1361#ifdef O_NOCTTY 1356#ifdef O_NOCTTY
1362 /* Don't let this terminal become our controlling terminal 1357 /* Don't let this terminal become our controlling terminal
1363 (in case we don't have one). */ 1358 (in case we don't have one). */
1364 forkout = forkin = open (pty_name, O_RDWR | O_NOCTTY, 0); 1359 forkout = forkin = emacs_open (pty_name, O_RDWR | O_NOCTTY, 0);
1365#else 1360#else
1366 forkout = forkin = open (pty_name, O_RDWR, 0); 1361 forkout = forkin = emacs_open (pty_name, O_RDWR, 0);
1367#endif 1362#endif
1368 if (forkin < 0) 1363 if (forkin < 0)
1369 report_file_error ("Opening pty", Qnil); 1364 report_file_error ("Opening pty", Qnil);
@@ -1392,8 +1387,8 @@ create_process (process, new_argv, current_dir)
1392 tem = pipe (sv); 1387 tem = pipe (sv);
1393 if (tem < 0) 1388 if (tem < 0)
1394 { 1389 {
1395 close (inchannel); 1390 emacs_close (inchannel);
1396 close (forkout); 1391 emacs_close (forkout);
1397 report_file_error ("Creating pipe", Qnil); 1392 report_file_error ("Creating pipe", Qnil);
1398 } 1393 }
1399 outchannel = sv[1]; 1394 outchannel = sv[1];
@@ -1592,7 +1587,7 @@ create_process (process, new_argv, current_dir)
1592 tcgetattr (xforkin, &t); 1587 tcgetattr (xforkin, &t);
1593 t.c_lflag = LDISC1; 1588 t.c_lflag = LDISC1;
1594 if (tcsetattr (xforkin, TCSANOW, &t) < 0) 1589 if (tcsetattr (xforkin, TCSANOW, &t) < 0)
1595 write (1, "create_process/tcsetattr LDISC1 failed\n", 39); 1590 emacs_write (1, "create_process/tcsetattr LDISC1 failed\n", 39);
1596 } 1591 }
1597#else 1592#else
1598#if defined (NTTYDISC) && defined (TIOCSETD) 1593#if defined (NTTYDISC) && defined (TIOCSETD)
@@ -1611,9 +1606,9 @@ create_process (process, new_argv, current_dir)
1611 { 1606 {
1612 /* I wonder: would just ioctl (0, TIOCNOTTY, 0) work here? 1607 /* I wonder: would just ioctl (0, TIOCNOTTY, 0) work here?
1613 I can't test it since I don't have 4.3. */ 1608 I can't test it since I don't have 4.3. */
1614 int j = open ("/dev/tty", O_RDWR, 0); 1609 int j = emacs_open ("/dev/tty", O_RDWR, 0);
1615 ioctl (j, TIOCNOTTY, 0); 1610 ioctl (j, TIOCNOTTY, 0);
1616 close (j); 1611 emacs_close (j);
1617#ifndef USG 1612#ifndef USG
1618 /* In order to get a controlling terminal on some versions 1613 /* In order to get a controlling terminal on some versions
1619 of BSD, it is necessary to put the process in pgrp 0 1614 of BSD, it is necessary to put the process in pgrp 0
@@ -1642,16 +1637,17 @@ create_process (process, new_argv, current_dir)
1642 int pgrp = getpid (); 1637 int pgrp = getpid ();
1643#endif 1638#endif
1644 1639
1645 /* I wonder if close (open (pty_name, ...)) would work? */ 1640 /* I wonder if emacs_close (emacs_open (pty_name, ...))
1641 would work? */
1646 if (xforkin >= 0) 1642 if (xforkin >= 0)
1647 close (xforkin); 1643 emacs_close (xforkin);
1648 xforkout = xforkin = open (pty_name, O_RDWR, 0); 1644 xforkout = xforkin = emacs_open (pty_name, O_RDWR, 0);
1649 1645
1650 if (xforkin < 0) 1646 if (xforkin < 0)
1651 { 1647 {
1652 write (1, "Couldn't open the pty terminal ", 31); 1648 emacs_write (1, "Couldn't open the pty terminal ", 31);
1653 write (1, pty_name, strlen (pty_name)); 1649 emacs_write (1, pty_name, strlen (pty_name));
1654 write (1, "\n", 1); 1650 emacs_write (1, "\n", 1);
1655 _exit (1); 1651 _exit (1);
1656 } 1652 }
1657 1653
@@ -1717,9 +1713,9 @@ create_process (process, new_argv, current_dir)
1717 if (pid < 0) 1713 if (pid < 0)
1718 { 1714 {
1719 if (forkin >= 0) 1715 if (forkin >= 0)
1720 close (forkin); 1716 emacs_close (forkin);
1721 if (forkin != forkout && forkout >= 0) 1717 if (forkin != forkout && forkout >= 0)
1722 close (forkout); 1718 emacs_close (forkout);
1723 } 1719 }
1724 else 1720 else
1725 { 1721 {
@@ -1738,11 +1734,11 @@ create_process (process, new_argv, current_dir)
1738 alarm (1); 1734 alarm (1);
1739 XPROCESS (process)->subtty = Qnil; 1735 XPROCESS (process)->subtty = Qnil;
1740 if (forkin >= 0) 1736 if (forkin >= 0)
1741 close (forkin); 1737 emacs_close (forkin);
1742 alarm (0); 1738 alarm (0);
1743 start_polling (); 1739 start_polling ();
1744 if (forkin != forkout && forkout >= 0) 1740 if (forkin != forkout && forkout >= 0)
1745 close (forkout); 1741 emacs_close (forkout);
1746 1742
1747#ifdef HAVE_PTYS 1743#ifdef HAVE_PTYS
1748 if (pty_flag) 1744 if (pty_flag)
@@ -1926,7 +1922,7 @@ Fourth arg SERVICE is name of the service desired, or an integer\n\
1926 ret = connect (s, lres->ai_addr, lres->ai_addrlen); 1922 ret = connect (s, lres->ai_addr, lres->ai_addrlen);
1927 if (ret == 0) 1923 if (ret == 0)
1928 break; 1924 break;
1929 close (s); 1925 emacs_close (s);
1930 s = -1; 1926 s = -1;
1931 } 1927 }
1932 1928
@@ -2033,7 +2029,7 @@ Fourth arg SERVICE is name of the service desired, or an integer\n\
2033 /* Discard the unwind protect. */ 2029 /* Discard the unwind protect. */
2034 specpdl_ptr = specpdl + count1; 2030 specpdl_ptr = specpdl + count1;
2035 2031
2036 close (s); 2032 emacs_close (s);
2037 2033
2038 if (interrupt_input) 2034 if (interrupt_input)
2039 request_sigio (); 2035 request_sigio ();
@@ -2200,9 +2196,9 @@ deactivate_process (proc)
2200 give_back_vms_process_stuff (vs); 2196 give_back_vms_process_stuff (vs);
2201 } 2197 }
2202#else 2198#else
2203 close (inchannel); 2199 emacs_close (inchannel);
2204 if (outchannel >= 0 && outchannel != inchannel) 2200 if (outchannel >= 0 && outchannel != inchannel)
2205 close (outchannel); 2201 emacs_close (outchannel);
2206#endif 2202#endif
2207 2203
2208 XSETINT (p->infd, -1); 2204 XSETINT (p->infd, -1);
@@ -2241,9 +2237,9 @@ close_process_descs ()
2241 int in = XINT (XPROCESS (process)->infd); 2237 int in = XINT (XPROCESS (process)->infd);
2242 int out = XINT (XPROCESS (process)->outfd); 2238 int out = XINT (XPROCESS (process)->outfd);
2243 if (in >= 0) 2239 if (in >= 0)
2244 close (in); 2240 emacs_close (in);
2245 if (out >= 0 && in != out) 2241 if (out >= 0 && in != out)
2246 close (out); 2242 emacs_close (out);
2247 } 2243 }
2248 } 2244 }
2249#endif 2245#endif
@@ -2651,7 +2647,7 @@ wait_reading_process_input (time_limit, microsecs, read_kbd, do_display)
2651#endif 2647#endif
2652 } 2648 }
2653 else 2649 else
2654 error ("select error: %s", strerror (xerrno)); 2650 error ("select error: %s", emacs_strerror (xerrno));
2655 } 2651 }
2656#if defined(sun) && !defined(USG5_4) 2652#if defined(sun) && !defined(USG5_4)
2657 else if (nfds > 0 && keyboard_bit_set (&Available) 2653 else if (nfds > 0 && keyboard_bit_set (&Available)
@@ -2955,13 +2951,13 @@ read_process_output (proc, channel)
2955 buf, carryover); 2951 buf, carryover);
2956 2952
2957 if (proc_buffered_char[channel] < 0) 2953 if (proc_buffered_char[channel] < 0)
2958 nbytes = read (channel, buf + carryover, (sizeof buf) - carryover); 2954 nbytes = emacs_read (channel, buf + carryover, (sizeof buf) - carryover);
2959 else 2955 else
2960 { 2956 {
2961 buf[carryover] = proc_buffered_char[channel]; 2957 buf[carryover] = proc_buffered_char[channel];
2962 proc_buffered_char[channel] = -1; 2958 proc_buffered_char[channel] = -1;
2963 nbytes = read (channel, buf + carryover + 1, 2959 nbytes = emacs_read (channel, buf + carryover + 1,
2964 (sizeof buf) - carryover - 1); 2960 (sizeof buf) - carryover - 1);
2965 if (nbytes < 0) 2961 if (nbytes < 0)
2966 nbytes = 1; 2962 nbytes = 1;
2967 else 2963 else
@@ -3452,7 +3448,7 @@ send_process (proc, buf, len, object)
3452 while (this > 0) 3448 while (this > 0)
3453 { 3449 {
3454 old_sigpipe = (SIGTYPE (*) ()) signal (SIGPIPE, send_process_trap); 3450 old_sigpipe = (SIGTYPE (*) ()) signal (SIGPIPE, send_process_trap);
3455 rv = write (XINT (XPROCESS (proc)->outfd), buf, this); 3451 rv = emacs_write (XINT (XPROCESS (proc)->outfd), buf, this);
3456 signal (SIGPIPE, old_sigpipe); 3452 signal (SIGPIPE, old_sigpipe);
3457 3453
3458 if (rv < 0) 3454 if (rv < 0)
@@ -4073,11 +4069,11 @@ text to PROCESS after you call this function.")
4073 shutdown (XINT (XPROCESS (proc)->outfd), 1); 4069 shutdown (XINT (XPROCESS (proc)->outfd), 1);
4074 /* In case of socketpair, outfd == infd, so don't close it. */ 4070 /* In case of socketpair, outfd == infd, so don't close it. */
4075 if (XINT (XPROCESS (proc)->outfd) != XINT (XPROCESS (proc)->infd)) 4071 if (XINT (XPROCESS (proc)->outfd) != XINT (XPROCESS (proc)->infd))
4076 close (XINT (XPROCESS (proc)->outfd)); 4072 emacs_close (XINT (XPROCESS (proc)->outfd));
4077#else /* not HAVE_SHUTDOWN */ 4073#else /* not HAVE_SHUTDOWN */
4078 close (XINT (XPROCESS (proc)->outfd)); 4074 emacs_close (XINT (XPROCESS (proc)->outfd));
4079#endif /* not HAVE_SHUTDOWN */ 4075#endif /* not HAVE_SHUTDOWN */
4080 new_outfd = open (NULL_DEVICE, O_WRONLY); 4076 new_outfd = emacs_open (NULL_DEVICE, O_WRONLY, 0);
4081 old_outfd = XINT (XPROCESS (proc)->outfd); 4077 old_outfd = XINT (XPROCESS (proc)->outfd);
4082 4078
4083 if (!proc_encode_coding_system[new_outfd]) 4079 if (!proc_encode_coding_system[new_outfd])
@@ -4256,17 +4252,11 @@ sigchld_handler (signo)
4256 else if (WIFSIGNALED (w)) 4252 else if (WIFSIGNALED (w))
4257 { 4253 {
4258 int code = WTERMSIG (w); 4254 int code = WTERMSIG (w);
4259 char *signame = 0; 4255 char *signame;
4256
4257 synchronize_messages_locale ();
4258 signame = strsignal (code);
4260 4259
4261 if (code < NSIG)
4262 {
4263#ifndef VMS
4264 /* Suppress warning if the table has const char *. */
4265 signame = (char *) sys_siglist[code];
4266#else
4267 signame = sys_errlist[code];
4268#endif
4269 }
4270 if (signame == 0) 4260 if (signame == 0)
4271 signame = "unknown"; 4261 signame = "unknown";
4272 4262
@@ -4923,7 +4913,7 @@ wait_reading_process_input (time_limit, microsecs, read_kbd, do_display)
4923 if (xerrno == EINTR) 4913 if (xerrno == EINTR)
4924 FD_ZERO (&waitchannels); 4914 FD_ZERO (&waitchannels);
4925 else 4915 else
4926 error ("select error: %s", strerror (xerrno)); 4916 error ("select error: %s", emacs_strerror (xerrno));
4927 } 4917 }
4928#ifdef sun 4918#ifdef sun
4929 else if (nfds > 0 && (waitchannels & 1) && interrupt_input) 4919 else if (nfds > 0 && (waitchannels & 1) && interrupt_input)
diff --git a/src/search.c b/src/search.c
index cbecadcdc00..df7b825edcb 100644
--- a/src/search.c
+++ b/src/search.c
@@ -1,5 +1,5 @@
1/* String search routines for GNU Emacs. 1/* String search routines for GNU Emacs.
2 Copyright (C) 1985, 86, 87, 93, 94, 97, 1998 Free Software Foundation, Inc. 2 Copyright (C) 1985, 86,87,93,94,97,98, 1999 Free Software Foundation, Inc.
3 3
4This file is part of GNU Emacs. 4This file is part of GNU Emacs.
5 5
@@ -20,9 +20,6 @@ Boston, MA 02111-1307, USA. */
20 20
21 21
22#include <config.h> 22#include <config.h>
23#ifdef STDC_HEADERS
24#include <stdlib.h>
25#endif
26#include "lisp.h" 23#include "lisp.h"
27#include "syntax.h" 24#include "syntax.h"
28#include "category.h" 25#include "category.h"
diff --git a/src/sound.c b/src/sound.c
index 871833dba9e..2909e8f0f3f 100644
--- a/src/sound.c
+++ b/src/sound.c
@@ -1,5 +1,5 @@
1/* sound.c -- sound support. 1/* sound.c -- sound support.
2 Copyright (C) 1998 Free Software Foundation. 2 Copyright (C) 1998, 1999 Free Software Foundation.
3 3
4This file is part of GNU Emacs. 4This file is part of GNU Emacs.
5 5
@@ -335,7 +335,7 @@ sound_cleanup (arg)
335 { 335 {
336 sound_device->close (sound_device); 336 sound_device->close (sound_device);
337 if (sound_file->fd > 0) 337 if (sound_file->fd > 0)
338 close (sound_file->fd); 338 emacs_close (sound_file->fd);
339 } 339 }
340} 340}
341 341
@@ -378,7 +378,7 @@ DEFUN ("play-sound", Fplay_sound, Splay_sound, 1, 1, 0,
378 sound_perror ("Open sound file"); 378 sound_perror ("Open sound file");
379 379
380 /* Read the first bytes from the file. */ 380 /* Read the first bytes from the file. */
381 nbytes = read (sf.fd, sf.header, MAX_SOUND_HEADER_BYTES); 381 nbytes = emacs_read (sf.fd, sf.header, MAX_SOUND_HEADER_BYTES);
382 if (nbytes < 0) 382 if (nbytes < 0)
383 sound_perror ("Reading sound file header"); 383 sound_perror ("Reading sound file header");
384 384
@@ -405,7 +405,7 @@ DEFUN ("play-sound", Fplay_sound, Splay_sound, 1, 1, 0,
405 sd.open (&sd); 405 sd.open (&sd);
406 406
407 sf.play (&sf, &sd); 407 sf.play (&sf, &sd);
408 close (sf.fd); 408 emacs_close (sf.fd);
409 sf.fd = -1; 409 sf.fd = -1;
410 sd.close (&sd); 410 sd.close (&sd);
411 sound_device = NULL; 411 sound_device = NULL;
@@ -557,7 +557,7 @@ wav_play (sf, sd)
557 buffer = (char *) alloca (blksize); 557 buffer = (char *) alloca (blksize);
558 lseek (sf->fd, sizeof *header, SEEK_SET); 558 lseek (sf->fd, sizeof *header, SEEK_SET);
559 559
560 while ((nbytes = read (sf->fd, buffer, blksize)) > 0) 560 while ((nbytes = emacs_read (sf->fd, buffer, blksize)) > 0)
561 sd->write (sd, buffer, nbytes); 561 sd->write (sd, buffer, nbytes);
562 562
563 if (nbytes < 0) 563 if (nbytes < 0)
@@ -639,7 +639,7 @@ au_play (sf, sd)
639 639
640 /* Copy sound data to the device. */ 640 /* Copy sound data to the device. */
641 buffer = (char *) alloca (blksize); 641 buffer = (char *) alloca (blksize);
642 while ((nbytes = read (sf->fd, buffer, blksize)) > 0) 642 while ((nbytes = emacs_read (sf->fd, buffer, blksize)) > 0)
643 sd->write (sd, buffer, nbytes); 643 sd->write (sd, buffer, nbytes);
644 644
645 if (nbytes < 0) 645 if (nbytes < 0)
@@ -671,7 +671,7 @@ vox_open (sd)
671 else 671 else
672 file = "/dev/dsp"; 672 file = "/dev/dsp";
673 673
674 sd->fd = open (file, O_WRONLY); 674 sd->fd = emacs_open (file, O_WRONLY, 0);
675 if (sd->fd < 0) 675 if (sd->fd < 0)
676 sound_perror (file); 676 sound_perror (file);
677} 677}
@@ -731,7 +731,7 @@ vox_close (sd)
731 ioctl (sd->fd, SNDCTL_DSP_RESET, NULL); 731 ioctl (sd->fd, SNDCTL_DSP_RESET, NULL);
732 732
733 /* Close the device. */ 733 /* Close the device. */
734 close (sd->fd); 734 emacs_close (sd->fd);
735 sd->fd = -1; 735 sd->fd = -1;
736 } 736 }
737} 737}
@@ -805,7 +805,7 @@ vox_write (sd, buffer, nbytes)
805 char *buffer; 805 char *buffer;
806 int nbytes; 806 int nbytes;
807{ 807{
808 int nwritten = write (sd->fd, buffer, nbytes); 808 int nwritten = emacs_write (sd->fd, buffer, nbytes);
809 if (nwritten < 0) 809 if (nwritten < 0)
810 sound_perror ("Writing to sound device"); 810 sound_perror ("Writing to sound device");
811} 811}
diff --git a/src/strftime.c b/src/strftime.c
index ec6068a3b28..b89d3243624 100644
--- a/src/strftime.c
+++ b/src/strftime.c
@@ -1,5 +1,4 @@
1/* Copyright (C) 1991,92,93,94,95,96,97,98 Free Software Foundation, Inc. 1/* Copyright (C) 1991,92,93,94,95,96,97,98 Free Software Foundation, Inc.
2
3 NOTE: The canonical source of this file is maintained with the GNU C Library. 2 NOTE: The canonical source of this file is maintained with the GNU C Library.
4 Bugs can be reported to bug-glibc@gnu.org. 3 Bugs can be reported to bug-glibc@gnu.org.
5 4
@@ -14,19 +13,13 @@
14 GNU General Public License for more details. 13 GNU General Public License for more details.
15 14
16 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software Foundation,
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 17 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
19 USA. */
20 18
21#ifdef HAVE_CONFIG_H 19#ifdef HAVE_CONFIG_H
22# include <config.h> 20# include <config.h>
23#endif 21#endif
24 22
25/* Some hosts need this in order to declare localtime_r properly. */
26#ifndef _REENTRANT
27# define _REENTRANT 1
28#endif
29
30#ifdef _LIBC 23#ifdef _LIBC
31# define HAVE_LIMITS_H 1 24# define HAVE_LIMITS_H 1
32# define HAVE_MBLEN 1 25# define HAVE_MBLEN 1
@@ -136,7 +129,7 @@ extern char *tzname[];
136 add one for integer division truncation; 129 add one for integer division truncation;
137 add one more for a minus sign if t is signed. */ 130 add one more for a minus sign if t is signed. */
138#define INT_STRLEN_BOUND(t) \ 131#define INT_STRLEN_BOUND(t) \
139 ((sizeof (t) * CHAR_BIT - TYPE_SIGNED (t)) * 302 / 100 + 1 + TYPE_SIGNED (t)) 132 ((sizeof (t) * CHAR_BIT - TYPE_SIGNED (t)) * 302 / 1000 + 1 + TYPE_SIGNED (t))
140 133
141#define TM_YEAR_BASE 1900 134#define TM_YEAR_BASE 1900
142 135
@@ -149,19 +142,20 @@ extern char *tzname[];
149 142
150 143
151#ifdef _LIBC 144#ifdef _LIBC
152# define gmtime_r __gmtime_r 145# define my_strftime_gmtime_r __gmtime_r
153# define localtime_r __localtime_r 146# define my_strftime_localtime_r __localtime_r
154# define tzname __tzname 147# define tzname __tzname
155# define tzset __tzset 148# define tzset __tzset
156#else 149#else
157# if ! HAVE_LOCALTIME_R 150
158# if ! HAVE_TM_GMTOFF 151/* If we're a strftime substitute in a GNU program, then prefer gmtime
159/* Approximate gmtime_r as best we can in its absence. */ 152 to gmtime_r, since many gmtime_r implementations are buggy.
160# undef gmtime_r 153 Similarly for localtime_r. */
161# define gmtime_r my_gmtime_r 154
162static struct tm *gmtime_r __P ((const time_t *, struct tm *)); 155# if ! HAVE_TM_GMTOFF
156static struct tm *my_strftime_gmtime_r __P ((const time_t *, struct tm *));
163static struct tm * 157static struct tm *
164gmtime_r (t, tp) 158my_strftime_gmtime_r (t, tp)
165 const time_t *t; 159 const time_t *t;
166 struct tm *tp; 160 struct tm *tp;
167{ 161{
@@ -171,14 +165,11 @@ gmtime_r (t, tp)
171 *tp = *l; 165 *tp = *l;
172 return tp; 166 return tp;
173} 167}
174# endif /* ! HAVE_TM_GMTOFF */ 168# endif /* ! HAVE_TM_GMTOFF */
175 169
176/* Approximate localtime_r as best we can in its absence. */ 170static struct tm *my_strftime_localtime_r __P ((const time_t *, struct tm *));
177# undef localtime_r
178# define localtime_r my_ftime_localtime_r
179static struct tm *localtime_r __P ((const time_t *, struct tm *));
180static struct tm * 171static struct tm *
181localtime_r (t, tp) 172my_strftime_localtime_r (t, tp)
182 const time_t *t; 173 const time_t *t;
183 struct tm *tp; 174 struct tm *tp;
184{ 175{
@@ -188,7 +179,6 @@ localtime_r (t, tp)
188 *tp = *l; 179 *tp = *l;
189 return tp; 180 return tp;
190} 181}
191# endif /* ! HAVE_LOCALTIME_R */
192#endif /* ! defined _LIBC */ 182#endif /* ! defined _LIBC */
193 183
194 184
@@ -376,30 +366,38 @@ static char const month_name[][10] =
376 366
377 367
378#ifdef emacs 368#ifdef emacs
379# define my_strftime emacs_strftime 369# define my_strftime emacs_strftimeu
370# define ut_argument , ut
371# define ut_argument_spec int ut;
372# define ut_argument_spec_iso , int ut
380#else 373#else
381# define my_strftime strftime 374# define my_strftime strftime
375# define ut_argument
376# define ut_argument_spec
377# define ut_argument_spec_iso
378/* We don't have this information in general. */
379# define ut 0
382#endif 380#endif
383 381
384#if !defined _LIBC && HAVE_TZNAME && HAVE_TZSET 382#if !defined _LIBC && HAVE_TZNAME && HAVE_TZSET
385 /* Solaris 2.5 tzset sometimes modifies the storage returned by localtime. 383 /* Solaris 2.5 tzset sometimes modifies the storage returned by localtime.
386 Work around this bug by copying *tp before it might be munged. */ 384 Work around this bug by copying *tp before it might be munged. */
387 size_t _strftime_copytm __P ((char *, size_t, const char *, 385 size_t _strftime_copytm __P ((char *, size_t, const char *,
388 const struct tm *)); 386 const struct tm * ut_argument_spec_iso));
389 size_t 387 size_t
390 my_strftime (s, maxsize, format, tp) 388 my_strftime (s, maxsize, format, tp ut_argument)
391 char *s; 389 char *s;
392 size_t maxsize; 390 size_t maxsize;
393 const char *format; 391 const char *format;
394 const struct tm *tp; 392 const struct tm *tp;
393 ut_argument_spec
395 { 394 {
396 struct tm tmcopy; 395 struct tm tmcopy;
397 tmcopy = *tp; 396 tmcopy = *tp;
398 return _strftime_copytm (s, maxsize, format, &tmcopy); 397 return _strftime_copytm (s, maxsize, format, &tmcopy ut_argument);
399 } 398 }
400# undef my_strftime 399# undef my_strftime
401# define my_strftime(S, Maxsize, Format, Tp) \ 400# define my_strftime _strftime_copytm
402 _strftime_copytm (S, Maxsize, Format, Tp)
403#endif 401#endif
404 402
405 403
@@ -410,41 +408,44 @@ static char const month_name[][10] =
410 anywhere, so to determine how many characters would be 408 anywhere, so to determine how many characters would be
411 written, use NULL for S and (size_t) UINT_MAX for MAXSIZE. */ 409 written, use NULL for S and (size_t) UINT_MAX for MAXSIZE. */
412size_t 410size_t
413my_strftime (s, maxsize, format, tp) 411my_strftime (s, maxsize, format, tp ut_argument)
414 char *s; 412 char *s;
415 size_t maxsize; 413 size_t maxsize;
416 const char *format; 414 const char *format;
417 const struct tm *tp; 415 const struct tm *tp;
416 ut_argument_spec
418{ 417{
419 int hour12 = tp->tm_hour; 418 int hour12 = tp->tm_hour;
420#ifdef _NL_CURRENT 419#ifdef _NL_CURRENT
421 const char *const a_wkday = _NL_CURRENT (LC_TIME, ABDAY_1 + tp->tm_wday); 420 /* We cannot make the following values variables since we must delay
422 const char *const f_wkday = _NL_CURRENT (LC_TIME, DAY_1 + tp->tm_wday); 421 the evaluation of these values until really needed since some
423 const char *const a_month = _NL_CURRENT (LC_TIME, ABMON_1 + tp->tm_mon); 422 expressions might not be valid in every situation. The `struct tm'
424 const char *const f_month = _NL_CURRENT (LC_TIME, MON_1 + tp->tm_mon); 423 might be generated by a strptime() call that initialized
425 const char *const ampm = _NL_CURRENT (LC_TIME, 424 only a few elements. Dereference the pointers only if the format
426 hour12 > 11 ? PM_STR : AM_STR); 425 requires this. Then it is ok to fail if the pointers are invalid. */
427 size_t aw_len = strlen (a_wkday); 426# define a_wkday _NL_CURRENT (LC_TIME, ABDAY_1 + tp->tm_wday)
428 size_t am_len = strlen (a_month); 427# define f_wkday _NL_CURRENT (LC_TIME, DAY_1 + tp->tm_wday)
429 size_t ap_len = strlen (ampm); 428# define a_month _NL_CURRENT (LC_TIME, ABMON_1 + tp->tm_mon)
429# define f_month _NL_CURRENT (LC_TIME, MON_1 + tp->tm_mon)
430# define ampm _NL_CURRENT (LC_TIME, tp->tm_hour > 11 ? PM_STR : AM_STR)
431
432# define aw_len strlen (a_wkday)
433# define am_len strlen (a_month)
434# define ap_len strlen (ampm)
430#else 435#else
431# if !HAVE_STRFTIME 436# if !HAVE_STRFTIME
432 const char *const f_wkday = weekday_name[tp->tm_wday]; 437# define f_wkday (weekday_name[tp->tm_wday])
433 const char *const f_month = month_name[tp->tm_mon]; 438# define f_month (month_name[tp->tm_mon])
434 const char *const a_wkday = f_wkday; 439# define a_wkday f_wkday
435 const char *const a_month = f_month; 440# define a_month f_month
436 const char *const ampm = "AMPM" + 2 * (hour12 > 11); 441# define ampm ("AMPM" + 2 * (tp->tm_hour > 11))
442
437 size_t aw_len = 3; 443 size_t aw_len = 3;
438 size_t am_len = 3; 444 size_t am_len = 3;
439 size_t ap_len = 2; 445 size_t ap_len = 2;
440# endif 446# endif
441#endif 447#endif
442#if defined _NL_CURRENT || !HAVE_STRFTIME
443 size_t wkday_len = strlen (f_wkday);
444 size_t month_len = strlen (f_month);
445#endif
446 const char *zone; 448 const char *zone;
447 size_t zonelen;
448 size_t i = 0; 449 size_t i = 0;
449 char *p = s; 450 char *p = s;
450 const char *f; 451 const char *f;
@@ -460,25 +461,27 @@ my_strftime (s, maxsize, format, tp)
460 zone = (const char *) tp->tm_zone; 461 zone = (const char *) tp->tm_zone;
461#endif 462#endif
462#if HAVE_TZNAME 463#if HAVE_TZNAME
463 /* POSIX.1 8.1.1 requires that whenever strftime() is called, the 464 if (ut)
464 time zone names contained in the external variable `tzname' shall 465 {
465 be set as if the tzset() function had been called. */ 466 if (! (zone && *zone))
467 zone = "GMT";
468 }
469 else
470 {
471 /* POSIX.1 8.1.1 requires that whenever strftime() is called, the
472 time zone names contained in the external variable `tzname' shall
473 be set as if the tzset() function had been called. */
466# if HAVE_TZSET 474# if HAVE_TZSET
467 tzset (); 475 tzset ();
468# endif 476# endif
469 477 }
470 if (!(zone && *zone) && tp->tm_isdst >= 0)
471 zone = tzname[tp->tm_isdst];
472#endif 478#endif
473 if (! zone)
474 zone = ""; /* POSIX.2 requires the empty string here. */
475
476 zonelen = strlen (zone);
477 479
478 if (hour12 > 12) 480 if (hour12 > 12)
479 hour12 -= 12; 481 hour12 -= 12;
480 else 482 else
481 if (hour12 == 0) hour12 = 12; 483 if (hour12 == 0)
484 hour12 = 12;
482 485
483 for (f = format; *f != '\0'; ++f) 486 for (f = format; *f != '\0'; ++f)
484 { 487 {
@@ -544,7 +547,13 @@ my_strftime (s, maxsize, format, tp)
544 if (bytes == 0) 547 if (bytes == 0)
545 break; 548 break;
546 549
547 if (bytes == (size_t) -2 || bytes == (size_t) -1) 550 if (bytes == (size_t) -2)
551 {
552 len += strlen (f + len);
553 break;
554 }
555
556 if (bytes == (size_t) -1)
548 { 557 {
549 len++; 558 len++;
550 break; 559 break;
@@ -555,6 +564,7 @@ my_strftime (s, maxsize, format, tp)
555 while (! mbsinit (&mbstate)); 564 while (! mbsinit (&mbstate));
556 565
557 cpy (len, f); 566 cpy (len, f);
567 f += len - 1;
558 continue; 568 continue;
559 } 569 }
560 } 570 }
@@ -664,7 +674,7 @@ my_strftime (s, maxsize, format, tp)
664 to_lowcase = 0; 674 to_lowcase = 0;
665 } 675 }
666#if defined _NL_CURRENT || !HAVE_STRFTIME 676#if defined _NL_CURRENT || !HAVE_STRFTIME
667 cpy (wkday_len, f_wkday); 677 cpy (strlen (f_wkday), f_wkday);
668 break; 678 break;
669#else 679#else
670 goto underlying_strftime; 680 goto underlying_strftime;
@@ -690,7 +700,7 @@ my_strftime (s, maxsize, format, tp)
690 to_lowcase = 0; 700 to_lowcase = 0;
691 } 701 }
692#if defined _NL_CURRENT || !HAVE_STRFTIME 702#if defined _NL_CURRENT || !HAVE_STRFTIME
693 cpy (month_len, f_month); 703 cpy (strlen (f_month), f_month);
694 break; 704 break;
695#else 705#else
696 goto underlying_strftime; 706 goto underlying_strftime;
@@ -714,10 +724,9 @@ my_strftime (s, maxsize, format, tp)
714 subformat: 724 subformat:
715 { 725 {
716 char *old_start = p; 726 char *old_start = p;
717 size_t len = my_strftime (NULL, maxsize - i, subfmt, tp); 727 size_t len = my_strftime (NULL, (size_t) -1, subfmt,
718 if (len == 0 && *subfmt) 728 tp ut_argument);
719 return 0; 729 add (len, my_strftime (p, maxsize - i, subfmt, tp ut_argument));
720 add (len, my_strftime (p, maxsize - i, subfmt, tp));
721 730
722 if (to_uppcase) 731 if (to_uppcase)
723 while (old_start < p) 732 while (old_start < p)
@@ -742,7 +751,6 @@ my_strftime (s, maxsize, format, tp)
742 *u++ = modifier; 751 *u++ = modifier;
743 *u++ = format_char; 752 *u++ = format_char;
744 *u = '\0'; 753 *u = '\0';
745 ubuf[0] = '\1';
746 len = strftime (ubuf, sizeof ubuf, ufmt, tp); 754 len = strftime (ubuf, sizeof ubuf, ufmt, tp);
747 if (len == 0 && ubuf[0] != '\0') 755 if (len == 0 && ubuf[0] != '\0')
748 return 0; 756 return 0;
@@ -1033,7 +1041,6 @@ my_strftime (s, maxsize, format, tp)
1033 add (1, *p = '\t'); 1041 add (1, *p = '\t');
1034 break; 1042 break;
1035 1043
1036 case 'f':
1037 case 'u': /* POSIX.2 extension. */ 1044 case 'u': /* POSIX.2 extension. */
1038 DO_NUMBER (1, (tp->tm_wday - 1 + 7) % 7 + 1); 1045 DO_NUMBER (1, (tp->tm_wday - 1 + 7) % 7 + 1);
1039 1046
@@ -1142,7 +1149,16 @@ my_strftime (s, maxsize, format, tp)
1142 to_uppcase = 0; 1149 to_uppcase = 0;
1143 to_lowcase = 1; 1150 to_lowcase = 1;
1144 } 1151 }
1145 cpy (zonelen, zone); 1152
1153#if HAVE_TZNAME
1154 /* The tzset() call might have changed the value. */
1155 if (!(zone && *zone) && tp->tm_isdst >= 0)
1156 zone = tzname[tp->tm_isdst];
1157#endif
1158 if (! zone)
1159 zone = ""; /* POSIX.2 requires the empty string here. */
1160
1161 cpy (strlen (zone), zone);
1146 break; 1162 break;
1147 1163
1148 case 'z': /* GNU extension. */ 1164 case 'z': /* GNU extension. */
@@ -1154,34 +1170,39 @@ my_strftime (s, maxsize, format, tp)
1154#if HAVE_TM_GMTOFF 1170#if HAVE_TM_GMTOFF
1155 diff = tp->tm_gmtoff; 1171 diff = tp->tm_gmtoff;
1156#else 1172#else
1157 struct tm gtm; 1173 if (ut)
1158 struct tm ltm; 1174 diff = 0;
1159 time_t lt; 1175 else
1176 {
1177 struct tm gtm;
1178 struct tm ltm;
1179 time_t lt;
1160 1180
1161 ltm = *tp; 1181 ltm = *tp;
1162 lt = mktime (&ltm); 1182 lt = mktime (&ltm);
1163 1183
1164 if (lt == (time_t) -1) 1184 if (lt == (time_t) -1)
1165 { 1185 {
1166 /* mktime returns -1 for errors, but -1 is also a 1186 /* mktime returns -1 for errors, but -1 is also a
1167 valid time_t value. Check whether an error really 1187 valid time_t value. Check whether an error really
1168 occurred. */ 1188 occurred. */
1169 struct tm tm; 1189 struct tm tm;
1170 1190
1171 if (! localtime_r (&lt, &tm) 1191 if (! my_strftime_localtime_r (&lt, &tm)
1172 || ((ltm.tm_sec ^ tm.tm_sec) 1192 || ((ltm.tm_sec ^ tm.tm_sec)
1173 | (ltm.tm_min ^ tm.tm_min) 1193 | (ltm.tm_min ^ tm.tm_min)
1174 | (ltm.tm_hour ^ tm.tm_hour) 1194 | (ltm.tm_hour ^ tm.tm_hour)
1175 | (ltm.tm_mday ^ tm.tm_mday) 1195 | (ltm.tm_mday ^ tm.tm_mday)
1176 | (ltm.tm_mon ^ tm.tm_mon) 1196 | (ltm.tm_mon ^ tm.tm_mon)
1177 | (ltm.tm_year ^ tm.tm_year))) 1197 | (ltm.tm_year ^ tm.tm_year)))
1178 break; 1198 break;
1179 } 1199 }
1180 1200
1181 if (! gmtime_r (&lt, &gtm)) 1201 if (! my_strftime_gmtime_r (&lt, &gtm))
1182 break; 1202 break;
1183 1203
1184 diff = tm_diff (&ltm, &gtm); 1204 diff = tm_diff (&ltm, &gtm);
1205 }
1185#endif 1206#endif
1186 1207
1187 if (diff < 0) 1208 if (diff < 0)
@@ -1214,7 +1235,7 @@ my_strftime (s, maxsize, format, tp)
1214 } 1235 }
1215 } 1236 }
1216 1237
1217 if (p) 1238 if (p && maxsize != 0)
1218 *p = '\0'; 1239 *p = '\0';
1219 return i; 1240 return i;
1220} 1241}
diff --git a/src/sunfns.c b/src/sunfns.c
index 504eed3d40e..2c94af082bd 100644
--- a/src/sunfns.c
+++ b/src/sunfns.c
@@ -1,5 +1,5 @@
1/* Functions for Sun Windows menus and selection buffer. 1/* Functions for Sun Windows menus and selection buffer.
2 Copyright (C) 1987 Free Software Foundation, Inc. 2 Copyright (C) 1987, 1999 Free Software Foundation, Inc.
3 3
4This file is probably totally obsolete. In any case, the FSF is 4This file is probably totally obsolete. In any case, the FSF is
5unwilling to support it. We agreed to include it in our distribution 5unwilling to support it. We agreed to include it in our distribution
@@ -120,7 +120,7 @@ or -1 if can not open it.")
120 120
121 if ((! already_initialized) || (!NILP(force))) { 121 if ((! already_initialized) || (!NILP(force))) {
122 cp = getenv("WINDOW_GFX"); 122 cp = getenv("WINDOW_GFX");
123 if (cp != 0) win_fd = open(cp, 2); 123 if (cp != 0) win_fd = emacs_open (cp, O_RDWR, 0);
124 if (win_fd > 0) 124 if (win_fd > 0)
125 { 125 {
126 Sun_Font = pf_default(); 126 Sun_Font = pf_default();
diff --git a/src/sysdep.c b/src/sysdep.c
index 90a0ebdb484..1a3123d7ac6 100644
--- a/src/sysdep.c
+++ b/src/sysdep.c
@@ -1,5 +1,5 @@
1/* Interfaces to system-dependent kernel and library entries. 1/* Interfaces to system-dependent kernel and library entries.
2 Copyright (C) 1985, 86, 87, 88, 93, 94, 95 Free Software Foundation, Inc. 2 Copyright (C) 1985, 86,87,88,93,94,95, 1999 Free Software Foundation, Inc.
3 3
4This file is part of GNU Emacs. 4This file is part of GNU Emacs.
5 5
@@ -19,13 +19,10 @@ the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19Boston, MA 02111-1307, USA. */ 19Boston, MA 02111-1307, USA. */
20 20
21 21
22#include <config.h>
22#include <signal.h> 23#include <signal.h>
23#include <setjmp.h> 24#include <setjmp.h>
24 25
25#include <config.h>
26#ifdef STDC_HEADERS
27#include <stdlib.h>
28#endif
29#include "lisp.h" 26#include "lisp.h"
30#include "blockinput.h" 27#include "blockinput.h"
31#undef NULL 28#undef NULL
@@ -50,18 +47,6 @@ Lisp_Object Vx_bitmap_file_path;
50 47
51#define min(x,y) ((x) > (y) ? (y) : (x)) 48#define min(x,y) ((x) > (y) ? (y) : (x))
52 49
53/* In this file, open, read and write refer to the system calls,
54 not our sugared interfaces sys_open, sys_read and sys_write.
55 Contrariwise, for systems where we use the system calls directly,
56 define sys_read, etc. here as aliases for them. */
57#ifndef read
58#define sys_read read
59#define sys_write write
60#endif /* `read' is not a macro */
61
62#undef read
63#undef write
64
65#ifdef WINDOWSNT 50#ifdef WINDOWSNT
66#define read _read 51#define read _read
67#define write _write 52#define write _write
@@ -69,18 +54,6 @@ Lisp_Object Vx_bitmap_file_path;
69extern int errno; 54extern int errno;
70#endif /* not WINDOWSNT */ 55#endif /* not WINDOWSNT */
71 56
72#ifndef close
73#define sys_close close
74#else
75#undef close
76#endif
77
78#ifndef open
79#define sys_open open
80#else /* `open' is a macro */
81#undef open
82#endif /* `open' is a macro */
83
84/* Does anyone other than VMS need this? */ 57/* Does anyone other than VMS need this? */
85#ifndef fwrite 58#ifndef fwrite
86#define sys_fwrite fwrite 59#define sys_fwrite fwrite
@@ -2710,25 +2683,6 @@ read_input_waiting ()
2710#endif /* not MSDOS */ 2683#endif /* not MSDOS */
2711 2684
2712#ifdef BSD4_1 2685#ifdef BSD4_1
2713/*
2714 * Partially emulate 4.2 open call.
2715 * open is defined as this in 4.1.
2716 *
2717 * - added by Michael Bloom @ Citicorp/TTI
2718 *
2719 */
2720
2721int
2722sys_open (path, oflag, mode)
2723 char *path;
2724 int oflag, mode;
2725{
2726 if (oflag & O_CREAT)
2727 return creat (path, mode);
2728 else
2729 return open (path, oflag);
2730}
2731
2732void 2686void
2733init_sigio (fd) 2687init_sigio (fd)
2734 int fd; 2688 int fd;
@@ -3093,27 +3047,25 @@ strerror (errnum)
3093#endif /* not WINDOWSNT */ 3047#endif /* not WINDOWSNT */
3094#endif /* ! HAVE_STRERROR */ 3048#endif /* ! HAVE_STRERROR */
3095 3049
3096#ifdef INTERRUPTIBLE_OPEN
3097
3098int 3050int
3099/* VARARGS 2 */ 3051emacs_open (path, oflag, mode)
3100sys_open (path, oflag, mode)
3101 char *path; 3052 char *path;
3102 int oflag, mode; 3053 int oflag, mode;
3103{ 3054{
3104 register int rtnval; 3055 register int rtnval;
3056
3057#ifdef BSD4_1
3058 if (oflag & O_CREAT)
3059 return creat (path, mode);
3060#endif
3105 3061
3106 while ((rtnval = open (path, oflag, mode)) == -1 3062 while ((rtnval = open (path, oflag, mode)) == -1
3107 && (errno == EINTR)); 3063 && (errno == EINTR));
3108 return (rtnval); 3064 return (rtnval);
3109} 3065}
3110 3066
3111#endif /* INTERRUPTIBLE_OPEN */
3112
3113#ifdef INTERRUPTIBLE_CLOSE
3114
3115int 3067int
3116sys_close (fd) 3068emacs_close (fd)
3117 int fd; 3069 int fd;
3118{ 3070{
3119 int did_retry = 0; 3071 int did_retry = 0;
@@ -3132,12 +3084,8 @@ sys_close (fd)
3132 return rtnval; 3084 return rtnval;
3133} 3085}
3134 3086
3135#endif /* INTERRUPTIBLE_CLOSE */
3136
3137#ifdef INTERRUPTIBLE_IO
3138
3139int 3087int
3140sys_read (fildes, buf, nbyte) 3088emacs_read (fildes, buf, nbyte)
3141 int fildes; 3089 int fildes;
3142 char *buf; 3090 char *buf;
3143 unsigned int nbyte; 3091 unsigned int nbyte;
@@ -3150,7 +3098,7 @@ sys_read (fildes, buf, nbyte)
3150} 3098}
3151 3099
3152int 3100int
3153sys_write (fildes, buf, nbyte) 3101emacs_write (fildes, buf, nbyte)
3154 int fildes; 3102 int fildes;
3155 char *buf; 3103 char *buf;
3156 unsigned int nbyte; 3104 unsigned int nbyte;
@@ -3177,8 +3125,6 @@ sys_write (fildes, buf, nbyte)
3177 } 3125 }
3178 return (bytes_written); 3126 return (bytes_written);
3179} 3127}
3180
3181#endif /* INTERRUPTIBLE_IO */
3182 3128
3183#ifndef HAVE_VFORK 3129#ifndef HAVE_VFORK
3184#ifndef WINDOWSNT 3130#ifndef WINDOWSNT
@@ -3210,6 +3156,7 @@ vfork ()
3210 * always negligible. Fred Fish, Unisoft Systems Inc. 3156 * always negligible. Fred Fish, Unisoft Systems Inc.
3211 */ 3157 */
3212 3158
3159#ifndef HAVE_STRSIGNAL
3213#ifndef HAVE_SYS_SIGLIST 3160#ifndef HAVE_SYS_SIGLIST
3214char *sys_siglist[NSIG + 1] = 3161char *sys_siglist[NSIG + 1] =
3215{ 3162{
@@ -3296,6 +3243,7 @@ char *sys_siglist[NSIG + 1] =
3296 0 3243 0
3297 }; 3244 };
3298#endif /* HAVE_SYS_SIGLIST */ 3245#endif /* HAVE_SYS_SIGLIST */
3246#endif /* HAVE_STRSIGNAL */
3299 3247
3300/* 3248/*
3301 * Warning, this function may not duplicate 4.2 action properly 3249 * Warning, this function may not duplicate 4.2 action properly
@@ -3384,12 +3332,10 @@ dup2 (oldd, newd)
3384{ 3332{
3385 register int fd, ret; 3333 register int fd, ret;
3386 3334
3387 sys_close (newd); 3335 emacs_close (newd);
3388 3336
3389#ifdef F_DUPFD 3337#ifdef F_DUPFD
3390 fd = fcntl (oldd, F_DUPFD, newd); 3338 return fcntl (oldd, F_DUPFD, newd);
3391 if (fd != newd)
3392 error ("can't dup2 (%i,%i) : %s", oldd, newd, strerror (errno));
3393#else 3339#else
3394 fd = dup (old); 3340 fd = dup (old);
3395 if (fd == -1) 3341 if (fd == -1)
@@ -3397,7 +3343,7 @@ dup2 (oldd, newd)
3397 if (fd == new) 3343 if (fd == new)
3398 return new; 3344 return new;
3399 ret = dup2 (old,new); 3345 ret = dup2 (old,new);
3400 sys_close (fd); 3346 emacs_close (fd);
3401 return ret; 3347 return ret;
3402#endif 3348#endif
3403} 3349}
@@ -3452,6 +3398,7 @@ croak (badfunc)
3452 3398
3453#ifdef DGUX 3399#ifdef DGUX
3454 3400
3401#ifndef HAVE_STRSIGNAL
3455char *sys_siglist[NSIG + 1] = 3402char *sys_siglist[NSIG + 1] =
3456{ 3403{
3457 "null signal", /* 0 SIGNULL */ 3404 "null signal", /* 0 SIGNULL */
@@ -3521,6 +3468,7 @@ char *sys_siglist[NSIG + 1] =
3521 "notification message in mess. queue", /* 64 SIGDGNOTIFY */ 3468 "notification message in mess. queue", /* 64 SIGDGNOTIFY */
3522 0 3469 0
3523}; 3470};
3471#endif /* HAVE_STRSIGNAL */
3524 3472
3525#endif /* DGUX */ 3473#endif /* DGUX */
3526 3474
@@ -3538,7 +3486,7 @@ closedir (dirp)
3538{ 3486{
3539 int rtnval; 3487 int rtnval;
3540 3488
3541 rtnval = sys_close (dirp->dd_fd); 3489 rtnval = emacs_close (dirp->dd_fd);
3542 3490
3543 /* Some systems (like Solaris) allocate the buffer and the DIR all 3491 /* Some systems (like Solaris) allocate the buffer and the DIR all
3544 in one block. Why in the world are we freeing this ourselves 3492 in one block. Why in the world are we freeing this ourselves
@@ -3563,7 +3511,7 @@ opendir (filename)
3563 register int fd; /* file descriptor for read */ 3511 register int fd; /* file descriptor for read */
3564 struct stat sbuf; /* result of fstat */ 3512 struct stat sbuf; /* result of fstat */
3565 3513
3566 fd = sys_open (filename, 0); 3514 fd = emacs_open (filename, O_RDONLY, 0);
3567 if (fd < 0) 3515 if (fd < 0)
3568 return 0; 3516 return 0;
3569 3517
@@ -3572,7 +3520,7 @@ opendir (filename)
3572 || (sbuf.st_mode & S_IFMT) != S_IFDIR 3520 || (sbuf.st_mode & S_IFMT) != S_IFDIR
3573 || (dirp = (DIR *) malloc (sizeof (DIR))) == 0) 3521 || (dirp = (DIR *) malloc (sizeof (DIR))) == 0)
3574 { 3522 {
3575 sys_close (fd); 3523 emacs_close (fd);
3576 UNBLOCK_INPUT; 3524 UNBLOCK_INPUT;
3577 return 0; /* bad luck today */ 3525 return 0; /* bad luck today */
3578 } 3526 }
@@ -3588,7 +3536,7 @@ void
3588closedir (dirp) 3536closedir (dirp)
3589 register DIR *dirp; /* stream from opendir */ 3537 register DIR *dirp; /* stream from opendir */
3590{ 3538{
3591 sys_close (dirp->dd_fd); 3539 emacs_close (dirp->dd_fd);
3592 xfree ((char *) dirp); 3540 xfree ((char *) dirp);
3593} 3541}
3594 3542
@@ -3622,7 +3570,7 @@ readdir (dirp)
3622 dirp->dd_loc = dirp->dd_size = 0; 3570 dirp->dd_loc = dirp->dd_size = 0;
3623 3571
3624 if (dirp->dd_size == 0 /* refill buffer */ 3572 if (dirp->dd_size == 0 /* refill buffer */
3625 && (dirp->dd_size = sys_read (dirp->dd_fd, dirp->dd_buf, DIRBLKSIZ)) <= 0) 3573 && (dirp->dd_size = emacs_read (dirp->dd_fd, dirp->dd_buf, DIRBLKSIZ)) <= 0)
3626 return 0; 3574 return 0;
3627 3575
3628#ifndef VMS 3576#ifndef VMS
@@ -3775,7 +3723,7 @@ mkdir (dpath, dmode)
3775 */ 3723 */
3776 status = umask (0); /* Get current umask */ 3724 status = umask (0); /* Get current umask */
3777 status = umask (status | (0777 & ~dmode)); /* Set for mkdir */ 3725 status = umask (status | (0777 & ~dmode)); /* Set for mkdir */
3778 fd = sys_open ("/dev/null", 2); 3726 fd = emacs_open ("/dev/null", O_RDWR, 0);
3779 if (fd >= 0) 3727 if (fd >= 0)
3780 { 3728 {
3781 dup2 (fd, 0); 3729 dup2 (fd, 0);
@@ -3821,7 +3769,7 @@ rmdir (dpath)
3821 return (-1); /* Errno is set already */ 3769 return (-1); /* Errno is set already */
3822 3770
3823 case 0: /* Child process */ 3771 case 0: /* Child process */
3824 fd = sys_open ("/dev/null", 2); 3772 fd = emacs_open ("/dev/null", O_RDWR, 0);
3825 if (fd >= 0) 3773 if (fd >= 0)
3826 { 3774 {
3827 dup2 (fd, 0); 3775 dup2 (fd, 0);
@@ -4240,6 +4188,7 @@ sys_getuid ()
4240 return (getgid () << 16) | getuid (); 4188 return (getgid () << 16) | getuid ();
4241} 4189}
4242 4190
4191#undef read
4243int 4192int
4244sys_read (fildes, buf, nbyte) 4193sys_read (fildes, buf, nbyte)
4245 int fildes; 4194 int fildes;
@@ -4279,6 +4228,7 @@ sys_write (fildes, buf, nbyte)
4279 * Thus we do this stupidity below. 4228 * Thus we do this stupidity below.
4280 */ 4229 */
4281 4230
4231#undef write
4282int 4232int
4283sys_write (fildes, buf, nbytes) 4233sys_write (fildes, buf, nbytes)
4284 int fildes; 4234 int fildes;
@@ -5322,7 +5272,28 @@ bcmp (b1, b2, length) /* This could be a macro! */
5322} 5272}
5323#endif /* no bcmp */ 5273#endif /* no bcmp */
5324#endif /* not BSTRING */ 5274#endif /* not BSTRING */
5275
5276#ifndef HAVE_STRSIGNAL
5277char *
5278strsignal (code)
5279 int code;
5280{
5281 char *signame = 0;
5282
5283 if (0 <= code && code < NSIG)
5284 {
5285#ifdef VMS
5286 signame = sys_errlist[code];
5287#else
5288 /* Cast to suppress warning if the table has const char *. */
5289 signame = (char *) sys_siglist[code];
5290#endif
5291 }
5325 5292
5293 return signame;
5294}
5295#endif /* HAVE_STRSIGNAL */
5296
5326/* All the Macintosh stuffs go here */ 5297/* All the Macintosh stuffs go here */
5327 5298
5328#ifdef macintosh 5299#ifdef macintosh
@@ -5502,10 +5473,10 @@ Unix2MacPathname (const char *ufn, char *mfn, int mfnbuflen)
5502 5473
5503/* Define our own stat function for both MrC and CW. The reason for 5474/* Define our own stat function for both MrC and CW. The reason for
5504 doing this: "stat" is both the name of a struct and function name: 5475 doing this: "stat" is both the name of a struct and function name:
5505 can't use the same trick like that for sys_open, sys_close, etc. to 5476 we can't #define stat to something else to
5506 redirect Emacs's calls to our own version that converts Unix style 5477 redirect Emacs's calls to our own version that converts Unix style
5507 filenames to Mac style filename because all sorts of compilation 5478 filenames to Mac style filename because all sorts of compilation
5508 errors will be generated if stat is #define'd to be sys_stat. */ 5479 errors will be generated if stat is #define'd to be something else. */
5509 5480
5510int 5481int
5511stat (const char *path, struct stat *buf) 5482stat (const char *path, struct stat *buf)
diff --git a/src/syssignal.h b/src/syssignal.h
index 868cfb7c719..66e6ffa61fc 100644
--- a/src/syssignal.h
+++ b/src/syssignal.h
@@ -1,5 +1,5 @@
1/* syssignal.h - System-dependent definitions for signals. 1/* syssignal.h - System-dependent definitions for signals.
2 Copyright (C) 1993 Free Software Foundation, Inc. 2 Copyright (C) 1993, 1999 Free Software Foundation, Inc.
3 3
4This file is part of GNU Emacs. 4This file is part of GNU Emacs.
5 5
@@ -123,6 +123,29 @@ sigset_t sys_sigsetmask P_ ((sigset_t new_mask));
123#define sigfree() sigsetmask (SIGEMPTYMASK) 123#define sigfree() sigsetmask (SIGEMPTYMASK)
124#endif /* not BSD4_1 */ 124#endif /* not BSD4_1 */
125 125
126#if defined (SIGINFO) && defined (BROKEN_SIGINFO)
127#undef SIGINFO
128#endif
129#if defined (SIGIO) && defined (BROKEN_SIGIO)
130#undef SIGIO
131#endif
132#if defined (SIGPOLL) && defined (BROKEN_SIGPOLL)
133#undef SIGPOLL
134#endif
135#if defined (SIGTSTP) && defined (BROKEN_SIGTSTP)
136#undef SIGTSTP
137#endif
138#if defined (SIGURG) && defined (BROKEN_SIGURG)
139#undef SIGURG
140#endif
141
142#if NSIG < NSIG_MINIMUM
143# ifdef NSIG
144# undef NSIG
145# endif
146# define NSIG NSIG_MINIMUM
147#endif
148
126#ifdef BSD4_1 149#ifdef BSD4_1
127#define SIGIO SIGTINT 150#define SIGIO SIGTINT
128/* sigfree is in sysdep.c */ 151/* sigfree is in sysdep.c */
@@ -149,3 +172,8 @@ sigset_t sys_sigsetmask P_ ((sigset_t new_mask));
149#endif /* SIGCHLD */ 172#endif /* SIGCHLD */
150#endif /* ! defined (SIGCLD) */ 173#endif /* ! defined (SIGCLD) */
151#endif /* VMS */ 174#endif /* VMS */
175
176#ifndef HAVE_STRSIGNAL
177/* strsignal is in sysdep.c */
178char *strsignal ();
179#endif
diff --git a/src/unexelf.c b/src/unexelf.c
index 015522638f4..804e86b45e0 100644
--- a/src/unexelf.c
+++ b/src/unexelf.c
@@ -1,4 +1,4 @@
1/* Copyright (C) 1985, 1986, 1987, 1988, 1990, 1992 1/* Copyright (C) 1985, 1986, 1987, 1988, 1990, 1992, 1999
2 Free Software Foundation, Inc. 2 Free Software Foundation, Inc.
3 3
4This file is part of GNU Emacs. 4This file is part of GNU Emacs.
@@ -412,6 +412,13 @@ Filesz Memsz Flags Align
412 412
413 */ 413 */
414 414
415#ifndef emacs
416#define fatal(a, b, c) fprintf (stderr, a, b, c), exit (1)
417#else
418#include <config.h>
419extern void fatal (char *, ...);
420#endif
421
415#include <sys/types.h> 422#include <sys/types.h>
416#include <stdio.h> 423#include <stdio.h>
417#include <sys/stat.h> 424#include <sys/stat.h>
@@ -517,17 +524,18 @@ typedef struct {
517 524
518#ifndef ElfW 525#ifndef ElfW
519# ifdef __STDC__ 526# ifdef __STDC__
520# define ElfW(type) Elf32_##type 527# define ElfBitsW(bits, type) Elf##bits##_##type
521# else 528# else
522# define ElfW(type) Elf32_/**/type 529# define ElfBitsW(bits, type) Elf/**/bits/**/_/**/type
523# endif 530# endif
524#endif 531# ifdef _LP64
525 532# define ELFSIZE 64
526#ifndef emacs 533# else
527#define fatal(a, b, c) fprintf (stderr, a, b, c), exit (1) 534# define ELFSIZE 32
528#else 535# endif
529#include <config.h> 536 /* This macro expands `bits' before invoking ElfBitsW. */
530extern void fatal (char *, ...); 537# define ElfExpandBitsW(bits, type) ElfBitsW (bits, type)
538# define ElfW(type) ElfExpandBitsW (ELFSIZE, type)
531#endif 539#endif
532 540
533#ifndef ELF_BSS_SECTION_NAME 541#ifndef ELF_BSS_SECTION_NAME
diff --git a/src/unexhp9k800.c b/src/unexhp9k800.c
index f33340c4d8c..686a1ed1ebb 100644
--- a/src/unexhp9k800.c
+++ b/src/unexhp9k800.c
@@ -37,16 +37,16 @@
37 sigsetreturn (_sigreturn); 37 sigsetreturn (_sigreturn);
38*/ 38*/
39 39
40#ifdef emacs
41#include <config.h>
42#endif
43
40#include <stdio.h> 44#include <stdio.h>
41#include <fcntl.h> 45#include <fcntl.h>
42#include <errno.h> 46#include <errno.h>
43 47
44#include <a.out.h> 48#include <a.out.h>
45 49
46#ifdef emacs
47#include <config.h>
48#endif
49
50#ifdef HPUX_USE_SHLIBS 50#ifdef HPUX_USE_SHLIBS
51#include <dl.h> 51#include <dl.h>
52#endif 52#endif
diff --git a/src/unexsunos4.c b/src/unexsunos4.c
index bdc20336282..76480db9b33 100644
--- a/src/unexsunos4.c
+++ b/src/unexsunos4.c
@@ -1,5 +1,5 @@
1/* Unexec for Sunos 4 using shared libraries. 1/* Unexec for Sunos 4 using shared libraries.
2 Copyright (C) 1990, 1994 Free Software Foundation, Inc. 2 Copyright (C) 1990, 1994, 1999 Free Software Foundation, Inc.
3 3
4This file is part of GNU Emacs. 4This file is part of GNU Emacs.
5 5
@@ -43,6 +43,11 @@ Boston, MA 02111-1307, USA. */
43 * is somewhat abused here) is loaded first! 43 * is somewhat abused here) is loaded first!
44 * 44 *
45 */ 45 */
46
47#ifdef emacs
48#include <config.h>
49#endif
50
46#include <sys/param.h> 51#include <sys/param.h>
47#include <sys/mman.h> 52#include <sys/mman.h>
48#include <sys/file.h> 53#include <sys/file.h>
@@ -51,12 +56,6 @@ Boston, MA 02111-1307, USA. */
51#include <stdio.h> 56#include <stdio.h>
52#include <a.out.h> 57#include <a.out.h>
53 58
54/* Do this after the above #include's in case a configuration file wants
55 to define things for this file based on what <a.out.h> defines. */
56#ifdef emacs
57#include <config.h>
58#endif
59
60#if defined (SUNOS4) || defined (__FreeBSD__) || defined (__NetBSD__) 59#if defined (SUNOS4) || defined (__FreeBSD__) || defined (__NetBSD__)
61#define UNDO_RELOCATION 60#define UNDO_RELOCATION
62#endif 61#endif
diff --git a/src/vmsfns.c b/src/vmsfns.c
index 716ba21def7..fe79ebee303 100644
--- a/src/vmsfns.c
+++ b/src/vmsfns.c
@@ -1,5 +1,5 @@
1/* VMS subprocess and command interface. 1/* VMS subprocess and command interface.
2 Copyright (C) 1987, 1988 Free Software Foundation, Inc. 2 Copyright (C) 1987, 1988, 1999 Free Software Foundation, Inc.
3 3
4This file is part of GNU Emacs. 4This file is part of GNU Emacs.
5 5
@@ -56,11 +56,11 @@ Boston, MA 02111-1307, USA. */
56 56
57#ifdef VMS 57#ifdef VMS
58 58
59#include <config.h>
59#include <stdio.h> 60#include <stdio.h>
60#include <ctype.h> 61#include <ctype.h>
61#undef NULL 62#undef NULL
62 63
63#include <config.h>
64#include "lisp.h" 64#include "lisp.h"
65#include <descrip.h> 65#include <descrip.h>
66#include <dvidef.h> 66#include <dvidef.h>
diff --git a/src/vmsgmalloc.c b/src/vmsgmalloc.c
index a3545f5eb01..93a3fd7f8bd 100644
--- a/src/vmsgmalloc.c
+++ b/src/vmsgmalloc.c
@@ -5,7 +5,7 @@
5/* The malloc headers and source files from the C library follow here. */ 5/* The malloc headers and source files from the C library follow here. */
6 6
7/* Declarations for `malloc' and friends. 7/* Declarations for `malloc' and friends.
8 Copyright 1990, 1991, 1992, 1993 Free Software Foundation, Inc. 8 Copyright 1990, 1991, 1992, 1993, 1999 Free Software Foundation, Inc.
9 Written May 1989 by Mike Haertel. 9 Written May 1989 by Mike Haertel.
10 10
11This file is part of GNU Emacs. 11This file is part of GNU Emacs.
@@ -57,6 +57,10 @@ extern "C"
57#define NULL 0 57#define NULL 0
58#endif 58#endif
59 59
60#if defined (HAVE_CONFIG_H) || defined (emacs)
61#include <config.h>
62#endif
63
60#ifdef __STDC__ 64#ifdef __STDC__
61#include <stddef.h> 65#include <stddef.h>
62#else 66#else
@@ -105,10 +109,6 @@ extern void __vms_free __P ((__ptr_t __ptr));
105 109
106#include <stdio.h> /* Harmless, gets __GNU_LIBRARY__ defined. */ 110#include <stdio.h> /* Harmless, gets __GNU_LIBRARY__ defined. */
107 111
108#if defined(HAVE_CONFIG_H) || defined(emacs)
109#include <config.h>
110#endif
111
112#if defined(__GNU_LIBRARY__) || defined(STDC_HEADERS) || defined(USG) 112#if defined(__GNU_LIBRARY__) || defined(STDC_HEADERS) || defined(USG)
113#include <string.h> 113#include <string.h>
114#else 114#else
diff --git a/src/w32faces.c b/src/w32faces.c
index 61aeee17794..1a13c28f11a 100644
--- a/src/w32faces.c
+++ b/src/w32faces.c
@@ -1,5 +1,5 @@
1/* "Face" primitives on the Microsoft W32 API. 1/* "Face" primitives on the Microsoft W32 API.
2 Copyright (C) 1993, 1994, 1995 Free Software Foundation. 2 Copyright (C) 1993, 1994, 1995, 1999 Free Software Foundation.
3 3
4This file is part of GNU Emacs. 4This file is part of GNU Emacs.
5 5
@@ -20,10 +20,10 @@ Boston, MA 02111-1307, USA. */
20 20
21/* Ported xfaces.c for w32 - Kevin Gallo */ 21/* Ported xfaces.c for w32 - Kevin Gallo */
22 22
23#include <config.h>
23#include <sys/types.h> 24#include <sys/types.h>
24#include <sys/stat.h> 25#include <sys/stat.h>
25 26
26#include <config.h>
27#include "lisp.h" 27#include "lisp.h"
28 28
29#include "w32term.h" 29#include "w32term.h"
diff --git a/src/w32menu.c b/src/w32menu.c
index aa3ef60d12b..c93c589f07d 100644
--- a/src/w32menu.c
+++ b/src/w32menu.c
@@ -1,5 +1,5 @@
1/* Menu support for GNU Emacs on the Microsoft W32 API. 1/* Menu support for GNU Emacs on the Microsoft W32 API.
2 Copyright (C) 1986, 1988, 1993, 1994, 1996, 1998 Free Software Foundation, Inc. 2 Copyright (C) 1986, 88, 93, 94, 96, 98, 1999 Free Software Foundation, Inc.
3 3
4This file is part of GNU Emacs. 4This file is part of GNU Emacs.
5 5
@@ -18,9 +18,8 @@ along with GNU Emacs; see the file COPYING. If not, write to
18the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19Boston, MA 02111-1307, USA. */ 19Boston, MA 02111-1307, USA. */
20 20
21#include <signal.h>
22#include <config.h> 21#include <config.h>
23 22#include <signal.h>
24#include <stdio.h> 23#include <stdio.h>
25#include "lisp.h" 24#include "lisp.h"
26#include "termhooks.h" 25#include "termhooks.h"
diff --git a/src/w32proc.c b/src/w32proc.c
index c64918c5bd6..8a188015d85 100644
--- a/src/w32proc.c
+++ b/src/w32proc.c
@@ -1,5 +1,5 @@
1/* Process support for GNU Emacs on the Microsoft W32 API. 1/* Process support for GNU Emacs on the Microsoft W32 API.
2 Copyright (C) 1992, 1995 Free Software Foundation, Inc. 2 Copyright (C) 1992, 1995, 1999 Free Software Foundation, Inc.
3 3
4This file is part of GNU Emacs. 4This file is part of GNU Emacs.
5 5
@@ -91,10 +91,6 @@ Lisp_Object Vw32_get_true_file_attributes;
91 91
92Lisp_Object Qhigh, Qlow; 92Lisp_Object Qhigh, Qlow;
93 93
94#ifndef SYS_SIGLIST_DECLARED
95extern char *sys_siglist[];
96#endif
97
98#ifdef EMACSDEBUG 94#ifdef EMACSDEBUG
99void _DebPrint (const char *fmt, ...) 95void _DebPrint (const char *fmt, ...)
100{ 96{
@@ -546,13 +542,11 @@ get_result:
546 else if (WIFSIGNALED (retval)) 542 else if (WIFSIGNALED (retval))
547 { 543 {
548 int code = WTERMSIG (retval); 544 int code = WTERMSIG (retval);
549 char *signame = 0; 545 char *signame;
550 546
551 if (code < NSIG) 547 synchronize_messages_locale ();
552 { 548 signame = strsignal (code);
553 /* Suppress warning if the table has const char *. */ 549
554 signame = (char *) sys_siglist[code];
555 }
556 if (signame == 0) 550 if (signame == 0)
557 signame = "unknown"; 551 signame = "unknown";
558 552
diff --git a/src/w32term.c b/src/w32term.c
index ac7a173feb1..cc71e411a0f 100644
--- a/src/w32term.c
+++ b/src/w32term.c
@@ -1,5 +1,5 @@
1/* Implementation of GUI terminal on the Microsoft W32 API. 1/* Implementation of GUI terminal on the Microsoft W32 API.
2 Copyright (C) 1989, 93, 94, 95, 96, 97, 98 Free Software Foundation, Inc. 2 Copyright (C) 1989, 93,94,95,96,97,98, 1999 Free Software Foundation, Inc.
3 3
4This file is part of GNU Emacs. 4This file is part of GNU Emacs.
5 5
@@ -18,8 +18,8 @@ along with GNU Emacs; see the file COPYING. If not, write to the
18Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19Boston, MA 02111-1307, USA. */ 19Boston, MA 02111-1307, USA. */
20 20
21#include <signal.h>
22#include <config.h> 21#include <config.h>
22#include <signal.h>
23#include <stdio.h> 23#include <stdio.h>
24#include "lisp.h" 24#include "lisp.h"
25#include "charset.h" 25#include "charset.h"
diff --git a/src/w32xfns.c b/src/w32xfns.c
index 617eec7841b..df3984eb4b4 100644
--- a/src/w32xfns.c
+++ b/src/w32xfns.c
@@ -1,5 +1,5 @@
1/* Functions taken directly from X sources for use with the Microsoft W32 API. 1/* Functions taken directly from X sources for use with the Microsoft W32 API.
2 Copyright (C) 1989, 1992, 1993, 1994, 1995 Free Software Foundation. 2 Copyright (C) 1989, 1992, 1993, 1994, 1995, 1999 Free Software Foundation.
3 3
4This file is part of GNU Emacs. 4This file is part of GNU Emacs.
5 5
@@ -18,8 +18,8 @@ along with GNU Emacs; see the file COPYING. If not, write to
18the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19Boston, MA 02111-1307, USA. */ 19Boston, MA 02111-1307, USA. */
20 20
21#include <signal.h>
22#include <config.h> 21#include <config.h>
22#include <signal.h>
23#include <stdio.h> 23#include <stdio.h>
24#include "lisp.h" 24#include "lisp.h"
25#include "frame.h" 25#include "frame.h"
diff --git a/src/xdisp.c b/src/xdisp.c
index 15ec41adf01..ebfe075d17d 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -169,9 +169,6 @@ Boston, MA 02111-1307, USA. */
169 169
170#include <config.h> 170#include <config.h>
171#include <stdio.h> 171#include <stdio.h>
172#ifdef STDC_HEADERS
173#include <stdlib.h>
174#endif
175#include "lisp.h" 172#include "lisp.h"
176#include "frame.h" 173#include "frame.h"
177#include "window.h" 174#include "window.h"
@@ -628,7 +625,7 @@ static void display_mode_lines P_ ((struct window *));
628static void display_mode_line P_ ((struct window *, enum face_id, 625static void display_mode_line P_ ((struct window *, enum face_id,
629 Lisp_Object)); 626 Lisp_Object));
630static int display_mode_element P_ ((struct it *, int, int, int, Lisp_Object)); 627static int display_mode_element P_ ((struct it *, int, int, int, Lisp_Object));
631static char *decode_mode_spec P_ ((struct window *, char, int, int)); 628static char *decode_mode_spec P_ ((struct window *, int, int, int));
632static void display_menu_bar P_ ((struct window *)); 629static void display_menu_bar P_ ((struct window *));
633static int display_count_lines P_ ((int, int, int, int, int *)); 630static int display_count_lines P_ ((int, int, int, int, int *));
634static int display_string P_ ((unsigned char *, Lisp_Object, Lisp_Object, 631static int display_string P_ ((unsigned char *, Lisp_Object, Lisp_Object,
@@ -11883,7 +11880,7 @@ static char lots_of_dashes[] = "------------------------------------------------
11883static char * 11880static char *
11884decode_mode_spec (w, c, field_width, precision) 11881decode_mode_spec (w, c, field_width, precision)
11885 struct window *w; 11882 struct window *w;
11886 register char c; 11883 register int c;
11887 int field_width, precision; 11884 int field_width, precision;
11888{ 11885{
11889 Lisp_Object obj; 11886 Lisp_Object obj;
@@ -12379,6 +12376,8 @@ display_string (string, lisp_string, face_string, face_string_pos,
12379 start, it, field_width, precision, max_x, multibyte) 12376 start, it, field_width, precision, max_x, multibyte)
12380 unsigned char *string; 12377 unsigned char *string;
12381 Lisp_Object lisp_string; 12378 Lisp_Object lisp_string;
12379 Lisp_Object face_string;
12380 int face_string_pos;
12382 int start; 12381 int start;
12383 struct it *it; 12382 struct it *it;
12384 int field_width, precision, max_x; 12383 int field_width, precision, max_x;
diff --git a/src/xfaces.c b/src/xfaces.c
index 7e1c0799e79..52b9f1b5841 100644
--- a/src/xfaces.c
+++ b/src/xfaces.c
@@ -177,9 +177,9 @@ Boston, MA 02111-1307, USA. */
177 177
178#define SCALABLE_FONTS 1 178#define SCALABLE_FONTS 1
179 179
180#include <config.h>
180#include <sys/types.h> 181#include <sys/types.h>
181#include <sys/stat.h> 182#include <sys/stat.h>
182#include <config.h>
183#include "lisp.h" 183#include "lisp.h"
184#include "charset.h" 184#include "charset.h"
185#include "frame.h" 185#include "frame.h"
@@ -223,7 +223,6 @@ Boston, MA 02111-1307, USA. */
223#endif /* HAVE_X_WINDOWS */ 223#endif /* HAVE_X_WINDOWS */
224 224
225#include <stdio.h> 225#include <stdio.h>
226#include <stdlib.h>
227#include <ctype.h> 226#include <ctype.h>
228#include "keyboard.h" 227#include "keyboard.h"
229 228
diff --git a/src/xfns.c b/src/xfns.c
index eee9b919eef..77615a78ac1 100644
--- a/src/xfns.c
+++ b/src/xfns.c
@@ -27,8 +27,8 @@ Boston, MA 02111-1307, USA. */
27 27
28/* Rewritten for X11 by Joseph Arceneaux */ 28/* Rewritten for X11 by Joseph Arceneaux */
29 29
30#include <signal.h>
31#include <config.h> 30#include <config.h>
31#include <signal.h>
32#include <stdio.h> 32#include <stdio.h>
33#include <math.h> 33#include <math.h>
34 34
@@ -52,9 +52,7 @@ Boston, MA 02111-1307, USA. */
52 52
53#ifdef HAVE_X_WINDOWS 53#ifdef HAVE_X_WINDOWS
54 54
55#ifdef STDC_HEADERS 55#ifndef STDC_HEADERS
56#include <stdlib.h>
57#else
58extern void abort (); 56extern void abort ();
59#endif 57#endif
60#include <ctype.h> 58#include <ctype.h>
@@ -667,7 +665,7 @@ x_create_bitmap_from_file (f, file)
667 /* XReadBitmapFile won't handle magic file names. */ 665 /* XReadBitmapFile won't handle magic file names. */
668 if (fd == 0) 666 if (fd == 0)
669 return -1; 667 return -1;
670 close (fd); 668 emacs_close (fd);
671 669
672 filename = (char *) XSTRING (found)->data; 670 filename = (char *) XSTRING (found)->data;
673 671
@@ -9761,7 +9759,7 @@ used to change the tooltip's appearance.\n\
9761Automatically hide the tooltip after TIMEOUT seconds.\n\ 9759Automatically hide the tooltip after TIMEOUT seconds.\n\
9762TIMEOUT nil means use the default timeout of 5 seconds.") 9760TIMEOUT nil means use the default timeout of 5 seconds.")
9763 (string, frame, parms, timeout) 9761 (string, frame, parms, timeout)
9764 Lisp_Object string, frame, parms; 9762 Lisp_Object string, frame, parms, timeout;
9765{ 9763{
9766 struct frame *f; 9764 struct frame *f;
9767 struct window *w; 9765 struct window *w;
diff --git a/src/xmenu.c b/src/xmenu.c
index e5fffdaef5f..a9bda2154d3 100644
--- a/src/xmenu.c
+++ b/src/xmenu.c
@@ -1,5 +1,5 @@
1/* X Communication module for terminals which understand the X protocol. 1/* X Communication module for terminals which understand the X protocol.
2 Copyright (C) 1986, 1988, 1993, 1994, 1996 Free Software Foundation, Inc. 2 Copyright (C) 1986, 88, 93, 94, 96, 1999 Free Software Foundation, Inc.
3 3
4This file is part of GNU Emacs. 4This file is part of GNU Emacs.
5 5
@@ -30,12 +30,10 @@ Boston, MA 02111-1307, USA. */
30 30
31/* Rewritten for clarity and GC protection by rms in Feb 94. */ 31/* Rewritten for clarity and GC protection by rms in Feb 94. */
32 32
33#include <config.h>
34
33/* On 4.3 this loses if it comes after xterm.h. */ 35/* On 4.3 this loses if it comes after xterm.h. */
34#include <signal.h> 36#include <signal.h>
35#include <config.h>
36#ifdef HAVE_STDLIB_H
37#include <stdlib.h>
38#endif
39 37
40#include <stdio.h> 38#include <stdio.h>
41#include "lisp.h" 39#include "lisp.h"
diff --git a/src/xterm.c b/src/xterm.c
index 2c671ffced2..e2f78508295 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -22,17 +22,13 @@ Boston, MA 02111-1307, USA. */
22/* New display code by Gerd Moellmann <gerd@gnu.org>. */ 22/* New display code by Gerd Moellmann <gerd@gnu.org>. */
23/* Xt features made by Fred Pierresteguy. */ 23/* Xt features made by Fred Pierresteguy. */
24 24
25#include <config.h>
26
25/* On 4.3 these lose if they come after xterm.h. */ 27/* On 4.3 these lose if they come after xterm.h. */
26/* On HP-UX 8.0 signal.h loses if it comes after config.h. */
27/* Putting these at the beginning seems to be standard for other .c files. */ 28/* Putting these at the beginning seems to be standard for other .c files. */
28#include <signal.h> 29#include <signal.h>
29 30
30#include <config.h>
31
32#include <stdio.h> 31#include <stdio.h>
33#ifdef STDC_HEADERS
34#include <stdlib.h>
35#endif
36 32
37#ifdef HAVE_X_WINDOWS 33#ifdef HAVE_X_WINDOWS
38 34
@@ -145,11 +141,6 @@ extern void _XEditResCheckMessages ();
145#endif 141#endif
146#endif 142#endif
147 143
148#ifdef HAVE_SETLOCALE
149/* So we can do setlocale. */
150#include <locale.h>
151#endif
152
153#ifdef SOLARIS2 144#ifdef SOLARIS2
154/* memmove will be defined as a macro in Xfuncs.h unless 145/* memmove will be defined as a macro in Xfuncs.h unless
155 <string.h> is included beforehand. The declaration for memmove in 146 <string.h> is included beforehand. The declaration for memmove in
@@ -2157,9 +2148,9 @@ static void x_get_glyph_overhangs P_ ((struct glyph *, struct frame *,
2157 int *, int *)); 2148 int *, int *));
2158static void x_compute_overhangs_and_x P_ ((struct glyph_string *, int, int)); 2149static void x_compute_overhangs_and_x P_ ((struct glyph_string *, int, int));
2159static int x_alloc_lighter_color P_ ((struct frame *, Display *, Colormap, 2150static int x_alloc_lighter_color P_ ((struct frame *, Display *, Colormap,
2160 unsigned long *, float, int)); 2151 unsigned long *, double, int));
2161static void x_setup_relief_color P_ ((struct frame *, struct relief *, 2152static void x_setup_relief_color P_ ((struct frame *, struct relief *,
2162 float, int, unsigned long)); 2153 double, int, unsigned long));
2163static void x_setup_relief_colors P_ ((struct glyph_string *)); 2154static void x_setup_relief_colors P_ ((struct glyph_string *));
2164static void x_draw_image_glyph_string P_ ((struct glyph_string *)); 2155static void x_draw_image_glyph_string P_ ((struct glyph_string *));
2165static void x_draw_image_relief P_ ((struct glyph_string *)); 2156static void x_draw_image_relief P_ ((struct glyph_string *));
@@ -3049,7 +3040,7 @@ x_alloc_lighter_color (f, display, cmap, pixel, factor, delta)
3049 Display *display; 3040 Display *display;
3050 Colormap cmap; 3041 Colormap cmap;
3051 unsigned long *pixel; 3042 unsigned long *pixel;
3052 float factor; 3043 double factor;
3053 int delta; 3044 int delta;
3054{ 3045{
3055 XColor color, new; 3046 XColor color, new;
@@ -3108,7 +3099,7 @@ static void
3108x_setup_relief_color (f, relief, factor, delta, default_pixel) 3099x_setup_relief_color (f, relief, factor, delta, default_pixel)
3109 struct frame *f; 3100 struct frame *f;
3110 struct relief *relief; 3101 struct relief *relief;
3111 float factor; 3102 double factor;
3112 int delta; 3103 int delta;
3113 unsigned long default_pixel; 3104 unsigned long default_pixel;
3114{ 3105{
@@ -12392,28 +12383,6 @@ same_x_server (name1, name2)
12392} 12383}
12393#endif 12384#endif
12394 12385
12395#if defined (HAVE_X_I18N) || (defined (USE_X_TOOLKIT) && defined (HAVE_X11XTR6))
12396/* Recover from setlocale (LC_ALL, ""). */
12397static void
12398fixup_locale ()
12399{
12400 /* Currently we require strerror to use the "C" locale,
12401 since we don't yet support decoding its string result. */
12402#ifdef LC_MESSAGES
12403 setlocale (LC_MESSAGES, "C");
12404#endif
12405
12406 /* The Emacs Lisp reader needs LC_NUMERIC to be "C",
12407 so that numbers are read and printed properly for Emacs Lisp. */
12408 setlocale (LC_NUMERIC, "C");
12409
12410 /* Currently we require strftime to use the "C" locale,
12411 since we don't yet support encoding its format argument,
12412 or decoding its string result. */
12413 setlocale (LC_TIME, "C");
12414}
12415#endif
12416
12417struct x_display_info * 12386struct x_display_info *
12418x_term_init (display_name, xrm_option, resource_name) 12387x_term_init (display_name, xrm_option, resource_name)
12419 Lisp_Object display_name; 12388 Lisp_Object display_name;
@@ -12433,11 +12402,6 @@ x_term_init (display_name, xrm_option, resource_name)
12433 x_initialized = 1; 12402 x_initialized = 1;
12434 } 12403 }
12435 12404
12436#ifdef HAVE_X_I18N
12437 setlocale (LC_ALL, "");
12438 fixup_locale ();
12439#endif
12440
12441#ifdef USE_X_TOOLKIT 12405#ifdef USE_X_TOOLKIT
12442 /* weiner@footloose.sps.mot.com reports that this causes 12406 /* weiner@footloose.sps.mot.com reports that this causes
12443 errors with X11R5: 12407 errors with X11R5: