changeset 26088:b7aa6ac26872

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.
author Paul Eggert <eggert@twinsun.com>
date Tue, 19 Oct 1999 07:25:11 +0000
parents e0d966fb548f
children 1a4c3573a216
files src/ChangeLog src/Makefile.in src/alloc.c src/buffer.c src/callproc.c src/ccl.c src/charset.c src/coding.c src/coding.h src/config.in src/data.c src/dired.c src/dispnew.c src/doc.c src/editfns.c src/emacs.c src/eval.c src/fileio.c src/filelock.c src/floatfns.c src/fns.c src/frame.c src/gmalloc.c src/hftctl.c src/insdel.c src/keyboard.c src/keymap.c src/lisp.h src/lread.c src/mktime.c src/msdos.c src/print.c src/process.c src/search.c src/sound.c src/strftime.c src/sunfns.c src/sysdep.c src/syssignal.h src/unexelf.c src/unexhp9k800.c src/unexsunos4.c src/vmsfns.c src/vmsgmalloc.c src/w32faces.c src/w32menu.c src/w32proc.c src/w32term.c src/w32xfns.c src/xdisp.c src/xfaces.c src/xfns.c src/xmenu.c src/xterm.c
diffstat 54 files changed, 829 insertions(+), 687 deletions(-) [+]
line wrap: on
line diff
Binary file src/ChangeLog has changed
--- a/src/Makefile.in	Tue Oct 19 07:21:16 1999 +0000
+++ b/src/Makefile.in	Tue Oct 19 07:25:11 1999 +0000
@@ -1,5 +1,5 @@
 # Makefile for GNU Emacs.
-# Copyright (C) 1985, 87, 88, 93, 94, 95 Free Software Foundation, Inc.
+# Copyright (C) 1985, 87, 88, 93, 94, 95, 1999 Free Software Foundation, Inc.
 
 # This file is part of GNU Emacs.
 
@@ -856,9 +856,9 @@
 	ln temacs emacs
 #else
 #ifdef HAVE_SHM
-	./temacs -nl -batch -l loadup dump
+	LC_ALL=C ./temacs -nl -batch -l loadup dump
 #else /* ! defined (HAVE_SHM) */
-	./temacs -batch -l loadup dump
+	LC_ALL=C ./temacs -batch -l loadup dump
 #endif /* ! defined (HAVE_SHM) */
 #endif /* ! defined (CANNOT_DUMP) */
 	-./emacs -q -batch -f list-load-path-shadows
@@ -1057,7 +1057,8 @@
 pre-crt0.o: pre-crt0.c
 ecrt0.o: ecrt0.c $(config_h)
 	CRT0_COMPILE ${srcdir}/ecrt0.c
-dired.o: dired.c commands.h buffer.h $(config_h) charset.h coding.h regex.h
+dired.o: dired.c commands.h buffer.h $(config_h) charset.h coding.h regex.h \
+   systime.h
 dispnew.o: dispnew.c  commands.h frame.h window.h buffer.h dispextern.h \
    termchar.h termopts.h termhooks.h cm.h disptab.h systty.h systime.h \
    xterm.h blockinput.h charset.h msdos.h $(config_h)
@@ -1065,7 +1066,7 @@
 doprnt.o: doprnt.c charset.h $(config_h)
 dosfns.o: buffer.h termchar.h termhooks.h frame.h msdos.h dosfns.h $(config_h)
 editfns.o: editfns.c window.h buffer.h systime.h INTERVAL_SRC charset.h \
-   $(config_h)
+   coding.h $(config_h)
 emacs.o: emacs.c commands.h systty.h syssignal.h blockinput.h process.h \
    termhooks.h buffer.h INTERVAL_SRC $(config_h)
 fileio.o: fileio.c window.h buffer.h systime.h INTERVAL_SRC charset.h \
--- a/src/alloc.c	Tue Oct 19 07:21:16 1999 +0000
+++ b/src/alloc.c	Tue Oct 19 07:25:11 1999 +0000
@@ -1,5 +1,5 @@
 /* Storage allocation and gc for GNU Emacs Lisp interpreter.
-   Copyright (C) 1985, 86, 88, 93, 94, 95, 97, 1998
+   Copyright (C) 1985, 86, 88, 93, 94, 95, 97, 98, 1999
       Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
@@ -19,15 +19,11 @@
 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 Boston, MA 02111-1307, USA.  */
 
+#include <config.h>
+
 /* Note that this declares bzero on OSF/1.  How dumb.  */
 #include <signal.h>
 
-#include <config.h>
-
-#ifdef STDC_HEADERS
-#include <stdlib.h>
-#endif
-
 #include "lisp.h"
 #include "intervals.h"
 #include "puresize.h"
--- a/src/buffer.c	Tue Oct 19 07:21:16 1999 +0000
+++ b/src/buffer.c	Tue Oct 19 07:25:11 1999 +0000
@@ -19,6 +19,7 @@
 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 Boston, MA 02111-1307, USA.  */
 
+#include <config.h>
 
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -32,10 +33,6 @@
 #define MAXPATHLEN 1024
 #endif /* not MAXPATHLEN */
 
-#include <config.h>
-#ifdef STDC_HEADERS
-#include <stdlib.h>
-#endif
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
 #endif
--- a/src/callproc.c	Tue Oct 19 07:21:16 1999 +0000
+++ b/src/callproc.c	Tue Oct 19 07:25:11 1999 +0000
@@ -1,5 +1,5 @@
 /* Synchronous subprocess invocation for GNU Emacs.
-   Copyright (C) 1985, 86, 87, 88, 93, 94, 95 Free Software Foundation, Inc.
+   Copyright (C) 1985, 86,87,88,93,94,95, 1999 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -19,10 +19,9 @@
 Boston, MA 02111-1307, USA.  */
 
 
+#include <config.h>
 #include <signal.h>
 #include <errno.h>
-
-#include <config.h>
 #include <stdio.h>
 
 extern int errno;
@@ -134,7 +133,7 @@
 call_process_kill (fdpid)
      Lisp_Object fdpid;
 {
-  close (XFASTINT (Fcar (fdpid)));
+  emacs_close (XFASTINT (Fcar (fdpid)));
   EMACS_KILLPG (XFASTINT (Fcdr (fdpid)), SIGKILL);
   synch_process_alive = 0;
   return Qnil;
@@ -148,7 +147,7 @@
   /* for MSDOS fdpid is really (fd . tempfile)  */
   register Lisp_Object file;
   file = Fcdr (fdpid);
-  close (XFASTINT (Fcar (fdpid)));
+  emacs_close (XFASTINT (Fcar (fdpid)));
   if (strcmp (XSTRING (file)-> data, NULL_DEVICE) != 0)
     unlink (XSTRING (file)->data);
 #else /* not MSDOS and not macintosh */
@@ -156,7 +155,7 @@
 
   if (call_process_exited)
     {
-      close (XFASTINT (Fcar (fdpid)));
+      emacs_close (XFASTINT (Fcar (fdpid)));
       return Qnil;
     }
 
@@ -173,7 +172,7 @@
       message1 ("Waiting for process to die...done");
     }
   synch_process_alive = 0;
-  close (XFASTINT (Fcar (fdpid)));
+  emacs_close (XFASTINT (Fcar (fdpid)));
 #endif /* not MSDOS */
   return Qnil;
 }
@@ -359,7 +358,7 @@
 
   display = nargs >= 4 ? args[3] : Qnil;
 
-  filefd = open (XSTRING (infile)->data, O_RDONLY, 0);
+  filefd = emacs_open (XSTRING (infile)->data, O_RDONLY, 0);
   if (filefd < 0)
     {
       report_file_error ("Opening process input file", Fcons (infile, Qnil));
@@ -374,7 +373,7 @@
   }
   if (NILP (path))
     {
-      close (filefd);
+      emacs_close (filefd);
       report_file_error ("Searching for program", Fcons (args[0], Qnil));
     }
   new_argv[0] = XSTRING (path)->data;
@@ -436,7 +435,7 @@
   outfilefd = creat (tempfile, S_IREAD | S_IWRITE);
   if (outfilefd < 0)
     {
-      close (filefd);
+      emacs_close (filefd);
       report_file_error ("Opening process output file",
 			 Fcons (build_string (tempfile), Qnil));
     }
@@ -465,7 +464,7 @@
 #endif /* macintosh */
 
   if (INTEGERP (buffer))
