comparison src/nt.c @ 288:e11d67e05968 r21-0b42

Import from CVS: tag r21-0b42
author cvs
date Mon, 13 Aug 2007 10:35:54 +0200
parents c42ec1d1cded
children c9fe270a4101
comparison
equal deleted inserted replaced
287:13a0bd77a29d 288:e11d67e05968
31 #include <io.h> 31 #include <io.h>
32 #include <errno.h> 32 #include <errno.h>
33 #include <fcntl.h> 33 #include <fcntl.h>
34 #include <ctype.h> 34 #include <ctype.h>
35 #include <signal.h> 35 #include <signal.h>
36 #include <direct.h>
36 37
37 /* must include CRT headers *before* config.h */ 38 /* must include CRT headers *before* config.h */
38 /* ### I don't believe it - martin */ 39 /* ### I don't believe it - martin */
39 #include <config.h> 40 #include <config.h>
40 #include "systime.h" 41 #include "systime.h"
81 #if 0 82 #if 0
82 extern Lisp_Object Vwin32_generate_fake_inodes; 83 extern Lisp_Object Vwin32_generate_fake_inodes;
83 #endif 84 #endif
84 extern Lisp_Object Vmswindows_get_true_file_attributes; 85 extern Lisp_Object Vmswindows_get_true_file_attributes;
85 86
87 extern char *get_home_directory(void);
88
86 static char startup_dir[ MAXPATHLEN ]; 89 static char startup_dir[ MAXPATHLEN ];
87 90
88 /* Get the current working directory. */ 91 /* Get the current working directory. */
89 char * 92 char *
90 getwd (char *dir) 93 getwd (char *dir)
172 return &the_passwd; 175 return &the_passwd;
173 return NULL; 176 return NULL;
174 } 177 }
175 178
176 struct passwd * 179 struct passwd *
177 getpwnam (char *name) 180 getpwnam (const char *name)
178 { 181 {
179 struct passwd *pw; 182 struct passwd *pw;
180 183
181 pw = getpwuid (getuid ()); 184 pw = getpwuid (getuid ());
182 if (!pw) 185 if (!pw)
265 the_passwd.pw_uid = 123; 268 the_passwd.pw_uid = 123;
266 the_passwd.pw_gid = 123; 269 the_passwd.pw_gid = 123;
267 } 270 }
268 271
269 /* Ensure HOME and SHELL are defined. */ 272 /* Ensure HOME and SHELL are defined. */
273 #if 0
274 /*
275 * With XEmacs, setting $HOME is deprecated.
276 */
270 if (getenv ("HOME") == NULL) 277 if (getenv ("HOME") == NULL)
271 putenv ("HOME=c:/"); 278 putenv ("HOME=c:/");
279 #endif
272 if (getenv ("SHELL") == NULL) 280 if (getenv ("SHELL") == NULL)
273 putenv ((GetVersion () & 0x80000000) ? "SHELL=command" : "SHELL=cmd"); 281 putenv ((GetVersion () & 0x80000000) ? "SHELL=command" : "SHELL=cmd");
274 282
275 /* Set dir and shell from environment variables. */ 283 /* Set dir and shell from environment variables. */
276 strcpy (the_passwd.pw_dir, getenv ("HOME")); 284 strcpy (the_passwd.pw_dir, get_home_directory());
277 strcpy (the_passwd.pw_shell, getenv ("SHELL")); 285 strcpy (the_passwd.pw_shell, getenv ("SHELL"));
278 286
279 if (token) 287 if (token)
280 CloseHandle (token); 288 CloseHandle (token);
281 } 289 }
688 user enter it, so we define EMACS_CONFIGURATION to invoke this runtime 696 user enter it, so we define EMACS_CONFIGURATION to invoke this runtime
689 routine. */ 697 routine. */
690 698
691 static char configuration_buffer[32]; 699 static char configuration_buffer[32];
692 700
693 char * 701 const char *
694 get_emacs_configuration (void) 702 get_emacs_configuration (void)
695 { 703 {
696 char *arch, *oem, *os; 704 char *arch, *oem, *os;
697 705
698 /* Determine the processor type. */ 706 /* Determine the processor type. */
1120 static int dir_is_fat; 1128 static int dir_is_fat;
1121 static char dir_pathname[MAXPATHLEN+1]; 1129 static char dir_pathname[MAXPATHLEN+1];
1122 static WIN32_FIND_DATA dir_find_data; 1130 static WIN32_FIND_DATA dir_find_data;
1123 1131
1124 DIR * 1132 DIR *
1125 opendir (char *filename) 1133 opendir (const char *filename)
1126 { 1134 {
1127 DIR *dirp; 1135 DIR *dirp;
1128 1136
1129 /* Opening is done by FindFirstFile. However, a read is inherent to 1137 /* Opening is done by FindFirstFile. However, a read is inherent to
1130 this operation, so we defer the open until read time. */ 1138 this operation, so we defer the open until read time. */
1722 case FILE_TYPE_CHAR: 1730 case FILE_TYPE_CHAR:
1723 case FILE_TYPE_UNKNOWN: 1731 case FILE_TYPE_UNKNOWN:
1724 default: 1732 default:
1725 buf->st_mode = _S_IFCHR; 1733 buf->st_mode = _S_IFCHR;
1726 } 1734 }
1727 buf->st_nlink = info.nNumberOfLinks; 1735 buf->st_nlink = (short) info.nNumberOfLinks;
1728 /* Might as well use file index to fake inode values, but this 1736 /* Might as well use file index to fake inode values, but this
1729 is not guaranteed to be unique unless we keep a handle open 1737 is not guaranteed to be unique unless we keep a handle open
1730 all the time (even then there are situations where it is 1738 all the time (even then there are situations where it is
1731 not unique). Reputedly, there are at most 48 bits of info 1739 not unique). Reputedly, there are at most 48 bits of info
1732 (on NTFS, presumably less on FAT). */ 1740 (on NTFS, presumably less on FAT). */
1757 static DWORD gen_num = 0; 1765 static DWORD gen_num = 0;
1758 fake_inode = ++gen_num; 1766 fake_inode = ++gen_num;
1759 } 1767 }
1760 #endif 1768 #endif
1761 1769
1762 /* MSVC defines _ino_t to be short; other libc's might not. */ 1770 /* #### MSVC defines _ino_t to be short; other libc's might not. */
1763 if (sizeof (buf->st_ino) == 2) 1771 buf->st_ino = (unsigned short) (fake_inode ^ (fake_inode >> 16));
1764 buf->st_ino = fake_inode ^ (fake_inode >> 16);
1765 else
1766 buf->st_ino = fake_inode;
1767 1772
1768 /* consider files to belong to current user */ 1773 /* consider files to belong to current user */
1769 buf->st_uid = the_passwd.pw_uid; 1774 buf->st_uid = the_passwd.pw_uid;
1770 buf->st_gid = the_passwd.pw_gid; 1775 buf->st_gid = the_passwd.pw_gid;
1771 1776
1904 int 1909 int
1905 sys_pipe (int * phandles) 1910 sys_pipe (int * phandles)
1906 { 1911 {
1907 int rc; 1912 int rc;
1908 unsigned flags; 1913 unsigned flags;
1909 child_process * cp;
1910 1914
1911 /* make pipe handles non-inheritable; when we spawn a child, we 1915 /* make pipe handles non-inheritable; when we spawn a child, we
1912 replace the relevant handle with an inheritable one. Also put 1916 replace the relevant handle with an inheritable one. Also put
1913 pipes into binary mode; we will do text mode translation ourselves 1917 pipes into binary mode; we will do text mode translation ourselves
1914 if required. */ 1918 if required. */
1950 return STATUS_READ_ERROR; 1954 return STATUS_READ_ERROR;
1951 1955
1952 if ((fd_info[fd].flags & (FILE_PIPE | FILE_SOCKET)) == 0 1956 if ((fd_info[fd].flags & (FILE_PIPE | FILE_SOCKET)) == 0
1953 || (fd_info[fd].flags & FILE_READ) == 0) 1957 || (fd_info[fd].flags & FILE_READ) == 0)
1954 { 1958 {
1955 DebPrint (("_sys_read_ahead: internal error: fd %d is not a pipe or socket!\n", fd)); 1959 /* fd is not a pipe or socket */
1956 abort (); 1960 abort ();
1957 } 1961 }
1958 1962
1959 cp->status = STATUS_READ_IN_PROGRESS; 1963 cp->status = STATUS_READ_IN_PROGRESS;
1960 1964
2045 fd_info[fd].flags |= FILE_AT_EOF; 2049 fd_info[fd].flags |= FILE_AT_EOF;
2046 return nchars; 2050 return nchars;
2047 2051
2048 case STATUS_READ_READY: 2052 case STATUS_READ_READY:
2049 case STATUS_READ_IN_PROGRESS: 2053 case STATUS_READ_IN_PROGRESS:
2050 DebPrint (("sys_read called when read is in progress\n"));
2051 errno = EWOULDBLOCK; 2054 errno = EWOULDBLOCK;
2052 return -1; 2055 return -1;
2053 2056
2054 case STATUS_READ_SUCCEEDED: 2057 case STATUS_READ_SUCCEEDED:
2055 /* consume read-ahead char */ 2058 /* consume read-ahead char */
2061 2064
2062 case STATUS_READ_ACKNOWLEDGED: 2065 case STATUS_READ_ACKNOWLEDGED:
2063 break; 2066 break;
2064 2067
2065 default: 2068 default:
2066 DebPrint (("sys_read: bad status %d\n", current_status));
2067 errno = EBADF; 2069 errno = EBADF;
2068 return -1; 2070 return -1;
2069 } 2071 }
2070 2072
2071 if (fd_info[fd].flags & FILE_PIPE) 2073 if (fd_info[fd].flags & FILE_PIPE)
2168 return nchars; 2170 return nchars;
2169 } 2171 }
2170 2172
2171 2173
2172 void 2174 void
2173 term_ntproc () 2175 term_ntproc (int unused)
2174 { 2176 {
2175 } 2177 }
2176 2178
2177 void 2179 void
2178 init_ntproc () 2180 init_ntproc ()
2312 2314
2313 msw_sighandler msw_sigset (int nsig, msw_sighandler handler) 2315 msw_sighandler msw_sigset (int nsig, msw_sighandler handler)
2314 { 2316 {
2315 /* We delegate some signals to the system function */ 2317 /* We delegate some signals to the system function */
2316 if (nsig == SIGFPE || nsig == SIGABRT || nsig == SIGINT) 2318 if (nsig == SIGFPE || nsig == SIGABRT || nsig == SIGINT)
2317 { 2319 return signal (nsig, handler);
2318 signal (nsig, handler);
2319 return;
2320 }
2321 2320
2322 if (nsig < 0 || nsig > SIG_MAX) 2321 if (nsig < 0 || nsig > SIG_MAX)
2323 { 2322 {
2324 errno = EINVAL; 2323 errno = EINVAL;
2325 return; 2324 return NULL;
2326 } 2325 }
2327 2326
2328 /* Store handler ptr */ 2327 /* Store handler ptr */
2329 signal_handlers[nsig] = handler; 2328 {
2329 msw_sighandler old_handler = signal_handlers[nsig];
2330 signal_handlers[nsig] = handler;
2331 return old_handler;
2332 }
2330 } 2333 }
2331 2334
2332 int msw_sighold (int nsig) 2335 int msw_sighold (int nsig)
2333 { 2336 {
2334 if (nsig < 0 || nsig > SIG_MAX) 2337 if (nsig < 0 || nsig > SIG_MAX)