comparison src/sysdep.c @ 398:74fd4e045ea6 r21-2-29

Import from CVS: tag r21-2-29
author cvs
date Mon, 13 Aug 2007 11:13:30 +0200
parents 6719134a07c2
children a86b2b5e0111
comparison
equal deleted inserted replaced
397:f4aeb21a5bad 398:74fd4e045ea6
31 31
32 #include <config.h> 32 #include <config.h>
33 33
34 #ifdef WINDOWSNT 34 #ifdef WINDOWSNT
35 #include <direct.h> 35 #include <direct.h>
36 #ifdef __MINGW32__
37 #include <mingw32/process.h>
38 #else
36 /* <process.h> should not conflict with "process.h", as per ANSI definition. 39 /* <process.h> should not conflict with "process.h", as per ANSI definition.
37 This is not true though with visual c though. The trick below works with 40 This is not true with visual c though. The trick below works with
38 VC4.2b and with VC5.0. It assumes that VC is installed in a kind of 41 VC4.2b, 5.0 and 6.0. It assumes that VC is installed in a kind of
39 standard way, so include files get to what/ever/path/include. 42 standard way, so include path ends with /include.
40 43
41 Unfortunately, this must go before lisp.h, since process.h defines abort() 44 Unfortunately, this must go before lisp.h, since process.h defines abort()
42 which will conflict with the macro defined in lisp.h 45 which will conflict with the macro defined in lisp.h
43 */ 46 */
44 #include <../include/process.h> 47 #include <../include/process.h>
48 #endif /* __MINGW32__ */
45 #endif /* WINDOWSNT */ 49 #endif /* WINDOWSNT */
46 50
47 #include "lisp.h" 51 #include "lisp.h"
48 52
49 #include <stddef.h>
50 #include <stdlib.h> 53 #include <stdlib.h>
51 54
52 /* ------------------------------- */ 55 /* ------------------------------- */
53 /* basic includes */ 56 /* basic includes */
54 /* ------------------------------- */ 57 /* ------------------------------- */
85 #include <sys/times.h> 88 #include <sys/times.h>
86 #endif 89 #endif
87 90
88 #ifdef WINDOWSNT 91 #ifdef WINDOWSNT
89 #include <sys/utime.h> 92 #include <sys/utime.h>
90 #include <windows.h>
91 #include "ntheap.h" 93 #include "ntheap.h"
92 #endif 94 #endif
93 95
94 /* ------------------------------- */ 96 /* ------------------------------- */
95 /* TTY definitions */ 97 /* TTY definitions */
229 #endif /* BSD */ 231 #endif /* BSD */
230 232
231 #endif /* NO_SUBPROCESSES */ 233 #endif /* NO_SUBPROCESSES */
232 234
233 235
234 void 236 #ifdef WINDOWSNT
235 wait_for_termination (int pid) 237 void wait_for_termination (HANDLE pHandle)
238 #else
239 void wait_for_termination (int pid)
240 #endif
236 { 241 {
237 /* #### With the new improved SIGCHLD handling stuff, there is much 242 /* #### With the new improved SIGCHLD handling stuff, there is much
238 less danger of race conditions and some of the comments below 243 less danger of race conditions and some of the comments below
239 don't apply. This should be updated. */ 244 don't apply. This should be updated. */
240 245
340 - EINVAL (incorrect arguments), 345 - EINVAL (incorrect arguments),
341 which are both program bugs. 346 which are both program bugs.
342 347
343 Since implementations may add their own error indicators on top, 348 Since implementations may add their own error indicators on top,
344 we ignore it by default. */ 349 we ignore it by default. */
350 #elif defined (WINDOWSNT)
351 int ret = 0, status = 0;
352 if (pHandle == NULL)
353 {
354 warn_when_safe (Qprocess, Qwarning, "Cannot wait for unknown process to terminate");
355 return;
356 }
357 do
358 {
359 QUIT;
360 ret = WaitForSingleObject(pHandle, 100);
361 }
362 while (ret == WAIT_TIMEOUT);
363 if (ret == WAIT_FAILED)
364 {
365 warn_when_safe (Qprocess, Qwarning, "waiting for process failed");
366 }
367 if (ret == WAIT_ABANDONED)
368 {
369 warn_when_safe (Qprocess, Qwarning,
370 "process to wait for has been abandoned");
371 }
372 if (ret == WAIT_OBJECT_0)
373 {
374 ret = GetExitCodeProcess(pHandle, &status);
375 if (ret)
376 {
377 synch_process_alive = 0;
378 synch_process_retcode = status;
379 }
380 else
381 {
382 /* GetExitCodeProcess() didn't return a valid exit status,
383 nothing to do. APA */
384 warn_when_safe (Qprocess, Qwarning,
385 "failure to obtain process exit value");
386 }
387 }
388 if (pHandle != NULL && !CloseHandle(pHandle))
389 {
390 warn_when_safe (Qprocess, Qwarning,
391 "failure to close unknown process");
392 }
345 #elif defined (EMACS_BLOCK_SIGNAL) && !defined (BROKEN_WAIT_FOR_SIGNAL) && defined (SIGCHLD) 393 #elif defined (EMACS_BLOCK_SIGNAL) && !defined (BROKEN_WAIT_FOR_SIGNAL) && defined (SIGCHLD)
346 while (1) 394 while (1)
347 { 395 {
348 static int wait_debugging = 0; /* Set nonzero to make following 396 static int wait_debugging = 0; /* Set nonzero to make following
349 function work under dbx (at least for bsd). */ 397 function work under dbx (at least for bsd). */
371 sigpause()/sigsuspend(), then your OS doesn't implement 419 sigpause()/sigsuspend(), then your OS doesn't implement
372 this properly (this applies under hpux9, for example). 420 this properly (this applies under hpux9, for example).
373 Try defining BROKEN_WAIT_FOR_SIGNAL. */ 421 Try defining BROKEN_WAIT_FOR_SIGNAL. */
374 EMACS_WAIT_FOR_SIGNAL (SIGCHLD); 422 EMACS_WAIT_FOR_SIGNAL (SIGCHLD);
375 } 423 }
376 #else /* not HAVE_WAITPID and (not EMACS_BLOCK_SIGNAL or BROKEN_WAIT_FOR_SIGNAL) */ 424 #else /* not HAVE_WAITPID and not WINDOWSNT and (not EMACS_BLOCK_SIGNAL or BROKEN_WAIT_FOR_SIGNAL) */
377 /* This approach is kind of cheesy but is guaranteed(?!) to work 425 /* This approach is kind of cheesy but is guaranteed(?!) to work
378 for all systems. */ 426 for all systems. */
379 while (1) 427 while (1)
380 { 428 {
381 QUIT; 429 QUIT;
419 467
420 void 468 void
421 child_setup_tty (int out) 469 child_setup_tty (int out)
422 { 470 {
423 struct emacs_tty s; 471 struct emacs_tty s;
424 EMACS_GET_TTY (out, &s); 472 emacs_get_tty (out, &s);
425 473
426 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS) 474 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
427 assert (isatty(out)); 475 assert (isatty(out));
428 s.main.c_oflag |= OPOST; /* Enable output postprocessing */ 476 s.main.c_oflag |= OPOST; /* Enable output postprocessing */
429 s.main.c_oflag &= ~ONLCR; /* Disable map of NL to CR-NL on output */ 477 s.main.c_oflag &= ~ONLCR; /* Disable map of NL to CR-NL on output */
488 s.main.c_cc[VSUSP] = _POSIX_VDISABLE; 536 s.main.c_cc[VSUSP] = _POSIX_VDISABLE;
489 s.main.c_lflag &= ~ISIG; 537 s.main.c_lflag &= ~ISIG;
490 #endif /* no TIOCGPGRP or no TIOCGLTC or no TIOCGETC */ 538 #endif /* no TIOCGPGRP or no TIOCGLTC or no TIOCGETC */
491 s.main.c_cc[VEOL] = _POSIX_VDISABLE; 539 s.main.c_cc[VEOL] = _POSIX_VDISABLE;
492 #if defined (CBAUD) 540 #if defined (CBAUD)
493 /* <mdiers> ### This is not portable. ### 541 /* <mdiers> #### This is not portable. ###
494 POSIX does not specify CBAUD, and 4.4BSD does not have it. 542 POSIX does not specify CBAUD, and 4.4BSD does not have it.
495 Instead, POSIX suggests to use cfset{i,o}speed(). 543 Instead, POSIX suggests to use cfset{i,o}speed().
496 [cf. D. Lewine, POSIX Programmer's Guide, Chapter 8: Terminal 544 [cf. D. Lewine, POSIX Programmer's Guide, Chapter 8: Terminal
497 I/O, O'Reilly 1991] */ 545 I/O, O'Reilly 1991] */
498 s.main.c_cflag = (s.main.c_cflag & ~CBAUD) | B9600; /* baud rate sanity */ 546 s.main.c_cflag = (s.main.c_cflag & ~CBAUD) | B9600; /* baud rate sanity */
511 s.main.sg_erase = 0377; 559 s.main.sg_erase = 0377;
512 s.main.sg_kill = 0377; 560 s.main.sg_kill = 0377;
513 s.lmode = LLITOUT | s.lmode; /* Don't strip 8th bit */ 561 s.lmode = LLITOUT | s.lmode; /* Don't strip 8th bit */
514 562
515 #endif /* not HAVE_TERMIO */ 563 #endif /* not HAVE_TERMIO */
516 EMACS_SET_TTY (out, &s, 0); 564 emacs_set_tty (out, &s, 0);
517 565
518 #ifdef RTU 566 #ifdef RTU
519 { 567 {
520 int zero = 0; 568 int zero = 0;
521 ioctl (out, FIOASYNC, &zero); 569 ioctl (out, FIOASYNC, &zero);
562 saved_handlers++; 610 saved_handlers++;
563 } 611 }
564 } 612 }
565 613
566 #ifdef WINDOWSNT 614 #ifdef WINDOWSNT
567 int 615 pid_t
568 sys_getpid (void) 616 sys_getpid (void)
569 { 617 {
570 return abs (getpid ()); 618 return abs (getpid ());
571 } 619 }
572 #endif /* WINDOWSNT */ 620 #endif /* WINDOWSNT */
573 621
574 /* Fork a subshell. */ 622 /* Fork a subshell. */
575 static void 623 static void
576 sys_subshell (void) 624 sys_subshell (void)
577 { 625 {
626 #ifdef WINDOWSNT
627 HANDLE pid;
628 #else
578 int pid; 629 int pid;
630 #endif
579 struct save_signal saved_handlers[5]; 631 struct save_signal saved_handlers[5];
580 Lisp_Object dir; 632 Lisp_Object dir;
581 unsigned char *str = 0; 633 unsigned char *str = 0;
582 int len; 634 int len;
583 struct gcpro gcpro1; 635 struct gcpro gcpro1;
612 if (str[len - 1] != '/') str[len++] = '/'; 664 if (str[len - 1] != '/') str[len++] = '/';
613 str[len] = 0; 665 str[len] = 0;
614 xyzzy: 666 xyzzy:
615 667
616 #ifdef WINDOWSNT 668 #ifdef WINDOWSNT
617 pid = -1; 669 pid = NULL;
618 #else /* not WINDOWSNT */ 670 #else /* not WINDOWSNT */
619 671
620 pid = fork (); 672 pid = fork ();
621 673
622 if (pid == -1) 674 if (pid == -1)
646 #endif 698 #endif
647 699
648 #ifdef WINDOWSNT 700 #ifdef WINDOWSNT
649 /* Waits for process completion */ 701 /* Waits for process completion */
650 pid = _spawnlp (_P_WAIT, sh, sh, NULL); 702 pid = _spawnlp (_P_WAIT, sh, sh, NULL);
651 if (pid == -1) 703 if (pid == NULL)
652 write (1, "Can't execute subshell", 22); 704 write (1, "Can't execute subshell", 22);
653 705
654 #else /* not WINDOWSNT */ 706 #else /* not WINDOWSNT */
655 execlp (sh, sh, 0); 707 execlp (sh, sh, 0);
656 write (1, "Can't execute subshell", 22); 708 write (1, "Can't execute subshell", 22);
730 /* Figure out the eof character for the FD. */ 782 /* Figure out the eof character for the FD. */
731 783
732 Bufbyte 784 Bufbyte
733 get_eof_char (int fd) 785 get_eof_char (int fd)
734 { 786 {
735 CONST Bufbyte ctrl_d = (Bufbyte) '\004'; 787 const Bufbyte ctrl_d = (Bufbyte) '\004';
736 788
737 if (!isatty (fd)) 789 if (!isatty (fd))
738 return ctrl_d; 790 return ctrl_d;
739 #ifdef HAVE_TERMIOS 791 #ifdef HAVE_TERMIOS
740 { 792 {
741 struct termios t; 793 struct termios t;
742 tcgetattr (fd, &t); 794 tcgetattr (fd, &t);
743 #if 0 795 #if 0
744 /* What is the following line designed to do??? -mrb */ 796 /* What is the following line designed to do??? -mrb */
745 if (strlen ((CONST char *) t.c_cc) < (unsigned int) (VEOF + 1)) 797 if (strlen ((const char *) t.c_cc) < (unsigned int) (VEOF + 1))
746 return ctrl_d; 798 return ctrl_d;
747 else 799 else
748 return (Bufbyte) t.c_cc[VEOF]; 800 return (Bufbyte) t.c_cc[VEOF];
749 #endif 801 #endif
750 return t.c_cc[VEOF] == _POSIX_VDISABLE ? ctrl_d : (Bufbyte) t.c_cc[VEOF]; 802 return t.c_cc[VEOF] == _POSIX_VDISABLE ? ctrl_d : (Bufbyte) t.c_cc[VEOF];
763 characters. */ 815 characters. */
764 #ifdef TCGETA 816 #ifdef TCGETA
765 { 817 {
766 struct termio t; 818 struct termio t;
767 ioctl (fd, TCGETA, &t); 819 ioctl (fd, TCGETA, &t);
768 if (strlen ((CONST char *) t.c_cc) < (unsigned int) (VINTR + 1)) 820 if (strlen ((const char *) t.c_cc) < (unsigned int) (VINTR + 1))
769 return ctrl_d; 821 return ctrl_d;
770 else 822 else
771 return (Bufbyte) t.c_cc[VINTR]; 823 return (Bufbyte) t.c_cc[VINTR];
772 } 824 }
773 #else /* ! defined (TCGETA) */ 825 #else /* ! defined (TCGETA) */
1013 static void 1065 static void
1014 request_sigio_on_device (struct device *d) 1066 request_sigio_on_device (struct device *d)
1015 { 1067 {
1016 int filedesc = DEVICE_INFD (d); 1068 int filedesc = DEVICE_INFD (d);
1017 1069
1018 #if defined (I_SETSIG) && !defined(HPUX10) 1070 #if defined (I_SETSIG) && !defined(HPUX10) && !defined(LINUX)
1019 { 1071 {
1020 int events=0; 1072 int events=0;
1021 ioctl (filedesc, I_GETSIG, &events); 1073 ioctl (filedesc, I_GETSIG, &events);
1022 ioctl (filedesc, I_SETSIG, events | S_INPUT); 1074 ioctl (filedesc, I_SETSIG, events | S_INPUT);
1023 } 1075 }
1367 return 0; 1419 return 0;
1368 } 1420 }
1369 1421
1370 /* Set the parameters of the tty on FD according to the contents of 1422 /* Set the parameters of the tty on FD according to the contents of
1371 *SETTINGS. If FLUSHP is non-zero, we discard input. 1423 *SETTINGS. If FLUSHP is non-zero, we discard input.
1372 Return 0 if all went well, and -1 if anything failed. */ 1424 Return 0 if all went well, and -1 if anything failed.
1425 #### All current callers use FLUSHP == 0. */
1373 1426
1374 int 1427 int
1375 emacs_set_tty (int fd, struct emacs_tty *settings, int flushp) 1428 emacs_set_tty (int fd, struct emacs_tty *settings, int flushp)
1376 { 1429 {
1377 /* Set the primary parameters - baud rate, character size, etcetera. */ 1430 /* Set the primary parameters - baud rate, character size, etcetera. */
1477 struct console *con = XCONSOLE (DEVICE_CONSOLE (d)); 1530 struct console *con = XCONSOLE (DEVICE_CONSOLE (d));
1478 1531
1479 input_fd = CONSOLE_TTY_DATA (con)->infd; 1532 input_fd = CONSOLE_TTY_DATA (con)->infd;
1480 output_fd = CONSOLE_TTY_DATA (con)->outfd; 1533 output_fd = CONSOLE_TTY_DATA (con)->outfd;
1481 1534
1482 EMACS_GET_TTY (input_fd, &CONSOLE_TTY_DATA (con)->old_tty); 1535 emacs_get_tty (input_fd, &CONSOLE_TTY_DATA (con)->old_tty);
1483 tty = CONSOLE_TTY_DATA (con)->old_tty; 1536 tty = CONSOLE_TTY_DATA (con)->old_tty;
1484 1537
1485 con->tty_erase_char = Qnil; 1538 con->tty_erase_char = Qnil;
1486 1539
1487 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS) 1540 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
1644 1697
1645 #ifdef HAVE_LTCHARS 1698 #ifdef HAVE_LTCHARS
1646 tty.ltchars = new_ltchars; 1699 tty.ltchars = new_ltchars;
1647 #endif /* HAVE_LTCHARS */ 1700 #endif /* HAVE_LTCHARS */
1648 1701
1649 EMACS_SET_TTY (input_fd, &tty, 0); 1702 emacs_set_tty (input_fd, &tty, 0);
1650 1703
1651 /* This code added to insure that, if flow-control is not to be used, 1704 /* This code added to insure that, if flow-control is not to be used,
1652 we have an unlocked terminal at the start. */ 1705 we have an unlocked terminal at the start. */
1653 1706
1654 #ifdef TCXONC 1707 #ifdef TCXONC
1655 if (!TTY_FLAGS (con).flow_control) ioctl (input_fd, TCXONC, 1); 1708 if (!TTY_FLAGS (con).flow_control) ioctl (input_fd, TCXONC, 1);
1656 #endif 1709 #endif
1657 #ifndef APOLLO
1658 #ifdef TIOCSTART 1710 #ifdef TIOCSTART
1659 if (!TTY_FLAGS (con).flow_control) ioctl (input_fd, TIOCSTART, 0); 1711 if (!TTY_FLAGS (con).flow_control) ioctl (input_fd, TIOCSTART, 0);
1660 #endif
1661 #endif 1712 #endif
1662 1713
1663 #if defined (HAVE_TERMIOS) || defined (HPUX9) 1714 #if defined (HAVE_TERMIOS) || defined (HPUX9)
1664 #ifdef TCOON 1715 #ifdef TCOON
1665 if (!TTY_FLAGS (con).flow_control) tcflow (input_fd, TCOON); 1716 if (!TTY_FLAGS (con).flow_control) tcflow (input_fd, TCOON);
1751 #ifdef HAVE_TTY 1802 #ifdef HAVE_TTY
1752 if (DEVICE_TTY_P (d)) 1803 if (DEVICE_TTY_P (d))
1753 { 1804 {
1754 struct emacs_tty tty; 1805 struct emacs_tty tty;
1755 1806
1756 EMACS_GET_TTY (DEVICE_INFD (d), &tty); 1807 emacs_get_tty (DEVICE_INFD (d), &tty);
1757 return EMACS_TTY_TABS_OK (&tty); 1808 return EMACS_TTY_TABS_OK (&tty);
1758 } 1809 }
1759 #endif 1810 #endif
1760 return 1; 1811 return 1;
1761 } 1812 }
1824 int eight_bit = 0; 1875 int eight_bit = 0;
1825 1876
1826 assert (DEVICE_TTY_P (d)); 1877 assert (DEVICE_TTY_P (d));
1827 input_fd = DEVICE_INFD (d); 1878 input_fd = DEVICE_INFD (d);
1828 1879
1829 EMACS_GET_TTY (input_fd, &s); 1880 emacs_get_tty (input_fd, &s);
1830 1881
1831 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS) 1882 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
1832 eight_bit = (s.main.c_cflag & CSIZE) == CS8; 1883 eight_bit = (s.main.c_cflag & CSIZE) == CS8;
1833 #else 1884 #else
1834 eight_bit = 0; /* I don't know how to do it */ 1885 eight_bit = 0; /* I don't know how to do it */
1874 #if defined (BSD) 1925 #if defined (BSD)
1875 /* Avoid possible loss of output when changing terminal modes. */ 1926 /* Avoid possible loss of output when changing terminal modes. */
1876 fsync (output_fd); 1927 fsync (output_fd);
1877 #endif 1928 #endif
1878 1929
1879 while (EMACS_SET_TTY (input_fd, &CONSOLE_TTY_DATA (con)->old_tty, 0) 1930 while (emacs_set_tty (input_fd, &CONSOLE_TTY_DATA (con)->old_tty, 0)
1880 < 0 && errno == EINTR) 1931 < 0 && errno == EINTR)
1881 ; 1932 ;
1882 1933
1883 #ifdef SET_LINE_DISCIPLINE 1934 #ifdef SET_LINE_DISCIPLINE
1884 /* Ultrix's termios *ignores* any line discipline except TERMIODISC. 1935 /* Ultrix's termios *ignores* any line discipline except TERMIODISC.
2068 2119
2069 /************************************************************************/ 2120 /************************************************************************/
2070 /* limits of text/data segments */ 2121 /* limits of text/data segments */
2071 /************************************************************************/ 2122 /************************************************************************/
2072 2123
2073 #ifndef CANNOT_DUMP 2124 #if !defined(CANNOT_DUMP) && !defined(PDUMP)
2074 #define NEED_STARTS 2125 #define NEED_STARTS
2075 #endif 2126 #endif
2076 2127
2077 #ifndef SYSTEM_MALLOC 2128 #ifndef SYSTEM_MALLOC
2078 #ifndef NEED_STARTS 2129 #ifndef NEED_STARTS
2088 * doing an unexec. After unexec the return value is undefined. 2139 * doing an unexec. After unexec the return value is undefined.
2089 * See crt0.c for further explanation and _start. 2140 * See crt0.c for further explanation and _start.
2090 * 2141 *
2091 */ 2142 */
2092 2143
2144 #if !defined(HAVE_TEXT_START) && !defined(PDUMP)
2145
2093 #ifdef __cplusplus 2146 #ifdef __cplusplus
2094 extern "C" int _start (); 2147 extern "C" int _start (void);
2095 #else 2148 #else
2096 extern int _start (); 2149 extern int _start (void);
2097 #endif 2150 #endif
2098 2151
2099 #ifndef HAVE_TEXT_START
2100 char * 2152 char *
2101 start_of_text (void) 2153 start_of_text (void)
2102 { 2154 {
2103 #ifdef TEXT_START 2155 #ifdef TEXT_START
2104 return ((char *) TEXT_START); 2156 return ((char *) TEXT_START);
2109 #else /* not GOULD */ 2161 #else /* not GOULD */
2110 return ((char *) _start); 2162 return ((char *) _start);
2111 #endif /* GOULD */ 2163 #endif /* GOULD */
2112 #endif /* TEXT_START */ 2164 #endif /* TEXT_START */
2113 } 2165 }
2114 #endif /* not HAVE_TEXT_START */ 2166 #endif /* !defined(HAVE_TEXT_START) && !defined(PDUMP) */
2115 2167
2116 /* 2168 /*
2117 * Return the address of the start of the data segment prior to 2169 * Return the address of the start of the data segment prior to
2118 * doing an unexec. After unexec the return value is undefined. 2170 * doing an unexec. After unexec the return value is undefined.
2119 * See crt0.c for further information and definition of data_start. 2171 * See crt0.c for further information and definition of data_start.
2168 #endif /* ORDINARY_LINK */ 2220 #endif /* ORDINARY_LINK */
2169 #endif /* DATA_START */ 2221 #endif /* DATA_START */
2170 } 2222 }
2171 #endif /* NEED_STARTS (not CANNOT_DUMP or not SYSTEM_MALLOC) */ 2223 #endif /* NEED_STARTS (not CANNOT_DUMP or not SYSTEM_MALLOC) */
2172 2224
2173 #ifndef CANNOT_DUMP 2225 #if !defined(CANNOT_DUMP) && !defined(PDUMP)
2174 /* Some systems that cannot dump also cannot implement these. */ 2226 /* Some systems that cannot dump also cannot implement these. */
2175 2227
2176 /* 2228 /*
2177 * Return the address of the end of the text segment prior to 2229 * Return the address of the end of the text segment prior to
2178 * doing an unexec. After unexec the return value is undefined. 2230 * doing an unexec. After unexec the return value is undefined.
2203 extern int edata; 2255 extern int edata;
2204 return ((char *) &edata); 2256 return ((char *) &edata);
2205 #endif 2257 #endif
2206 } 2258 }
2207 2259
2208 #endif /* not CANNOT_DUMP */ 2260 #endif /* !defined(CANNOT_DUMP) && !defined(PDUMP) */
2209 2261
2210 2262
2211 /************************************************************************/ 2263 /************************************************************************/
2212 /* get the system name */ 2264 /* get the system name */
2213 /************************************************************************/ 2265 /************************************************************************/
2225 void 2277 void
2226 init_system_name (void) 2278 init_system_name (void)
2227 { 2279 {
2228 #if defined (WINDOWSNT) 2280 #if defined (WINDOWSNT)
2229 char hostname [MAX_COMPUTERNAME_LENGTH + 1]; 2281 char hostname [MAX_COMPUTERNAME_LENGTH + 1];
2230 size_t size = sizeof(hostname); 2282 size_t size = sizeof (hostname);
2231 GetComputerName (hostname, &size); 2283 GetComputerName (hostname, &size);
2232 Vsystem_name = build_string (hostname); 2284 Vsystem_name = build_string (hostname);
2233 #elif !defined (HAVE_GETHOSTNAME) 2285 #elif !defined (HAVE_GETHOSTNAME)
2234 struct utsname uts; 2286 struct utsname uts;
2235 uname (&uts); 2287 uname (&uts);
2259 Don't do this if we're going to dump; this can confuse system 2311 Don't do this if we're going to dump; this can confuse system
2260 libraries on some machines and make the dumped emacs core dump. */ 2312 libraries on some machines and make the dumped emacs core dump. */
2261 # ifndef CANNOT_DUMP 2313 # ifndef CANNOT_DUMP
2262 if (initialized) 2314 if (initialized)
2263 # endif /* not CANNOT_DUMP */ 2315 # endif /* not CANNOT_DUMP */
2264 { 2316 if (!strchr (hostname, '.'))
2265 struct hostent *hp = NULL; 2317 {
2266 int count; 2318 # if !(defined(HAVE_GETADDRINFO) && defined(HAVE_GETNAMEINFO))
2267 # ifdef TRY_AGAIN 2319 struct hostent *hp = NULL;
2268 for (count = 0; count < 10; count++) 2320 int count;
2269 { 2321 # ifdef TRY_AGAIN
2270 h_errno = 0; 2322 for (count = 0; count < 10; count++)
2271 # endif 2323 {
2272 /* Some systems can't handle SIGALARM/SIGIO in gethostbyname(). */ 2324 h_errno = 0;
2273 stop_interrupts (); 2325 # endif
2274 hp = gethostbyname (hostname); 2326 /* Some systems can't handle SIGALARM/SIGIO in gethostbyname(). */
2275 start_interrupts (); 2327 stop_interrupts ();
2276 # ifdef TRY_AGAIN 2328 hp = gethostbyname (hostname);
2277 if (! (hp == 0 && h_errno == TRY_AGAIN)) 2329 start_interrupts ();
2278 break; 2330 # ifdef TRY_AGAIN
2279 Fsleep_for (make_int (1)); 2331 if (! (hp == 0 && h_errno == TRY_AGAIN))
2280 } 2332 break;
2281 # endif 2333 Fsleep_for (make_int (1));
2282 if (hp) 2334 }
2283 { 2335 # endif
2284 CONST char *fqdn = (CONST char *) hp->h_name; 2336 if (hp)
2285 2337 {
2286 if (!strchr (fqdn, '.')) 2338 const char *fqdn = (const char *) hp->h_name;
2287 { 2339
2288 /* We still don't have a fully qualified domain name. 2340 if (!strchr (fqdn, '.'))
2289 Try to find one in the list of alternate names */ 2341 {
2290 char **alias = hp->h_aliases; 2342 /* We still don't have a fully qualified domain name.
2291 while (*alias && !strchr (*alias, '.')) 2343 Try to find one in the list of alternate names */
2292 alias++; 2344 char **alias = hp->h_aliases;
2293 if (*alias) 2345 while (*alias && !strchr (*alias, '.'))
2294 fqdn = *alias; 2346 alias++;
2295 } 2347 if (*alias)
2296 hostname = (char *) alloca (strlen (fqdn) + 1); 2348 fqdn = *alias;
2297 strcpy (hostname, fqdn); 2349 }
2298 } 2350 hostname = (char *) alloca (strlen (fqdn) + 1);
2299 } 2351 strcpy (hostname, fqdn);
2352 }
2353 # else /* !(HAVE_GETADDRINFO && HAVE_GETNAMEINFO) */
2354 struct addrinfo hints, *res;
2355
2356 xzero (hints);
2357 hints.ai_flags = AI_CANONNAME;
2358 hints.ai_family = AF_UNSPEC;
2359 hints.ai_socktype = SOCK_STREAM;
2360 hints.ai_protocol = 0;
2361 if (!getaddrinfo (hostname, NULL, &hints, &res))
2362 {
2363 hostname = (char *) alloca (strlen (res->ai_canonname) + 1);
2364 strcpy (hostname, res->ai_canonname);
2365
2366 freeaddrinfo (res);
2367 }
2368 # endif /* !(HAVE_GETADDRINFO && HAVE_GETNAMEINFO) */
2369 }
2300 # endif /* HAVE_SOCKETS */ 2370 # endif /* HAVE_SOCKETS */
2301 Vsystem_name = build_string (hostname); 2371 Vsystem_name = build_string (hostname);
2302 #endif /* HAVE_GETHOSTNAME */ 2372 #endif /* HAVE_GETHOSTNAME */
2303 { 2373 {
2304 Bufbyte *p; 2374 Bufbyte *p;
2423 2493
2424 #if !defined(NeXT) && !defined(__alpha) && !defined(MACH) && !defined(LINUX) && !defined(IRIX) && !defined(__NetBSD__) 2494 #if !defined(NeXT) && !defined(__alpha) && !defined(MACH) && !defined(LINUX) && !defined(IRIX) && !defined(__NetBSD__)
2425 /* Linux added here by Raymond L. Toy <toy@alydar.crd.ge.com> for XEmacs. */ 2495 /* Linux added here by Raymond L. Toy <toy@alydar.crd.ge.com> for XEmacs. */
2426 /* Irix added here by gparker@sni-usa.com for XEmacs. */ 2496 /* Irix added here by gparker@sni-usa.com for XEmacs. */
2427 /* NetBSD added here by James R Grinter <jrg@doc.ic.ac.uk> for XEmacs */ 2497 /* NetBSD added here by James R Grinter <jrg@doc.ic.ac.uk> for XEmacs */
2428 extern CONST char *sys_errlist[]; 2498 extern const char *sys_errlist[];
2429 extern int sys_nerr; 2499 extern int sys_nerr;
2430 #endif 2500 #endif
2431 2501
2432 #ifdef __NetBSD__ 2502 #ifdef __NetBSD__
2433 extern char *sys_errlist[]; 2503 extern char *sys_errlist[];
2434 extern int sys_nerr; 2504 extern int sys_nerr;
2435 #endif 2505 #endif
2436 2506
2437 2507
2438 CONST char * 2508 const char *
2439 strerror (int errnum) 2509 strerror (int errnum)
2440 { 2510 {
2441 if (errnum >= 0 && errnum < sys_nerr) 2511 if (errnum >= 0 && errnum < sys_nerr)
2442 return sys_errlist[errnum]; 2512 return sys_errlist[errnum];
2443 return ((CONST char *) GETTEXT ("Unknown error")); 2513 return ((const char *) GETTEXT ("Unknown error"));
2444 } 2514 }
2445 2515
2446 #endif /* ! HAVE_STRERROR */ 2516 #endif /* ! HAVE_STRERROR */
2447 2517
2448 #ifdef WINDOWSNT 2518 #ifdef WINDOWSNT
2514 mswindows_set_errno (unsigned long win32_error) 2584 mswindows_set_errno (unsigned long win32_error)
2515 { 2585 {
2516 int i; 2586 int i;
2517 2587
2518 /* check the table for the OS error code */ 2588 /* check the table for the OS error code */
2519 for (i = 0; i < sizeof(errtable)/sizeof(errtable[0]); ++i) 2589 for (i = 0; i < countof (errtable); ++i)
2520 { 2590 {
2521 if (win32_error == errtable[i].oscode) 2591 if (win32_error == errtable[i].oscode)
2522 { 2592 {
2523 errno = errtable[i].errnocode; 2593 errno = errtable[i].errnocode;
2524 return; 2594 return;
2548 /************************************************************************/ 2618 /************************************************************************/
2549 /* Encapsulations of system calls */ 2619 /* Encapsulations of system calls */
2550 /************************************************************************/ 2620 /************************************************************************/
2551 2621
2552 #define PATHNAME_CONVERT_OUT(path) \ 2622 #define PATHNAME_CONVERT_OUT(path) \
2553 GET_C_CHARPTR_EXT_FILENAME_DATA_ALLOCA ((CONST Bufbyte *) path, path) 2623 TO_EXTERNAL_FORMAT (C_STRING, (path), C_STRING_ALLOCA, (path), Qfile_name);
2554 2624
2555 /***************** low-level calls ****************/ 2625 /***************** low-level calls ****************/
2556 2626
2557 /* 2627 /*
2558 * On USG systems the system calls are INTERRUPTIBLE by signals 2628 * On USG systems the system calls are INTERRUPTIBLE by signals
2567 * always negligible. Fred Fish, Unisoft Systems Inc. 2637 * always negligible. Fred Fish, Unisoft Systems Inc.
2568 */ 2638 */
2569 2639
2570 /* Ben sez: read Dick Gabriel's essay about the Worse Is Better 2640 /* Ben sez: read Dick Gabriel's essay about the Worse Is Better
2571 approach to programming and its connection to the silly 2641 approach to programming and its connection to the silly
2572 interruptible-system-call business. To find it, look at 2642 interruptible-system-call business. To find it, look on
2573 Jamie's home page (http://www.netscape.com/people/jwz). */ 2643 Jamie's home page (http://www.jwz.org/worse-is-better.html). */
2574 2644
2575 #ifdef ENCAPSULATE_OPEN 2645 #ifdef ENCAPSULATE_OPEN
2576 int 2646 int
2577 sys_open (CONST char *path, int oflag, ...) 2647 sys_open (const char *path, int oflag, ...)
2578 { 2648 {
2579 int mode; 2649 int mode;
2580 va_list ap; 2650 va_list ap;
2581 2651
2582 va_start (ap, oflag); 2652 va_start (ap, oflag);
2583 mode = va_arg (ap, int); 2653 mode = va_arg (ap, int);
2584 va_end (ap); 2654 va_end (ap);
2585 2655
2586 PATHNAME_CONVERT_OUT (path); 2656 #ifdef WINDOWSNT
2587 #if defined (WINDOWSNT)
2588 /* Make all handles non-inheritable */ 2657 /* Make all handles non-inheritable */
2589 return open (path, oflag | _O_NOINHERIT, mode); 2658 oflag |= _O_NOINHERIT;
2590 #elif defined (INTERRUPTIBLE_OPEN) 2659 #endif
2660
2661 #ifdef INTERRUPTIBLE_OPEN
2591 { 2662 {
2592 int rtnval; 2663 int rtnval;
2593 while ((rtnval = open (path, oflag, mode)) == -1 2664 while ((rtnval = open (path, oflag, mode)) == -1
2594 && (errno == EINTR)) 2665 && (errno == EINTR))
2595 DO_NOTHING; 2666 DO_NOTHING;
2608 2679
2609 This function will not function as expected on systems where open() 2680 This function will not function as expected on systems where open()
2610 is not interrupted by C-g. However, the worst that can happen is 2681 is not interrupted by C-g. However, the worst that can happen is
2611 the fallback to simple open(). */ 2682 the fallback to simple open(). */
2612 int 2683 int
2613 interruptible_open (CONST char *path, int oflag, int mode) 2684 interruptible_open (const char *path, int oflag, int mode)
2614 { 2685 {
2615 /* This function can GC */ 2686 /* This function can GC */
2616 size_t len = strlen (path); 2687 size_t len = strlen (path);
2617 char *nonreloc = (char *) alloca (len + 1); 2688 char *nonreloc = (char *) alloca (len + 1);
2618 2689
2619 /* Must copy PATH, because it might be the data of a Lisp_String, 2690 /* Must copy PATH, because it might be the data of a Lisp_String,
2620 which could be relocated by GC when checking for QUIT. */ 2691 which could be relocated by GC when checking for QUIT. */
2621 memcpy (nonreloc, path, len + 1); 2692 memcpy (nonreloc, path, len + 1);
2622 2693
2623 PATHNAME_CONVERT_OUT (nonreloc); 2694 PATHNAME_CONVERT_OUT (nonreloc);
2695
2696 #ifdef WINDOWSNT
2697 /* Make all handles non-inheritable */
2698 oflag |= _O_NOINHERIT;
2699 #endif
2624 2700
2625 for (;;) 2701 for (;;)
2626 { 2702 {
2627 int rtnval = open (nonreloc, oflag, mode); 2703 int rtnval = open (nonreloc, oflag, mode);
2628 if (!(rtnval == -1 && errno == EINTR)) 2704 if (!(rtnval == -1 && errno == EINTR))
2632 } 2708 }
2633 } 2709 }
2634 2710
2635 #ifdef ENCAPSULATE_CLOSE 2711 #ifdef ENCAPSULATE_CLOSE
2636 int 2712 int
2637 sys_close (int fd) 2713 sys_close (int filedes)
2638 { 2714 {
2639 #ifdef INTERRUPTIBLE_CLOSE 2715 #ifdef INTERRUPTIBLE_CLOSE
2640 int did_retry = 0; 2716 int did_retry = 0;
2641 REGISTER int rtnval; 2717 REGISTER int rtnval;
2642 2718
2643 while ((rtnval = close (fd)) == -1 2719 while ((rtnval = close (filedes)) == -1
2644 && (errno == EINTR)) 2720 && (errno == EINTR))
2645 did_retry = 1; 2721 did_retry = 1;
2646 2722
2647 /* If close is interrupted SunOS 4.1 may or may not have closed the 2723 /* If close is interrupted SunOS 4.1 may or may not have closed the
2648 file descriptor. If it did the second close will fail with 2724 file descriptor. If it did the second close will fail with
2650 if (rtnval == -1 && did_retry && errno == EBADF) 2726 if (rtnval == -1 && did_retry && errno == EBADF)
2651 return 0; 2727 return 0;
2652 2728
2653 return rtnval; 2729 return rtnval;
2654 #else 2730 #else
2655 return close (fd); 2731 return close (filedes);
2656 #endif 2732 #endif
2657 } 2733 }
2658 #endif /* ENCAPSULATE_CLOSE */ 2734 #endif /* ENCAPSULATE_CLOSE */
2659 2735
2660 int 2736 ssize_t
2661 sys_read_1 (int fildes, void *buf, size_t nbyte, int allow_quit) 2737 sys_read_1 (int fildes, void *buf, size_t nbyte, int allow_quit)
2662 { 2738 {
2663 int rtnval; 2739 ssize_t rtnval;
2664 2740
2665 /* No harm in looping regardless of the INTERRUPTIBLE_IO setting. */ 2741 /* No harm in looping regardless of the INTERRUPTIBLE_IO setting. */
2666 while ((rtnval = read (fildes, buf, nbyte)) == -1 2742 while ((rtnval = read (fildes, buf, nbyte)) == -1
2667 && (errno == EINTR)) 2743 && (errno == EINTR))
2668 { 2744 {
2671 } 2747 }
2672 return rtnval; 2748 return rtnval;
2673 } 2749 }
2674 2750
2675 #ifdef ENCAPSULATE_READ 2751 #ifdef ENCAPSULATE_READ
2676 int 2752 ssize_t
2677 sys_read (int fildes, void *buf, size_t nbyte) 2753 sys_read (int fildes, void *buf, size_t nbyte)
2678 { 2754 {
2679 return sys_read_1 (fildes, buf, nbyte, 0); 2755 return sys_read_1 (fildes, buf, nbyte, 0);
2680 } 2756 }
2681 #endif /* ENCAPSULATE_READ */ 2757 #endif /* ENCAPSULATE_READ */
2682 2758
2683 int 2759 ssize_t
2684 sys_write_1 (int fildes, CONST void *buf, size_t nbyte, int allow_quit) 2760 sys_write_1 (int fildes, const void *buf, size_t nbyte, int allow_quit)
2685 { 2761 {
2686 int rtnval; 2762 ssize_t bytes_written = 0;
2687 int bytes_written = 0; 2763 const char *b = (const char *) buf;
2688 CONST char *b = (CONST char *) buf;
2689 2764
2690 /* No harm in looping regardless of the INTERRUPTIBLE_IO setting. */ 2765 /* No harm in looping regardless of the INTERRUPTIBLE_IO setting. */
2691 while (nbyte > 0) 2766 while (nbyte > 0)
2692 { 2767 {
2693 rtnval = write (fildes, b, nbyte); 2768 ssize_t rtnval = write (fildes, b, nbyte);
2694 2769
2695 if (allow_quit) 2770 if (allow_quit)
2696 REALLY_QUIT; 2771 REALLY_QUIT;
2697 2772
2698 if (rtnval == -1) 2773 if (rtnval == -1)
2699 { 2774 {
2700 if (errno == EINTR) 2775 if (errno == EINTR)
2701 continue; 2776 continue;
2702 else 2777 else
2703 return (bytes_written ? bytes_written : -1); 2778 return bytes_written ? bytes_written : -1;
2704 } 2779 }
2705 b += rtnval; 2780 b += rtnval;
2706 nbyte -= rtnval; 2781 nbyte -= rtnval;
2707 bytes_written += rtnval; 2782 bytes_written += rtnval;
2708 } 2783 }
2709 return (bytes_written); 2784 return bytes_written;
2710 } 2785 }
2711 2786
2712 #ifdef ENCAPSULATE_WRITE 2787 #ifdef ENCAPSULATE_WRITE
2713 int 2788 ssize_t
2714 sys_write (int fildes, CONST void *buf, size_t nbyte) 2789 sys_write (int fildes, const void *buf, size_t nbyte)
2715 { 2790 {
2716 return sys_write_1 (fildes, buf, nbyte, 0); 2791 return sys_write_1 (fildes, buf, nbyte, 0);
2717 } 2792 }
2718 #endif /* ENCAPSULATE_WRITE */ 2793 #endif /* ENCAPSULATE_WRITE */
2719 2794
2727 /* #### Should also encapsulate fflush(). 2802 /* #### Should also encapsulate fflush().
2728 #### Should conceivably encapsulate getchar() etc. What a pain! */ 2803 #### Should conceivably encapsulate getchar() etc. What a pain! */
2729 2804
2730 #ifdef ENCAPSULATE_FOPEN 2805 #ifdef ENCAPSULATE_FOPEN
2731 FILE * 2806 FILE *
2732 sys_fopen (CONST char *path, CONST char *type) 2807 sys_fopen (const char *path, const char *type)
2733 { 2808 {
2734 PATHNAME_CONVERT_OUT (path); 2809 PATHNAME_CONVERT_OUT (path);
2735 #if defined (WINDOWSNT) 2810 #if defined (WINDOWSNT)
2736 { 2811 {
2737 int fd; 2812 int fd;
2837 #endif /* ENCAPSULATE_FREAD */ 2912 #endif /* ENCAPSULATE_FREAD */
2838 2913
2839 2914
2840 #ifdef ENCAPSULATE_FWRITE 2915 #ifdef ENCAPSULATE_FWRITE
2841 size_t 2916 size_t
2842 sys_fwrite (CONST void *ptr, size_t size, size_t nitem, FILE *stream) 2917 sys_fwrite (const void *ptr, size_t size, size_t nitem, FILE *stream)
2843 { 2918 {
2844 #ifdef INTERRUPTIBLE_IO 2919 #ifdef INTERRUPTIBLE_IO
2845 size_t rtnval; 2920 size_t rtnval;
2846 size_t items_written = 0; 2921 size_t items_written = 0;
2847 CONST char *b = (CONST char *) ptr; 2922 const char *b = (const char *) ptr;
2848 2923
2849 while (nitem > 0) 2924 while (nitem > 0)
2850 { 2925 {
2851 rtnval = fwrite (b, size, nitem, stream); 2926 rtnval = fwrite (b, size, nitem, stream);
2852 if (rtnval == 0) 2927 if (rtnval == 0)
2870 2945
2871 /********************* directory calls *******************/ 2946 /********************* directory calls *******************/
2872 2947
2873 #ifdef ENCAPSULATE_CHDIR 2948 #ifdef ENCAPSULATE_CHDIR
2874 int 2949 int
2875 sys_chdir (CONST char *path) 2950 sys_chdir (const char *path)
2876 { 2951 {
2877 PATHNAME_CONVERT_OUT (path); 2952 PATHNAME_CONVERT_OUT (path);
2878 return chdir (path); 2953 return chdir (path);
2879 } 2954 }
2880 #endif /* ENCAPSULATE_CHDIR */ 2955 #endif /* ENCAPSULATE_CHDIR */
2881 2956
2882 2957
2883 #ifdef ENCAPSULATE_MKDIR 2958 #ifdef ENCAPSULATE_MKDIR
2884 int 2959 int
2885 sys_mkdir (CONST char *path, mode_t mode) 2960 sys_mkdir (const char *path, mode_t mode)
2886 { 2961 {
2887 PATHNAME_CONVERT_OUT (path); 2962 PATHNAME_CONVERT_OUT (path);
2888 #ifdef WINDOWSNT 2963 #ifdef WINDOWSNT
2889 return mkdir (path); 2964 return mkdir (path);
2890 #else 2965 #else
2894 #endif /* ENCAPSULATE_MKDIR */ 2969 #endif /* ENCAPSULATE_MKDIR */
2895 2970
2896 2971
2897 #ifdef ENCAPSULATE_OPENDIR 2972 #ifdef ENCAPSULATE_OPENDIR
2898 DIR * 2973 DIR *
2899 sys_opendir (CONST char *filename) 2974 sys_opendir (const char *filename)
2900 { 2975 {
2901 DIR *rtnval; 2976 DIR *rtnval;
2902 PATHNAME_CONVERT_OUT (filename); 2977 PATHNAME_CONVERT_OUT (filename);
2903 2978
2904 while (!(rtnval = opendir (filename)) 2979 while (!(rtnval = opendir (filename))
2926 if (rtnval == NULL) /* End of directory */ 3001 if (rtnval == NULL) /* End of directory */
2927 return NULL; 3002 return NULL;
2928 { 3003 {
2929 Extcount external_len; 3004 Extcount external_len;
2930 int ascii_filename_p = 1; 3005 int ascii_filename_p = 1;
2931 CONST Extbyte * CONST external_name = (CONST Extbyte *) rtnval->d_name; 3006 const Extbyte * const external_name = (const Extbyte *) rtnval->d_name;
2932 3007
2933 /* Optimize for the common all-ASCII case, computing len en passant */ 3008 /* Optimize for the common all-ASCII case, computing len en passant */
2934 for (external_len = 0; external_name[external_len] ; external_len++) 3009 for (external_len = 0; external_name[external_len] ; external_len++)
2935 { 3010 {
2936 if (!BYTE_ASCII_P (external_name[external_len])) 3011 if (!BYTE_ASCII_P (external_name[external_len]))
2939 if (ascii_filename_p) 3014 if (ascii_filename_p)
2940 return rtnval; 3015 return rtnval;
2941 3016
2942 { /* Non-ASCII filename */ 3017 { /* Non-ASCII filename */
2943 static Bufbyte_dynarr *internal_DIRENTRY; 3018 static Bufbyte_dynarr *internal_DIRENTRY;
2944 CONST Bufbyte *internal_name; 3019 const Bufbyte *internal_name;
2945 Bytecount internal_len; 3020 Bytecount internal_len;
2946 if (!internal_DIRENTRY) 3021 if (!internal_DIRENTRY)
2947 internal_DIRENTRY = Dynarr_new (Bufbyte); 3022 internal_DIRENTRY = Dynarr_new (Bufbyte);
2948 else 3023 else
2949 Dynarr_reset (internal_DIRENTRY); 3024 Dynarr_reset (internal_DIRENTRY);
2950 3025
2951 Dynarr_add_many (internal_DIRENTRY, (Bufbyte *) rtnval, 3026 Dynarr_add_many (internal_DIRENTRY, (Bufbyte *) rtnval,
2952 offsetof (DIRENTRY, d_name)); 3027 offsetof (DIRENTRY, d_name));
2953 3028
2954 internal_name = 3029 TO_INTERNAL_FORMAT (DATA, (external_name, external_len),
2955 convert_from_external_format (external_name, external_len, 3030 ALLOCA, (internal_name, internal_len),
2956 &internal_len, FORMAT_FILENAME); 3031 Qfile_name);
2957 3032
2958 Dynarr_add_many (internal_DIRENTRY, internal_name, internal_len); 3033 Dynarr_add_many (internal_DIRENTRY, internal_name, internal_len);
2959 Dynarr_add (internal_DIRENTRY, 0); /* zero-terminate */ 3034 Dynarr_add (internal_DIRENTRY, 0); /* zero-terminate */
2960 return (DIRENTRY *) Dynarr_atp (internal_DIRENTRY, 0); 3035 return (DIRENTRY *) Dynarr_atp (internal_DIRENTRY, 0);
2961 } 3036 }
2979 #endif /* ENCAPSULATE_CLOSEDIR */ 3054 #endif /* ENCAPSULATE_CLOSEDIR */
2980 3055
2981 3056
2982 #ifdef ENCAPSULATE_RMDIR 3057 #ifdef ENCAPSULATE_RMDIR
2983 int 3058 int
2984 sys_rmdir (CONST char *path) 3059 sys_rmdir (const char *path)
2985 { 3060 {
2986 PATHNAME_CONVERT_OUT (path); 3061 PATHNAME_CONVERT_OUT (path);
2987 return rmdir (path); 3062 return rmdir (path);
2988 } 3063 }
2989 #endif /* ENCAPSULATE_RMDIR */ 3064 #endif /* ENCAPSULATE_RMDIR */
2991 3066
2992 /***************** file-information calls ******************/ 3067 /***************** file-information calls ******************/
2993 3068
2994 #ifdef ENCAPSULATE_ACCESS 3069 #ifdef ENCAPSULATE_ACCESS
2995 int 3070 int
2996 sys_access (CONST char *path, int mode) 3071 sys_access (const char *path, int mode)
2997 { 3072 {
2998 PATHNAME_CONVERT_OUT (path); 3073 PATHNAME_CONVERT_OUT (path);
2999 return access (path, mode); 3074 return access (path, mode);
3000 } 3075 }
3001 #endif /* ENCAPSULATE_ACCESS */ 3076 #endif /* ENCAPSULATE_ACCESS */
3002 3077
3003 3078
3004 #ifdef HAVE_EACCESS 3079 #ifdef HAVE_EACCESS
3005 #ifdef ENCAPSULATE_EACCESS 3080 #ifdef ENCAPSULATE_EACCESS
3006 int 3081 int
3007 sys_eaccess (CONST char *path, int mode) 3082 sys_eaccess (const char *path, int mode)
3008 { 3083 {
3009 PATHNAME_CONVERT_OUT (path); 3084 PATHNAME_CONVERT_OUT (path);
3010 return eaccess (path, mode); 3085 return eaccess (path, mode);
3011 } 3086 }
3012 #endif /* ENCAPSULATE_EACCESS */ 3087 #endif /* ENCAPSULATE_EACCESS */
3013 #endif /* HAVE_EACCESS */ 3088 #endif /* HAVE_EACCESS */
3014 3089
3015 3090
3016 #ifdef ENCAPSULATE_LSTAT 3091 #ifdef ENCAPSULATE_LSTAT
3017 int 3092 int
3018 sys_lstat (CONST char *path, struct stat *buf) 3093 sys_lstat (const char *path, struct stat *buf)
3019 { 3094 {
3020 PATHNAME_CONVERT_OUT (path); 3095 PATHNAME_CONVERT_OUT (path);
3021 return lstat (path, buf); 3096 return lstat (path, buf);
3022 } 3097 }
3023 #endif /* ENCAPSULATE_LSTAT */ 3098 #endif /* ENCAPSULATE_LSTAT */
3024 3099
3025 3100
3026 #ifdef ENCAPSULATE_READLINK 3101 #ifdef ENCAPSULATE_READLINK
3027 int 3102 int
3028 sys_readlink (CONST char *path, char *buf, size_t bufsiz) 3103 sys_readlink (const char *path, char *buf, size_t bufsiz)
3029 { 3104 {
3030 PATHNAME_CONVERT_OUT (path); 3105 PATHNAME_CONVERT_OUT (path);
3031 /* #### currently we don't do conversions on the incoming data */ 3106 /* #### currently we don't do conversions on the incoming data */
3032 return readlink (path, buf, bufsiz); 3107 return readlink (path, buf, bufsiz);
3033 } 3108 }
3034 #endif /* ENCAPSULATE_READLINK */ 3109 #endif /* ENCAPSULATE_READLINK */
3035 3110
3036 3111
3112 #ifdef ENCAPSULATE_FSTAT
3113 int
3114 sys_fstat (int fd, struct stat *buf)
3115 {
3116 return fstat (fd, buf);
3117 }
3118 #endif /* ENCAPSULATE_FSTAT */
3119
3120
3037 #ifdef ENCAPSULATE_STAT 3121 #ifdef ENCAPSULATE_STAT
3038 int 3122 int
3039 sys_stat (CONST char *path, struct stat *buf) 3123 sys_stat (const char *path, struct stat *buf)
3040 { 3124 {
3041 PATHNAME_CONVERT_OUT (path); 3125 PATHNAME_CONVERT_OUT (path);
3042 return stat (path, buf); 3126 return stat (path, buf);
3043 } 3127 }
3044 #endif /* ENCAPSULATE_STAT */ 3128 #endif /* ENCAPSULATE_STAT */
3046 3130
3047 /****************** file-manipulation calls *****************/ 3131 /****************** file-manipulation calls *****************/
3048 3132
3049 #ifdef ENCAPSULATE_CHMOD 3133 #ifdef ENCAPSULATE_CHMOD
3050 int 3134 int
3051 sys_chmod (CONST char *path, mode_t mode) 3135 sys_chmod (const char *path, mode_t mode)
3052 { 3136 {
3053 PATHNAME_CONVERT_OUT (path); 3137 PATHNAME_CONVERT_OUT (path);
3054 return chmod (path, mode); 3138 return chmod (path, mode);
3055 } 3139 }
3056 #endif /* ENCAPSULATE_CHMOD */ 3140 #endif /* ENCAPSULATE_CHMOD */
3057 3141
3058 3142
3059 #ifdef ENCAPSULATE_CREAT 3143 #ifdef ENCAPSULATE_CREAT
3060 int 3144 int
3061 sys_creat (CONST char *path, mode_t mode) 3145 sys_creat (const char *path, mode_t mode)
3062 { 3146 {
3063 PATHNAME_CONVERT_OUT (path); 3147 PATHNAME_CONVERT_OUT (path);
3064 return creat (path, mode); 3148 return creat (path, mode);
3065 } 3149 }
3066 #endif /* ENCAPSULATE_CREAT */ 3150 #endif /* ENCAPSULATE_CREAT */
3067 3151
3068 3152
3069 #ifdef ENCAPSULATE_LINK 3153 #ifdef ENCAPSULATE_LINK
3070 int 3154 int
3071 sys_link (CONST char *existing, CONST char *new) 3155 sys_link (const char *existing, const char *new)
3072 { 3156 {
3073 PATHNAME_CONVERT_OUT (existing); 3157 PATHNAME_CONVERT_OUT (existing);
3074 PATHNAME_CONVERT_OUT (new); 3158 PATHNAME_CONVERT_OUT (new);
3075 return link (existing, new); 3159 return link (existing, new);
3076 } 3160 }
3077 #endif /* ENCAPSULATE_LINK */ 3161 #endif /* ENCAPSULATE_LINK */
3078 3162
3079 3163
3080 #ifdef ENCAPSULATE_RENAME 3164 #ifdef ENCAPSULATE_RENAME
3081 int 3165 int
3082 sys_rename (CONST char *old, CONST char *new) 3166 sys_rename (const char *old, const char *new)
3083 { 3167 {
3084 PATHNAME_CONVERT_OUT (old); 3168 PATHNAME_CONVERT_OUT (old);
3085 PATHNAME_CONVERT_OUT (new); 3169 PATHNAME_CONVERT_OUT (new);
3086 #ifdef WINDOWSNT 3170 #ifdef WINDOWSNT
3087 /* Windows rename fails if NEW exists */ 3171 /* Windows rename fails if NEW exists */
3096 #endif /* ENCAPSULATE_RENAME */ 3180 #endif /* ENCAPSULATE_RENAME */
3097 3181
3098 3182
3099 #ifdef ENCAPSULATE_SYMLINK 3183 #ifdef ENCAPSULATE_SYMLINK
3100 int 3184 int
3101 sys_symlink (CONST char *name1, CONST char *name2) 3185 sys_symlink (const char *name1, const char *name2)
3102 { 3186 {
3103 PATHNAME_CONVERT_OUT (name1); 3187 PATHNAME_CONVERT_OUT (name1);
3104 PATHNAME_CONVERT_OUT (name2); 3188 PATHNAME_CONVERT_OUT (name2);
3105 return symlink (name1, name2); 3189 return symlink (name1, name2);
3106 } 3190 }
3107 #endif /* ENCAPSULATE_SYMLINK */ 3191 #endif /* ENCAPSULATE_SYMLINK */
3108 3192
3109 3193
3110 #ifdef ENCAPSULATE_UNLINK 3194 #ifdef ENCAPSULATE_UNLINK
3111 int 3195 int
3112 sys_unlink (CONST char *path) 3196 sys_unlink (const char *path)
3113 { 3197 {
3114 PATHNAME_CONVERT_OUT (path); 3198 PATHNAME_CONVERT_OUT (path);
3115 return unlink (path); 3199 return unlink (path);
3116 } 3200 }
3117 #endif /* ENCAPSULATE_UNLINK */ 3201 #endif /* ENCAPSULATE_UNLINK */
3118 3202
3119 3203
3120 #ifdef ENCAPSULATE_EXECVP 3204 #ifdef ENCAPSULATE_EXECVP
3121 int 3205 int
3122 sys_execvp (CONST char *path, char * CONST * argv) 3206 sys_execvp (const char *path, char * const * argv)
3123 { 3207 {
3124 int i, argc; 3208 int i, argc;
3125 char ** new_argv; 3209 char ** new_argv;
3126 3210
3127 PATHNAME_CONVERT_OUT (path); 3211 PATHNAME_CONVERT_OUT (path);
3145 3229
3146 /***** (these are primarily required for USG, it seems) *****/ 3230 /***** (these are primarily required for USG, it seems) *****/
3147 3231
3148 #ifndef HAVE_GETCWD 3232 #ifndef HAVE_GETCWD
3149 char * 3233 char *
3150 getcwd (char *pathname, int size) 3234 getcwd (char *pathname, size_t size)
3151 { 3235 {
3152 return getwd (pathname); 3236 return getwd (pathname);
3153 } 3237 }
3154 #endif /* emulate getcwd */ 3238 #endif /* emulate getcwd */
3155 3239
3189 * that files be of same type (regular->regular, dir->dir, etc). 3273 * that files be of same type (regular->regular, dir->dir, etc).
3190 */ 3274 */
3191 3275
3192 #ifndef HAVE_RENAME 3276 #ifndef HAVE_RENAME
3193 int 3277 int
3194 rename (CONST char *from, CONST char *to) 3278 rename (const char *from, const char *to)
3195 { 3279 {
3196 if (access (from, 0) == 0) 3280 if (access (from, 0) == 0)
3197 { 3281 {
3198 unlink (to); 3282 unlink (to);
3199 if (link (from, to) == 0) 3283 if (link (from, to) == 0)
3446 /************************************************************************/ 3530 /************************************************************************/
3447 3531
3448 #if !defined (SYS_SIGLIST_DECLARED) && !defined (HAVE_SYS_SIGLIST) 3532 #if !defined (SYS_SIGLIST_DECLARED) && !defined (HAVE_SYS_SIGLIST)
3449 3533
3450 #if defined(WINDOWSNT) || defined(__CYGWIN32__) 3534 #if defined(WINDOWSNT) || defined(__CYGWIN32__)
3451 CONST char *sys_siglist[] = 3535 const char *sys_siglist[] =
3452 { 3536 {
3453 "bum signal!!", 3537 "bum signal!!",
3454 "hangup", 3538 "hangup",
3455 "interrupt", 3539 "interrupt",
3456 "quit", 3540 "quit",
3479 }; 3563 };
3480 #endif 3564 #endif
3481 3565
3482 #ifdef USG 3566 #ifdef USG
3483 #ifdef AIX 3567 #ifdef AIX
3484 CONST char *sys_siglist[NSIG + 1] = 3568 const char *sys_siglist[NSIG + 1] =
3485 { 3569 {
3486 /* AIX has changed the signals a bit */ 3570 /* AIX has changed the signals a bit */
3487 DEFER_GETTEXT ("bogus signal"), /* 0 */ 3571 DEFER_GETTEXT ("bogus signal"), /* 0 */
3488 DEFER_GETTEXT ("hangup"), /* 1 SIGHUP */ 3572 DEFER_GETTEXT ("hangup"), /* 1 SIGHUP */
3489 DEFER_GETTEXT ("interrupt"), /* 2 SIGINT */ 3573 DEFER_GETTEXT ("interrupt"), /* 2 SIGINT */
3519 DEFER_GETTEXT ("HFT input ready"), /* 31 SIGMSG */ 3603 DEFER_GETTEXT ("HFT input ready"), /* 31 SIGMSG */
3520 #endif 3604 #endif
3521 0 3605 0
3522 }; 3606 };
3523 #else /* USG, not AIX */ 3607 #else /* USG, not AIX */
3524 CONST char *sys_siglist[NSIG + 1] = 3608 const char *sys_siglist[NSIG + 1] =
3525 { 3609 {
3526 DEFER_GETTEXT ("bogus signal"), /* 0 */ 3610 DEFER_GETTEXT ("bogus signal"), /* 0 */
3527 DEFER_GETTEXT ("hangup"), /* 1 SIGHUP */ 3611 DEFER_GETTEXT ("hangup"), /* 1 SIGHUP */
3528 DEFER_GETTEXT ("interrupt"), /* 2 SIGINT */ 3612 DEFER_GETTEXT ("interrupt"), /* 2 SIGINT */
3529 DEFER_GETTEXT ("quit"), /* 3 SIGQUIT */ 3613 DEFER_GETTEXT ("quit"), /* 3 SIGQUIT */
3568 0 3652 0
3569 }; 3653 };
3570 #endif /* not AIX */ 3654 #endif /* not AIX */
3571 #endif /* USG */ 3655 #endif /* USG */
3572 #ifdef DGUX 3656 #ifdef DGUX
3573 CONST char *sys_siglist[NSIG + 1] = 3657 const char *sys_siglist[NSIG + 1] =
3574 { 3658 {
3575 DEFER_GETTEXT ("null signal"), /* 0 SIGNULL */ 3659 DEFER_GETTEXT ("null signal"), /* 0 SIGNULL */
3576 DEFER_GETTEXT ("hangup"), /* 1 SIGHUP */ 3660 DEFER_GETTEXT ("hangup"), /* 1 SIGHUP */
3577 DEFER_GETTEXT ("interrupt"), /* 2 SIGINT */ 3661 DEFER_GETTEXT ("interrupt"), /* 2 SIGINT */
3578 DEFER_GETTEXT ("quit"), /* 3 SIGQUIT */ 3662 DEFER_GETTEXT ("quit"), /* 3 SIGQUIT */
3673 #endif /* SYSV_SYSTEM_DIR */ 3757 #endif /* SYSV_SYSTEM_DIR */
3674 3758
3675 #ifdef NONSYSTEM_DIR_LIBRARY 3759 #ifdef NONSYSTEM_DIR_LIBRARY
3676 3760
3677 DIR * 3761 DIR *
3678 opendir (CONST char *filename) /* name of directory */ 3762 opendir (const char *filename) /* name of directory */
3679 { 3763 {
3680 DIR *dirp; /* -> malloc'ed storage */ 3764 DIR *dirp; /* -> malloc'ed storage */
3681 int fd; /* file descriptor for read */ 3765 int fd; /* file descriptor for read */
3682 struct stat sbuf; /* result of fstat */ 3766 struct stat sbuf; /* result of fstat */
3683 3767
3775 */ 3859 */
3776 #ifdef MKDIR_PROTOTYPE 3860 #ifdef MKDIR_PROTOTYPE
3777 MKDIR_PROTOTYPE 3861 MKDIR_PROTOTYPE
3778 #else 3862 #else
3779 int 3863 int
3780 mkdir (CONST char *dpath, int dmode) 3864 mkdir (const char *dpath, int dmode)
3781 #endif 3865 #endif
3782 { 3866 {
3783 int cpid, status, fd; 3867 int cpid, status, fd;
3784 struct stat statbuf; 3868 struct stat statbuf;
3785 3869
3835 } 3919 }
3836 #endif /* not HAVE_MKDIR */ 3920 #endif /* not HAVE_MKDIR */
3837 3921
3838 #ifndef HAVE_RMDIR 3922 #ifndef HAVE_RMDIR
3839 int 3923 int
3840 rmdir (CONST char *dpath) 3924 rmdir (const char *dpath)
3841 { 3925 {
3842 int cpid, status, fd; 3926 int cpid, status, fd;
3843 struct stat statbuf; 3927 struct stat statbuf;
3844 3928
3845 if (stat (dpath, &statbuf) != 0) 3929 if (stat (dpath, &statbuf) != 0)