-    fd[1] = open (NULL_DEVICE, O_WRONLY), fd[0] = -1;
+    fd[1] = emacs_open (NULL_DEVICE, O_WRONLY, 0), fd[0] = -1;
   else
     {
 #ifndef MSDOS
@@ -500,13 +499,13 @@
     synch_process_retcode = 0;
 
     if (NILP (error_file))
-      fd_error = open (NULL_DEVICE, O_WRONLY);
+      fd_error = emacs_open (NULL_DEVICE, O_WRONLY, 0);
     else if (STRINGP (error_file))
       {
 #ifdef DOS_NT
-	fd_error = open (XSTRING (error_file)->data,
-			 O_WRONLY | O_TRUNC | O_CREAT | O_TEXT,
-			 S_IREAD | S_IWRITE);
+	fd_error = emacs_open (XSTRING (error_file)->data,
+			       O_WRONLY | O_TRUNC | O_CREAT | O_TEXT,
+			       S_IREAD | S_IWRITE);
 #else  /* not DOS_NT */
 	fd_error = creat (XSTRING (error_file)->data, 0666);
 #endif /* not DOS_NT */
@@ -514,11 +513,11 @@
 
     if (fd_error < 0)
       {
-	close (filefd);
+	emacs_close (filefd);
 	if (fd[0] != filefd)
-	  close (fd[0]);
+	  emacs_close (fd[0]);
 	if (fd1 >= 0)
-	  close (fd1);
+	  emacs_close (fd1);
 #ifdef MSDOS
 	unlink (tempfile);
 #endif
@@ -560,7 +559,10 @@
       synch_process_alive = 0;
       synch_process_retcode = pid;
       if (synch_process_retcode < 0)  /* means it couldn't be exec'ed */
-        synch_process_death = strerror (errno);
+	{
+	  synchronize_messages_locale ();
+	  synch_process_death = strerror (errno);
+	}
 
       /* Since CRLF is converted to LF within `decode_coding', we can
          always open a file with binary mode.  */
@@ -585,19 +587,22 @@
     synch_process_alive = 0;
     synch_process_retcode = pid;
     if (synch_process_retcode < 0)  /* means it couldn't be exec'ed */
-      synch_process_death = strerror (errno);
+      {
+	synchronize_messages_locale ();
+	synch_process_death = strerror (errno);
+      }
 
-    close (outfilefd);
+    emacs_close (outfilefd);
     if (fd_error != outfilefd)
-      close (fd_error);
+      emacs_close (fd_error);
     fd1 = -1; /* No harm in closing that one!  */
     /* Since CRLF is converted to LF within `decode_coding', we can
        always open a file with binary mode.  */
-    fd[0] = open (tempfile, O_BINARY);
+    fd[0] = emacs_open (tempfile, O_RDONLY | O_BINARY, 0);
     if (fd[0] < 0)
       {
 	unlink (tempfile);
-	close (filefd);
+	emacs_close (filefd);
 	report_file_error ("Cannot re-open temporary file", Qnil);
       }
 #else /* not MSDOS */
@@ -610,7 +615,7 @@
     if (pid == 0)
       {
 	if (fd[0] >= 0)
-	  close (fd[0]);
+	  emacs_close (fd[0]);
 #ifdef HAVE_SETSID
         setsid ();
 #endif
@@ -626,7 +631,7 @@
 
     /* The MSDOS case did this already.  */
     if (fd_error >= 0)
-      close (fd_error);
+      emacs_close (fd_error);
 #endif /* not MSDOS */
 #endif /* not macintosh */
 
@@ -634,22 +639,22 @@
 
     /* Close most of our fd's, but not fd[0]
        since we will use that to read input from.  */
-    close (filefd);
+    emacs_close (filefd);
     if (fd1 >= 0 && fd1 != fd_error)
-      close (fd1);
+      emacs_close (fd1);
   }
 
   if (pid < 0)
     {
       if (fd[0] >= 0)
-	close (fd[0]);
+	emacs_close (fd[0]);
       report_file_error ("Doing vfork", Qnil);
     }
 
   if (INTEGERP (buffer))
     {
       if (fd[0] >= 0)
-	close (fd[0]);
+	emacs_close (fd[0]);
 #ifndef subprocesses
       /* If Emacs has been built with asynchronous subprocess support,
 	 we don't need to do this, I think because it will then have
@@ -737,7 +742,8 @@
 	nread = carryover;
 	while (nread < bufsize - 1024)
 	  {
-	    int this_read = read (fd[0], bufptr + nread, bufsize - nread);
+	    int this_read = emacs_read (fd[0], bufptr + nread,
+					bufsize - nread);
 
 	    if (this_read < 0)
 	      goto give_up;
@@ -849,7 +855,8 @@
   unbind_to (count, Qnil);
 
   if (synch_process_death)
-    return build_string (synch_process_death);
+    return code_convert_string_norecord (build_string (synch_process_death),
+					 Vlocale_coding_system, 0);
   return make_number (synch_process_retcode);
 }
 #endif
@@ -1163,16 +1170,16 @@
   }
 
 #ifndef MSDOS
-  close (0);
-  close (1);
-  close (2);
+  emacs_close (0);
+  emacs_close (1);
+  emacs_close (2);
 
   dup2 (in, 0);
   dup2 (out, 1);
   dup2 (err, 2);
-  close (in);
-  close (out);
-  close (err);
+  emacs_close (in);
+  emacs_close (out);
+  emacs_close (err);
 #endif /* not MSDOS */
 #endif /* not WINDOWSNT */
 
@@ -1212,9 +1219,9 @@
   environ = env;
   execvp (new_argv[0], new_argv);
 
-  write (1, "Can't exec program: ", 20);
-  write (1, new_argv[0], strlen (new_argv[0]));
-  write (1, "\n", 1);
+  emacs_write (1, "Can't exec program: ", 20);
+  emacs_write (1, new_argv[0], strlen (new_argv[0]));
+  emacs_write (1, "\n", 1);
   _exit (1);
 #endif /* not WINDOWSNT */
 #endif /* not MSDOS */
@@ -1236,15 +1243,15 @@
 	  char *message1 = "Error while setting up child: ";
 	  char *errmessage = strerror (errno);
 	  char *message2 = "\n";
-	  write (2, message1, strlen (message1));
-	  write (2, errmessage, strlen (errmessage));
-	  write (2, message2, strlen (message2));
+	  emacs_write (2, message1, strlen (message1));
+	  emacs_write (2, errmessage, strlen (errmessage));
+	  emacs_write (2, message2, strlen (message2));
 	  _exit (1);
 	}
       /* Note that we hold the original FD open while we recurse,
 	 to guarantee we'll get a new FD if we need it.  */
       new = relocate_fd (new, minfd);
-      close (fd);
+      emacs_close (fd);
       return new;
     }
 }
--- a/src/ccl.c	Tue Oct 19 07:21:16 1999 +0000
+++ b/src/ccl.c	Tue Oct 19 07:25:11 1999 +0000
@@ -19,16 +19,14 @@
 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 Boston, MA 02111-1307, USA.  */
 
+#ifdef emacs
+#include <config.h>
+#endif
+
 #include <stdio.h>
 
 #ifdef emacs
 
-#include <config.h>
-
-#ifdef STDC_HEADERS
-#include <stdlib.h>
-#endif
-
 #include "lisp.h"
 #include "charset.h"
 #include "ccl.h"
--- a/src/charset.c	Tue Oct 19 07:21:16 1999 +0000
+++ b/src/charset.c	Tue Oct 19 07:25:11 1999 +0000
@@ -22,12 +22,15 @@
 /* At first, see the document in `charset.h' to understand the code in
    this file.  */
 
+#ifdef emacs
+#include <config.h>
+#endif
+
 #include <stdio.h>
 
 #ifdef emacs
 
 #include <sys/types.h>
-#include <config.h>
 #include "lisp.h"
 #include "buffer.h"
 #include "charset.h"
--- a/src/coding.c	Tue Oct 19 07:21:16 1999 +0000
+++ b/src/coding.c	Tue Oct 19 07:25:11 1999 +0000
@@ -268,11 +268,14 @@
 
 /*** 1. Preamble ***/
 
+#ifdef emacs
+#include <config.h>
+#endif
+
 #include <stdio.h>
 
 #ifdef emacs
 
-#include <config.h>
 #include "lisp.h"
 #include "buffer.h"
 #include "charset.h"
@@ -357,6 +360,8 @@
 Lisp_Object Vprocess_coding_system_alist;
 Lisp_Object Vnetwork_coding_system_alist;
 
+Lisp_Object Vlocale_coding_system;
+
 #endif /* emacs */
 
 Lisp_Object Qcoding_category, Qcoding_category_index;
@@ -5786,6 +5791,10 @@
 See also the function `find-operation-coding-system'.");
   Vnetwork_coding_system_alist = Qnil;
 
+  DEFVAR_LISP ("locale-coding-system", &Vlocale_coding_system,
+    "Coding system to use with system messages.");
+  Vlocale_coding_system = Qnil;
+
   DEFVAR_LISP ("eol-mnemonic-unix", &eol_mnemonic_unix,
     "*String displayed in mode line for UNIX-like (LF) end-of-line format.");
   eol_mnemonic_unix = build_string (":");
@@ -5853,4 +5862,24 @@
 
 }
 
+char *
+emacs_strerror (error_number)
+     int error_number;
+{
+  char *str;
+
+  synchronize_messages_locale ();
+  str = strerror (error_number);
+
+  if (! NILP (Vlocale_coding_system))
+    {
+      Lisp_Object dec = code_convert_string_norecord (build_string (str),
+						      Vlocale_coding_system,
+						      0);
+      str = (char *) XSTRING (dec)->data;
+    }
+
+  return str;
+}
+
 #endif /* emacs */
--- a/src/coding.h	Tue Oct 19 07:21:16 1999 +0000
+++ b/src/coding.h	Tue Oct 19 07:25:11 1999 +0000
@@ -551,12 +551,16 @@
 extern Lisp_Object Qcall_process, Qcall_process_region, Qprocess_argument;
 extern Lisp_Object Qstart_process, Qopen_network_stream;
 
+extern char *emacs_strerror P_ ((int));
+
 /* Coding-system for reading files and receiving data from process.  */
 extern Lisp_Object Vcoding_system_for_read;
 /* Coding-system for writing files and sending data to process.  */
 extern Lisp_Object Vcoding_system_for_write;
 /* Coding-system actually used in the latest I/O.  */
 extern Lisp_Object Vlast_coding_system_used;
+/* Coding-system to use with system messages (e.g. strerror).  */
+extern Lisp_Object Vlocale_coding_system;
 
 /* If non-zero, process buffer inherits the coding system used to decode
    the subprocess output.  */
--- a/src/config.in	Tue Oct 19 07:21:16 1999 +0000
+++ b/src/config.in	Tue Oct 19 07:25:11 1999 +0000
@@ -1,5 +1,5 @@
 /* GNU Emacs site configuration template file.  -*- C -*-
-   Copyright (C) 1988, 1993, 1994 Free Software Foundation, Inc.
+   Copyright (C) 1988, 1993, 1994, 1999 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -166,10 +166,11 @@
 #undef HAVE_TERMIOS_H
 #undef HAVE_LIMITS_H
 #undef HAVE_STRING_H
+#undef HAVE_STDLIB_H
+#undef HAVE_TERMCAP_H
+#undef HAVE_STDIO_EXT_H
 #undef STDC_HEADERS
 #undef TIME_WITH_SYS_TIME
-#undef HAVE_STDLIB_H
-#undef HAVE_TERMCAP_H
 
 #undef HAVE_LIBDNET
 #undef HAVE_LIBPTHREADS
@@ -226,6 +227,7 @@
 #undef TM_IN_SYS_TIME
 #undef HAVE_TM_ZONE
 #undef HAVE_TZNAME
+#undef HAVE_TM_GMTOFF
 
 #undef const
 
@@ -270,6 +272,12 @@
 #undef HAVE_SHUTDOWN
 #undef HAVE_STRFTIME
 #undef HAVE_GETADDRINFO
+#undef HAVE___FPENDING
+#undef HAVE_FTELLO
+#undef HAVE_GETLOADAVG
+#undef HAVE_MBLEN
+#undef HAVE_MBRLEN
+#undef HAVE_STRSIGNAL
 
 #undef LOCALTIME_CACHE
 #undef HAVE_INET_SOCKETS
@@ -447,12 +455,19 @@
 #endif
 
 #ifndef BITS_PER_LONG
+#ifdef _LP64
+#define BITS_PER_LONG 64
+#else
 #define BITS_PER_LONG 32
 #endif
+#endif
 
-/* Don't include <string.h> during configure.  */
+/* Don't include "string.h" or <stdlib.h> in non-C code.  */
 #ifndef NOT_C_CODE
 #ifdef HAVE_STRING_H
 #include "string.h"
 #endif
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
 #endif
+#endif
--- a/src/data.c	Tue Oct 19 07:21:16 1999 +0000
+++ b/src/data.c	Tue Oct 19 07:25:11 1999 +0000
@@ -1,5 +1,5 @@
 /* Primitive operations on Lisp data types for GNU Emacs Lisp interpreter.
-   Copyright (C) 1985,86,88,93,94,95,97, 1998 Free Software Foundation, Inc.
+   Copyright (C) 1985,86,88,93,94,95,97,98, 1999 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -19,9 +19,8 @@
 Boston, MA 02111-1307, USA.  */
 
 
+#include <config.h>
 #include <signal.h>
-
-#include <config.h>
 #include <stdio.h>
 #include "lisp.h"
 #include "puresize.h"
@@ -38,7 +37,6 @@
 #ifdef LISP_FLOAT_TYPE
 
 #ifdef STDC_HEADERS
-#include <stdlib.h>
 #include <float.h>
 #endif
 
--- a/src/dired.c	Tue Oct 19 07:21:16 1999 +0000
+++ b/src/dired.c	Tue Oct 19 07:25:11 1999 +0000
@@ -1,5 +1,5 @@
 /* Lisp functions for making directory listings.
-   Copyright (C) 1985, 1986, 1993, 1994 Free Software Foundation, Inc.
+   Copyright (C) 1985, 1986, 1993, 1994, 1999 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -25,6 +25,8 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 
+#include "systime.h"
+
 #ifdef VMS
 #include <string.h>
 #include <rms.h>
@@ -790,7 +792,7 @@
   values[4] = make_time (s.st_atime);
   values[5] = make_time (s.st_mtime);
   values[6] = make_time (s.st_ctime);
-  values[7] = make_number ((int) s.st_size);
+  values[7] = make_number (s.st_size);
   /* If the size is out of range for an integer, return a float.  */
   if (XINT (values[7]) != s.st_size)
     values[7] = make_float ((double)s.st_size);
@@ -822,7 +824,14 @@
   else
     /* But keep the most common cases as integers.  */
     values[10] = make_number (s.st_ino);
-  values[11] = make_number (s.st_dev);
+
+  /* Likewise for device.  */
+  if (s.st_dev & (((EMACS_INT) (-1)) << VALBITS))
+    values[11] = Fcons (make_number (s.st_dev >> 16),
+			make_number (s.st_dev & 0xffff));
+  else
+    values[11] = make_number (s.st_dev);
+
   return Flist (sizeof(values) / sizeof(values[0]), values);
 }
 
--- a/src/dispnew.c	Tue Oct 19 07:21:16 1999 +0000
+++ b/src/dispnew.c	Tue Oct 19 07:25:11 1999 +0000
@@ -1,5 +1,5 @@
 /* Updating of data structures for redisplay.
-   Copyright (C) 1985, 86, 87, 88, 93, 94, 95, 97, 1998
+   Copyright (C) 1985, 86, 87, 88, 93, 94, 95, 97, 98, 1999
        Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
@@ -19,8 +19,8 @@
 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 Boston, MA 02111-1307, USA.  */
 
+#include <config.h>
 #include <signal.h>
-#include <config.h>
 #include <stdio.h>
 #include <ctype.h>
 
@@ -91,6 +91,10 @@
 #define	PENDING_OUTPUT_COUNT(FILE) ((FILE)->__bufp - (FILE)->__buffer)
 #endif
 #else /* not __GNU_LIBRARY__ */
+#if !defined (PENDING_OUTPUT_COUNT) && HAVE_STDIO_EXT_H && HAVE___FPENDING
+#include <stdio_ext.h>
+#define PENDING_OUTPUT_COUNT(FILE) __fpending (FILE)
+#endif
 #ifndef PENDING_OUTPUT_COUNT
 #define PENDING_OUTPUT_COUNT(FILE) ((FILE)->_ptr - (FILE)->_base)
 #endif
--- a/src/doc.c	Tue Oct 19 07:21:16 1999 +0000
+++ b/src/doc.c	Tue Oct 19 07:25:11 1999 +0000
@@ -1,5 +1,5 @@
 /* Record indices of function doc strings stored in a file.
-   Copyright (C) 1985, 86, 93, 94, 95, 97, 1998 Free Software Foundation, Inc.
+   Copyright (C) 1985, 86,93,94,95,97,98, 1999 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -161,7 +161,7 @@
       name = (char *) XSTRING (file)->data;
     }
 
-  fd = open (name, O_RDONLY, 0);
+  fd = emacs_open (name, O_RDONLY, 0);
   if (fd < 0)
     {
 #ifndef CANNOT_DUMP
@@ -173,7 +173,7 @@
 	  strcat (name, XSTRING (file)->data);
 	  munge_doc_file_name (name);
 
-	  fd = open (name, O_RDONLY, 0);
+	  fd = emacs_open (name, O_RDONLY, 0);
 	}
 #endif
       if (fd < 0)
@@ -184,7 +184,7 @@
   offset = position % (8 * 1024);
   if (0 > lseek (fd, position - offset, 0))
     {
-      close (fd);
+      emacs_close (fd);
       error ("Position %ld out of range in doc string file \"%s\"",
 	     position, name);
     }
@@ -216,10 +216,10 @@
          If we read the same block last time, maybe skip this?  */
       if (space_left > 1024 * 8)
 	space_left = 1024 * 8;
-      nread = read (fd, p, space_left);
+      nread = emacs_read (fd, p, space_left);
       if (nread < 0)
 	{
-	  close (fd);
+	  emacs_close (fd);
 	  error ("Read error on documentation file");
 	}
       p[nread] = 0;
@@ -237,7 +237,7 @@
 	}
       p += nread;
     }
-  close (fd);
+  emacs_close (fd);
 
   /* Scan the text and perform quoting with ^A (char code 1).
      ^A^A becomes ^A, ^A0 becomes a null char, and ^A_ becomes a ^_.  */
@@ -507,7 +507,7 @@
 #endif /* VMS4_4 */
 #endif /* VMS */
 
-  fd = open (name, O_RDONLY, 0);
+  fd = emacs_open (name, O_RDONLY, 0);
   if (fd < 0)
     report_file_error ("Opening doc string file",
 		       Fcons (build_string (name), Qnil));
@@ -517,7 +517,7 @@
   while (1)
     {
       if (filled < 512)
-	filled += read (fd, &buf[filled], sizeof buf - 1 - filled);
+	filled += emacs_read (fd, &buf[filled], sizeof buf - 1 - filled);
       if (!filled)
 	break;
 
@@ -557,7 +557,7 @@
       filled -= end - buf;
       bcopy (end, buf, filled);
     }
-  close (fd);
+  emacs_close (fd);
   return Qnil;
 }
 
--- a/src/editfns.c	Tue Oct 19 07:21:16 1999 +0000
+++ b/src/editfns.c	Tue Oct 19 07:25:11 1999 +0000
@@ -19,20 +19,15 @@
 Boston, MA 02111-1307, USA.  */
 
 
+#include <config.h>
 #include <sys/types.h>
 
-#include <config.h>
-
 #ifdef VMS
 #include "vms-pwd.h"
 #else
 #include <pwd.h>
 #endif
 
-#ifdef STDC_HEADERS
-#include <stdlib.h>
-#endif
-
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
 #endif
@@ -41,6 +36,7 @@
 #include "intervals.h"
 #include "buffer.h"
 #include "charset.h"
+#include "coding.h"
 #include "window.h"
 
 #include "systime.h"
@@ -57,7 +53,7 @@
 extern void insert_from_buffer ();
 static int tm_diff ();
 static void update_buffer_properties ();
-size_t emacs_strftime ();
+size_t emacs_strftimeu ();
 void set_time_zone_rule ();
 
 Lisp_Object Vbuffer_access_fontify_functions;
@@ -1174,27 +1170,29 @@
 
 /* Write information into buffer S of size MAXSIZE, according to the
    FORMAT of length FORMAT_LEN, using time information taken from *TP.
+   Default to Universal Time if UT is nonzero, local time otherwise.
    Return the number of bytes written, not including the terminating
    '\0'.  If S is NULL, nothing will be written anywhere; so to
    determine how many bytes would be written, use NULL for S and
    ((size_t) -1) for MAXSIZE.
 
-   This function behaves like emacs_strftime, except it allows null
+   This function behaves like emacs_strftimeu, except it allows null
    bytes in FORMAT.  */
 static size_t
-emacs_memftime (s, maxsize, format, format_len, tp)
+emacs_memftimeu (s, maxsize, format, format_len, tp, ut)
       char *s;
       size_t maxsize;
       const char *format;
       size_t format_len;
       const struct tm *tp;
+      int ut;
 {
   size_t total = 0;
 
   /* Loop through all the null-terminated strings in the format
      argument.  Normally there's just one null-terminated string, but
      there can be arbitrarily many, concatenated together, if the
-     format contains '\0' bytes.  emacs_strftime stops at the first
+     format contains '\0' bytes.  emacs_strftimeu stops at the first
      '\0' byte so we must invoke it separately for each such string.  */
   for (;;)
     {
@@ -1204,7 +1202,7 @@
       if (s)
 	s[0] = '\1';
 
-      result = emacs_strftime (s, maxsize, format, tp);
+      result = emacs_strftimeu (s, maxsize, format, tp, ut);
 
       if (s)
 	{
@@ -1283,36 +1281,43 @@
   time_t value;
   int size;
   struct tm *tm;
+  int ut = ! NILP (universal);
 
   CHECK_STRING (format_string, 1);
 
   if (! lisp_time_argument (time, &value))
     error ("Invalid time specification");
 
+  format_string = code_convert_string_norecord (format_string,
+						Vlocale_coding_system, 1);
+
   /* This is probably enough.  */
   size = STRING_BYTES (XSTRING (format_string)) * 6 + 50;
 
-  tm = NILP (universal) ? localtime (&value) : gmtime (&value);
+  tm = ut ? gmtime (&value) : localtime (&value);
   if (! tm)
     error ("Specified time is not representable");
 
+  synchronize_time_locale ();
+
   while (1)
     {
       char *buf = (char *) alloca (size + 1);
       int result;
 
       buf[0] = '\1';
-      result = emacs_memftime (buf, size, XSTRING (format_string)->data,
-			       STRING_BYTES (XSTRING (format_string)),
-			       tm);
+      result = emacs_memftimeu (buf, size, XSTRING (format_string)->data,
+				STRING_BYTES (XSTRING (format_string)),
+				tm, ut);
       if ((result > 0 && result < size) || (result == 0 && buf[0] == '\0'))
-	return make_string (buf, result);
+	return code_convert_string_norecord (make_string (buf, result),
+					     Vlocale_coding_system, 0);
 
       /* If buffer was too small, make it bigger and try again.  */
-      result = emacs_memftime (NULL, (size_t) -1,
-			       XSTRING (format_string)->data,
-			       STRING_BYTES (XSTRING (format_string)),
-			       tm);
+      result = emacs_memftimeu (NULL, (size_t) -1,
+				XSTRING (format_string)->data,
+				STRING_BYTES (XSTRING (format_string)),
+				tm, ut);
       size = result + 1;
     }
 }
--- a/src/emacs.c	Tue Oct 19 07:21:16 1999 +0000
+++ b/src/emacs.c	Tue Oct 19 07:25:11 1999 +0000
@@ -1,5 +1,5 @@
 /* Fully extensible Emacs, running on Unix, intended for GNU.
-   Copyright (C) 1985,86,87,93,94,95,97,1998 Free Software Foundation, Inc.
+   Copyright (C) 1985,86,87,93,94,95,97,98,1999 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -19,10 +19,9 @@
 Boston, MA 02111-1307, USA.  */
 
 
+#include <config.h>
 #include <signal.h>
 #include <errno.h>
-
-#include <config.h>
 #include <stdio.h>
 
 #include <sys/types.h>
@@ -40,10 +39,6 @@
 #include <sys/ioctl.h>
 #endif
 
-#ifdef STDC_HEADERS
-#include <stdlib.h>
-#endif
-
 #include "lisp.h"
 #include "commands.h"
 #include "intervals.h"
@@ -56,6 +51,10 @@
 #include "termhooks.h"
 #include "keyboard.h"
 
+#ifdef HAVE_SETLOCALE
+#include <locale.h>
+#endif
+
 #ifdef HAVE_SETRLIMIT
 #include <sys/time.h>
 #include <sys/resource.h>
@@ -128,6 +127,12 @@
 
 Lisp_Object Qfile_name_handler_alist;
 
+/* Current and previous system locales for messages and time.  */
+Lisp_Object Vmessages_locale;
+Lisp_Object Vprevious_messages_locale;
+Lisp_Object Vtime_locale;
+Lisp_Object Vprevious_time_locale;
+
 /* If non-zero, emacs should not attempt to use an window-specific code,
    but instead should use the virtual terminal under which it was started */
 int inhibit_window_system;
@@ -602,6 +607,7 @@
      char **envp;
 {
   char stack_bottom_variable;
+  int do_initial_setlocale;
   int skip_args = 0;
   extern int errno;
   extern int sys_nerr;
@@ -785,6 +791,20 @@
   setuid (getuid ());
 #endif /* SET_EMACS_PRIORITY */
 
+  /* Skip initial setlocale if LC_ALL is "C", as it's not needed in that case.
+     The build procedure uses this while dumping, to ensure that the
+     dumped Emacs does not have its system locale tables initialized,
+     as that might cause screwups when the dumped Emacs starts up.  */
+  {
+    char *lc_all = getenv ("LC_ALL");
+    do_initial_setlocale = ! lc_all || strcmp (lc_all, "C");
+  }
+
+  /* Set locale now, so that initial error messages are localized properly.
+     fixup_locale must wait until later, since it builds strings.  */
+  if (do_initial_setlocale)
+    setlocale (LC_ALL, "");
+
 #ifdef EXTRA_INITIALIZE
   EXTRA_INITIALIZE;
 #endif
@@ -798,9 +818,9 @@
       if (argmatch (argv, argc, "-t", "--terminal", 4, &term, &skip_args))
 	{
 	  int result;
-	  close (0);
-	  close (1);
-	  result = open (term, O_RDWR, 2 );
+	  emacs_close (0);
+	  emacs_close (1);
+	  result = emacs_open (term, O_RDWR, 0);
 	  if (result < 0)
 	    {
 	      char *errstring = strerror (errno);
@@ -994,6 +1014,14 @@
     }
 
   init_alloc ();
+
+  if (do_initial_setlocale)
+    {
+      fixup_locale ();
+      Vmessages_locale = Vprevious_messages_locale;
+      Vtime_locale = Vprevious_time_locale;
+    }
+
   init_eval ();
   init_coding ();
   init_data ();
@@ -1859,6 +1887,55 @@
 
 #endif /* not CANNOT_DUMP */
 
+#if HAVE_SETLOCALE
+/* Recover from setlocale (LC_ALL, "").  */
+void
+fixup_locale ()
+{
+  char *l;
+
+  /* The Emacs Lisp reader needs LC_NUMERIC to be "C",
+     so that numbers are read and printed properly for Emacs Lisp.  */
+  setlocale (LC_NUMERIC, "C");
+
+#ifdef LC_MESSAGES
+  l = setlocale (LC_MESSAGES, (char *) 0);
+  Vprevious_messages_locale = l ? build_string (l) : Qnil;
+#endif
+  l = setlocale (LC_TIME, (char *) 0);
+  Vprevious_time_locale = l ? build_string (l) : Qnil;
+}
+
+static void
+synchronize_locale (category, plocale, desired_locale)
+     int category;
+     Lisp_Object *plocale;
+     Lisp_Object desired_locale;
+{
+  if (STRINGP (desired_locale)
+      && (NILP (*plocale) || NILP (Fstring_equal (*plocale, desired_locale)))
+      && setlocale (category, XSTRING (desired_locale)->data))
+    *plocale = desired_locale;
+}
+
+/* Set system time locale to match Vtime_locale, if possible.  */
+void
+synchronize_time_locale ()
+{
+  synchronize_locale (LC_TIME, &Vprevious_time_locale, Vtime_locale);
+}
+
+/* Set system messages locale to match Vmessages_locale, if possible.  */
+void
+synchronize_messages_locale ()
+{
+#ifdef LC_MESSAGES
+  synchronize_locale (LC_MESSAGES, &Vprevious_messages_locale,
+		      Vmessages_locale);
+#endif
+}
+#endif /* HAVE_SETLOCALE */
+
 #ifndef SEPCHAR
 #define SEPCHAR ':'
 #endif
@@ -2003,4 +2080,20 @@
 installed locations, but we can find them\n\
 near where the Emacs executable was found.");
   Vinstallation_directory = Qnil;
+
+  DEFVAR_LISP ("messages-locale", &Vmessages_locale,
+    "System locale for messages.");
+  Vmessages_locale = Qnil;
+
+  DEFVAR_LISP ("previous-messages-locale", &Vprevious_messages_locale,
+    "Most recently used system locale for messages.");
+  Vprevious_messages_locale = Qnil;
+
+  DEFVAR_LISP ("time-locale", &Vtime_locale,
+    "System locale for time.");
+  Vtime_locale = Qnil;
+
+  DEFVAR_LISP ("previous-time-locale", &Vprevious_time_locale,
+    "Most recently used system locale for time.");
+  Vprevious_time_locale = Qnil;
 }
--- a/src/eval.c	Tue Oct 19 07:21:16 1999 +0000
+++ b/src/eval.c	Tue Oct 19 07:25:11 1999 +0000
@@ -1,5 +1,5 @@
 /* Evaluator for GNU Emacs Lisp interpreter.
-   Copyright (C) 1985, 1986, 1987, 1993, 1994, 1995 Free Software Foundation, Inc.
+   Copyright (C) 1985, 86, 87, 93, 94, 95, 1999 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -21,10 +21,6 @@
 
 #include <config.h>
 
-#ifdef STDC_HEADERS
-#include <stdlib.h>
-#endif
-
 #include "lisp.h"
 #include "blockinput.h"
 
--- a/src/fileio.c	Tue Oct 19 07:21:16 1999 +0000
+++ b/src/fileio.c	Tue Oct 19 07:25:11 1999 +0000
@@ -1,5 +1,5 @@
 /* File IO for GNU Emacs.
-   Copyright (C) 1985,86,87,88,93,94,95,96,97,1998 Free Software Foundation, Inc.
+   Copyright (C) 1985,86,87,88,93,94,95,96,97,98,1999 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -32,10 +32,6 @@
 #include <unistd.h>
 #endif
 
-#ifdef STDC_HEADERS
-#include <stdlib.h>
-#endif
-
 #if !defined (S_ISLNK) && defined (S_IFLNK)
 #  define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
 #endif
@@ -253,7 +249,10 @@
   Lisp_Object errstring;
   int errorno = errno;
 
-  errstring = build_string (strerror (errno));
+  synchronize_messages_locale ();
+  errstring = code_convert_string_norecord (build_string (strerror (errorno)),
+					    Vlocale_coding_system, 0);
+
   while (1)
     switch (errorno)
       {
@@ -275,7 +274,7 @@
 close_file_unwind (fd)
      Lisp_Object fd;
 {
-  close (XFASTINT (fd));
+  emacs_close (XFASTINT (fd));
   return Qnil;
 }
 
@@ -2287,7 +2286,7 @@
   else if (stat (XSTRING (encoded_newname)->data, &out_st) < 0)
     out_st.st_mode = 0;
 
-  ifd = open (XSTRING (encoded_file)->data, O_RDONLY);
+  ifd = emacs_open (XSTRING (encoded_file)->data, O_RDONLY, 0);
   if (ifd < 0)
     report_file_error ("Opening input file", Fcons (file, Qnil));
 
@@ -2339,13 +2338,13 @@
 
   immediate_quit = 1;
   QUIT;
-  while ((n = read (ifd, buf, sizeof buf)) > 0)
-    if (write (ofd, buf, n) != n)
+  while ((n = emacs_read (ifd, buf, sizeof buf)) > 0)
+    if (emacs_write (ofd, buf, n) != n)
       report_file_error ("I/O error", Fcons (newname, Qnil));
   immediate_quit = 0;
 
   /* Closing the output clobbers the file times on some systems.  */
-  if (close (ofd) < 0)
+  if (emacs_close (ofd) < 0)
     report_file_error ("I/O error", Fcons (newname, Qnil));
 
   if (input_file_statable_p)
@@ -2375,7 +2374,7 @@
 #endif /* MSDOS */
     }
 
-  close (ifd);
+  emacs_close (ifd);
 
   /* Discard the unwind protects.  */
   specpdl_ptr = specpdl + count;
@@ -2914,10 +2913,10 @@
   if (S_ISFIFO (statbuf.st_mode))
     flags |= O_NONBLOCK;
 #endif
-  desc = open (XSTRING (absname)->data, flags);
+  desc = emacs_open (XSTRING (absname)->data, flags, 0);
   if (desc < 0)
     return Qnil;
-  close (desc);
+  emacs_close (desc);
   return Qt;
 #endif /* not DOS_NT */
 }
@@ -2983,10 +2982,10 @@
 
   encoded_filename = ENCODE_FILE (filename);
 
-  fd = open (XSTRING (encoded_filename)->data, O_RDONLY);
+  fd = emacs_open (XSTRING (encoded_filename)->data, O_RDONLY, 0);
   if (fd < 0)
     report_file_error (XSTRING (string)->data, Fcons (filename, Qnil));
-  close (fd);
+  emacs_close (fd);
 
   return Qnil;
 }
@@ -3403,12 +3402,12 @@
 #ifndef APOLLO
   if (stat (XSTRING (filename)->data, &st) < 0)
 #else
-  if ((fd = open (XSTRING (filename)->data, O_RDONLY)) < 0
+  if ((fd = emacs_open (XSTRING (filename)->data, O_RDONLY, 0)) < 0
       || fstat (fd, &st) < 0)
 #endif /* not APOLLO */
 #endif /* WINDOWSNT */
     {
-      if (fd >= 0) close (fd);
+      if (fd >= 0) emacs_close (fd);
     badopen:
       if (NILP (visit))
 	report_file_error ("Opening input file", Fcons (orig_filename, Qnil));
@@ -3438,7 +3437,7 @@
 #endif
 
   if (fd < 0)
-    if ((fd = open (XSTRING (filename)->data, O_RDONLY)) < 0)
+    if ((fd = emacs_open (XSTRING (filename)->data, O_RDONLY, 0)) < 0)
       goto badopen;
 
   /* Replacement should preserve point as it preserves markers.  */
@@ -3470,7 +3469,13 @@
       if (! not_regular)
 	{
 	  XSETINT (end, st.st_size);
-	  if (XINT (end) != st.st_size)
+
+	  /* Arithmetic overflow can occur if an Emacs integer cannot
+	     represent the file size, or if the calculations below
+	     overflow.  The calculations below double the file size
+	     twice, so check that it can be multiplied by 4 safely.  */
+	  if (XINT (end) != st.st_size
+	      || ((int) st.st_size * 4) / 4 != st.st_size)
 	    error ("Maximum buffer size exceeded");
 	}
     }
@@ -3503,22 +3508,22 @@
 	      int how_many, nread;
 
 	      if (st.st_size <= (1024 * 4))
-		nread = read (fd, read_buf, 1024 * 4);
+		nread = emacs_read (fd, read_buf, 1024 * 4);
 	      else
 		{
-		  nread = read (fd, read_buf, 1024);
+		  nread = emacs_read (fd, read_buf, 1024);
 		  if (nread >= 0)
 		    {
 		      if (lseek (fd, st.st_size - (1024 * 3), 0) < 0)
 			report_file_error ("Setting file position",
 					   Fcons (orig_filename, Qnil));
-		      nread += read (fd, read_buf + nread, 1024 * 3);
+		      nread += emacs_read (fd, read_buf + nread, 1024 * 3);
 		    }
 		}
 
 	      if (nread < 0)
 		error ("IO error reading %s: %s",
-		       XSTRING (orig_filename)->data, strerror (errno));
+		       XSTRING (orig_filename)->data, emacs_strerror (errno));
 	      else if (nread > 0)
 		{
 		  int count = specpdl_ptr - specpdl;
@@ -3618,10 +3623,10 @@
 	{
 	  int nread, bufpos;
 
-	  nread = read (fd, buffer, sizeof buffer);
+	  nread = emacs_read (fd, buffer, sizeof buffer);
 	  if (nread < 0)
 	    error ("IO error reading %s: %s",
-		   XSTRING (orig_filename)->data, strerror (errno));
+		   XSTRING (orig_filename)->data, emacs_strerror (errno));
 	  else if (nread == 0)
 	    break;
 
@@ -3660,7 +3665,7 @@
 	 there's no need to replace anything.  */
       if (same_at_start - BEGV_BYTE == XINT (end))
 	{
-	  close (fd);
+	  emacs_close (fd);
 	  specpdl_ptr--;
 	  /* Truncate the buffer to the size of the file.  */
 	  del_range_1 (same_at_start, same_at_end, 0);
@@ -3689,10 +3694,10 @@
 	  total_read = 0;
 	  while (total_read < trial)
 	    {
-	      nread = read (fd, buffer + total_read, trial - total_read);
+	      nread = emacs_read (fd, buffer + total_read, trial - total_read);
 	      if (nread <= 0)
 		error ("IO error reading %s: %s",
-		       XSTRING (orig_filename)->data, strerror (errno));
+		       XSTRING (orig_filename)->data, emacs_strerror (errno));
 	      total_read += nread;
 	    }
 	  /* Scan this bufferful from the end, comparing with
@@ -3809,7 +3814,7 @@
 	  /* Allow quitting out of the actual I/O.  */
 	  immediate_quit = 1;
 	  QUIT;
-	  this = read (fd, destination, trytry);
+	  this = emacs_read (fd, destination, trytry);
 	  immediate_quit = 0;
 
 	  if (this < 0 || this + unprocessed == 0)
@@ -3862,7 +3867,7 @@
 
 	  if (how_much == -1)
 	    error ("IO error reading %s: %s",
-		   XSTRING (orig_filename)->data, strerror (errno));
+		   XSTRING (orig_filename)->data, emacs_strerror (errno));
 	  else if (how_much == -2)
 	    error ("maximum buffer size exceeded");
 	}
@@ -3881,7 +3886,7 @@
       if (bufpos == inserted)
 	{
 	  xfree (conversion_buffer);
-	  close (fd);
+	  emacs_close (fd);
 	  specpdl_ptr--;
 	  /* Truncate the buffer to the size of the file.  */
 	  del_range_byte (same_at_start, same_at_end, 0);
@@ -3946,7 +3951,7 @@
       inserted = PT - temp;
 
       free (conversion_buffer);
-      close (fd);
+      emacs_close (fd);
       specpdl_ptr--;
 
       goto handled;
@@ -4003,7 +4008,8 @@
       /* Allow quitting out of the actual I/O.  */
       immediate_quit = 1;
       QUIT;
-      this = read (fd, BYTE_POS_ADDR (PT_BYTE + inserted - 1) + 1, trytry);
+      this = emacs_read (fd, BYTE_POS_ADDR (PT_BYTE + inserted - 1) + 1,
+			 trytry);
       immediate_quit = 0;
 
       if (this <= 0)
@@ -4034,14 +4040,14 @@
     /* Put an anchor to ensure multi-byte form ends at gap.  */
     *GPT_ADDR = 0;
 
-  close (fd);
+  emacs_close (fd);
 
   /* Discard the unwind protect for closing the file.  */
   specpdl_ptr--;
 
   if (how_much < 0)
     error ("IO error reading %s: %s",
-	   XSTRING (orig_filename)->data, strerror (errno));
+	   XSTRING (orig_filename)->data, emacs_strerror (errno));
 
   if (! coding_system_decided)
     {
@@ -4496,9 +4502,9 @@
   desc = -1;
   if (!NILP (append))
 #ifdef DOS_NT
-    desc = open (fn, O_WRONLY | buffer_file_type);
+    desc = emacs_open (fn, O_WRONLY | buffer_file_type, 0);
 #else  /* not DOS_NT */
-    desc = open (fn, O_WRONLY);
+    desc = emacs_open (fn, O_WRONLY, 0);
 #endif /* not DOS_NT */
 
   if (desc < 0 && (NILP (append) || errno == ENOENT))
@@ -4506,7 +4512,7 @@
     if (auto_saving)    /* Overwrite any previous version of autosave file */
       {
 	vms_truncate (fn);      /* if fn exists, truncate to zero length */
-	desc = open (fn, O_RDWR);
+	desc = emacs_open (fn, O_RDWR, 0);
 	if (desc < 0)
 	  desc = creat_copy_attrs (STRINGP (current_buffer->filename)
 				   ? XSTRING (current_buffer->filename)->data : 0,
@@ -4539,7 +4545,7 @@
 		    /* We can't make a new version;
 		       try to truncate and rewrite existing version if any.  */
 		    vms_truncate (fn);
-		    desc = open (fn, O_RDWR);
+		    desc = emacs_open (fn, O_RDWR, 0);
 		  }
 #endif
 	      }
@@ -4549,14 +4555,14 @@
       }
 #else /* not VMS */
 #ifdef DOS_NT
-  desc = open (fn,
-	       O_WRONLY | O_TRUNC | O_CREAT | buffer_file_type
-	       | (mustbenew == Qexcl ? O_EXCL : 0),
-	       S_IREAD | S_IWRITE);
+  desc = emacs_open (fn,
+		     O_WRONLY | O_TRUNC | O_CREAT | buffer_file_type
+		     | (mustbenew == Qexcl ? O_EXCL : 0),
+		     S_IREAD | S_IWRITE);
 #else  /* not DOS_NT */
-  desc = open (fn, O_WRONLY | O_TRUNC | O_CREAT
-	       | (mustbenew == Qexcl ? O_EXCL : 0),
-	       auto_saving ? auto_save_mode_bits : 0666);
+  desc = emacs_open (fn, O_WRONLY | O_TRUNC | O_CREAT
+		     | (mustbenew == Qexcl ? O_EXCL : 0),
+		     auto_saving ? auto_save_mode_bits : 0666);
 #endif /* not DOS_NT */
 #endif /* not VMS */
 
@@ -4701,7 +4707,7 @@
 #endif
 
   /* NFS can report a write failure now.  */
-  if (close (desc) < 0)
+  if (emacs_close (desc) < 0)
     failure = 1, save_errno = errno;
 
 #ifdef VMS
@@ -4735,7 +4741,7 @@
 
   if (failure)
     error ("IO error writing %s: %s", XSTRING (filename)->data,
-	   strerror (save_errno));
+	   emacs_strerror (save_errno));
 
   if (visiting)
     {
@@ -4927,14 +4933,14 @@
       nbytes -= coding->consumed, addr += coding->consumed;
       if (coding->produced > 0)
 	{
-	  coding->produced -= write (desc, buf, coding->produced);
+	  coding->produced -= emacs_write (desc, buf, coding->produced);
 	  if (coding->produced) return -1;
 	}
       if (result == CODING_FINISH_INSUFFICIENT_SRC)
 	{
 	  /* The source text ends by an incomplete multibyte form.
              There's no way other than write it out as is.  */
-	  nbytes -= write (desc, addr, nbytes);
+	  nbytes -= emacs_write (desc, addr, nbytes);
 	  if (nbytes) return -1;
 	}
       if (nbytes <= 0)
--- a/src/filelock.c	Tue Oct 19 07:21:16 1999 +0000
+++ b/src/filelock.c	Tue Oct 19 07:25:11 1999 +0000
@@ -19,14 +19,11 @@
 Boston, MA 02111-1307, USA.  */
 
 
+#include <config.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <signal.h>
-#include <config.h>
 #include <stdio.h>
-#ifdef HAVE_STDLIB_H
-#include <stdlib.h>
-#endif
 
 #ifdef VMS
 #include "vms-pwd.h"
@@ -255,11 +252,11 @@
     {
       /* On some versions of IRIX, opening a nonexistent file name
 	 is likely to crash in the utmp routines.  */
-      desc = open (filename, O_RDONLY);
+      desc = emacs_open (filename, O_RDONLY, 0);
       if (desc < 0)
 	return;
 
-      close (desc);
+      emacs_close (desc);
 
       utmpname (filename);
     }
--- a/src/floatfns.c	Tue Oct 19 07:21:16 1999 +0000
+++ b/src/floatfns.c	Tue Oct 19 07:25:11 1999 +0000
@@ -1,5 +1,5 @@
 /* Primitive operations on floating point for GNU Emacs Lisp interpreter.
-   Copyright (C) 1988, 1993, 1994 Free Software Foundation, Inc.
+   Copyright (C) 1988, 1993, 1994, 1999 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -44,9 +44,8 @@
    a domain error occurs.)
  */
 
+#include <config.h>
 #include <signal.h>
-
-#include <config.h>
 #include "lisp.h"
 #include "syssignal.h"
 
--- a/src/fns.c	Tue Oct 19 07:21:16 1999 +0000
+++ b/src/fns.c	Tue Oct 19 07:25:11 1999 +0000
@@ -4404,7 +4404,7 @@
   "Look up KEY in TABLE and return its associated value.\n\
 If KEY is not found, return DFLT which defaults to nil.")
   (key, table, dflt)
-     Lisp_Object key, table;
+     Lisp_Object key, table, dflt;
 {
   struct Lisp_Hash_Table *h = check_hash_table (table);
   int i = hash_lookup (h, key, NULL);
--- a/src/frame.c	Tue Oct 19 07:21:16 1999 +0000
+++ b/src/frame.c	Tue Oct 19 07:25:11 1999 +0000
@@ -1,5 +1,5 @@
 /* Generic frame functions.
-   Copyright (C) 1993, 1994, 1995, 1997 Free Software Foundation.
+   Copyright (C) 1993, 1994, 1995, 1997, 1999 Free Software Foundation.
 
 This file is part of GNU Emacs.
 
@@ -21,9 +21,6 @@
 #include <config.h>
 
 #include <stdio.h>
-#ifdef HAVE_STDLIB_H
-#include <stdlib.h>
-#endif
 #include "lisp.h"
 #include "charset.h"
 #ifdef HAVE_X_WINDOWS
--- a/src/gmalloc.c	Tue Oct 19 07:21:16 1999 +0000
+++ b/src/gmalloc.c	Tue Oct 19 07:25:11 1999 +0000
@@ -5,7 +5,7 @@
 /* The malloc headers and source files from the C library follow here.  */
 
 /* Declarations for `malloc' and friends.
-   Copyright 1990, 91, 92, 93, 95, 96 Free Software Foundation, Inc.
+   Copyright 1990, 91, 92, 93, 95, 96, 99 Free Software Foundation, Inc.
 		  Written May 1989 by Mike Haertel.
 
 This library is free software; you can redistribute it and/or
@@ -44,8 +44,10 @@
 #else /* Not C++ or ANSI C.  */
 #undef	PP
 #define	PP(args)	()
+#ifndef HAVE_CONFIG_H
 #undef	const
 #define	const
+#endif
 #undef	__ptr_t
 #define	__ptr_t		char *
 #endif /* C++ or ANSI C.  */
--- a/src/hftctl.c	Tue Oct 19 07:21:16 1999 +0000
+++ b/src/hftctl.c	Tue Oct 19 07:25:11 1999 +0000
@@ -41,11 +41,9 @@
 /*                                                             */
 /***************************************************************/
 
+#include <config.h>
 #include <sys/signal.h>
 #include <errno.h>
-
-#include <config.h>
-
 #include <stdio.h>
 #include <fcntl.h>
 #include <setjmp.h>
@@ -102,7 +100,7 @@
 					/* read a buffer        */
 #define RD_BUF(f,p,l) \
         while ((l)) \
-          if ((j = read((f),(p),(l))) < 0) \
+          if ((j = emacs_read (f, p, l)) < 0) \
              if (errno != EINTR) return (-1); \
              else continue; \
           else { (l) -= j; (p) += j; }
@@ -333,7 +331,7 @@
     }
 
   /* write request to terminal   */
