comparison src/sysdep.c @ 9794:64a874af5a58

[WINDOWSNT]: Add includes for NT. Define _P_WAIT. Declare _spawnlp, _getpid. [WINDOWSNT] (select, strerror, vfork): Don't use these definitions. (init_sys_modes): Test DOS_NT, not MSDOS. (emacs_get_tty, emacs_set_tty,(child_setup_tty, init_baud_rate): Ditto. (sys_subshell) [WINDOWSNT]: Use _spawnlp. not vfork. (wait_for_termination) [WINDOWSNT]: Use wait. (discard_tty_input) [WINDOWSNT]: Do nothing at all.
author Richard M. Stallman <rms@gnu.org>
date Tue, 01 Nov 1994 08:39:49 +0000
parents 31f317386c4c
children cd2db9aeeb25
comparison
equal deleted inserted replaced
9793:28267fcc61be 9794:64a874af5a58
37 #define sys_write write 37 #define sys_write write
38 #endif /* `read' is not a macro */ 38 #endif /* `read' is not a macro */
39 39
40 #undef read 40 #undef read
41 #undef write 41 #undef write
42
43 #ifdef WINDOWSNT
44 #define read _read
45 #define write _write
46 #include <windows.h>
47 extern int errno;
48 #endif /* not WINDOWSNT */
42 49
43 #ifndef close 50 #ifndef close
44 #define sys_close close 51 #define sys_close close
45 #else 52 #else
46 #undef close 53 #undef close
95 #endif 102 #endif
96 #undef F_SETFL 103 #undef F_SETFL
97 #ifndef RAB$C_BID 104 #ifndef RAB$C_BID
98 #include <rab.h> 105 #include <rab.h>
99 #endif 106 #endif
100 #define MAXIOSIZE ( 32 * PAGESIZE ) /* Don't I/O more than 32 blocks at a time */ 107 #define MAXIOSIZE (32 * PAGESIZE) /* Don't I/O more than 32 blocks at a time */
101 #endif /* VMS */ 108 #endif /* VMS */
102 109
103 #ifndef BSD4_1 110 #ifndef BSD4_1
104 #ifdef BSD /* this is done this way to avoid defined (BSD) || defined (USG) 111 #ifdef BSD /* this is done this way to avoid defined (BSD) || defined (USG)
105 because the vms compiler doesn't grok `defined' */ 112 because the vms compiler doesn't grok `defined' */
147 #include "termhooks.h" 154 #include "termhooks.h"
148 #include "termchar.h" 155 #include "termchar.h"
149 #include "termopts.h" 156 #include "termopts.h"
150 #include "dispextern.h" 157 #include "dispextern.h"
151 #include "process.h" 158 #include "process.h"
159
160 #ifdef WINDOWSNT
161 #include <direct.h>
162 /* In process.h which conflicts with the local copy. */
163 #define _P_WAIT 0
164 int _CRTAPI1 _spawnlp (int, const char *, const char *, ...);
165 int _CRTAPI1 _getpid (void);
166 #endif
152 167
153 #ifdef NONSYSTEM_DIR_LIBRARY 168 #ifdef NONSYSTEM_DIR_LIBRARY
154 #include "ndir.h" 169 #include "ndir.h"
155 #endif /* NONSYSTEM_DIR_LIBRARY */ 170 #endif /* NONSYSTEM_DIR_LIBRARY */
156 171
208 223
209 /* Discard pending input on descriptor input_fd. */ 224 /* Discard pending input on descriptor input_fd. */
210 225
211 discard_tty_input () 226 discard_tty_input ()
212 { 227 {
228 #ifndef WINDOWSNT
213 struct emacs_tty buf; 229 struct emacs_tty buf;
214 230
215 if (noninteractive) 231 if (noninteractive)
216 return; 232 return;
217 233
230 { 246 {
231 int zero = 0; 247 int zero = 0;
232 ioctl (input_fd, TIOCFLUSH, &zero); 248 ioctl (input_fd, TIOCFLUSH, &zero);
233 } 249 }
234 #else /* not Apollo */ 250 #else /* not Apollo */
235 #ifdef MSDOS /* Demacs 1.1.1 91/10/16 HIRANO Satoshi */ 251 #ifdef MSDOS /* Demacs 1.1.1 91/10/16 HIRANO Satoshi */
236 while (dos_keyread () != -1) 252 while (dos_keyread () != -1)
237 ; 253 ;
238 #else /* not MSDOS */ 254 #else /* not MSDOS */
239 EMACS_GET_TTY (input_fd, &buf); 255 EMACS_GET_TTY (input_fd, &buf);
240 EMACS_SET_TTY (input_fd, &buf, 0); 256 EMACS_SET_TTY (input_fd, &buf, 0);
241 #endif /* not MSDOS */ 257 #endif /* not MSDOS */
242 #endif /* not Apollo */ 258 #endif /* not Apollo */
243 #endif /* not VMS */ 259 #endif /* not VMS */
260 #endif /* not WINDOWSNT */
244 } 261 }
245 262
246 #ifdef SIGTSTP 263 #ifdef SIGTSTP
247 264
248 /* Arrange for character C to be read as the next input from 265 /* Arrange for character C to be read as the next input from
268 { 285 {
269 if (noninteractive) 286 if (noninteractive)
270 ospeed = 0; 287 ospeed = 0;
271 else 288 else
272 { 289 {
273 #ifdef MSDOS 290 #ifdef DOS_NT
274 ospeed = 15; 291 ospeed = 15;
275 #else 292 #else /* not DOS_NT */
276 #ifdef VMS 293 #ifdef VMS
277 struct sensemode sg; 294 struct sensemode sg;
278 295
279 SYS$QIOW (0, input_fd, IO$_SENSEMODE, &sg, 0, 0, 296 SYS$QIOW (0, input_fd, IO$_SENSEMODE, &sg, 0, 0,
280 &sg.class, 12, 0, 0, 0, 0 ); 297 &sg.class, 12, 0, 0, 0, 0 );
310 abort (); 327 abort ();
311 ospeed = sg.sg_ospeed; 328 ospeed = sg.sg_ospeed;
312 #endif /* not HAVE_TERMIO */ 329 #endif /* not HAVE_TERMIO */
313 #endif /* not HAVE_TERMIOS */ 330 #endif /* not HAVE_TERMIOS */
314 #endif /* not VMS */ 331 #endif /* not VMS */
315 #endif /* not MSDOS */ 332 #endif /* not DOS_NT */
316 } 333 }
317 334
318 baud_rate = (ospeed < sizeof baud_convert / sizeof baud_convert[0] 335 baud_rate = (ospeed < sizeof baud_convert / sizeof baud_convert[0]
319 ? baud_convert[ospeed] : 9600); 336 ? baud_convert[ospeed] : 9600);
320 if (baud_rate == 0) 337 if (baud_rate == 0)
321 baud_rate = 1200; 338 baud_rate = 1200;
322 } 339 }
323 340
324 /*ARGSUSED*/ 341 /*ARGSUSED*/
344 } 361 }
345 362
346 #endif /* not subprocesses */ 363 #endif /* not subprocesses */
347 364
348 int wait_debugging; /* Set nonzero to make following function work under dbx 365 int wait_debugging; /* Set nonzero to make following function work under dbx
349 (at least for bsd). */ 366 (at least for bsd). */
350 367
351 SIGTYPE 368 SIGTYPE
352 wait_for_termination_signal () 369 wait_for_termination_signal ()
353 {} 370 {}
354 371
375 termination of subprocesses, perhaps involving a kernel bug too, 392 termination of subprocesses, perhaps involving a kernel bug too,
376 but no idea what it is. Just as a hunch we signal SIGCHLD to see 393 but no idea what it is. Just as a hunch we signal SIGCHLD to see
377 if that causes the problem to go away or get worse. */ 394 if that causes the problem to go away or get worse. */
378 sigsetmask (sigmask (SIGCHLD)); 395 sigsetmask (sigmask (SIGCHLD));
379 if (0 > kill (pid, 0)) 396 if (0 > kill (pid, 0))
380 { 397 {
381 sigsetmask (SIGEMPTYMASK); 398 sigsetmask (SIGEMPTYMASK);
382 kill (getpid (), SIGCHLD); 399 kill (getpid (), SIGCHLD);
383 break; 400 break;
384 } 401 }
385 if (wait_debugging) 402 if (wait_debugging)
390 #if defined (UNIPLUS) 407 #if defined (UNIPLUS)
391 if (0 > kill (pid, 0)) 408 if (0 > kill (pid, 0))
392 break; 409 break;
393 wait (0); 410 wait (0);
394 #else /* neither BSD nor UNIPLUS: random sysV */ 411 #else /* neither BSD nor UNIPLUS: random sysV */
395 #ifdef POSIX_SIGNALS /* would this work for LINUX as well? */ 412 #ifdef POSIX_SIGNALS /* would this work for LINUX as well? */
396 sigblock (sigmask (SIGCHLD)); 413 sigblock (sigmask (SIGCHLD));
397 if (0 > kill (pid, 0)) 414 if (0 > kill (pid, 0))
398 { 415 {
399 sigunblock (sigmask (SIGCHLD)); 416 sigunblock (sigmask (SIGCHLD));
400 break; 417 break;
408 sigrelse (SIGCHLD); 425 sigrelse (SIGCHLD);
409 break; 426 break;
410 } 427 }
411 sigpause (SIGCHLD); 428 sigpause (SIGCHLD);
412 #else /* not HAVE_SYSV_SIGPAUSE */ 429 #else /* not HAVE_SYSV_SIGPAUSE */
430 #ifdef WINDOWSNT
431 wait (0);
432 break;
433 #else /* not WINDOWSNT */
413 if (0 > kill (pid, 0)) 434 if (0 > kill (pid, 0))
414 break; 435 break;
415 /* Using sleep instead of pause avoids timing error. 436 /* Using sleep instead of pause avoids timing error.
416 If the inferior dies just before the sleep, 437 If the inferior dies just before the sleep,
417 we lose just one second. */ 438 we lose just one second. */
418 sleep (1); 439 sleep (1);
440 #endif /* not WINDOWSNT */
419 #endif /* not HAVE_SYSV_SIGPAUSE */ 441 #endif /* not HAVE_SYSV_SIGPAUSE */
420 #endif /* not POSIX_SIGNALS */ 442 #endif /* not POSIX_SIGNALS */
421 #endif /* not UNIPLUS */ 443 #endif /* not UNIPLUS */
422 #endif /* not BSD, and not HPUX version >= 6 */ 444 #endif /* not BSD, and not HPUX version >= 6 */
423 #endif /* not VMS */ 445 #endif /* not VMS */
471 in Emacs. No padding needed for insertion into an Emacs buffer. */ 493 in Emacs. No padding needed for insertion into an Emacs buffer. */
472 494
473 child_setup_tty (out) 495 child_setup_tty (out)
474 int out; 496 int out;
475 { 497 {
476 #ifndef MSDOS 498 #ifndef DOS_NT
477 struct emacs_tty s; 499 struct emacs_tty s;
478 500
479 EMACS_GET_TTY (out, &s); 501 EMACS_GET_TTY (out, &s);
480 502
481 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS) 503 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
559 { 581 {
560 int zero = 0; 582 int zero = 0;
561 ioctl (out, FIOASYNC, &zero); 583 ioctl (out, FIOASYNC, &zero);
562 } 584 }
563 #endif /* RTU */ 585 #endif /* RTU */
564 #endif /* not MSDOS */ 586 #endif /* not DOS_NT */
565 } 587 }
566 #endif /* not VMS */ 588 #endif /* not VMS */
567 589
568 #endif /* subprocesses */ 590 #endif /* subprocesses */
569 591
684 bcopy (XSTRING (dir)->data, str, len); 706 bcopy (XSTRING (dir)->data, str, len);
685 if (str[len - 1] != '/') str[len++] = '/'; 707 if (str[len - 1] != '/') str[len++] = '/';
686 str[len] = 0; 708 str[len] = 0;
687 xyzzy: 709 xyzzy:
688 710
711 #ifdef WINDOWSNT
712 pid = -1;
713 #else /* not WINDOWSNT */
689 pid = vfork (); 714 pid = vfork ();
690 715
691 if (pid == -1) 716 if (pid == -1)
692 error ("Can't spawn subshell"); 717 error ("Can't spawn subshell");
693 if (pid == 0) 718 if (pid == 0)
719 #endif /* not WINDOWSNT */
694 { 720 {
695 char *sh; 721 char *sh;
696 722
697 #ifdef MSDOS /* MW, Aug 1993 */ 723 #ifdef MSDOS /* MW, Aug 1993 */
698 getwd (oldwd); 724 getwd (oldwd);
699 #endif 725 #endif
700 sh = (char *) egetenv ("SHELL"); 726 sh = (char *) egetenv ("SHELL");
701 if (sh == 0) 727 if (sh == 0)
702 sh = "sh"; 728 sh = "sh";
716 if (emacs_priority < 0) 742 if (emacs_priority < 0)
717 nice (-emacs_priority); 743 nice (-emacs_priority);
718 } 744 }
719 #endif 745 #endif
720 746
721 #ifdef MSDOS /* Demacs 1.1.2 91/10/20 Manabu Higashida */ 747 #ifdef MSDOS /* Demacs 1.1.2 91/10/20 Manabu Higashida */
722 st = system (sh); 748 st = system (sh);
723 chdir (oldwd); 749 chdir (oldwd);
724 if (st) 750 if (st)
725 report_file_error ("Can't execute subshell", Fcons (build_string (sh), Qnil)); 751 report_file_error ("Can't execute subshell", Fcons (build_string (sh), Qnil));
726 #else /* not MSDOS */ 752 #else /* not MSDOS */
753 #ifdef WINDOWSNT
754 restore_console ();
755
756 /* Waits for process completion */
757 pid = _spawnlp (_P_WAIT, sh, sh, NULL);
758 if (pid == -1)
759 write (1, "Can't execute subshell", 22);
760
761 take_console ();
762 #else /* not WINDOWSNT */
727 execlp (sh, sh, 0); 763 execlp (sh, sh, 0);
728 write (1, "Can't execute subshell", 22); 764 write (1, "Can't execute subshell", 22);
729 _exit (1); 765 _exit (1);
766 #endif /* not WINDOWSNT */
730 #endif /* not MSDOS */ 767 #endif /* not MSDOS */
731 } 768 }
732 769
733 save_signal_handlers (saved_handlers); 770 save_signal_handlers (saved_handlers);
734 synch_process_alive = 1; 771 synch_process_alive = 1;
961 &settings->main.class, 12, 0, 0, 0, 0) 998 &settings->main.class, 12, 0, 0, 0, 0)
962 & 1)) 999 & 1))
963 return -1; 1000 return -1;
964 1001
965 #else 1002 #else
966 #ifndef MSDOS 1003 #ifndef DOS_NT
967 /* I give up - I hope you have the BSD ioctls. */ 1004 /* I give up - I hope you have the BSD ioctls. */
968 if (ioctl (fd, TIOCGETP, &settings->main) < 0) 1005 if (ioctl (fd, TIOCGETP, &settings->main) < 0)
969 return -1; 1006 return -1;
970 #endif /* not MSDOS */ 1007 #endif /* not DOS_NT */
971 #endif 1008 #endif
972 #endif 1009 #endif
973 #endif 1010 #endif
974 1011
975 /* Suivant - Do we have to get struct ltchars data? */ 1012 /* Suivant - Do we have to get struct ltchars data? */
1053 &settings->main.class, 12, 0, 0, 0, 0) 1090 &settings->main.class, 12, 0, 0, 0, 0)
1054 & 1)) 1091 & 1))
1055 return -1; 1092 return -1;
1056 1093
1057 #else 1094 #else
1058 #ifndef MSDOS 1095 #ifndef DOS_NT
1059 /* I give up - I hope you have the BSD ioctls. */ 1096 /* I give up - I hope you have the BSD ioctls. */
1060 if (ioctl (fd, (waitp) ? TIOCSETP : TIOCSETN, &settings->main) < 0) 1097 if (ioctl (fd, (waitp) ? TIOCSETP : TIOCSETN, &settings->main) < 0)
1061 return -1; 1098 return -1;
1062 #endif /* not MSDOS */ 1099 #endif /* not DOS_NT */
1063 1100
1064 #endif 1101 #endif
1065 #endif 1102 #endif
1066 #endif 1103 #endif
1067 1104
1280 tty.main.tt_char |= TT$M_TTSYNC; 1317 tty.main.tt_char |= TT$M_TTSYNC;
1281 else 1318 else
1282 tty.main.tt_char &= ~TT$M_TTSYNC; 1319 tty.main.tt_char &= ~TT$M_TTSYNC;
1283 tty.main.tt2_char |= TT2$M_PASTHRU | TT2$M_XON; 1320 tty.main.tt2_char |= TT2$M_PASTHRU | TT2$M_XON;
1284 #else /* not VMS (BSD, that is) */ 1321 #else /* not VMS (BSD, that is) */
1285 #ifndef MSDOS 1322 #ifndef DOS_NT
1286 tty.main.sg_flags &= ~(ECHO | CRMOD | XTABS); 1323 tty.main.sg_flags &= ~(ECHO | CRMOD | XTABS);
1287 if (meta_key) 1324 if (meta_key)
1288 tty.main.sg_flags |= ANYP; 1325 tty.main.sg_flags |= ANYP;
1289 tty.main.sg_flags |= interrupt_input ? RAW : CBREAK; 1326 tty.main.sg_flags |= interrupt_input ? RAW : CBREAK;
1290 #endif 1327 #endif /* not DOS_NT */
1291 #endif /* not VMS (BSD, that is) */ 1328 #endif /* not VMS (BSD, that is) */
1292 #endif /* not HAVE_TERMIO */ 1329 #endif /* not HAVE_TERMIO */
1293 1330
1294 /* If going to use CBREAK mode, we must request C-g to interrupt 1331 /* If going to use CBREAK mode, we must request C-g to interrupt
1295 and turn off start and stop chars, etc. If not going to use 1332 and turn off start and stop chars, etc. If not going to use
2179 #endif /* not BSD4_1 */ 2216 #endif /* not BSD4_1 */
2180 if (read_alarm_should_throw) 2217 if (read_alarm_should_throw)
2181 longjmp (read_alarm_throw, 1); 2218 longjmp (read_alarm_throw, 1);
2182 } 2219 }
2183 2220
2221 #ifndef WINDOWSNT
2184 /* Only rfds are checked. */ 2222 /* Only rfds are checked. */
2185 int 2223 int
2186 select (nfds, rfds, wfds, efds, timeout) 2224 select (nfds, rfds, wfds, efds, timeout)
2187 int nfds; 2225 int nfds;
2188 int *rfds, *wfds, *efds, *timeout; 2226 int *rfds, *wfds, *efds, *timeout;
2309 if (*local_timeout == 0) /* Stop on timer being cleared */ 2347 if (*local_timeout == 0) /* Stop on timer being cleared */
2310 break; 2348 break;
2311 } 2349 }
2312 return ravail; 2350 return ravail;
2313 } 2351 }
2352 #endif /* not WINDOWSNT */
2314 2353
2315 /* Read keyboard input into the standard buffer, 2354 /* Read keyboard input into the standard buffer,
2316 waiting for at least one character. */ 2355 waiting for at least one character. */
2317 2356
2318 /* Make all keyboard buffers much bigger when using X windows. */ 2357 /* Make all keyboard buffers much bigger when using X windows. */
2799 #endif /* SHAREABLE_LIB_BUG */ 2838 #endif /* SHAREABLE_LIB_BUG */
2800 #endif /* LINK_CRTL_SHARE */ 2839 #endif /* LINK_CRTL_SHARE */
2801 #endif /* VMS */ 2840 #endif /* VMS */
2802 2841
2803 #ifndef HAVE_STRERROR 2842 #ifndef HAVE_STRERROR
2843 #ifndef WINDOWSNT
2804 char * 2844 char *
2805 strerror (errnum) 2845 strerror (errnum)
2806 int errnum; 2846 int errnum;
2807 { 2847 {
2808 extern char *sys_errlist[]; 2848 extern char *sys_errlist[];
2810 2850
2811 if (errnum >= 0 && errnum < sys_nerr) 2851 if (errnum >= 0 && errnum < sys_nerr)
2812 return sys_errlist[errnum]; 2852 return sys_errlist[errnum];
2813 return (char *) "Unknown error"; 2853 return (char *) "Unknown error";
2814 } 2854 }
2815 2855 #endif /* not WINDOWSNT */
2816 #endif /* ! HAVE_STRERROR */ 2856 #endif /* ! HAVE_STRERROR */
2817 2857
2818 #ifdef INTERRUPTIBLE_OPEN 2858 #ifdef INTERRUPTIBLE_OPEN
2819 2859
2820 int 2860 int
2891 } 2931 }
2892 2932
2893 #endif /* INTERRUPTIBLE_IO */ 2933 #endif /* INTERRUPTIBLE_IO */
2894 2934
2895 #ifndef HAVE_VFORK 2935 #ifndef HAVE_VFORK
2896 2936 #ifndef WINDOWSNT
2897 /* 2937 /*
2898 * Substitute fork for vfork on USG flavors. 2938 * Substitute fork for vfork on USG flavors.
2899 */ 2939 */
2900 2940
2901 vfork () 2941 vfork ()
2902 { 2942 {
2903 return (fork ()); 2943 return (fork ());
2904 } 2944 }
2905 2945 #endif /* not WINDOWSNT */
2906 #endif /* not HAVE_VFORK */ 2946 #endif /* not HAVE_VFORK */
2907 2947
2908 #ifdef USG 2948 #ifdef USG
2909 /* 2949 /*
2910 * All of the following are for USG. 2950 * All of the following are for USG.
3660 } 3700 }
3661 3701
3662 #else /* not VMS4_4 */ 3702 #else /* not VMS4_4 */
3663 3703
3664 #include <prvdef.h> 3704 #include <prvdef.h>
3665 #define ACE$M_WRITE 2 3705 #define ACE$M_WRITE 2
3666 #define ACE$C_KEYID 1 3706 #define ACE$C_KEYID 1
3667 3707
3668 static unsigned short memid, grpid; 3708 static unsigned short memid, grpid;
3669 static unsigned int uic; 3709 static unsigned int uic;
3670 3710
3671 /* Called from init_sys_modes, so it happens not very often 3711 /* Called from init_sys_modes, so it happens not very often
3694 return -1; 3734 return -1;
3695 memid = uic & 0xFFFF; 3735 memid = uic & 0xFFFF;
3696 grpid = uic >> 16; 3736 grpid = uic >> 16;
3697 } 3737 }
3698 3738
3699 if (type != 2) /* not checking write access */ 3739 if (type != 2) /* not checking write access */
3700 return access (filename, type); 3740 return access (filename, type);
3701 3741
3702 /* Check write protection. */ 3742 /* Check write protection. */
3703 3743
3704 #define CHECKPRIV(bit) (prvmask.bit) 3744 #define CHECKPRIV(bit) (prvmask.bit)
3705 #define WRITEABLE(field) (! ((xab.xab$w_pro >> field) & XAB$M_NOWRITE)) 3745 #define WRITEABLE(field) (! ((xab.xab$w_pro >> field) & XAB$M_NOWRITE))
3706 3746
3707 /* Find privilege bits */ 3747 /* Find privilege bits */
3708 status = SYS$SETPRV (0, 0, 0, prvmask); 3748 status = SYS$SETPRV (0, 0, 0, prvmask);
3709 if (! (status & 1)) 3749 if (! (status & 1))
3710 error ("Unable to find privileges: %s", vmserrstr (status)); 3750 error ("Unable to find privileges: %s", vmserrstr (status));