Mercurial > hg > xemacs-beta
comparison src/sysdep.c @ 440:8de8e3f6228a r21-2-28
Import from CVS: tag r21-2-28
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:33:38 +0200 |
parents | 84b14dcb0985 |
children | abe6d1db359e |
comparison
equal
deleted
inserted
replaced
439:357dd071b03c | 440:8de8e3f6228a |
---|---|
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 #ifndef __MINGW32__ | 36 #ifdef __MINGW32__ |
37 #include <mingw32/process.h> | |
38 #else | |
37 /* <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. |
38 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 |
39 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 |
40 standard way, so include files get to what/ever/path/include. | 42 standard way, so include path ends with /include. |
41 | 43 |
42 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() |
43 which will conflict with the macro defined in lisp.h | 45 which will conflict with the macro defined in lisp.h |
44 */ | 46 */ |
45 #include <../include/process.h> | 47 #include <../include/process.h> |
46 #else | 48 #endif /* __MINGW32__ */ |
47 #include <mingw32/process.h> | |
48 #endif | |
49 #endif /* WINDOWSNT */ | 49 #endif /* WINDOWSNT */ |
50 | 50 |
51 #include "lisp.h" | 51 #include "lisp.h" |
52 | 52 |
53 #include <stdlib.h> | 53 #include <stdlib.h> |
88 #include <sys/times.h> | 88 #include <sys/times.h> |
89 #endif | 89 #endif |
90 | 90 |
91 #ifdef WINDOWSNT | 91 #ifdef WINDOWSNT |
92 #include <sys/utime.h> | 92 #include <sys/utime.h> |
93 #include <windows.h> | |
94 #include "ntheap.h" | 93 #include "ntheap.h" |
95 #endif | 94 #endif |
96 | 95 |
97 /* ------------------------------- */ | 96 /* ------------------------------- */ |
98 /* TTY definitions */ | 97 /* TTY definitions */ |
384 nothing to do. APA */ | 383 nothing to do. APA */ |
385 warn_when_safe (Qprocess, Qwarning, | 384 warn_when_safe (Qprocess, Qwarning, |
386 "failure to obtain process exit value"); | 385 "failure to obtain process exit value"); |
387 } | 386 } |
388 } | 387 } |
389 if (pHandle != NULL && !CloseHandle(pHandle)) | 388 if (pHandle != NULL && !CloseHandle(pHandle)) |
390 { | 389 { |
391 warn_when_safe (Qprocess, Qwarning, | 390 warn_when_safe (Qprocess, Qwarning, |
392 "failure to close unknown process"); | 391 "failure to close unknown process"); |
393 } | 392 } |
394 #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) |
537 s.main.c_cc[VSUSP] = _POSIX_VDISABLE; | 536 s.main.c_cc[VSUSP] = _POSIX_VDISABLE; |
538 s.main.c_lflag &= ~ISIG; | 537 s.main.c_lflag &= ~ISIG; |
539 #endif /* no TIOCGPGRP or no TIOCGLTC or no TIOCGETC */ | 538 #endif /* no TIOCGPGRP or no TIOCGLTC or no TIOCGETC */ |
540 s.main.c_cc[VEOL] = _POSIX_VDISABLE; | 539 s.main.c_cc[VEOL] = _POSIX_VDISABLE; |
541 #if defined (CBAUD) | 540 #if defined (CBAUD) |
542 /* <mdiers> ### This is not portable. ### | 541 /* <mdiers> #### This is not portable. ### |
543 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. |
544 Instead, POSIX suggests to use cfset{i,o}speed(). | 543 Instead, POSIX suggests to use cfset{i,o}speed(). |
545 [cf. D. Lewine, POSIX Programmer's Guide, Chapter 8: Terminal | 544 [cf. D. Lewine, POSIX Programmer's Guide, Chapter 8: Terminal |
546 I/O, O'Reilly 1991] */ | 545 I/O, O'Reilly 1991] */ |
547 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 */ |
1706 we have an unlocked terminal at the start. */ | 1705 we have an unlocked terminal at the start. */ |
1707 | 1706 |
1708 #ifdef TCXONC | 1707 #ifdef TCXONC |
1709 if (!TTY_FLAGS (con).flow_control) ioctl (input_fd, TCXONC, 1); | 1708 if (!TTY_FLAGS (con).flow_control) ioctl (input_fd, TCXONC, 1); |
1710 #endif | 1709 #endif |
1711 #ifndef APOLLO | |
1712 #ifdef TIOCSTART | 1710 #ifdef TIOCSTART |
1713 if (!TTY_FLAGS (con).flow_control) ioctl (input_fd, TIOCSTART, 0); | 1711 if (!TTY_FLAGS (con).flow_control) ioctl (input_fd, TIOCSTART, 0); |
1714 #endif | |
1715 #endif | 1712 #endif |
1716 | 1713 |
1717 #if defined (HAVE_TERMIOS) || defined (HPUX9) | 1714 #if defined (HAVE_TERMIOS) || defined (HPUX9) |
1718 #ifdef TCOON | 1715 #ifdef TCOON |
1719 if (!TTY_FLAGS (con).flow_control) tcflow (input_fd, TCOON); | 1716 if (!TTY_FLAGS (con).flow_control) tcflow (input_fd, TCOON); |
2122 | 2119 |
2123 /************************************************************************/ | 2120 /************************************************************************/ |
2124 /* limits of text/data segments */ | 2121 /* limits of text/data segments */ |
2125 /************************************************************************/ | 2122 /************************************************************************/ |
2126 | 2123 |
2127 #ifndef CANNOT_DUMP | 2124 #if !defined(CANNOT_DUMP) && !defined(PDUMP) |
2128 #define NEED_STARTS | 2125 #define NEED_STARTS |
2129 #endif | 2126 #endif |
2130 | 2127 |
2131 #ifndef SYSTEM_MALLOC | 2128 #ifndef SYSTEM_MALLOC |
2132 #ifndef NEED_STARTS | 2129 #ifndef NEED_STARTS |
2142 * doing an unexec. After unexec the return value is undefined. | 2139 * doing an unexec. After unexec the return value is undefined. |
2143 * See crt0.c for further explanation and _start. | 2140 * See crt0.c for further explanation and _start. |
2144 * | 2141 * |
2145 */ | 2142 */ |
2146 | 2143 |
2144 #if !defined(HAVE_TEXT_START) && !defined(PDUMP) | |
2145 | |
2147 #ifdef __cplusplus | 2146 #ifdef __cplusplus |
2148 extern "C" int _start (void); | 2147 extern "C" int _start (void); |
2149 #else | 2148 #else |
2150 extern int _start (void); | 2149 extern int _start (void); |
2151 #endif | 2150 #endif |
2152 | 2151 |
2153 #ifndef HAVE_TEXT_START | |
2154 char * | 2152 char * |
2155 start_of_text (void) | 2153 start_of_text (void) |
2156 { | 2154 { |
2157 #ifdef TEXT_START | 2155 #ifdef TEXT_START |
2158 return ((char *) TEXT_START); | 2156 return ((char *) TEXT_START); |
2163 #else /* not GOULD */ | 2161 #else /* not GOULD */ |
2164 return ((char *) _start); | 2162 return ((char *) _start); |
2165 #endif /* GOULD */ | 2163 #endif /* GOULD */ |
2166 #endif /* TEXT_START */ | 2164 #endif /* TEXT_START */ |
2167 } | 2165 } |
2168 #endif /* not HAVE_TEXT_START */ | 2166 #endif /* !defined(HAVE_TEXT_START) && !defined(PDUMP) */ |
2169 | 2167 |
2170 /* | 2168 /* |
2171 * 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 |
2172 * doing an unexec. After unexec the return value is undefined. | 2170 * doing an unexec. After unexec the return value is undefined. |
2173 * See crt0.c for further information and definition of data_start. | 2171 * See crt0.c for further information and definition of data_start. |
2222 #endif /* ORDINARY_LINK */ | 2220 #endif /* ORDINARY_LINK */ |
2223 #endif /* DATA_START */ | 2221 #endif /* DATA_START */ |
2224 } | 2222 } |
2225 #endif /* NEED_STARTS (not CANNOT_DUMP or not SYSTEM_MALLOC) */ | 2223 #endif /* NEED_STARTS (not CANNOT_DUMP or not SYSTEM_MALLOC) */ |
2226 | 2224 |
2227 #ifndef CANNOT_DUMP | 2225 #if !defined(CANNOT_DUMP) && !defined(PDUMP) |
2228 /* Some systems that cannot dump also cannot implement these. */ | 2226 /* Some systems that cannot dump also cannot implement these. */ |
2229 | 2227 |
2230 /* | 2228 /* |
2231 * 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 |
2232 * doing an unexec. After unexec the return value is undefined. | 2230 * doing an unexec. After unexec the return value is undefined. |
2257 extern int edata; | 2255 extern int edata; |
2258 return ((char *) &edata); | 2256 return ((char *) &edata); |
2259 #endif | 2257 #endif |
2260 } | 2258 } |
2261 | 2259 |
2262 #endif /* not CANNOT_DUMP */ | 2260 #endif /* !defined(CANNOT_DUMP) && !defined(PDUMP) */ |
2263 | 2261 |
2264 | 2262 |
2265 /************************************************************************/ | 2263 /************************************************************************/ |
2266 /* get the system name */ | 2264 /* get the system name */ |
2267 /************************************************************************/ | 2265 /************************************************************************/ |
2279 void | 2277 void |
2280 init_system_name (void) | 2278 init_system_name (void) |
2281 { | 2279 { |
2282 #if defined (WINDOWSNT) | 2280 #if defined (WINDOWSNT) |
2283 char hostname [MAX_COMPUTERNAME_LENGTH + 1]; | 2281 char hostname [MAX_COMPUTERNAME_LENGTH + 1]; |
2284 size_t size = sizeof(hostname); | 2282 size_t size = sizeof (hostname); |
2285 GetComputerName (hostname, &size); | 2283 GetComputerName (hostname, &size); |
2286 Vsystem_name = build_string (hostname); | 2284 Vsystem_name = build_string (hostname); |
2287 #elif !defined (HAVE_GETHOSTNAME) | 2285 #elif !defined (HAVE_GETHOSTNAME) |
2288 struct utsname uts; | 2286 struct utsname uts; |
2289 uname (&uts); | 2287 uname (&uts); |
2315 # ifndef CANNOT_DUMP | 2313 # ifndef CANNOT_DUMP |
2316 if (initialized) | 2314 if (initialized) |
2317 # endif /* not CANNOT_DUMP */ | 2315 # endif /* not CANNOT_DUMP */ |
2318 if (!strchr (hostname, '.')) | 2316 if (!strchr (hostname, '.')) |
2319 { | 2317 { |
2318 # if !(defined(HAVE_GETADDRINFO) && defined(HAVE_GETNAMEINFO)) | |
2320 struct hostent *hp = NULL; | 2319 struct hostent *hp = NULL; |
2321 int count; | 2320 int count; |
2322 # ifdef TRY_AGAIN | 2321 # ifdef TRY_AGAIN |
2323 for (count = 0; count < 10; count++) | 2322 for (count = 0; count < 10; count++) |
2324 { | 2323 { |
2325 h_errno = 0; | 2324 h_errno = 0; |
2326 # endif | 2325 # endif |
2327 /* Some systems can't handle SIGALARM/SIGIO in gethostbyname(). */ | 2326 /* Some systems can't handle SIGALARM/SIGIO in gethostbyname(). */ |
2328 stop_interrupts (); | 2327 stop_interrupts (); |
2329 hp = gethostbyname (hostname); | 2328 hp = gethostbyname (hostname); |
2330 start_interrupts (); | 2329 start_interrupts (); |
2331 # ifdef TRY_AGAIN | 2330 # ifdef TRY_AGAIN |
2332 if (! (hp == 0 && h_errno == TRY_AGAIN)) | 2331 if (! (hp == 0 && h_errno == TRY_AGAIN)) |
2333 break; | 2332 break; |
2334 Fsleep_for (make_int (1)); | 2333 Fsleep_for (make_int (1)); |
2335 } | 2334 } |
2336 # endif | 2335 # endif |
2337 if (hp) | 2336 if (hp) |
2338 { | 2337 { |
2339 CONST char *fqdn = (CONST char *) hp->h_name; | 2338 CONST char *fqdn = (CONST char *) hp->h_name; |
2340 | 2339 |
2341 if (!strchr (fqdn, '.')) | 2340 if (!strchr (fqdn, '.')) |
2349 fqdn = *alias; | 2348 fqdn = *alias; |
2350 } | 2349 } |
2351 hostname = (char *) alloca (strlen (fqdn) + 1); | 2350 hostname = (char *) alloca (strlen (fqdn) + 1); |
2352 strcpy (hostname, fqdn); | 2351 strcpy (hostname, fqdn); |
2353 } | 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) */ | |
2354 } | 2369 } |
2355 # endif /* HAVE_SOCKETS */ | 2370 # endif /* HAVE_SOCKETS */ |
2356 Vsystem_name = build_string (hostname); | 2371 Vsystem_name = build_string (hostname); |
2357 #endif /* HAVE_GETHOSTNAME */ | 2372 #endif /* HAVE_GETHOSTNAME */ |
2358 { | 2373 { |
2569 mswindows_set_errno (unsigned long win32_error) | 2584 mswindows_set_errno (unsigned long win32_error) |
2570 { | 2585 { |
2571 int i; | 2586 int i; |
2572 | 2587 |
2573 /* check the table for the OS error code */ | 2588 /* check the table for the OS error code */ |
2574 for (i = 0; i < sizeof(errtable)/sizeof(errtable[0]); ++i) | 2589 for (i = 0; i < countof (errtable); ++i) |
2575 { | 2590 { |
2576 if (win32_error == errtable[i].oscode) | 2591 if (win32_error == errtable[i].oscode) |
2577 { | 2592 { |
2578 errno = errtable[i].errnocode; | 2593 errno = errtable[i].errnocode; |
2579 return; | 2594 return; |
2603 /************************************************************************/ | 2618 /************************************************************************/ |
2604 /* Encapsulations of system calls */ | 2619 /* Encapsulations of system calls */ |
2605 /************************************************************************/ | 2620 /************************************************************************/ |
2606 | 2621 |
2607 #define PATHNAME_CONVERT_OUT(path) \ | 2622 #define PATHNAME_CONVERT_OUT(path) \ |
2608 GET_C_CHARPTR_EXT_FILENAME_DATA_ALLOCA ((CONST Bufbyte *) path, path) | 2623 TO_EXTERNAL_FORMAT (C_STRING, (path), C_STRING_ALLOCA, (path), Qfile_name); |
2609 | 2624 |
2610 /***************** low-level calls ****************/ | 2625 /***************** low-level calls ****************/ |
2611 | 2626 |
2612 /* | 2627 /* |
2613 * On USG systems the system calls are INTERRUPTIBLE by signals | 2628 * On USG systems the system calls are INTERRUPTIBLE by signals |
2636 | 2651 |
2637 va_start (ap, oflag); | 2652 va_start (ap, oflag); |
2638 mode = va_arg (ap, int); | 2653 mode = va_arg (ap, int); |
2639 va_end (ap); | 2654 va_end (ap); |
2640 | 2655 |
2641 PATHNAME_CONVERT_OUT (path); | 2656 #ifdef WINDOWSNT |
2642 #if defined (WINDOWSNT) | |
2643 /* Make all handles non-inheritable */ | 2657 /* Make all handles non-inheritable */ |
2644 return open (path, oflag | _O_NOINHERIT, mode); | 2658 oflag |= _O_NOINHERIT; |
2645 #elif defined (INTERRUPTIBLE_OPEN) | 2659 #endif |
2660 | |
2661 #ifdef INTERRUPTIBLE_OPEN | |
2646 { | 2662 { |
2647 int rtnval; | 2663 int rtnval; |
2648 while ((rtnval = open (path, oflag, mode)) == -1 | 2664 while ((rtnval = open (path, oflag, mode)) == -1 |
2649 && (errno == EINTR)) | 2665 && (errno == EINTR)) |
2650 DO_NOTHING; | 2666 DO_NOTHING; |
2674 /* 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, |
2675 which could be relocated by GC when checking for QUIT. */ | 2691 which could be relocated by GC when checking for QUIT. */ |
2676 memcpy (nonreloc, path, len + 1); | 2692 memcpy (nonreloc, path, len + 1); |
2677 | 2693 |
2678 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 | |
2679 | 2700 |
2680 for (;;) | 2701 for (;;) |
2681 { | 2702 { |
2682 int rtnval = open (nonreloc, oflag, mode); | 2703 int rtnval = open (nonreloc, oflag, mode); |
2683 if (!(rtnval == -1 && errno == EINTR)) | 2704 if (!(rtnval == -1 && errno == EINTR)) |
3003 Dynarr_reset (internal_DIRENTRY); | 3024 Dynarr_reset (internal_DIRENTRY); |
3004 | 3025 |
3005 Dynarr_add_many (internal_DIRENTRY, (Bufbyte *) rtnval, | 3026 Dynarr_add_many (internal_DIRENTRY, (Bufbyte *) rtnval, |
3006 offsetof (DIRENTRY, d_name)); | 3027 offsetof (DIRENTRY, d_name)); |
3007 | 3028 |
3008 internal_name = | 3029 TO_INTERNAL_FORMAT (DATA, (external_name, external_len), |
3009 convert_from_external_format (external_name, external_len, | 3030 ALLOCA, (internal_name, internal_len), |
3010 &internal_len, FORMAT_FILENAME); | 3031 Qfile_name); |
3011 | 3032 |
3012 Dynarr_add_many (internal_DIRENTRY, internal_name, internal_len); | 3033 Dynarr_add_many (internal_DIRENTRY, internal_name, internal_len); |
3013 Dynarr_add (internal_DIRENTRY, 0); /* zero-terminate */ | 3034 Dynarr_add (internal_DIRENTRY, 0); /* zero-terminate */ |
3014 return (DIRENTRY *) Dynarr_atp (internal_DIRENTRY, 0); | 3035 return (DIRENTRY *) Dynarr_atp (internal_DIRENTRY, 0); |
3015 } | 3036 } |