-  if (write(fd,p.c,size) == -1) return (-1);
+  if (emacs_write (fd, p.c, size) == -1) return (-1);
   if (p.req != &req)		/* free if allocated           */
     xfree (p.c);
   return (0);
--- a/src/insdel.c	Tue Oct 19 07:21:16 1999 +0000
+++ b/src/insdel.c	Tue Oct 19 07:25:11 1999 +0000
@@ -1,5 +1,5 @@
 /* Buffer insertion/deletion and gap motion for GNU Emacs.
-   Copyright (C) 1985, 86, 93, 94, 95, 97, 1998 Free Software Foundation, Inc.
+   Copyright (C) 1985, 86,93,94,95,97,98, 1999 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -20,9 +20,6 @@
 
 
 #include <config.h>
-#ifdef HAVE_STDLIB_H
-#include <stdlib.h>
-#endif
 #include "lisp.h"
 #include "intervals.h"
 #include "buffer.h"
--- a/src/keyboard.c	Tue Oct 19 07:21:16 1999 +0000
+++ b/src/keyboard.c	Tue Oct 19 07:25:11 1999 +0000
@@ -1,5 +1,5 @@
 /* Keyboard and mouse input; editor command loop.
-   Copyright (C) 1985,86,87,88,89,93,94,95,96,97 Free Software Foundation, Inc.
+   Copyright (C) 1985,86,87,88,89,93,94,95,96,97,99 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -18,10 +18,8 @@
 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 Boston, MA 02111-1307, USA.  */
 
