diff options
Diffstat (limited to 'src/sysdep.c')
| -rw-r--r-- | src/sysdep.c | 128 |
1 files changed, 60 insertions, 68 deletions
diff --git a/src/sysdep.c b/src/sysdep.c index 46667cf292f..edaaa4c93d7 100644 --- a/src/sysdep.c +++ b/src/sysdep.c | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* Interfaces to system-dependent kernel and library entries. | 1 | /* Interfaces to system-dependent kernel and library entries. |
| 2 | Copyright (C) 1985-1988, 1993-1995, 1999-2011 | 2 | Copyright (C) 1985-1988, 1993-1995, 1999-2012 |
| 3 | Free Software Foundation, Inc. | 3 | Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | This file is part of GNU Emacs. | 5 | This file is part of GNU Emacs. |
| @@ -26,9 +26,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 26 | #include <pwd.h> | 26 | #include <pwd.h> |
| 27 | #include <grp.h> | 27 | #include <grp.h> |
| 28 | #endif /* HAVE_PWD_H */ | 28 | #endif /* HAVE_PWD_H */ |
| 29 | #ifdef HAVE_LIMITS_H | ||
| 30 | #include <limits.h> | 29 | #include <limits.h> |
| 31 | #endif /* HAVE_LIMITS_H */ | ||
| 32 | #include <unistd.h> | 30 | #include <unistd.h> |
| 33 | 31 | ||
| 34 | #include <allocator.h> | 32 | #include <allocator.h> |
| @@ -302,7 +300,7 @@ wait_for_termination_1 (int pid, int interruptible) | |||
| 302 | { | 300 | { |
| 303 | while (1) | 301 | while (1) |
| 304 | { | 302 | { |
| 305 | #if (defined (BSD_SYSTEM) || defined (HPUX)) && !defined(__GNU__) | 303 | #if (defined (BSD_SYSTEM) || defined (HPUX)) && !defined (__GNU__) |
| 306 | /* Note that kill returns -1 even if the process is just a zombie now. | 304 | /* Note that kill returns -1 even if the process is just a zombie now. |
| 307 | But inevitably a SIGCHLD interrupt should be generated | 305 | But inevitably a SIGCHLD interrupt should be generated |
| 308 | and child_sig will do wait3 and make the process go away. */ | 306 | and child_sig will do wait3 and make the process go away. */ |
| @@ -435,7 +433,7 @@ child_setup_tty (int out) | |||
| 435 | #endif /* AIX */ | 433 | #endif /* AIX */ |
| 436 | 434 | ||
| 437 | /* We originally enabled ICANON (and set VEOF to 04), and then had | 435 | /* We originally enabled ICANON (and set VEOF to 04), and then had |
| 438 | proces.c send additional EOF chars to flush the output when faced | 436 | process.c send additional EOF chars to flush the output when faced |
| 439 | with long lines, but this leads to weird effects when the | 437 | with long lines, but this leads to weird effects when the |
| 440 | subprocess has disabled ICANON and ends up seeing those spurious | 438 | subprocess has disabled ICANON and ends up seeing those spurious |
| 441 | extra EOFs. So we don't send EOFs any more in | 439 | extra EOFs. So we don't send EOFs any more in |
| @@ -856,6 +854,7 @@ void | |||
| 856 | init_sys_modes (struct tty_display_info *tty_out) | 854 | init_sys_modes (struct tty_display_info *tty_out) |
| 857 | { | 855 | { |
| 858 | struct emacs_tty tty; | 856 | struct emacs_tty tty; |
| 857 | Lisp_Object terminal; | ||
| 859 | 858 | ||
| 860 | Vtty_erase_char = Qnil; | 859 | Vtty_erase_char = Qnil; |
| 861 | 860 | ||
| @@ -909,7 +908,9 @@ init_sys_modes (struct tty_display_info *tty_out) | |||
| 909 | tty.main.c_cflag &= ~PARENB;/* Don't check parity */ | 908 | tty.main.c_cflag &= ~PARENB;/* Don't check parity */ |
| 910 | } | 909 | } |
| 911 | #endif | 910 | #endif |
| 912 | if (tty_out->input == stdin) | 911 | |
| 912 | XSETTERMINAL(terminal, tty_out->terminal); | ||
| 913 | if (!NILP (Fcontrolling_tty_p (terminal))) | ||
| 913 | { | 914 | { |
| 914 | tty.main.c_cc[VINTR] = quit_char; /* C-g (usually) gives SIGINT */ | 915 | tty.main.c_cc[VINTR] = quit_char; /* C-g (usually) gives SIGINT */ |
| 915 | /* Set up C-g for both SIGQUIT and SIGINT. | 916 | /* Set up C-g for both SIGQUIT and SIGINT. |
| @@ -1328,7 +1329,7 @@ setup_pty (int fd) | |||
| 1328 | Since the latter lossage is more benign, we may as well | 1329 | Since the latter lossage is more benign, we may as well |
| 1329 | lose that way. -- cph */ | 1330 | lose that way. -- cph */ |
| 1330 | #ifdef FIONBIO | 1331 | #ifdef FIONBIO |
| 1331 | #if defined(UNIX98_PTYS) | 1332 | #if defined (UNIX98_PTYS) |
| 1332 | { | 1333 | { |
| 1333 | int on = 1; | 1334 | int on = 1; |
| 1334 | ioctl (fd, FIONBIO, &on); | 1335 | ioctl (fd, FIONBIO, &on); |
| @@ -1501,7 +1502,7 @@ sys_signal (int signal_number, signal_handler_t action) | |||
| 1501 | after a signal that sets the interrupt_input_pending flag. */ | 1502 | after a signal that sets the interrupt_input_pending flag. */ |
| 1502 | /* Non-interactive keyboard input goes through stdio, where we always | 1503 | /* Non-interactive keyboard input goes through stdio, where we always |
| 1503 | want restartable system calls. */ | 1504 | want restartable system calls. */ |
| 1504 | # if defined (BROKEN_SA_RESTART) || defined(SYNC_INPUT) | 1505 | # if defined (BROKEN_SA_RESTART) || defined (SYNC_INPUT) |
| 1505 | if (noninteractive) | 1506 | if (noninteractive) |
| 1506 | # endif | 1507 | # endif |
| 1507 | new_action.sa_flags = SA_RESTART; | 1508 | new_action.sa_flags = SA_RESTART; |
| @@ -1662,7 +1663,7 @@ init_signals (void) | |||
| 1662 | sys_siglist[SIGQUIT] = "Quit"; | 1663 | sys_siglist[SIGQUIT] = "Quit"; |
| 1663 | # endif | 1664 | # endif |
| 1664 | # ifdef SIGRETRACT | 1665 | # ifdef SIGRETRACT |
| 1665 | sys_siglist[SIGRETRACT] = "Need to relinguish monitor mode"; | 1666 | sys_siglist[SIGRETRACT] = "Need to relinquish monitor mode"; |
| 1666 | # endif | 1667 | # endif |
| 1667 | # ifdef SIGSAK | 1668 | # ifdef SIGSAK |
| 1668 | sys_siglist[SIGSAK] = "Secure attention"; | 1669 | sys_siglist[SIGSAK] = "Secure attention"; |
| @@ -1802,8 +1803,7 @@ get_random (void) | |||
| 1802 | #ifndef HAVE_STRERROR | 1803 | #ifndef HAVE_STRERROR |
| 1803 | #ifndef WINDOWSNT | 1804 | #ifndef WINDOWSNT |
| 1804 | char * | 1805 | char * |
| 1805 | strerror (errnum) | 1806 | strerror (int errnum) |
| 1806 | int errnum; | ||
| 1807 | { | 1807 | { |
| 1808 | extern char *sys_errlist[]; | 1808 | extern char *sys_errlist[]; |
| 1809 | extern int sys_nerr; | 1809 | extern int sys_nerr; |
| @@ -1814,6 +1814,49 @@ strerror (errnum) | |||
| 1814 | } | 1814 | } |
| 1815 | #endif /* not WINDOWSNT */ | 1815 | #endif /* not WINDOWSNT */ |
| 1816 | #endif /* ! HAVE_STRERROR */ | 1816 | #endif /* ! HAVE_STRERROR */ |
| 1817 | |||
| 1818 | #ifndef HAVE_SNPRINTF | ||
| 1819 | /* Approximate snprintf as best we can on ancient hosts that lack it. */ | ||
| 1820 | int | ||
| 1821 | snprintf (char *buf, size_t bufsize, char const *format, ...) | ||
| 1822 | { | ||
| 1823 | ptrdiff_t size = min (bufsize, PTRDIFF_MAX); | ||
| 1824 | ptrdiff_t nbytes = size - 1; | ||
| 1825 | va_list ap; | ||
| 1826 | |||
| 1827 | if (size) | ||
| 1828 | { | ||
| 1829 | va_start (ap, format); | ||
| 1830 | nbytes = doprnt (buf, size, format, 0, ap); | ||
| 1831 | va_end (ap); | ||
| 1832 | } | ||
| 1833 | |||
| 1834 | if (nbytes == size - 1) | ||
| 1835 | { | ||
| 1836 | /* Calculate the length of the string that would have been created | ||
| 1837 | had the buffer been large enough. */ | ||
| 1838 | char stackbuf[4000]; | ||
| 1839 | char *b = stackbuf; | ||
| 1840 | ptrdiff_t bsize = sizeof stackbuf; | ||
| 1841 | va_start (ap, format); | ||
| 1842 | nbytes = evxprintf (&b, &bsize, stackbuf, -1, format, ap); | ||
| 1843 | va_end (ap); | ||
| 1844 | if (b != stackbuf) | ||
| 1845 | xfree (b); | ||
| 1846 | } | ||
| 1847 | |||
| 1848 | if (INT_MAX < nbytes) | ||
| 1849 | { | ||
| 1850 | #ifdef EOVERFLOW | ||
| 1851 | errno = EOVERFLOW; | ||
| 1852 | #else | ||
| 1853 | errno = EDOM; | ||
| 1854 | #endif | ||
| 1855 | return -1; | ||
| 1856 | } | ||
| 1857 | return nbytes; | ||
| 1858 | } | ||
| 1859 | #endif | ||
| 1817 | 1860 | ||
| 1818 | int | 1861 | int |
| 1819 | emacs_open (const char *path, int oflag, int mode) | 1862 | emacs_open (const char *path, int oflag, int mode) |
| @@ -2004,7 +2047,7 @@ rename (const char *from, const char *to) | |||
| 2004 | #endif | 2047 | #endif |
| 2005 | 2048 | ||
| 2006 | 2049 | ||
| 2007 | #if defined(HPUX) && !defined(HAVE_PERROR) | 2050 | #if defined (HPUX) && !defined (HAVE_PERROR) |
| 2008 | 2051 | ||
| 2009 | /* HPUX curses library references perror, but as far as we know | 2052 | /* HPUX curses library references perror, but as far as we know |
| 2010 | it won't be called. Anyway this definition will do for now. */ | 2053 | it won't be called. Anyway this definition will do for now. */ |
| @@ -2216,59 +2259,6 @@ rmdir (char *dpath) | |||
| 2216 | #endif /* !HAVE_RMDIR */ | 2259 | #endif /* !HAVE_RMDIR */ |
| 2217 | 2260 | ||
| 2218 | 2261 | ||
| 2219 | #ifndef HAVE_MEMSET | ||
| 2220 | void * | ||
| 2221 | memset (void *b, int n, size_t length) | ||
| 2222 | { | ||
| 2223 | unsigned char *p = b; | ||
| 2224 | while (length-- > 0) | ||
| 2225 | *p++ = n; | ||
| 2226 | return b; | ||
| 2227 | } | ||
| 2228 | #endif /* !HAVE_MEMSET */ | ||
| 2229 | |||
| 2230 | #ifndef HAVE_MEMCPY | ||
| 2231 | void * | ||
| 2232 | memcpy (void *b1, void *b2, size_t length) | ||
| 2233 | { | ||
| 2234 | unsigned char *p1 = b1, *p2 = b2; | ||
| 2235 | while (length-- > 0) | ||
| 2236 | *p1++ = *p2++; | ||
| 2237 | return b1; | ||
| 2238 | } | ||
| 2239 | #endif /* !HAVE_MEMCPY */ | ||
| 2240 | |||
| 2241 | #ifndef HAVE_MEMMOVE | ||
| 2242 | void * | ||
| 2243 | memmove (void *b1, void *b2, size_t length) | ||
| 2244 | { | ||
| 2245 | unsigned char *p1 = b1, *p2 = b2; | ||
| 2246 | if (p1 < p2 || p1 >= p2 + length) | ||
| 2247 | while (length-- > 0) | ||
| 2248 | *p1++ = *p2++; | ||
| 2249 | else | ||
| 2250 | { | ||
| 2251 | p1 += length; | ||
| 2252 | p2 += length; | ||
| 2253 | while (length-- > 0) | ||
| 2254 | *--p1 = *--p2; | ||
| 2255 | } | ||
| 2256 | return b1; | ||
| 2257 | } | ||
| 2258 | #endif /* !HAVE_MEMCPY */ | ||
| 2259 | |||
| 2260 | #ifndef HAVE_MEMCMP | ||
| 2261 | int | ||
| 2262 | memcmp (void *b1, void *b2, size_t length) | ||
| 2263 | { | ||
| 2264 | unsigned char *p1 = b1, *p2 = b2; | ||
| 2265 | while (length-- > 0) | ||
| 2266 | if (*p1++ != *p2++) | ||
| 2267 | return p1[-1] < p2[-1] ? -1 : 1; | ||
| 2268 | return 0; | ||
| 2269 | } | ||
| 2270 | #endif /* !HAVE_MEMCMP */ | ||
| 2271 | |||
| 2272 | #ifndef HAVE_STRSIGNAL | 2262 | #ifndef HAVE_STRSIGNAL |
| 2273 | char * | 2263 | char * |
| 2274 | strsignal (int code) | 2264 | strsignal (int code) |
| @@ -2696,7 +2686,7 @@ system_process_attributes (Lisp_Object pid) | |||
| 2696 | ssize_t nread; | 2686 | ssize_t nread; |
| 2697 | const char *cmd = NULL; | 2687 | const char *cmd = NULL; |
| 2698 | char *cmdline = NULL; | 2688 | char *cmdline = NULL; |
| 2699 | size_t cmdsize = 0, cmdline_size; | 2689 | ptrdiff_t cmdsize = 0, cmdline_size; |
| 2700 | unsigned char c; | 2690 | unsigned char c; |
| 2701 | int proc_id, ppid, uid, gid, pgrp, sess, tty, tpgid, thcount; | 2691 | int proc_id, ppid, uid, gid, pgrp, sess, tty, tpgid, thcount; |
| 2702 | unsigned long long u_time, s_time, cutime, cstime, start; | 2692 | unsigned long long u_time, s_time, cutime, cstime, start; |
| @@ -2878,8 +2868,10 @@ system_process_attributes (Lisp_Object pid) | |||
| 2878 | if (fd >= 0) | 2868 | if (fd >= 0) |
| 2879 | { | 2869 | { |
| 2880 | char ch; | 2870 | char ch; |
| 2881 | for (cmdline_size = 0; emacs_read (fd, &ch, 1) == 1; cmdline_size++) | 2871 | for (cmdline_size = 0; cmdline_size < STRING_BYTES_BOUND; cmdline_size++) |
| 2882 | { | 2872 | { |
| 2873 | if (emacs_read (fd, &ch, 1) != 1) | ||
| 2874 | break; | ||
| 2883 | c = ch; | 2875 | c = ch; |
| 2884 | if (isspace (c) || c == '\\') | 2876 | if (isspace (c) || c == '\\') |
| 2885 | cmdline_size++; /* for later quoting, see below */ | 2877 | cmdline_size++; /* for later quoting, see below */ |
| @@ -2900,7 +2892,7 @@ system_process_attributes (Lisp_Object pid) | |||
| 2900 | nread = 0; | 2892 | nread = 0; |
| 2901 | } | 2893 | } |
| 2902 | /* We don't want trailing null characters. */ | 2894 | /* We don't want trailing null characters. */ |
| 2903 | for (p = cmdline + nread - 1; p > cmdline && !*p; p--) | 2895 | for (p = cmdline + nread; p > cmdline + 1 && !p[-1]; p--) |
| 2904 | nread--; | 2896 | nread--; |
| 2905 | for (p = cmdline; p < cmdline + nread; p++) | 2897 | for (p = cmdline; p < cmdline + nread; p++) |
| 2906 | { | 2898 | { |