comparison src/nt.c @ 410:de805c49cfc1 r21-2-35

Import from CVS: tag r21-2-35
author cvs
date Mon, 13 Aug 2007 11:19:21 +0200
parents 501cfd01ee6d
children 697ef44129c6
comparison
equal deleted inserted replaced
409:301b9ebbdf3b 410:de805c49cfc1
23 23
24 /* Adapted for XEmacs by David Hobley <david@spook-le0.cia.com.au> */ 24 /* Adapted for XEmacs by David Hobley <david@spook-le0.cia.com.au> */
25 /* Sync'ed with Emacs 19.34.6 by Marc Paquette <marcpa@cam.org> */ 25 /* Sync'ed with Emacs 19.34.6 by Marc Paquette <marcpa@cam.org> */
26 26
27 #include <config.h> 27 #include <config.h>
28
29 #undef signal
30 #define getwd _getwd 28 #define getwd _getwd
31 #include "lisp.h" 29 #include "lisp.h"
32 #undef getwd 30 #undef getwd
33 31
34 #include "systime.h" 32 #include "systime.h"
35 #include "syssignal.h" 33 #include "syssignal.h"
36 #include "sysproc.h" 34 #include "sysproc.h"
37 #include "sysfile.h" 35 #include "sysfile.h"
38 36 #include "syspwd.h"
39 #include <ctype.h> 37 #include "sysdir.h"
40 #include <direct.h>
41 #include <errno.h>
42 #include <fcntl.h>
43 #include <io.h>
44 #include <pwd.h>
45 #include <signal.h>
46 #include <string.h>
47 #include <stdlib.h>
48 #include <stdio.h>
49 38
50 #include "syswindows.h" 39 #include "syswindows.h"
51 40
52 #include "nt.h" 41 #include "nt.h"
53 #include <sys/dir.h>
54 #include "ntheap.h" 42 #include "ntheap.h"
55 43
56 44
57 extern Lisp_Object Vmswindows_downcase_file_names; 45 extern Lisp_Object Vmswindows_downcase_file_names;
58 #if 0 46 #if 0
1073 dir_is_fat = is_fat_volume (filename, NULL); 1061 dir_is_fat = is_fat_volume (filename, NULL);
1074 1062
1075 return dirp; 1063 return dirp;
1076 } 1064 }
1077 1065
1078 void 1066 int
1079 closedir (DIR *dirp) 1067 closedir (DIR *dirp)
1080 { 1068 {
1069 BOOL retval;
1070
1081 /* If we have a find-handle open, close it. */ 1071 /* If we have a find-handle open, close it. */
1082 if (dir_find_handle != INVALID_HANDLE_VALUE) 1072 if (dir_find_handle != INVALID_HANDLE_VALUE)
1083 { 1073 {
1084 FindClose (dir_find_handle); 1074 retval = FindClose (dir_find_handle);
1085 dir_find_handle = INVALID_HANDLE_VALUE; 1075 dir_find_handle = INVALID_HANDLE_VALUE;
1086 } 1076 }
1087 xfree (dirp); 1077 xfree (dirp);
1078 if (retval)
1079 return 0;
1080 else
1081 return -1;
1088 } 1082 }
1089 1083
1090 struct direct * 1084 struct direct *
1091 readdir (DIR *dirp) 1085 readdir (DIR *dirp)
1092 { 1086 {
1234 ret -= utc_base; 1228 ret -= utc_base;
1235 return (time_t) (ret * 1e-7); 1229 return (time_t) (ret * 1e-7);
1236 } 1230 }
1237 #else 1231 #else
1238 1232
1239 #if defined(__MINGW32__) && CYGWIN_VERSION_DLL_MAJOR <= 21 1233 #if defined(MINGW) && CYGWIN_VERSION_DLL_MAJOR <= 21
1240 #define LowPart u.LowPart 1234 #define LowPart u.LowPart
1241 #define HighPart u.HighPart 1235 #define HighPart u.HighPart
1242 #endif 1236 #endif
1243 1237
1244 static LARGE_INTEGER utc_base_li; 1238 static LARGE_INTEGER utc_base_li;
1308 #endif 1302 #endif
1309 1303
1310 return ret; 1304 return ret;
1311 } 1305 }
1312 #endif 1306 #endif
1313 #if defined(__MINGW32__) && CYGWIN_VERSION_DLL_MAJOR <= 21 1307 #if defined(MINGW) && CYGWIN_VERSION_DLL_MAJOR <= 21
1314 #undef LowPart 1308 #undef LowPart
1315 #undef HighPart 1309 #undef HighPart
1316 #endif 1310 #endif
1317 1311
1318 #if 0 1312 #if 0
1389 return hashval (p); 1383 return hashval (p);
1390 } 1384 }
1391 1385
1392 #endif 1386 #endif
1393 1387
1394 /* stat has been fixed since MSVC 5.0.
1395 Oh, and do not encapsulater stat for non-MS compilers, too */
1396 /* #### popineau@ese-metz.fr says they still might be broken.
1397 Oh well... Let's add that `1 ||' condition.... --kkm */
1398 /* #### aichner@ecf.teradyne.com reported that with the library 1388 /* #### aichner@ecf.teradyne.com reported that with the library
1399 provided stat/fstat, (file-exist "d:\\tmp\\") =>> nil, 1389 provided stat/fstat, (file-exist "d:\\tmp\\") =>> nil,
1400 (file-exist "d:\\tmp") =>> t, when d:\tmp exists. Whenever 1390 (file-exist "d:\\tmp") =>> t, when d:\tmp exists. Whenever
1401 we opt to use non-encapsulated stat(), this should serve as 1391 we opt to use non-encapsulated stat(), this should serve as
1402 a compatibility test. --kkm */ 1392 a compatibility test. --kkm */
1403 1393
1404 #if 1 || defined(_MSC_VER) && _MSC_VER < 1100
1405
1406 /* Since stat is encapsulated on Windows NT, we need to encapsulate 1394 /* Since stat is encapsulated on Windows NT, we need to encapsulate
1407 the equally broken fstat as well. */ 1395 the equally broken fstat as well. */
1408 int _cdecl 1396 int
1409 fstat (int handle, struct stat *buffer) 1397 mswindows_fstat (int handle, struct stat *buffer)
1410 { 1398 {
1411 int ret; 1399 int ret;
1412 BY_HANDLE_FILE_INFORMATION lpFileInfo; 1400 BY_HANDLE_FILE_INFORMATION lpFileInfo;
1413 /* Initialize values */ 1401 /* Initialize values */
1414 buffer->st_mode = 0; 1402 buffer->st_mode = 0;
1439 1427
1440 /* MSVC stat function can't cope with UNC names and has other bugs, so 1428 /* MSVC stat function can't cope with UNC names and has other bugs, so
1441 replace it with our own. This also allows us to calculate consistent 1429 replace it with our own. This also allows us to calculate consistent
1442 inode values without hacks in the main Emacs code. */ 1430 inode values without hacks in the main Emacs code. */
1443 int 1431 int
1444 stat (const char * path, struct stat * buf) 1432 mswindows_stat (const char * path, struct stat * buf)
1445 { 1433 {
1446 char * name; 1434 char * name;
1447 WIN32_FIND_DATA wfd; 1435 WIN32_FIND_DATA wfd;
1448 HANDLE fh; 1436 HANDLE fh;
1449 DWORD fake_inode; 1437 DWORD fake_inode;
1625 1613
1626 buf->st_mode |= permission | (permission >> 3) | (permission >> 6); 1614 buf->st_mode |= permission | (permission >> 3) | (permission >> 6);
1627 1615
1628 return 0; 1616 return 0;
1629 } 1617 }
1630 #endif /* defined(_MSC_VER) && _MSC_VER < 1100 */
1631 1618
1632 /* From callproc.c */ 1619 /* From callproc.c */
1633 extern Lisp_Object Vbinary_process_input; 1620 extern Lisp_Object Vbinary_process_input;
1634 extern Lisp_Object Vbinary_process_output; 1621 extern Lisp_Object Vbinary_process_output;
1635 1622
1799 unsigned signal_block_mask = 0; 1786 unsigned signal_block_mask = 0;
1800 1787
1801 /* Signal pending mask: bit set to 1 means sig is pending */ 1788 /* Signal pending mask: bit set to 1 means sig is pending */
1802 unsigned signal_pending_mask = 0; 1789 unsigned signal_pending_mask = 0;
1803 1790
1804 msw_sighandler msw_sigset (int nsig, msw_sighandler handler) 1791 mswindows_sighandler mswindows_sigset (int nsig, mswindows_sighandler handler)
1805 { 1792 {
1806 /* We delegate some signals to the system function */ 1793 /* We delegate some signals to the system function */
1807 if (nsig == SIGFPE || nsig == SIGABRT || nsig == SIGINT) 1794 if (nsig == SIGFPE || nsig == SIGABRT || nsig == SIGINT)
1808 return signal (nsig, handler); 1795 return signal (nsig, handler);
1809 1796
1813 return NULL; 1800 return NULL;
1814 } 1801 }
1815 1802
1816 /* Store handler ptr */ 1803 /* Store handler ptr */
1817 { 1804 {
1818 msw_sighandler old_handler = signal_handlers[nsig]; 1805 mswindows_sighandler old_handler = signal_handlers[nsig];
1819 signal_handlers[nsig] = handler; 1806 signal_handlers[nsig] = handler;
1820 return old_handler; 1807 return old_handler;
1821 } 1808 }
1822 } 1809 }
1823 1810
1824 int msw_sighold (int nsig) 1811 int mswindows_sighold (int nsig)
1825 { 1812 {
1826 if (nsig < 0 || nsig > SIG_MAX) 1813 if (nsig < 0 || nsig > SIG_MAX)
1827 return errno = EINVAL; 1814 return errno = EINVAL;
1828 1815
1829 signal_block_mask |= sigmask(nsig); 1816 signal_block_mask |= sigmask(nsig);
1830 return 0; 1817 return 0;
1831 } 1818 }
1832 1819
1833 int msw_sigrelse (int nsig) 1820 int mswindows_sigrelse (int nsig)
1834 { 1821 {
1835 if (nsig < 0 || nsig > SIG_MAX) 1822 if (nsig < 0 || nsig > SIG_MAX)
1836 return errno = EINVAL; 1823 return errno = EINVAL;
1837 1824
1838 signal_block_mask &= ~sigmask(nsig); 1825 signal_block_mask &= ~sigmask(nsig);
1839 1826
1840 if (signal_pending_mask & sigmask(nsig)) 1827 if (signal_pending_mask & sigmask(nsig))
1841 msw_raise (nsig); 1828 mswindows_raise (nsig);
1842 1829
1843 return 0; 1830 return 0;
1844 } 1831 }
1845 1832
1846 int msw_sigpause (int nsig) 1833 int mswindows_sigpause (int nsig)
1847 { 1834 {
1848 /* This is currently not called, because the only 1835 /* This is currently not called, because the only
1849 call to sigpause inside XEmacs is with SIGCHLD 1836 call to sigpause inside XEmacs is with SIGCHLD
1850 parameter. Just in case, we put an assert here, 1837 parameter. Just in case, we put an assert here,
1851 so anyone who will add a call to sigpause will 1838 so anyone who will add a call to sigpause will
1852 be surprised (or surprise someone else...) */ 1839 be surprised (or surprise someone else...) */
1853 assert (0); 1840 assert (0);
1854 return 0; 1841 return 0;
1855 } 1842 }
1856 1843
1857 int msw_raise (int nsig) 1844 int mswindows_raise (int nsig)
1858 { 1845 {
1859 /* We delegate some raises to the system routine */ 1846 /* We delegate some raises to the system routine */
1860 if (nsig == SIGFPE || nsig == SIGABRT || nsig == SIGINT) 1847 if (nsig == SIGFPE || nsig == SIGABRT || nsig == SIGINT)
1861 return raise (nsig); 1848 return raise (nsig);
1862 1849
1918 1905
1919 static void CALLBACK timer_proc (UINT uID, UINT uMsg, DWORD dwUser, 1906 static void CALLBACK timer_proc (UINT uID, UINT uMsg, DWORD dwUser,
1920 DWORD dw1, DWORD dw2) 1907 DWORD dw1, DWORD dw2)
1921 { 1908 {
1922 /* Just raise a signal indicated by dwUser parameter */ 1909 /* Just raise a signal indicated by dwUser parameter */
1923 msw_raise (dwUser); 1910 mswindows_raise (dwUser);
1924 } 1911 }
1925 1912
1926 /* Divide time in ms specified by IT by DENOM. Return 1 ms 1913 /* Divide time in ms specified by IT by DENOM. Return 1 ms
1927 if division results in zero */ 1914 if division results in zero */
1928 static UINT period (const struct itimerval* it, UINT denom) 1915 static UINT period (const struct itimerval* it, UINT denom)
2070 p_file->file_base = (char*) file_base; 2057 p_file->file_base = (char*) file_base;
2071 2058
2072 return TRUE; 2059 return TRUE;
2073 } 2060 }
2074 2061
2075 #if 1 /* !defined(__MINGW32__) */ 2062 #if 1 /* !defined(MINGW) */
2076 /* Return pointer to section header for section containing the given 2063 /* Return pointer to section header for section containing the given
2077 relative virtual address. */ 2064 relative virtual address. */
2078 static IMAGE_SECTION_HEADER * 2065 static IMAGE_SECTION_HEADER *
2079 rva_to_section (DWORD rva, IMAGE_NT_HEADERS * nt_header) 2066 rva_to_section (DWORD rva, IMAGE_NT_HEADERS * nt_header)
2080 { 2067 {
2081 /* Synched with FSF 20.6. We added MINGW32 stuff. */ 2068 /* Synched with FSF 20.6. We added MINGW stuff. */
2082 PIMAGE_SECTION_HEADER section; 2069 PIMAGE_SECTION_HEADER section;
2083 int i; 2070 int i;
2084 2071
2085 section = IMAGE_FIRST_SECTION (nt_header); 2072 section = IMAGE_FIRST_SECTION (nt_header);
2086 2073
2105 2092
2106 void 2093 void
2107 mswindows_executable_type (const char * filename, int * is_dos_app, 2094 mswindows_executable_type (const char * filename, int * is_dos_app,
2108 int * is_cygnus_app) 2095 int * is_cygnus_app)
2109 { 2096 {
2110 /* Synched with FSF 20.6. We added MINGW32 stuff and casts. */ 2097 /* Synched with FSF 20.6. We added MINGW stuff and casts. */
2111 file_data executable; 2098 file_data executable;
2112 char * p; 2099 char * p;
2113 2100
2114 /* Default values in case we can't tell for sure. */ 2101 /* Default values in case we can't tell for sure. */
2115 *is_dos_app = FALSE; 2102 *is_dos_app = FALSE;
2141 /* Look for DOS .exe signature - if found, we must also check that 2128 /* Look for DOS .exe signature - if found, we must also check that
2142 it isn't really a 16- or 32-bit Windows exe, since both formats 2129 it isn't really a 16- or 32-bit Windows exe, since both formats
2143 start with a DOS program stub. Note that 16-bit Windows 2130 start with a DOS program stub. Note that 16-bit Windows
2144 executables use the OS/2 1.x format. */ 2131 executables use the OS/2 1.x format. */
2145 2132
2146 #if 0 /* defined( __MINGW32__ ) */ 2133 #if 0 /* defined( MINGW ) */
2147 /* mingw32 doesn't have enough headers to detect cygwin 2134 /* mingw32 doesn't have enough headers to detect cygwin
2148 apps, just do what we can. */ 2135 apps, just do what we can. */
2149 FILHDR * exe_header; 2136 FILHDR * exe_header;
2150 2137
2151 exe_header = (FILHDR*) executable.file_base; 2138 exe_header = (FILHDR*) executable.file_base;