-/* Allow config.h to undefine symbols found here.  */
+#include <config.h>
 #include <signal.h>
-
-#include <config.h>
 #include <stdio.h>
 #include "termchar.h"
 #include "termopts.h"
@@ -5572,7 +5570,7 @@
 	  cbuf[0] = dos_keyread ();
 	  nread = 1;
 #else
-	  nread = read (input_fd, cbuf, n_to_read);
+	  nread = emacs_read (input_fd, cbuf, n_to_read);
 #endif
 	  /* POSIX infers that processes which are not in the session leader's
 	     process group won't get SIGHUP's at logout time.  BSDI adheres to
--- a/src/keymap.c	Tue Oct 19 07:21:16 1999 +0000
+++ b/src/keymap.c	Tue Oct 19 07:25:11 1999 +0000
@@ -1,5 +1,5 @@
 /* Manipulation of keymaps
-   Copyright (C) 1985, 86,87,88,93,94,95,98 Free Software Foundation, Inc.
+   Copyright (C) 1985, 86,87,88,93,94,95,98,99 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -21,9 +21,6 @@
 
 #include <config.h>
 #include <stdio.h>
-#ifdef STDC_HEADERS
-#include <stdlib.h>
-#endif
 #undef NULL
 #include "lisp.h"
 #include "commands.h"
--- a/src/lisp.h	Tue Oct 19 07:21:16 1999 +0000
+++ b/src/lisp.h	Tue Oct 19 07:25:11 1999 +0000
@@ -1,5 +1,5 @@
 /* Fundamental definitions for GNU Emacs Lisp interpreter.
-   Copyright (C) 1985,86,87,93,94,95,97,1998 Free Software Foundation, Inc.
+   Copyright (C) 1985,86,87,93,94,95,97,98,1999 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -27,6 +27,15 @@
 
 
 /* These are default choices for the types to use.  */
+#ifdef _LP64
+#ifndef EMACS_INT
+#define EMACS_INT long
+#define BITS_PER_EMACS_INT BITS_PER_LONG
+#endif
+#ifndef EMACS_UINT
+#define EMACS_UINT unsigned long
+#endif
+#else /* not _LP64 */
 #ifndef EMACS_INT
 #define EMACS_INT int
 #define BITS_PER_EMACS_INT BITS_PER_INT
@@ -34,6 +43,7 @@
 #ifndef EMACS_UINT
 #define EMACS_UINT unsigned int
 #endif
+#endif
 
 /* Define the fundamental Lisp data structures.  */
 
@@ -98,7 +108,7 @@
 
 /* These values are overridden by the m- file on some machines.  */
 #ifndef VALBITS
-#define VALBITS 28
+#define VALBITS (BITS_PER_EMACS_INT - 4)
 #endif
 
 #ifndef GCTYPEBITS
@@ -212,7 +222,7 @@
    rather than being part of a string block.  */
 
 #ifndef MARKBIT
-#define MARKBIT ((int) ((unsigned int) 1 << (VALBITS + GCTYPEBITS)))
+#define MARKBIT ((EMACS_INT) ((EMACS_UINT) 1 << (VALBITS + GCTYPEBITS)))
 #endif /*MARKBIT */
 
 /* In the size word of a vector, this bit means the vector has been marked.
@@ -278,7 +288,7 @@
 /* Extract the value of a Lisp_Object as a signed integer.  */
 
 #ifndef XINT   /* Some machines need to do this differently.  */
-#define XINT(a) (((a) << (BITS_PER_INT-VALBITS)) >> (BITS_PER_INT-VALBITS))
+#define XINT(a) (((a) << (BITS_PER_EMACS_INT-VALBITS)) >> (BITS_PER_EMACS_INT-VALBITS))
 #endif
 
 /* Extract the value as an unsigned integer.  This is a basis
@@ -1332,7 +1342,7 @@
 
 /* Cast pointers to this type to compare them.  Some machines want int.  */
 #ifndef PNTR_COMPARISON_TYPE
-#define PNTR_COMPARISON_TYPE unsigned int
+#define PNTR_COMPARISON_TYPE EMACS_UINT
 #endif
 
 /* Define a built-in function for calling from Lisp.
@@ -1765,6 +1775,7 @@
 EXFUN (Fencode_coding_string, 3);
 EXFUN (Fdecode_coding_string, 3);
 extern Lisp_Object detect_coding_system P_ ((unsigned char *, int, int));
+Lisp_Object code_convert_string_norecord P_ ((Lisp_Object, Lisp_Object, int));
 extern void init_coding P_ ((void));
 extern void init_coding_once P_ ((void));
 extern void syms_of_coding P_ ((void));
@@ -2506,6 +2517,16 @@
 extern Lisp_Object Vinvocation_name, Vinvocation_directory;
 extern Lisp_Object Vinstallation_directory;
 EXFUN (Fkill_emacs, 1);
+#if HAVE_SETLOCALE
+void fixup_locale P_ ((void));
+void synchronize_messages_locale P_ ((void));
+void synchronize_time_locale P_ ((void));
+#else
+#define setlocale(category, locale)
+#define fixup_locale()
+#define synchronize_messages_locale()
+#define synchronize_time_locale()
+#endif
 void shut_down_emacs P_ ((int, int, Lisp_Object));
 /* Nonzero means don't do interactive redisplay and don't change tty modes */
 extern int noninteractive;
@@ -2627,6 +2648,10 @@
 extern void create_process P_ ((Lisp_Object, char **, Lisp_Object));
 extern int tabs_safe_p P_ ((void));
 extern void init_baud_rate P_ ((void));
+extern int emacs_open P_ ((char *, int, int));
+extern int emacs_close P_ ((int));
+extern int emacs_read P_ ((int, char *, unsigned int));
+extern int emacs_write P_ ((int, char *, unsigned int));
 
 /* defined in filelock.c */
 EXFUN (Funlock_buffer, 0);
--- a/src/lread.c	Tue Oct 19 07:21:16 1999 +0000
+++ b/src/lread.c	Tue Oct 19 07:25:11 1999 +0000
@@ -1,5 +1,5 @@
 /* Lisp parsing and input streams.
-   Copyright (C) 1985, 86, 87, 88, 89, 93, 94, 95, 97, 1998
+   Copyright (C) 1985, 86, 87, 88, 89, 93, 94, 95, 97, 98, 1999
       Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
@@ -58,10 +58,6 @@
 #endif
 
 #ifdef LISP_FLOAT_TYPE
-#ifdef STDC_HEADERS
-#include <stdlib.h>
-#endif
-
 #include <math.h>
 #endif /* LISP_FLOAT_TYPE */
 
@@ -73,6 +69,14 @@
 #define O_RDONLY 0
 #endif
 
+#ifdef HAVE_FTELLO
+#define file_offset off_t
+#define file_tell ftello
+#else
+#define file_offset long
+#define file_tell ftell
+#endif
+
 extern int errno;
 
 Lisp_Object Qread_char, Qget_file_char, Qstandard_input, Qcurrent_load_list;
@@ -156,7 +160,7 @@
 /* Length of actual data in saved_doc_string.  */
 static int saved_doc_string_length;
 /* This is the file position that string came from.  */
-static int saved_doc_string_position;
+static file_offset saved_doc_string_position;
 
 /* This contains the previous string skipped with #@.
    We copy it from saved_doc_string when a new string
@@ -167,7 +171,7 @@
 /* Length of actual data in prev_saved_doc_string.  */
 static int prev_saved_doc_string_length;
 /* This is the file position that string came from.  */
-static int prev_saved_doc_string_position;
+static file_offset prev_saved_doc_string_position;
 
 /* Nonzero means inside a new-style backquote
    with no surrounding parentheses.
@@ -714,7 +718,7 @@
       if (!NILP (Vload_source_file_function))
 	{
 	  if (fd != 0)
-	    close (fd);
+	    emacs_close (fd);
 	  return call4 (Vload_source_file_function, found, file,
 			NILP (noerror) ? Qnil : Qt,
 			NILP (nomessage) ? Qnil : Qt);
@@ -722,14 +726,14 @@
     }
 
 #ifdef WINDOWSNT
-  close (fd);
+  emacs_close (fd);
   stream = fopen ((char *) XSTRING (found)->data, fmode);
 #else  /* not WINDOWSNT */
   stream = fdopen (fd, fmode);
 #endif /* not WINDOWSNT */
   if (stream == 0)
     {
-      close (fd);
+      emacs_close (fd);
       error ("Failure to create stdio stream for %s", XSTRING (file)->data);
     }
 
@@ -817,7 +821,7 @@
 #ifndef WINDOWSNT
   Lisp_Object tail;
   for (tail = load_descriptor_list; !NILP (tail); tail = XCDR (tail))
-    close (XFASTINT (XCAR (tail)));
+    emacs_close (XFASTINT (XCAR (tail)));
 #endif
 }
 
@@ -966,7 +970,7 @@
 		  if (exec_only)
 		    fd = (access (fn, X_OK) == 0) ? 1 : -1;
 		  else
-		    fd = open (fn, O_RDONLY, 0);
+		    fd = emacs_open (fn, O_RDONLY, 0);
 
 		  if (fd >= 0)
 		    {
@@ -1751,7 +1755,7 @@
 	      {
 		char *temp = saved_doc_string;
 		int temp_size = saved_doc_string_size;
-		int temp_pos = saved_doc_string_position;
+		file_offset temp_pos = saved_doc_string_position;
 		int temp_len = saved_doc_string_length;
 
 		saved_doc_string = prev_saved_doc_string;
@@ -1777,7 +1781,7 @@
 							saved_doc_string_size);
 		}
 
-	      saved_doc_string_position = ftell (instream);
+	      saved_doc_string_position = file_tell (instream);
 
 	      /* Copy that many characters into saved_doc_string.  */
 	      for (i = 0; i < nskip && c >= 0; i++)
@@ -3129,11 +3133,6 @@
   char *normal;
   int turn_off_warning = 0;
 
-#ifdef HAVE_SETLOCALE
-  /* Make sure numbers are parsed as we expect.  */
-  setlocale (LC_NUMERIC, "C");
-#endif /* HAVE_SETLOCALE */
-
   /* Compute the default load-path.  */
 #ifdef CANNOT_DUMP
   normal = PATH_LOADSEARCH;
--- a/src/mktime.c	Tue Oct 19 07:21:16 1999 +0000
+++ b/src/mktime.c	Tue Oct 19 07:25:11 1999 +0000
@@ -1,4 +1,5 @@
-/* Copyright (C) 1993, 94, 95, 96, 97, 98 Free Software Foundation, Inc.
+/* Convert a `struct tm' to a time_t value.
+   Copyright (C) 1993, 94, 95, 96, 97, 98, 99 Free Software Foundation, Inc.
    Contributed by Paul Eggert (eggert@twinsun.com).
 
    NOTE: The canonical source of this file is maintained with the GNU C Library.
@@ -27,14 +28,8 @@
 # include <config.h>
 #endif
 
-/* Some systems need this in order to declare localtime_r properly.  */
-#ifndef _REENTRANT
-# define _REENTRANT 1
-#endif
-
 #ifdef _LIBC
 # define HAVE_LIMITS_H 1
-# define HAVE_LOCALTIME_R 1
 # define STDC_HEADERS 1
 #endif
 
