diff src/process.c @ 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 079b0f1b92be
children 6f64bccafad6
line wrap: on
line diff
--- 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)