@@ -62,7 +57,7 @@
 #endif /* DEBUG */
 
 #ifndef __P
-# if defined (__GNUC__) || (defined (__STDC__) && __STDC__)
+# if defined __GNUC__ || (defined __STDC__ && __STDC__)
 #  define __P(args) args
 # else
 #  define __P(args) ()
@@ -114,26 +109,15 @@
     { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 }
   };
 
-static struct tm *ranged_convert __P ((struct tm *(*) __P ((const time_t *,
-							    struct tm *)),
-				       time_t *, struct tm *));
-static time_t ydhms_tm_diff __P ((int, int, int, int, int, const struct tm *));
-time_t __mktime_internal __P ((struct tm *,
-			       struct tm *(*) (const time_t *, struct tm *),
-			       time_t *));
-
 
 #ifdef _LIBC
-# define localtime_r __localtime_r
+# define my_mktime_localtime_r __localtime_r
 #else
-# if ! HAVE_LOCALTIME_R && ! defined localtime_r
-/* Approximate localtime_r as best we can in its absence.  */
-#  define localtime_r my_mktime_localtime_r
-static struct tm *localtime_r __P ((const time_t *, struct tm *));
+/* If we're a mktime substitute in a GNU program, then prefer
+   localtime to localtime_r, since many localtime_r implementations
+   are buggy.  */
 static struct tm *
-localtime_r (t, tp)
-     const time_t *t;
-     struct tm *tp;
+my_mktime_localtime_r (const time_t *t, struct tm *tp)
 {
   struct tm *l = localtime (t);
   if (! l)
@@ -141,7 +125,6 @@
   *tp = *l;
   return tp;
 }
-# endif /* ! HAVE_LOCALTIME_R && ! defined (localtime_r) */
 #endif /* ! _LIBC */
 
 
@@ -152,9 +135,8 @@
    If TP is null, return a nonzero value.
    If overflow occurs, yield the low order bits of the correct answer.  */
 static time_t
-ydhms_tm_diff (year, yday, hour, min, sec, tp)
-     int year, yday, hour, min, sec;
-     const struct tm *tp;
+ydhms_tm_diff (int year, int yday, int hour, int min, int sec,
+	       const struct tm *tp)
 {
   if (!tp)
     return 1;
@@ -181,32 +163,12 @@
     }
 }
 
-
-static time_t localtime_offset;
-
-/* Convert *TP to a time_t value.  */
-time_t
-mktime (tp)
-     struct tm *tp;
-{
-#ifdef _LIBC
-  /* POSIX.1 8.1.1 requires that whenever mktime() is called, the
-     time zone names contained in the external variable `tzname' shall
-     be set as if the tzset() function had been called.  */
-  __tzset ();
-#endif
-
-  return __mktime_internal (tp, localtime_r, &localtime_offset);
-}
-
 /* Use CONVERT to convert *T to a broken down time in *TP.
    If *T is out of range for conversion, adjust it so that
    it is the nearest in-range value and then convert that.  */
 static struct tm *
-ranged_convert (convert, t, tp)
-     struct tm *(*convert) __P ((const time_t *, struct tm *));
-     time_t *t;
-     struct tm *tp;
+ranged_convert (struct tm *(*convert) (const time_t *, struct tm *),
+		time_t *t, struct tm *tp)
 {
   struct tm *r;
 
@@ -253,19 +215,18 @@
    compared to what the result would be for UTC without leap seconds.
    If *OFFSET's guess is correct, only one CONVERT call is needed.  */
 time_t
-__mktime_internal (tp, convert, offset)
-     struct tm *tp;
-     struct tm *(*convert) __P ((const time_t *, struct tm *));
-     time_t *offset;
+__mktime_internal (struct tm *tp,
+		   struct tm *(*convert) (const time_t *, struct tm *),
+		   time_t *offset)
 {
-  time_t t, dt, t0;
+  time_t t, dt, t0, t1, t2;
   struct tm tm;
 
   /* The maximum number of probes (calls to CONVERT) should be enough
      to handle any combinations of time zone rule changes, solar time,
-     and leap seconds.  POSIX.1 prohibits leap seconds, but some hosts
-     have them anyway.  */
-  int remaining_probes = 4;
+     leap seconds, and oscillations around a spring-forward gap.
+     POSIX.1 prohibits leap seconds, but some hosts have them anyway.  */
+  int remaining_probes = 6;
 
   /* Time requested.  Copy it in case CONVERT modifies *TP; this can
      occur if TP is localtime's returned value and CONVERT is localtime.  */
@@ -311,36 +272,52 @@
   tm.tm_yday = tm.tm_hour = tm.tm_min = tm.tm_sec = 0;
   t0 = ydhms_tm_diff (year, yday, hour, min, sec, &tm);
 
-  for (t = t0 + *offset;
+  for (t = t1 = t2 = t0 + *offset;
        (dt = ydhms_tm_diff (year, yday, hour, min, sec,
 			    ranged_convert (convert, &t, &tm)));
-       t += dt)
-    if (--remaining_probes == 0)
+       t1 = t2, t2 = t, t += dt)
+    if (t == t1 && t != t2
+	&& (isdst < 0 || tm.tm_isdst < 0
+	    || (isdst != 0) != (tm.tm_isdst != 0)))
+      /* We can't possibly find a match, as we are oscillating
+	 between two values.  The requested time probably falls
+	 within a spring-forward gap of size DT.  Follow the common
+	 practice in this case, which is to return a time that is DT
+	 away from the requested time, preferring a time whose
+	 tm_isdst differs from the requested value.  In practice,
+	 this is more useful than returning -1.  */
+      break;
+    else if (--remaining_probes == 0)
       return -1;
 
-  /* Check whether tm.tm_isdst has the requested value, if any.  */
-  if (0 <= isdst && 0 <= tm.tm_isdst)
+  /* If we have a match, check whether tm.tm_isdst has the requested
+     value, if any.  */
+  if (dt == 0 && isdst != tm.tm_isdst && 0 <= isdst && 0 <= tm.tm_isdst)
     {
-      int dst_diff = (isdst != 0) - (tm.tm_isdst != 0);
-      if (dst_diff)
+      /* tm.tm_isdst has the wrong value.  Look for a neighboring
+	 time with the right value, and use its UTC offset.
+	 Heuristic: probe the previous three calendar quarters (approximately),
+	 looking for the desired isdst.  This isn't perfect,
+	 but it's good enough in practice.  */
+      int quarter = 7889238; /* seconds per average 1/4 Gregorian year */
+      int i;
+
+      /* If we're too close to the time_t limit, look in future quarters.  */
+      if (t < TIME_T_MIN + 3 * quarter)
+	quarter = -quarter;
+
+      for (i = 1; i <= 3; i++)
 	{
-	  /* Move two hours in the direction indicated by the disagreement,
-	     probe some more, and switch to a new time if found.
-	     The largest known fallback due to daylight savings is two hours:
-	     once, in Newfoundland, 1988-10-30 02:00 -> 00:00.  */
-	  time_t ot = t - 2 * 60 * 60 * dst_diff;
-	  while (--remaining_probes != 0)
+	  time_t ot = t - i * quarter;
+	  struct tm otm;
+	  ranged_convert (convert, &ot, &otm);
+	  if (otm.tm_isdst == isdst)
 	    {
-	      struct tm otm;
-	      if (! (dt = ydhms_tm_diff (year, yday, hour, min, sec,
-					 ranged_convert (convert, &ot, &otm))))
-		{
-		  t = ot;
-		  tm = otm;
-		  break;
-		}
-	      if ((ot += dt) == t)
-		break;  /* Avoid a redundant probe.  */
+	      /* We found the desired tm_isdst.
+		 Extrapolate back to the desired time.  */
+	      t = ot + ydhms_tm_diff (year, yday, hour, min, sec, &otm);
+	      ranged_convert (convert, &t, &tm);
+	      break;
 	    }
 	}
     }
@@ -386,6 +363,24 @@
   return t;
 }
 
+
+static time_t localtime_offset;
+
+/* Convert *TP to a time_t value.  */
+time_t
+mktime (tp)
+     struct tm *tp;
+{
+#ifdef _LIBC
+  /* POSIX.1 8.1.1 requires that whenever mktime() is called, the
+     time zone names contained in the external variable `tzname' shall
+     be set as if the tzset() function had been called.  */
+  __tzset ();
+#endif
+
+  return __mktime_internal (tp, my_mktime_localtime_r, &localtime_offset);
+}
+
 #ifdef weak_alias
 weak_alias (mktime, timelocal)
 #endif
@@ -530,6 +525,6 @@
 
 /*
 Local Variables:
-compile-command: "gcc -DDEBUG -D__EXTENSIONS__ -DHAVE_LIMITS_H -DHAVE_LOCALTIME_R -DSTDC_HEADERS -Wall -W -O -g mktime.c -o mktime"
+compile-command: "gcc -DDEBUG -DHAVE_LIMITS_H -DSTDC_HEADERS -Wall -W -O -g mktime.c -o mktime"
 End:
 */
--- a/src/msdos.c	Tue Oct 19 07:21:16 1999 +0000
+++ b/src/msdos.c	Tue Oct 19 07:25:11 1999 +0000
@@ -1,5 +1,5 @@
 /* MS-DOS specific C utilities.          -*- coding: raw-text -*-
-   Copyright (C) 1993, 1994, 1995, 1996, 1997 Free Software Foundation, Inc.
+   Copyright (C) 1993, 94, 95, 96, 97, 1999 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -3654,9 +3654,9 @@
   dup2 (inbak, 0);
   dup2 (outbak, 1);
   dup2 (errbak, 2);
-  close (inbak);
-  close (outbak);
-  close (errbak);
+  emacs_close (inbak);
+  emacs_close (outbak);
+  emacs_close (errbak);
 
   dos_ttraw ();
   if (have_mouse > 0)
--- a/src/print.c	Tue Oct 19 07:21:16 1999 +0000
+++ b/src/print.c	Tue Oct 19 07:25:11 1999 +0000
@@ -1,5 +1,5 @@
 /* Lisp object printing and output streams.
-   Copyright (C) 1985, 86, 88, 93, 94, 95, 97, 1998
+   Copyright (C) 1985, 86, 88, 93, 94, 95, 97, 98, 1999
 	Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
@@ -60,7 +60,6 @@
 
 #if STDC_HEADERS
 #include <float.h>
-#include <stdlib.h>
 #endif
 
 /* Default to values appropriate for IEEE floating point.  */
@@ -960,6 +959,19 @@
   /* Check for NaN in a way that won't fail if there are no NaNs.  */
   if (! (data * 0.0 >= 0.0))
     {
+      /* Prepend "-" if the NaN's sign bit is negative.
+	 The sign bit of a double is the bit that is 1 in -0.0.  */
+      int i;
+      union { double d; char c[sizeof (double)]; } u_data, u_minus_zero;
+      u_data.d = data;
+      u_minus_zero.d = - 0.0;
+      for (i = 0; i < sizeof (double); i++)
+	if (u_data.c[i] & u_minus_zero.c[i])
+	  {
+	    *buf++ = '-';
+	    break;
+	  }
+      
       strcpy (buf, "0.0e+NaN");
       return;
     }
--- a/src/process.c	Tue Oct 19 07:21:16 1999 +0000
+++ b/src/process.c	Tue Oct 19 07:25:11 1999 +0000
@@ -1,5 +1,5 @@
 /* Asynchronous subprocess control for GNU Emacs.
-   Copyright (C) 1985, 86, 87, 88, 93, 94, 95, 96, 1998
+   Copyright (C) 1985, 86, 87, 88, 93, 94, 95, 96, 98, 1999
       Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
@@ -20,10 +20,10 @@
 Boston, MA 02111-1307, USA.  */
 
 
+#include <config.h>
+
 #include <signal.h>
 
-#include <config.h>
-
 /* This file is split into two parts by the following preprocessor
    conditional.  The 'then' clause contains all of the support for
    asynchronous subprocesses.  The 'else' clause contains stub
@@ -155,6 +155,7 @@
 extern int h_errno;
 #endif
 
+#ifndef HAVE_STRSIGNAL
 #ifndef SYS_SIGLIST_DECLARED
 #ifndef VMS
 #ifndef BSD4_1
@@ -196,6 +197,7 @@
 #endif
 #endif /* VMS */
 #endif /* ! SYS_SIGLIST_DECLARED */
+#endif /* ! HAVE_STRSIGNAL */
 
 /* t means use pty, nil means use a pipe,
    maybe other values to come.  */
@@ -357,16 +359,9 @@
 
   if (EQ (symbol, Qsignal) || EQ (symbol, Qstop))
     {
-      char *signame = 0;
-      if (code < NSIG)
-	{
-#ifndef VMS
-	  /* Cast to suppress warning if the table has const char *.  */
-	  signame = (char *) sys_siglist[code];
-#else
-	  signame = sys_errlist[code];
-#endif
-	}
+      char *signame;
+      synchronize_messages_locale ();
+      signame = strsignal (code);
       if (signame == 0)
 	signame = "unknown";
       string = build_string (signame);
@@ -426,7 +421,7 @@
 #else /* no PTY_OPEN */
 #ifdef IRIS
 	/* Unusual IRIS code */
- 	*ptyv = open ("/dev/ptc", O_RDWR | O_NDELAY, 0);
+ 	*ptyv = emacs_open ("/dev/ptc", O_RDWR | O_NDELAY, 0);
  	if (fd < 0)
  	  return -1;
 	if (fstat (fd, &stb) < 0)
@@ -441,9 +436,9 @@
 	else
 	  failed_count = 0;
 #ifdef O_NONBLOCK
-	fd = open (pty_name, O_RDWR | O_NONBLOCK, 0);
+	fd = emacs_open (pty_name, O_RDWR | O_NONBLOCK, 0);
 #else
-	fd = open (pty_name, O_RDWR | O_NDELAY, 0);
+	fd = emacs_open (pty_name, O_RDWR | O_NDELAY, 0);
 #endif
 #endif /* not IRIS */
 #endif /* no PTY_OPEN */
@@ -460,7 +455,7 @@
 #ifndef UNIPLUS
 	    if (access (pty_name, 6) != 0)
 	      {
-		close (fd);
+		emacs_close (fd);
 #if !defined(IRIS) && !defined(__sgi)
 		continue;
 #else
@@ -1361,9 +1356,9 @@
 #ifdef O_NOCTTY
       /* Don't let this terminal become our controlling terminal
 	 (in case we don't have one).  */
-      forkout = forkin = open (pty_name, O_RDWR | O_NOCTTY, 0);
+      forkout = forkin = emacs_open (pty_name, O_RDWR | O_NOCTTY, 0);
 #else
-      forkout = forkin = open (pty_name, O_RDWR, 0);
+      forkout = forkin = emacs_open (pty_name, O_RDWR, 0);
 #endif
       if (forkin < 0)
 	report_file_error ("Opening pty", Qnil);
@@ -1392,8 +1387,8 @@
       tem = pipe (sv);
       if (tem < 0)
 	{
-	  close (inchannel);
-	  close (forkout);
+	  emacs_close (inchannel);
+	  emacs_close (forkout);
 	  report_file_error ("Creating pipe", Qnil);
 	}
       outchannel = sv[1];
@@ -1592,7 +1587,7 @@
 	    tcgetattr (xforkin, &t);
 	    t.c_lflag = LDISC1;
 	    if (tcsetattr (xforkin, TCSANOW, &t) < 0)
-	      write (1, "create_process/tcsetattr LDISC1 failed\n", 39);
+	      emacs_write (1, "create_process/tcsetattr LDISC1 failed\n", 39);
 	  }
 #else
 #if defined (NTTYDISC) && defined (TIOCSETD)
@@ -1611,9 +1606,9 @@
 	  {
 	    /* I wonder: would just ioctl (0, TIOCNOTTY, 0) work here? 
 	       I can't test it since I don't have 4.3.  */
-	    int j = open ("/dev/tty", O_RDWR, 0);
+	    int j = emacs_open ("/dev/tty", O_RDWR, 0);
 	    ioctl (j, TIOCNOTTY, 0);
-	    close (j);
+	    emacs_close (j);
 #ifndef USG
 	    /* In order to get a controlling terminal on some versions
 	       of BSD, it is necessary to put the process in pgrp 0
@@ -1642,16 +1637,17 @@
 	    int pgrp = getpid ();
 #endif
 
-	    /* I wonder if close (open (pty_name, ...)) would work?  */
+	    /* I wonder if emacs_close (emacs_open (pty_name, ...))
+	       would work?  */
 	    if (xforkin >= 0)
-	      close (xforkin);
-	    xforkout = xforkin = open (pty_name, O_RDWR, 0);
+	      emacs_close (xforkin);
+	    xforkout = xforkin = emacs_open (pty_name, O_RDWR, 0);
 
 	    if (xforkin < 0)
 	      {
-		write (1, "Couldn't open the pty terminal ", 31);
-		write (1, pty_name, strlen (pty_name));
-		write (1, "\n", 1);
+		emacs_write (1, "Couldn't open the pty terminal ", 31);
+		emacs_write (1, pty_name, strlen (pty_name));
+		emacs_write (1, "\n", 1);
 		_exit (1);
 	      }
 
@@ -1717,9 +1713,9 @@
   if (pid < 0)
     {
       if (forkin >= 0)
-	close (forkin);
+	emacs_close (forkin);
       if (forkin != forkout && forkout >= 0)
-	close (forkout);
+	emacs_close (forkout);
     }
   else
     {
@@ -1738,11 +1734,11 @@
       alarm (1);
       XPROCESS (process)->subtty = Qnil;
       if (forkin >= 0)
-	close (forkin);
+	emacs_close (forkin);
       alarm (0);
       start_polling ();
       if (forkin != forkout && forkout >= 0)
-	close (forkout);
+	emacs_close (forkout);
 
 #ifdef HAVE_PTYS
       if (pty_flag)
@@ -1926,7 +1922,7 @@
       ret = connect (s, lres->ai_addr, lres->ai_addrlen);
       if (ret == 0)
 	break;
-      close (s);
+      emacs_close (s);
       s = -1;
     }
 
@@ -2033,7 +2029,7 @@
       /* Discard the unwind protect.  */
       specpdl_ptr = specpdl + count1;
 
-      close (s);
+      emacs_close (s);
 
       if (interrupt_input)
 	request_sigio ();
@@ -2200,9 +2196,9 @@
 	  give_back_vms_process_stuff (vs);
       }
 #else
-      close (inchannel);
+      emacs_close (inchannel);
       if (outchannel >= 0 && outchannel != inchannel)
- 	close (outchannel);
+ 	emacs_close (outchannel);
 #endif
 
       XSETINT (p->infd, -1);
@@ -2241,9 +2237,9 @@
 	  int in = XINT (XPROCESS (process)->infd);
 	  int out = XINT (XPROCESS (process)->outfd);
 	  if (in >= 0)
-	    close (in);
+	    emacs_close (in);
 	  if (out >= 0 && in != out)
-	    close (out);
+	    emacs_close (out);
 	}
     }
 #endif
@@ -2651,7 +2647,7 @@
 #endif
 	    }
 	  else
-	    error ("select error: %s", strerror (xerrno));
+	    error ("select error: %s", emacs_strerror (xerrno));
 	}
 #if defined(sun) && !defined(USG5_4)
       else if (nfds > 0 && keyboard_bit_set (&Available)
@@ -2955,13 +2951,13 @@
 	   buf, carryover);
 
   if (proc_buffered_char[channel] < 0)
-    nbytes = read (channel, buf + carryover, (sizeof buf) - carryover);
+    nbytes = emacs_read (channel, buf + carryover, (sizeof buf) - carryover);
   else
     {
       buf[carryover] = proc_buffered_char[channel];
       proc_buffered_char[channel] = -1;
-      nbytes = read (channel, buf + carryover + 1,
-		     (sizeof buf) - carryover - 1);
+      nbytes = emacs_read (channel, buf + carryover + 1,
+			   (sizeof buf) - carryover - 1);
       if (nbytes < 0)
 	nbytes = 1;
       else
@@ -3452,7 +3448,7 @@
 	while (this > 0)
 	  {
 	    old_sigpipe = (SIGTYPE (*) ()) signal (SIGPIPE, send_process_trap);
-	    rv = write (XINT (XPROCESS (proc)->outfd), buf, this);
+	    rv = emacs_write (XINT (XPROCESS (proc)->outfd), buf, this);
 	    signal (SIGPIPE, old_sigpipe);
 
 	    if (rv < 0)
@@ -4073,11 +4069,11 @@
 	shutdown (XINT (XPROCESS (proc)->outfd), 1);
       /* In case of socketpair, outfd == infd, so don't close it.  */
       if (XINT (XPROCESS (proc)->outfd) != XINT (XPROCESS (proc)->infd))
-	close (XINT (XPROCESS (proc)->outfd));
+	emacs_close (XINT (XPROCESS (proc)->outfd));
 #else /* not HAVE_SHUTDOWN */
-      close (XINT (XPROCESS (proc)->outfd));
+      emacs_close (XINT (XPROCESS (proc)->outfd));
 #endif /* not HAVE_SHUTDOWN */
-      new_outfd = open (NULL_DEVICE, O_WRONLY);
+      new_outfd = emacs_open (NULL_DEVICE, O_WRONLY, 0);
       old_outfd = XINT (XPROCESS (proc)->outfd);
 
       if (!proc_encode_coding_system[new_outfd])
@@ -4256,17 +4252,11 @@
 	  else if (WIFSIGNALED (w))
 	    {
 	      int code = WTERMSIG (w);
-	      char *signame = 0;
-
-	      if (code < NSIG)
-		{
-#ifndef VMS
-		  /* Suppress warning if the table has const char *.  */
-		  signame = (char *) sys_siglist[code];
-#else
-		  signame = sys_errlist[code];
-#endif
-		}
+	      char *signame;
+
+	      synchronize_messages_locale ();
+	      signame = strsignal (code);
+
 	      if (signame == 0)
 		signame = "unknown";
 
@@ -4923,7 +4913,7 @@
 	  if (xerrno == EINTR)
 	    FD_ZERO (&waitchannels);
 	  else
-	    error ("select error: %s", strerror (xerrno));
+	    error ("select error: %s", emacs_strerror (xerrno));
 	}
 #ifdef sun
       else if (nfds > 0 && (waitchannels & 1)  && interrupt_input)
--- a/src/search.c	Tue Oct 19 07:21:16 1999 +0000
+++ b/src/search.c	Tue Oct 19 07:25:11 1999 +0000
@@ -1,5 +1,5 @@
 /* String search routines for GNU Emacs.
-   Copyright (C) 1985, 86, 87, 93, 94, 97, 1998 Free Software Foundation, Inc.
+   Copyright (C) 1985, 86,87,93,94,97,98, 1999 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -20,9 +20,6 @@
 
 
 #include <config.h>
-#ifdef STDC_HEADERS
-#include <stdlib.h>
-#endif
 #include "lisp.h"
 #include "syntax.h"
 #include "category.h"
--- a/src/sound.c	Tue Oct 19 07:21:16 1999 +0000
+++ b/src/sound.c	Tue Oct 19 07:25:11 1999 +0000
@@ -1,5 +1,5 @@
 /* sound.c -- sound support.
-   Copyright (C) 1998 Free Software Foundation.
+   Copyright (C) 1998, 1999 Free Software Foundation.
 
 This file is part of GNU Emacs.
 
@@ -335,7 +335,7 @@
     {
       sound_device->close (sound_device);
       if (sound_file->fd > 0)
-	close (sound_file->fd);
+	emacs_close (sound_file->fd);
     }
 }
 
@@ -378,7 +378,7 @@
     sound_perror ("Open sound file");
 
   /* Read the first bytes from the file.  */
-  nbytes = read (sf.fd, sf.header, MAX_SOUND_HEADER_BYTES);
+  nbytes = emacs_read (sf.fd, sf.header, MAX_SOUND_HEADER_BYTES);
   if (nbytes < 0)
     sound_perror ("Reading sound file header");
 
@@ -405,7 +405,7 @@
   sd.open (&sd);
 
   sf.play (&sf, &sd);
-  close (sf.fd);
+  emacs_close (sf.fd);
   sf.fd = -1;
   sd.close (&sd);
   sound_device = NULL;
@@ -557,7 +557,7 @@
   buffer = (char *) alloca (blksize);
   lseek (sf->fd, sizeof *header, SEEK_SET);
   
-  while ((nbytes = read (sf->fd, buffer, blksize)) > 0)
+  while ((nbytes = emacs_read (sf->fd, buffer, blksize)) > 0)
     sd->write (sd, buffer, nbytes);
 
   if (nbytes < 0)
@@ -639,7 +639,7 @@
   
   /* Copy sound data to the device.  */
   buffer = (char *) alloca (blksize);
-  while ((nbytes = read (sf->fd, buffer, blksize)) > 0)
+  while ((nbytes = emacs_read (sf->fd, buffer, blksize)) > 0)
     sd->write (sd, buffer, nbytes);
 
   if (nbytes < 0)
@@ -671,7 +671,7 @@
   else
     file = "/dev/dsp";
   
-  sd->fd = open (file, O_WRONLY);
+  sd->fd = emacs_open (file, O_WRONLY, 0);
   if (sd->fd < 0)
     sound_perror (file);
 }
@@ -731,7 +731,7 @@
       ioctl (sd->fd, SNDCTL_DSP_RESET, NULL);
 
       /* Close the device.  */
-      close (sd->fd);
+      emacs_close (sd->fd);
       sd->fd = -1;
     }
 }
@@ -805,7 +805,7 @@
      char *buffer;
      int nbytes;
 {
-  int nwritten = write (sd->fd, buffer, nbytes);
+  int nwritten = emacs_write (sd->fd, buffer, nbytes);
   if (nwritten < 0)
     sound_perror ("Writing to sound device");
 }
--- a/src/strftime.c	Tue Oct 19 07:21:16 1999 +0000
+++ b/src/strftime.c	Tue Oct 19 07:25:11 1999 +0000
@@ -1,5 +1,4 @@
 /* Copyright (C) 1991,92,93,94,95,96,97,98 Free Software Foundation, Inc.
-
    NOTE: The canonical source of this file is maintained with the GNU C Library.
    Bugs can be reported to bug-glibc@gnu.org.
 
@@ -14,19 +13,13 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
-   USA.  */
+   along with this program; if not, write to the Free Software Foundation,
+   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
 #endif
 
-/* Some hosts need this in order to declare localtime_r properly.  */
-#ifndef _REENTRANT
-# define _REENTRANT 1
-#endif
-
 #ifdef _LIBC
 # define HAVE_LIMITS_H 1
 # define HAVE_MBLEN 1
@@ -136,7 +129,7 @@
    add one for integer division truncation;
    add one more for a minus sign if t is signed.  */
 #define INT_STRLEN_BOUND(t) \
-  ((sizeof (t) * CHAR_BIT - TYPE_SIGNED (t)) * 302 / 100 + 1 + TYPE_SIGNED (t))
+ ((sizeof (t) * CHAR_BIT - TYPE_SIGNED (t)) * 302 / 1000 + 1 + TYPE_SIGNED (t))
 
 #define TM_YEAR_BASE 1900
 
@@ -149,19 +142,20 @@
 
 
 #ifdef _LIBC
-# define gmtime_r __gmtime_r
-# define localtime_r __localtime_r
+# define my_strftime_gmtime_r __gmtime_r
+# define my_strftime_localtime_r __localtime_r
 # define tzname __tzname
 # define tzset __tzset
 #else
-# if ! HAVE_LOCALTIME_R
-#  if ! HAVE_TM_GMTOFF
-/* Approximate gmtime_r as best we can in its absence.  */
-#   undef gmtime_r
-#   define gmtime_r my_gmtime_r
-static struct tm *gmtime_r __P ((const time_t *, struct tm *));
+
+/* If we're a strftime substitute in a GNU program, then prefer gmtime
+   to gmtime_r, since many gmtime_r implementations are buggy.
+   Similarly for localtime_r.  */
+
+# if ! HAVE_TM_GMTOFF
+static struct tm *my_strftime_gmtime_r __P ((const time_t *, struct tm *));
 static struct tm *
-gmtime_r (t, tp)
+my_strftime_gmtime_r (t, tp)
      const time_t *t;
      struct tm *tp;
 {
@@ -171,14 +165,11 @@
   *tp = *l;
   return tp;
 }
-#  endif /* ! HAVE_TM_GMTOFF */
+# endif /* ! HAVE_TM_GMTOFF */
 
-/* Approximate localtime_r as best we can in its absence.  */
-#  undef localtime_r
-#  define localtime_r my_ftime_localtime_r
-static struct tm *localtime_r __P ((const time_t *, struct tm *));
+static struct tm *my_strftime_localtime_r __P ((const time_t *, struct tm *));
 static struct tm *
-localtime_r (t, tp)
+my_strftime_localtime_r (t, tp)
      const time_t *t;
      struct tm *tp;
 {
@@ -188,7 +179,6 @@
   *tp = *l;
   return tp;
 }
-# endif /* ! HAVE_LOCALTIME_R */
 #endif /* ! defined _LIBC */
 
 
@@ -376,30 +366,38 @@
 
 
 #ifdef emacs
-# define my_strftime emacs_strftime
+# define my_strftime emacs_strftimeu
+# define ut_argument , ut
+# define ut_argument_spec int ut;
+# define ut_argument_spec_iso , int ut
 #else
 # define my_strftime strftime
+# define ut_argument
+# define ut_argument_spec
+# define ut_argument_spec_iso
+/* We don't have this information in general.  */
+# define ut 0
 #endif
 
 #if !defined _LIBC && HAVE_TZNAME && HAVE_TZSET
   /* Solaris 2.5 tzset sometimes modifies the storage returned by localtime.
      Work around this bug by copying *tp before it might be munged.  */
   size_t _strftime_copytm __P ((char *, size_t, const char *,
-			        const struct tm *));
+			        const struct tm * ut_argument_spec_iso));
   size_t
-  my_strftime (s, maxsize, format, tp)
+  my_strftime (s, maxsize, format, tp ut_argument)
       char *s;
       size_t maxsize;
       const char *format;
       const struct tm *tp;
+      ut_argument_spec
   {
     struct tm tmcopy;
     tmcopy = *tp;
-    return _strftime_copytm (s, maxsize, format, &tmcopy);
+    return _strftime_copytm (s, maxsize, format, &tmcopy ut_argument);
   }
 # undef my_strftime
-# define my_strftime(S, Maxsize, Format, Tp) \
-  _strftime_copytm (S, Maxsize, Format, Tp)
+# define my_strftime _strftime_copytm
 #endif
 
 
@@ -410,41 +408,44 @@
    anywhere, so to determine how many characters would be
    written, use NULL for S and (size_t) UINT_MAX for MAXSIZE.  */
 size_t
-my_strftime (s, maxsize, format, tp)
+my_strftime (s, maxsize, format, tp ut_argument)
       char *s;
       size_t maxsize;
       const char *format;
       const struct tm *tp;
+      ut_argument_spec
 {
   int hour12 = tp->tm_hour;
 #ifdef _NL_CURRENT
-  const char *const a_wkday = _NL_CURRENT (LC_TIME, ABDAY_1 + tp->tm_wday);
-  const char *const f_wkday = _NL_CURRENT (LC_TIME, DAY_1 + tp->tm_wday);
-  const char *const a_month = _NL_CURRENT (LC_TIME, ABMON_1 + tp->tm_mon);
-  const char *const f_month = _NL_CURRENT (LC_TIME, MON_1 + tp->tm_mon);
-  const char *const ampm = _NL_CURRENT (LC_TIME,
-					hour12 > 11 ? PM_STR : AM_STR);
-  size_t aw_len = strlen (a_wkday);
-  size_t am_len = strlen (a_month);
-  size_t ap_len = strlen (ampm);
+  /* We cannot make the following values variables since we must delay
+     the evaluation of these values until really needed since some
+     expressions might not be valid in every situation.  The `struct tm'
+     might be generated by a strptime() call that initialized
+     only a few elements.  Dereference the pointers only if the format
+     requires this.  Then it is ok to fail if the pointers are invalid.  */
+# define a_wkday _NL_CURRENT (LC_TIME, ABDAY_1 + tp->tm_wday)
+# define f_wkday _NL_CURRENT (LC_TIME, DAY_1 + tp->tm_wday)
+# define a_month _NL_CURRENT (LC_TIME, ABMON_1 + tp->tm_mon)
+# define f_month _NL_CURRENT (LC_TIME, MON_1 + tp->tm_mon)
+# define ampm _NL_CURRENT (LC_TIME, tp->tm_hour > 11 ? PM_STR : AM_STR)
+
+# define aw_len strlen (a_wkday)
+# define am_len strlen (a_month)
+# define ap_len strlen (ampm)
 #else
 # if !HAVE_STRFTIME
-  const char *const f_wkday = weekday_name[tp->tm_wday];
-  const char *const f_month = month_name[tp->tm_mon];
-  const char *const a_wkday = f_wkday;
-  const char *const a_month = f_month;
-  const char *const ampm = "AMPM" + 2 * (hour12 > 11);
+# define f_wkday (weekday_name[tp->tm_wday])
+# define f_month (month_name[tp->tm_mon])
+# define a_wkday f_wkday
+# define a_month f_month
+# define ampm ("AMPM" + 2 * (tp->tm_hour > 11))
+
   size_t aw_len = 3;
   size_t am_len = 3;
   size_t ap_len = 2;
 # endif
 #endif
-#if defined _NL_CURRENT || !HAVE_STRFTIME
-  size_t wkday_len = strlen (f_wkday);
-  size_t month_len = strlen (f_month);
-#endif
   const char *zone;
-  size_t zonelen;
   size_t i = 0;
   char *p = s;
   const char *f;
@@ -460,25 +461,27 @@
   zone = (const char *) tp->tm_zone;
 #endif
 #if HAVE_TZNAME
-  /* POSIX.1 8.1.1 requires that whenever strftime() is called, the
-     time zone names contained in the external variable `tzname' shall
-     be set as if the tzset() function had been called.  */
+  if (ut)
+    {
+      if (! (zone && *zone))
+	zone = "GMT";
+    }
+  else
+    {
+      /* POSIX.1 8.1.1 requires that whenever strftime() is called, the
+	 time zone names contained in the external variable `tzname' shall
+	 be set as if the tzset() function had been called.  */
 # if HAVE_TZSET
-  tzset ();
+      tzset ();
 # endif
-
-  if (!(zone && *zone) && tp->tm_isdst >= 0)
-    zone = tzname[tp->tm_isdst];
+    }
 #endif
-  if (! zone)
-    zone = "";		/* POSIX.2 requires the empty string here.  */
-
-  zonelen = strlen (zone);
 
   if (hour12 > 12)
     hour12 -= 12;
   else
-    if (hour12 == 0) hour12 = 12;
+    if (hour12 == 0)
+      hour12 = 12;
 
   for (f = format; *f != '\0'; ++f)
     {
@@ -544,7 +547,13 @@
 		if (bytes == 0)
 		  break;
 
-		if (bytes == (size_t) -2 || bytes == (size_t) -1)
+		if (bytes == (size_t) -2)
+		  {
+		    len += strlen (f + len);
+		    break;
+		  }
+
+		if (bytes == (size_t) -1)
 		  {
 		    len++;
 		    break;
@@ -555,6 +564,7 @@
 	    while (! mbsinit (&mbstate));
 
 	    cpy (len, f);
+	    f += len - 1;
 	    continue;
 	  }
 	}
@@ -664,7 +674,7 @@
 	      to_lowcase = 0;
 	    }
 #if defined _NL_CURRENT || !HAVE_STRFTIME
-	  cpy (wkday_len, f_wkday);
+	  cpy (strlen (f_wkday), f_wkday);
 	  break;
 #else
 	  goto underlying_strftime;
@@ -690,7 +700,7 @@
 	      to_lowcase = 0;
 	    }
 #if defined _NL_CURRENT || !HAVE_STRFTIME
-	  cpy (month_len, f_month);
+	  cpy (strlen (f_month), f_month);
 	  break;
 #else
 	  goto underlying_strftime;
@@ -714,10 +724,9 @@
 	subformat:
 	  {
 	    char *old_start = p;
-	    size_t len = my_strftime (NULL, maxsize - i, subfmt, tp);
-	    if (len == 0 && *subfmt)
-	      return 0;
-	    add (len, my_strftime (p, maxsize - i, subfmt, tp));
+	    size_t len = my_strftime (NULL, (size_t) -1, subfmt,
+				      tp ut_argument);
+	    add (len, my_strftime (p, maxsize - i, subfmt, tp ut_argument));
 
 	    if (to_uppcase)
 	      while (old_start < p)
@@ -742,7 +751,6 @@
 	      *u++ = modifier;
 	    *u++ = format_char;
 	    *u = '\0';
-	    ubuf[0] = '\1';
 	    len = strftime (ubuf, sizeof ubuf, ufmt, tp);
 	    if (len == 0 && ubuf[0] != '\0')
 	      return 0;
@@ -1033,7 +1041,6 @@
 	  add (1, *p = '\t');
 	  break;
 
-	case 'f':
 	case 'u':		/* POSIX.2 extension.  */
 	  DO_NUMBER (1, (tp->tm_wday - 1 + 7) % 7 + 1);
 
@@ -1142,7 +1149,16 @@
 	      to_uppcase = 0;
 	      to_lowcase = 1;
 	    }
-	  cpy (zonelen, zone);
+
+#if HAVE_TZNAME
+	  /* The tzset() call might have changed the value.  */
+	  if (!(zone && *zone) && tp->tm_isdst >= 0)
+	    zone = tzname[tp->tm_isdst];
+#endif
+	  if (! zone)
+	    zone = "";		/* POSIX.2 requires the empty string here.  */
+
+	  cpy (strlen (zone), zone);
 	  break;
 
 	case 'z':		/* GNU extension.  */
@@ -1154,34 +1170,39 @@
 #if HAVE_TM_GMTOFF
 	    diff = tp->tm_gmtoff;
 #else
-	    struct tm gtm;
-	    struct tm ltm;
-	    time_t lt;
-
-	    ltm = *tp;
-	    lt = mktime (&ltm);
+	    if (ut)
+	      diff = 0;
+	    else
+	      {
+		struct tm gtm;
+		struct tm ltm;
+		time_t lt;
 
-	    if (lt == (time_t) -1)
-	      {
-		/* mktime returns -1 for errors, but -1 is also a
-		   valid time_t value.  Check whether an error really
-		   occurred.  */
-		struct tm tm;
+		ltm = *tp;
+		lt = mktime (&ltm);
 
-		if (! localtime_r (&lt, &tm)
-		    || ((ltm.tm_sec ^ tm.tm_sec)
-			| (ltm.tm_min ^ tm.tm_min)
-			| (ltm.tm_hour ^ tm.tm_hour)
-			| (ltm.tm_mday ^ tm.tm_mday)
-			| (ltm.tm_mon ^ tm.tm_mon)
-			| (ltm.tm_year ^ tm.tm_year)))
+		if (lt == (time_t) -1)
+		  {
+		    /* mktime returns -1 for errors, but -1 is also a
+		       valid time_t value.  Check whether an error really
+		       occurred.  */
+		    struct tm tm;
+
+		    if (! my_strftime_localtime_r (&lt, &tm)
+			|| ((ltm.tm_sec ^ tm.tm_sec)
+			    | (ltm.tm_min ^ tm.tm_min)
+			    | (ltm.tm_hour ^ tm.tm_hour)
+			    | (ltm.tm_mday ^ tm.tm_mday)
+			    | (ltm.tm_mon ^ tm.tm_mon)
+			    | (ltm.tm_year ^ tm.tm_year)))
+		      break;
+		  }
+
+		if (! my_strftime_gmtime_r (&lt, &gtm))
 		  break;
+
+		diff = tm_diff (&ltm, &gtm);
 	      }
-
-	    if (! gmtime_r (&lt, &gtm))
-	      break;
-
-	    diff = tm_diff (&ltm, &gtm);
 #endif
 
 	    if (diff < 0)
@@ -1214,7 +1235,7 @@
 	}
     }
 
-  if (p)
+  if (p && maxsize != 0)
     *p = '\0';
   return i;
 }
--- a/src/sunfns.c	Tue Oct 19 07:21:16 1999 +0000
+++ b/src/sunfns.c	Tue Oct 19 07:25:11 1999 +0000
@@ -1,5 +1,5 @@
 /* Functions for Sun Windows menus and selection buffer.
-   Copyright (C) 1987 Free Software Foundation, Inc.
+   Copyright (C) 1987, 1999 Free Software Foundation, Inc.
 
 This file is probably totally obsolete.  In any case, the FSF is
 unwilling to support it.  We agreed to include it in our distribution
@@ -120,7 +120,7 @@
 
   if ((! already_initialized) || (!NILP(force))) {
     cp = getenv("WINDOW_GFX");
-    if (cp != 0) win_fd = open(cp, 2);
+    if (cp != 0) win_fd = emacs_open (cp, O_RDWR, 0);
     if (win_fd > 0)
       {
 	Sun_Font = pf_default();
--- a/src/sysdep.c	Tue Oct 19 07:21:16 1999 +0000
+++ b/src/sysdep.c	Tue Oct 19 07:25:11 1999 +0000
@@ -1,5 +1,5 @@
 /* Interfaces to system-dependent kernel and library entries.
-   Copyright (C) 1985, 86, 87, 88, 93, 94, 95 Free Software Foundation, Inc.
+   Copyright (C) 1985, 86,87,88,93,94,95, 1999 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -19,13 +19,10 @@
 Boston, MA 02111-1307, USA.  */
 
 
+#include <config.h>
 #include <signal.h>
 #include <setjmp.h>
 
-#include <config.h>
-#ifdef STDC_HEADERS
-#include <stdlib.h>
-#endif
 #include "lisp.h"
 #include "blockinput.h"
 #undef NULL
@@ -50,18 +47,6 @@
 
 #define min(x,y) ((x) > (y) ? (y) : (x))
 
-/* In this file, open, read and write refer to the system calls,
-   not our sugared interfaces  sys_open, sys_read and sys_write.
-   Contrariwise, for systems where we use the system calls directly,
-   define sys_read, etc. here as aliases for them.  */
-#ifndef read
-#define sys_read read
-#define sys_write write
-#endif /* `read' is not a macro */
-
-#undef read
-#undef write
-
 #ifdef WINDOWSNT
 #define read _read
 #define write _write
@@ -69,18 +54,6 @@
 extern int errno;
 #endif /* not WINDOWSNT */
 
-#ifndef close
-#define sys_close close
-#else 
-#undef close
-#endif
-
-#ifndef open
-#define sys_open open
-#else /* `open' is a macro */
-#undef open
-#endif /* `open' is a macro */
-
 /* Does anyone other than VMS need this? */
 #ifndef fwrite
 #define sys_fwrite fwrite
@@ -2710,25 +2683,6 @@
 #endif /* not MSDOS */
 
 #ifdef BSD4_1
-/*
- * Partially emulate 4.2 open call.
- * open is defined as this in 4.1.
- *
- * - added by Michael Bloom @ Citicorp/TTI
- *
- */
-
-int
-sys_open (path, oflag, mode)
-     char *path;
-     int oflag, mode;
-{
-  if (oflag & O_CREAT) 
-    return creat (path, mode);
-  else
-    return open (path, oflag);
-}
-
 void
 init_sigio (fd)
      int fd;
@@ -3093,27 +3047,25 @@
 #endif /* not WINDOWSNT */
 #endif /* ! HAVE_STRERROR */
 
-#ifdef INTERRUPTIBLE_OPEN
-
 int
-/* VARARGS 2 */
-sys_open (path, oflag, mode)
+emacs_open (path, oflag, mode)
      char *path;
      int oflag, mode;
 {
   register int rtnval;
+
+#ifdef BSD4_1
+  if (oflag & O_CREAT) 
+    return creat (path, mode);
+#endif
   
   while ((rtnval = open (path, oflag, mode)) == -1
 	 && (errno == EINTR));
   return (rtnval);
 }
 
-#endif /* INTERRUPTIBLE_OPEN */
-
-#ifdef INTERRUPTIBLE_CLOSE
-
 int
-sys_close (fd)
+emacs_close (fd)
      int fd;
 {
   int did_retry = 0;
@@ -3132,12 +3084,8 @@
   return rtnval;
 }
 
-#endif /* INTERRUPTIBLE_CLOSE */
-
-#ifdef INTERRUPTIBLE_IO
-
 int
-sys_read (fildes, buf, nbyte)
+emacs_read (fildes, buf, nbyte)
      int fildes;
      char *buf;
      unsigned int nbyte;
@@ -3150,7 +3098,7 @@
 }
 
 int
-sys_write (fildes, buf, nbyte)
+emacs_write (fildes, buf, nbyte)
      int fildes;
      char *buf;
      unsigned int nbyte;
@@ -3177,8 +3125,6 @@
     }
   return (bytes_written);
 }
-
-#endif /* INTERRUPTIBLE_IO */
 
 #ifndef HAVE_VFORK
 #ifndef WINDOWSNT
@@ -3210,6 +3156,7 @@
  *	always negligible.   Fred Fish, Unisoft Systems Inc.
  */
 
+#ifndef HAVE_STRSIGNAL
 #ifndef HAVE_SYS_SIGLIST
 char *sys_siglist[NSIG + 1] =
 {
@@ -3296,6 +3243,7 @@
   0
   };
 #endif /* HAVE_SYS_SIGLIST */
+#endif /* HAVE_STRSIGNAL */
 
 /*
  *	Warning, this function may not duplicate 4.2 action properly
@@ -3384,12 +3332,10 @@
 {
   register int fd, ret;
   
-  sys_close (newd);
+  emacs_close (newd);
 
 #ifdef F_DUPFD
-  fd = fcntl (oldd, F_DUPFD, newd);
-  if (fd != newd)
-    error ("can't dup2 (%i,%i) : %s", oldd, newd, strerror (errno));
+  return fcntl (oldd, F_DUPFD, newd);
 #else
   fd = dup (old);
   if (fd == -1)
@@ -3397,7 +3343,7 @@
   if (fd == new)
     return new;
   ret = dup2 (old,new);
-  sys_close (fd);
+  emacs_close (fd);
   return ret;
 #endif
 }
@@ -3452,6 +3398,7 @@
 
 #ifdef DGUX
 
+#ifndef HAVE_STRSIGNAL
 char *sys_siglist[NSIG + 1] =
 {
   "null signal",			 /*  0 SIGNULL   */
@@ -3521,6 +3468,7 @@
   "notification message in mess. queue", /* 64 SIGDGNOTIFY */
   0
 };
+#endif /* HAVE_STRSIGNAL */
 
 #endif /* DGUX */
 
@@ -3538,7 +3486,7 @@
 {
   int rtnval;
 
-  rtnval = sys_close (dirp->dd_fd);
+  rtnval = emacs_close (dirp->dd_fd);
 
   /* Some systems (like Solaris) allocate the buffer and the DIR all
      in one block.  Why in the world are we freeing this ourselves
@@ -3563,7 +3511,7 @@
   register int fd;		/* file descriptor for read */
   struct stat sbuf;		/* result of fstat */
 
-  fd = sys_open (filename, 0);
+  fd = emacs_open (filename, O_RDONLY, 0);
   if (fd < 0)
     return 0;
 
@@ -3572,7 +3520,7 @@
       || (sbuf.st_mode & S_IFMT) != S_IFDIR
       || (dirp = (DIR *) malloc (sizeof (DIR))) == 0)
     {
-      sys_close (fd);
+      emacs_close (fd);
       UNBLOCK_INPUT;
       return 0;		/* bad luck today */
     }
@@ -3588,7 +3536,7 @@
 closedir (dirp)
      register DIR *dirp;		/* stream from opendir */
 {
-  sys_close (dirp->dd_fd);
+  emacs_close (dirp->dd_fd);
   xfree ((char *) dirp);
 }
 
@@ -3622,7 +3570,7 @@
 	dirp->dd_loc = dirp->dd_size = 0;
 
       if (dirp->dd_size == 0 	/* refill buffer */
-	  && (dirp->dd_size = sys_read (dirp->dd_fd, dirp->dd_buf, DIRBLKSIZ)) <= 0)
+	  && (dirp->dd_size = emacs_read (dirp->dd_fd, dirp->dd_buf, DIRBLKSIZ)) <= 0)
 	return 0;
 
 #ifndef VMS
@@ -3775,7 +3723,7 @@
 		 */
       status = umask (0);	/* Get current umask */
       status = umask (status | (0777 & ~dmode));	/* Set for mkdir */
-      fd = sys_open ("/dev/null", 2);
+      fd = emacs_open ("/dev/null", O_RDWR, 0);
       if (fd >= 0)
         {
 	  dup2 (fd, 0);
@@ -3821,7 +3769,7 @@
       return (-1);		/* Errno is set already */
 
     case 0:			/* Child process */
-      fd = sys_open ("/dev/null", 2);
+      fd = emacs_open ("/dev/null", O_RDWR, 0);
       if (fd >= 0)
         {
 	  dup2 (fd, 0);
@@ -4240,6 +4188,7 @@
   return (getgid () << 16) | getuid ();
 }
 
+#undef read
 int
 sys_read (fildes, buf, nbyte)
      int fildes;
@@ -4279,6 +4228,7 @@
  *	Thus we do this stupidity below.
  */
 
+#undef write
 int
 sys_write (fildes, buf, nbytes)
      int fildes;
@@ -5322,7 +5272,28 @@
 }
 #endif /* no bcmp */
 #endif /* not BSTRING */
-
+
+#ifndef HAVE_STRSIGNAL
+char *
+strsignal (code)
+     int code;
+{
+  char *signame = 0;
+
+  if (0 <= code && code < NSIG)
+    {
+#ifdef VMS
+      signame = sys_errlist[code];
+#else
+      /* Cast to suppress warning if the table has const char *.  */
+      signame = (char *) sys_siglist[code];
+#endif
+    }
+
+  return signame;
+}
+#endif /* HAVE_STRSIGNAL */
+
 /* All the Macintosh stuffs go here */
 
 #ifdef macintosh
@@ -5502,10 +5473,10 @@
 
 /* Define our own stat function for both MrC and CW.  The reason for
    doing this: "stat" is both the name of a struct and function name:
-   can't use the same trick like that for sys_open, sys_close, etc. to
+   we can't #define stat to something else to
    redirect Emacs's calls to our own version that converts Unix style
    filenames to Mac style filename because all sorts of compilation
-   errors will be generated if stat is #define'd to be sys_stat.  */
+   errors will be generated if stat is #define'd to be something else.  */
 
 int
 stat (const char *path, struct stat *buf)
--- a/src/syssignal.h	Tue Oct 19 07:21:16 1999 +0000
+++ b/src/syssignal.h	Tue Oct 19 07:25:11 1999 +0000
@@ -1,5 +1,5 @@
 /* syssignal.h - System-dependent definitions for signals.
-   Copyright (C) 1993 Free Software Foundation, Inc.
+   Copyright (C) 1993, 1999 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -123,6 +123,29 @@
 #define sigfree() sigsetmask (SIGEMPTYMASK)
 #endif /* not BSD4_1 */
 
+#if defined (SIGINFO) && defined (BROKEN_SIGINFO)
+#undef SIGINFO
+#endif
+#if defined (SIGIO) && defined (BROKEN_SIGIO)
+#undef SIGIO
+#endif
+#if defined (SIGPOLL) && defined (BROKEN_SIGPOLL)
+#undef SIGPOLL
+#endif
+#if defined (SIGTSTP) && defined (BROKEN_SIGTSTP)
+#undef SIGTSTP
+#endif
+#if defined (SIGURG) && defined (BROKEN_SIGURG)
+#undef SIGURG
+#endif
+
+#if NSIG < NSIG_MINIMUM
+# ifdef NSIG
+#  undef NSIG
+# endif
+# define NSIG NSIG_MINIMUM
+#endif
+
 #ifdef BSD4_1
 #define SIGIO SIGTINT
 /* sigfree is in sysdep.c */
@@ -149,3 +172,8 @@
 #endif /* SIGCHLD */
 #endif /* ! defined (SIGCLD) */
 #endif /* VMS */
+
+#ifndef HAVE_STRSIGNAL
+/* strsignal is in sysdep.c */
+char *strsignal ();
+#endif
--- a/src/unexelf.c	Tue Oct 19 07:21:16 1999 +0000
+++ b/src/unexelf.c	Tue Oct 19 07:25:11 1999 +0000
@@ -1,4 +1,4 @@
-/* Copyright (C) 1985, 1986, 1987, 1988, 1990, 1992
+/* Copyright (C) 1985, 1986, 1987, 1988, 1990, 1992, 1999
    Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
@@ -412,6 +412,13 @@
 
  */
 
+#ifndef emacs
+#define fatal(a, b, c) fprintf (stderr, a, b, c), exit (1)
+#else
+#include <config.h>
+extern void fatal (char *, ...);
+#endif
+
 #include <sys/types.h>
 #include <stdio.h>
 #include <sys/stat.h>
@@ -517,17 +524,18 @@
 
 #ifndef ElfW
 # ifdef __STDC__
-#  define ElfW(type)	Elf32_##type
+#  define ElfBitsW(bits, type) Elf##bits##_##type
 # else
-#  define ElfW(type)	Elf32_/**/type
+#  define ElfBitsW(bits, type) Elf/**/bits/**/_/**/type
 # endif
-#endif
-
-#ifndef emacs
-#define fatal(a, b, c) fprintf (stderr, a, b, c), exit (1)
-#else
-#include <config.h>
-extern void fatal (char *, ...);
+# ifdef _LP64
+#  define ELFSIZE 64
+# else
+#  define ELFSIZE 32
+# endif
+  /* This macro expands `bits' before invoking ElfBitsW.  */
+# define ElfExpandBitsW(bits, type) ElfBitsW (bits, type)
+# define ElfW(type) ElfExpandBitsW (ELFSIZE, type)
 #endif
 
 #ifndef ELF_BSS_SECTION_NAME
--- a/src/unexhp9k800.c	Tue Oct 19 07:21:16 1999 +0000
+++ b/src/unexhp9k800.c	Tue Oct 19 07:25:11 1999 +0000
@@ -37,16 +37,16 @@
   sigsetreturn (_sigreturn);
 */
 
+#ifdef emacs
+#include <config.h>
+#endif
+
 #include <stdio.h>
 #include <fcntl.h>
 #include <errno.h>
 
 #include <a.out.h>
 
-#ifdef emacs
-#include <config.h>
-#endif
-
 #ifdef HPUX_USE_SHLIBS
 #include <dl.h>
 #endif
--- a/src/unexsunos4.c	Tue Oct 19 07:21:16 1999 +0000
+++ b/src/unexsunos4.c	Tue Oct 19 07:25:11 1999 +0000
@@ -1,5 +1,5 @@
 /* Unexec for Sunos 4 using shared libraries.
-   Copyright (C) 1990, 1994 Free Software Foundation, Inc.
+   Copyright (C) 1990, 1994, 1999 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -43,6 +43,11 @@
  *  is somewhat abused here) is loaded first!
  *
  */
+
+#ifdef emacs
+#include <config.h>
+#endif
+
 #include <sys/param.h>
 #include <sys/mman.h>
 #include <sys/file.h>
@@ -51,12 +56,6 @@
 #include <stdio.h>
 #include <a.out.h>
 
-/* Do this after the above #include's in case a configuration file wants
-   to define things for this file based on what <a.out.h> defines.  */
-#ifdef emacs
-#include <config.h>
-#endif
-
 #if defined (SUNOS4) || defined (__FreeBSD__) || defined (__NetBSD__)
 #define UNDO_RELOCATION
 #endif
--- a/src/vmsfns.c	Tue Oct 19 07:21:16 1999 +0000
+++ b/src/vmsfns.c	Tue Oct 19 07:25:11 1999 +0000
@@ -1,5 +1,5 @@
 /* VMS subprocess and command interface.
-   Copyright (C) 1987, 1988 Free Software Foundation, Inc.
+   Copyright (C) 1987, 1988, 1999 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -56,11 +56,11 @@
 
 #ifdef VMS
 
+#include <config.h>
 #include <stdio.h>
 #include <ctype.h>
 #undef NULL
 
-#include <config.h>
 #include "lisp.h"
 #include <descrip.h>
 #include <dvidef.h>
--- a/src/vmsgmalloc.c	Tue Oct 19 07:21:16 1999 +0000
+++ b/src/vmsgmalloc.c	Tue Oct 19 07:25:11 1999 +0000
@@ -5,7 +5,7 @@
 /* The malloc headers and source files from the C library follow here.  */
 
 /* Declarations for `malloc' and friends.
-   Copyright 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
+   Copyright 1990, 1991, 1992, 1993, 1999 Free Software Foundation, Inc.
 		  Written May 1989 by Mike Haertel.
 
 This file is part of GNU Emacs.
@@ -57,6 +57,10 @@
 #define	NULL	0
 #endif
 
+#if defined (HAVE_CONFIG_H) || defined (emacs)
+#include <config.h>
+#endif
+
 #ifdef	__STDC__
 #include <stddef.h>
 #else
@@ -105,10 +109,6 @@
 
 #include <stdio.h>		/* Harmless, gets __GNU_LIBRARY__ defined.  */
 
-#if defined(HAVE_CONFIG_H) || defined(emacs)
-#include <config.h>
-#endif
-
 #if	defined(__GNU_LIBRARY__) || defined(STDC_HEADERS) || defined(USG)
 #include <string.h>
 #else
--- a/src/w32faces.c	Tue Oct 19 07:21:16 1999 +0000
+++ b/src/w32faces.c	Tue Oct 19 07:25:11 1999 +0000
@@ -1,5 +1,5 @@
 /* "Face" primitives on the Microsoft W32 API.
-   Copyright (C) 1993, 1994, 1995 Free Software Foundation.
+   Copyright (C) 1993, 1994, 1995, 1999 Free Software Foundation.
 
 This file is part of GNU Emacs.
 
@@ -20,10 +20,10 @@
 
 /* Ported xfaces.c for w32 - Kevin Gallo */
 
+#include <config.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 
-#include <config.h>
 #include "lisp.h"
 
 #include "w32term.h"
--- a/src/w32menu.c	Tue Oct 19 07:21:16 1999 +0000
+++ b/src/w32menu.c	Tue Oct 19 07:25:11 1999 +0000
@@ -1,5 +1,5 @@
 /* Menu support for GNU Emacs on the Microsoft W32 API.
-   Copyright (C) 1986, 1988, 1993, 1994, 1996, 1998 Free Software Foundation, Inc.
+   Copyright (C) 1986, 88, 93, 94, 96, 98, 1999 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -18,9 +18,8 @@
 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 Boston, MA 02111-1307, USA.  */
 
+#include <config.h>
 #include <signal.h>
-#include <config.h>
-
 #include <stdio.h>
 #include "lisp.h"
 #include "termhooks.h"
--- a/src/w32proc.c	Tue Oct 19 07:21:16 1999 +0000
+++ b/src/w32proc.c	Tue Oct 19 07:25:11 1999 +0000
@@ -1,5 +1,5 @@
 /* Process support for GNU Emacs on the Microsoft W32 API.
-   Copyright (C) 1992, 1995 Free Software Foundation, Inc.
+   Copyright (C) 1992, 1995, 1999 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -91,10 +91,6 @@
 
 Lisp_Object Qhigh, Qlow;
 
-#ifndef SYS_SIGLIST_DECLARED
-extern char *sys_siglist[];
-#endif
-
 #ifdef EMACSDEBUG
 void _DebPrint (const char *fmt, ...)
 {
@@ -546,13 +542,11 @@
       else if (WIFSIGNALED (retval))
 	{
 	  int code = WTERMSIG (retval);
-	  char *signame = 0;
-	  
-	  if (code < NSIG)
-	    {
-	      /* Suppress warning if the table has const char *.  */
-	      signame = (char *) sys_siglist[code];
-	    }
+	  char *signame;
+
+	  synchronize_messages_locale ();
+	  signame = strsignal (code);
+
 	  if (signame == 0)
 	    signame = "unknown";
 
--- a/src/w32term.c	Tue Oct 19 07:21:16 1999 +0000
+++ b/src/w32term.c	Tue Oct 19 07:25:11 1999 +0000
@@ -1,5 +1,5 @@
 /* Implementation of GUI terminal on the Microsoft W32 API.
-   Copyright (C) 1989, 93, 94, 95, 96, 97, 98 Free Software Foundation, Inc.
+   Copyright (C) 1989, 93,94,95,96,97,98, 1999 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -18,8 +18,8 @@
 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 Boston, MA 02111-1307, USA.  */
 
+#include <config.h>
 #include <signal.h>
-#include <config.h>
 #include <stdio.h>
 #include "lisp.h"
 #include "charset.h"
--- a/src/w32xfns.c	Tue Oct 19 07:21:16 1999 +0000
+++ b/src/w32xfns.c	Tue Oct 19 07:25:11 1999 +0000
@@ -1,5 +1,5 @@
 /* Functions taken directly from X sources for use with the Microsoft W32 API.
-   Copyright (C) 1989, 1992, 1993, 1994, 1995 Free Software Foundation.
+   Copyright (C) 1989, 1992, 1993, 1994, 1995, 1999 Free Software Foundation.
 
 This file is part of GNU Emacs.
 
@@ -18,8 +18,8 @@
 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 Boston, MA 02111-1307, USA.  */
 
+#include <config.h>
 #include <signal.h>
-#include <config.h>
 #include <stdio.h>
 #include "lisp.h"
 #include "frame.h"
--- a/src/xdisp.c	Tue Oct 19 07:21:16 1999 +0000
+++ b/src/xdisp.c	Tue Oct 19 07:25:11 1999 +0000
@@ -169,9 +169,6 @@
 
 #include <config.h>
 #include <stdio.h>
-#ifdef STDC_HEADERS
-#include <stdlib.h>
-#endif
 #include "lisp.h"
 #include "frame.h"
 #include "window.h"
@@ -628,7 +625,7 @@
 static void display_mode_line P_ ((struct window *, enum face_id,
 				   Lisp_Object));
 static int display_mode_element P_ ((struct it *, int, int, int, Lisp_Object));
-static char *decode_mode_spec P_ ((struct window *, char, int, int));
+static char *decode_mode_spec P_ ((struct window *, int, int, int));
 static void display_menu_bar P_ ((struct window *));
 static int display_count_lines P_ ((int, int, int, int, int *));
 static int display_string P_ ((unsigned char *, Lisp_Object, Lisp_Object,
@@ -11883,7 +11880,7 @@
 static char *
 decode_mode_spec (w, c, field_width, precision)
      struct window *w;
-     register char c;
+     register int c;
      int field_width, precision;
 {
   Lisp_Object obj;
@@ -12379,6 +12376,8 @@
 		start, it, field_width, precision, max_x, multibyte)
      unsigned char *string;
      Lisp_Object lisp_string;
+     Lisp_Object face_string;
+     int face_string_pos;
      int start;
      struct it *it;
      int field_width, precision, max_x;
--- a/src/xfaces.c	Tue Oct 19 07:21:16 1999 +0000
+++ b/src/xfaces.c	Tue Oct 19 07:25:11 1999 +0000
@@ -177,9 +177,9 @@
 
 #define SCALABLE_FONTS 1
 
+#include <config.h>
 #include <sys/types.h>
 #include <sys/stat.h>
-#include <config.h>
 #include "lisp.h"
 #include "charset.h"
 #include "frame.h"
@@ -223,7 +223,6 @@
 #endif /* HAVE_X_WINDOWS */
 
 #include <stdio.h>
-#include <stdlib.h>
 #include <ctype.h>
 #include "keyboard.h"
 
--- a/src/xfns.c	Tue Oct 19 07:21:16 1999 +0000
+++ b/src/xfns.c	Tue Oct 19 07:25:11 1999 +0000
@@ -27,8 +27,8 @@
 
 /* Rewritten for X11 by Joseph Arceneaux */
 
+#include <config.h>
 #include <signal.h>
-#include <config.h>
 #include <stdio.h>
 #include <math.h>
 
@@ -52,9 +52,7 @@
 
 #ifdef HAVE_X_WINDOWS
 
-#ifdef STDC_HEADERS
-#include <stdlib.h>
-#else
+#ifndef STDC_HEADERS
 extern void abort ();
 #endif
 #include <ctype.h>
@@ -667,7 +665,7 @@
   /* XReadBitmapFile won't handle magic file names.  */
   if (fd == 0)
     return -1;
-  close (fd);
+  emacs_close (fd);
 
   filename = (char *) XSTRING (found)->data;
 
@@ -9761,7 +9759,7 @@
 Automatically hide the tooltip after TIMEOUT seconds.\n\
 TIMEOUT nil means use the default timeout of 5 seconds.")
   (string, frame, parms, timeout)
-     Lisp_Object string, frame, parms;
+     Lisp_Object string, frame, parms, timeout;
 {
   struct frame *f;
   struct window *w;
--- a/src/xmenu.c	Tue Oct 19 07:21:16 1999 +0000
+++ b/src/xmenu.c	Tue Oct 19 07:25:11 1999 +0000
@@ -1,5 +1,5 @@
 /* X Communication module for terminals which understand the X protocol.
-   Copyright (C) 1986, 1988, 1993, 1994, 1996 Free Software Foundation, Inc.
+   Copyright (C) 1986, 88, 93, 94, 96, 1999 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -30,12 +30,10 @@
 
 /* Rewritten for clarity and GC protection by rms in Feb 94.  */
 
+#include <config.h>
+
 /* On 4.3 this loses if it comes after xterm.h.  */
 #include <signal.h>
-#include <config.h>
-#ifdef HAVE_STDLIB_H
-#include <stdlib.h>
-#endif
 
 #include <stdio.h>
 #include "lisp.h"
--- a/src/xterm.c	Tue Oct 19 07:21:16 1999 +0000
+++ b/src/xterm.c	Tue Oct 19 07:25:11 1999 +0000
@@ -22,17 +22,13 @@
 /* New display code by Gerd Moellmann <gerd@gnu.org>.  */
 /* Xt features made by Fred Pierresteguy.  */
 
+#include <config.h>
+
 /* On 4.3 these lose if they come after xterm.h.  */
-/* On HP-UX 8.0 signal.h loses if it comes after config.h.  */
 /* Putting these at the beginning seems to be standard for other .c files.  */
 #include <signal.h>
 
-#include <config.h>
-
 #include <stdio.h>
-#ifdef STDC_HEADERS
-#include <stdlib.h>
-#endif
 
 #ifdef HAVE_X_WINDOWS
 
@@ -145,11 +141,6 @@
 #endif
 #endif
 
-#ifdef HAVE_SETLOCALE
-/* So we can do setlocale.  */
-#include <locale.h>
-#endif
-
 #ifdef SOLARIS2
 /* memmove will be defined as a macro in Xfuncs.h unless
    <string.h> is included beforehand.  The declaration for memmove in
@@ -2157,9 +2148,9 @@
 				       int *, int *));
 static void x_compute_overhangs_and_x P_ ((struct glyph_string *, int, int));
 static int x_alloc_lighter_color P_ ((struct frame *, Display *, Colormap,
-				      unsigned long *, float, int));
+				      unsigned long *, double, int));
 static void x_setup_relief_color P_ ((struct frame *, struct relief *,
-				      float, int, unsigned long));
+				      double, int, unsigned long));
 static void x_setup_relief_colors P_ ((struct glyph_string *));
 static void x_draw_image_glyph_string P_ ((struct glyph_string *));
 static void x_draw_image_relief P_ ((struct glyph_string *));
@@ -3049,7 +3040,7 @@
      Display *display;
      Colormap cmap;
      unsigned long *pixel;
-     float factor;
+     double factor;
      int delta;
 {
   XColor color, new;
@@ -3108,7 +3099,7 @@
 x_setup_relief_color (f, relief, factor, delta, default_pixel)
      struct frame *f;
      struct relief *relief;
-     float factor;
+     double factor;
      int delta;
      unsigned long default_pixel;
 {
@@ -12392,28 +12383,6 @@
 }
 #endif
 
-#if defined (HAVE_X_I18N) || (defined (USE_X_TOOLKIT) && defined (HAVE_X11XTR6))
-/* Recover from setlocale (LC_ALL, "").  */
-static void
-fixup_locale ()
-{
-  /* Currently we require strerror to use the "C" locale,
-     since we don't yet support decoding its string result.  */
-#ifdef LC_MESSAGES
-  setlocale (LC_MESSAGES, "C");
-#endif
-
-  /* The Emacs Lisp reader needs LC_NUMERIC to be "C",
-     so that numbers are read and printed properly for Emacs Lisp.  */
-  setlocale (LC_NUMERIC, "C");
-
-  /* Currently we require strftime to use the "C" locale,
-     since we don't yet support encoding its format argument,
-     or decoding its string result.  */
-  setlocale (LC_TIME, "C");
-}
-#endif
-
 struct x_display_info *
 x_term_init (display_name, xrm_option, resource_name)
      Lisp_Object display_name;
@@ -12433,11 +12402,6 @@
       x_initialized = 1;
     }
 
-#ifdef HAVE_X_I18N
-  setlocale (LC_ALL, "");
-  fixup_locale ();
-#endif
-
 #ifdef USE_X_TOOLKIT
   /* weiner@footloose.sps.mot.com reports that this causes
      errors with X11R5: