comparison src/sysdep.c @ 290:c9fe270a4101 r21-0b43

Import from CVS: tag r21-0b43
author cvs
date Mon, 13 Aug 2007 10:36:47 +0200
parents e11d67e05968
children 7c94d56991e1
comparison
equal deleted inserted replaced
289:6e6992ccc4b6 290:c9fe270a4101
411 and nonzero means something different. */ 411 and nonzero means something different. */
412 ioctl (channel, TIOCFLUSH, &zero); 412 ioctl (channel, TIOCFLUSH, &zero);
413 #endif 413 #endif
414 } 414 }
415 415
416 #ifndef MSDOS
417 #ifndef WINDOWSNT 416 #ifndef WINDOWSNT
418 /* Set up the terminal at the other end of a pseudo-terminal that 417 /* Set up the terminal at the other end of a pseudo-terminal that
419 we will be controlling an inferior through. 418 we will be controlling an inferior through.
420 It should not echo or do line-editing, since that is done 419 It should not echo or do line-editing, since that is done
421 in Emacs. No padding needed for insertion into an Emacs buffer. */ 420 in Emacs. No padding needed for insertion into an Emacs buffer. */
524 ioctl (out, FIOASYNC, &zero); 523 ioctl (out, FIOASYNC, &zero);
525 } 524 }
526 #endif /* RTU */ 525 #endif /* RTU */
527 } 526 }
528 #endif /* WINDOWSNT */ 527 #endif /* WINDOWSNT */
529 #endif /* not MSDOS */
530 528
531 #endif /* not NO_SUBPROCESSES */ 529 #endif /* not NO_SUBPROCESSES */
532 530
533 531
534 #if !defined (SIGTSTP) && !defined (USG_JOBCTRL) 532 #if !defined (SIGTSTP) && !defined (USG_JOBCTRL)
577 575
578 /* Fork a subshell. */ 576 /* Fork a subshell. */
579 static void 577 static void
580 sys_subshell (void) 578 sys_subshell (void)
581 { 579 {
582 #ifdef MSDOS
583 int st;
584 char oldwd[MAXPATHLEN+1]; /* Fixed length is safe on MSDOS. */
585 #endif /* MSDOS */
586 int pid; 580 int pid;
587 struct save_signal saved_handlers[5]; 581 struct save_signal saved_handlers[5];
588 Lisp_Object dir; 582 Lisp_Object dir;
589 unsigned char *str = 0; 583 unsigned char *str = 0;
590 int len; 584 int len;
633 627
634 #endif /* not WINDOWSNT */ 628 #endif /* not WINDOWSNT */
635 { 629 {
636 char *sh = 0; 630 char *sh = 0;
637 631
638 #ifdef MSDOS /* MW, Aug 1993 */
639 getwd (oldwd);
640 if (sh == 0)
641 sh = (char *) egetenv ("SUSPEND"); /* KFS, 1994-12-14 */
642 #endif
643 if (sh == 0) 632 if (sh == 0)
644 sh = (char *) egetenv ("SHELL"); 633 sh = (char *) egetenv ("SHELL");
645 if (sh == 0) 634 if (sh == 0)
646 sh = "sh"; 635 sh = "sh";
647 636
656 #ifdef SET_EMACS_PRIORITY 645 #ifdef SET_EMACS_PRIORITY
657 if (emacs_priority != 0) 646 if (emacs_priority != 0)
658 nice (-emacs_priority); /* Give the new shell the default priority */ 647 nice (-emacs_priority); /* Give the new shell the default priority */
659 #endif 648 #endif
660 649
661 #ifdef MSDOS
662 st = system (sh);
663 sys_chdir (oldwd);
664 #if 0 /* This is also reported if last command executed in subshell failed, KFS */
665 if (st)
666 report_file_error ("Can't execute subshell",
667 Fcons (build_string (sh), Qnil));
668 #endif
669 #else /* not MSDOS */
670 #ifdef WINDOWSNT 650 #ifdef WINDOWSNT
671 /* Waits for process completion */ 651 /* Waits for process completion */
672 pid = _spawnlp (_P_WAIT, sh, sh, NULL); 652 pid = _spawnlp (_P_WAIT, sh, sh, NULL);
673 if (pid == -1) 653 if (pid == -1)
674 write (1, "Can't execute subshell", 22); 654 write (1, "Can't execute subshell", 22);
675 655
676 #if 0
677 /* This relates to the GNU Emacs console port, not required under X ? */
678 take_console ();
679 #endif
680 #else /* not WINDOWSNT */ 656 #else /* not WINDOWSNT */
681 execlp (sh, sh, 0); 657 execlp (sh, sh, 0);
682 write (1, "Can't execute subshell", 22); 658 write (1, "Can't execute subshell", 22);
683 _exit (1); 659 _exit (1);
684 #endif /* not WINDOWSNT */ 660 #endif /* not WINDOWSNT */
685 #endif /* not MSDOS */
686 } 661 }
687 662
688 save_signal_handlers (saved_handlers); 663 save_signal_handlers (saved_handlers);
689 synch_process_alive = 1; 664 synch_process_alive = 1;
690 #ifndef MSDOS
691 wait_for_termination (pid); 665 wait_for_termination (pid);
692 #endif
693 restore_signal_handlers (saved_handlers); 666 restore_signal_handlers (saved_handlers);
694 } 667 }
695 668
696 #endif /* !defined (SIGTSTP) && !defined (USG_JOBCTRL) */ 669 #endif /* !defined (SIGTSTP) && !defined (USG_JOBCTRL) */
697 670
699 672
700 /* Suspend the Emacs process; give terminal to its superior. */ 673 /* Suspend the Emacs process; give terminal to its superior. */
701 void 674 void
702 sys_suspend (void) 675 sys_suspend (void)
703 { 676 {
704 #if defined (SIGTSTP) && !defined (MSDOS) 677 #if defined (SIGTSTP)
705 { 678 {
706 int pgrp = EMACS_GET_PROCESS_GROUP (); 679 int pgrp = EMACS_GET_PROCESS_GROUP ();
707 EMACS_KILLPG (pgrp, SIGTSTP); 680 EMACS_KILLPG (pgrp, SIGTSTP);
708 } 681 }
709 682
728 { 701 {
729 /* I don't doubt that it is possible to suspend processes on 702 /* I don't doubt that it is possible to suspend processes on
730 * VMS machines or thost that use USG_JOBCTRL, 703 * VMS machines or thost that use USG_JOBCTRL,
731 * but I don't know how to do it, so... 704 * but I don't know how to do it, so...
732 */ 705 */
733 #if defined (SIGTSTP) && !defined (MSDOS) 706 #if defined (SIGTSTP)
734 kill(process, SIGTSTP); 707 kill(process, SIGTSTP);
735 #endif 708 #endif
736 } 709 }
737 710
738 711
926 899
927 #ifdef HAVE_TTY 900 #ifdef HAVE_TTY
928 assert (DEVICE_TTY_P (d)); 901 assert (DEVICE_TTY_P (d));
929 { 902 {
930 int input_fd = CONSOLE_TTY_DATA (con)->infd; 903 int input_fd = CONSOLE_TTY_DATA (con)->infd;
931 #if defined (MSDOS) || defined(WIN32) 904 #if defined (WINDOWSNT)
932 DEVICE_TTY_DATA (d)->ospeed = 15; 905 DEVICE_TTY_DATA (d)->ospeed = 15;
933 #elif defined (HAVE_TERMIOS) 906 #elif defined (HAVE_TERMIOS)
934 struct termios sg; 907 struct termios sg;
935 908
936 sg.c_cflag = B9600; 909 sg.c_cflag = B9600;
1371 #elif defined HAVE_TERMIO 1344 #elif defined HAVE_TERMIO
1372 /* The SYSV-style interface? */ 1345 /* The SYSV-style interface? */
1373 if (ioctl (fd, TCGETA, &settings->main) < 0) 1346 if (ioctl (fd, TCGETA, &settings->main) < 0)
1374 return -1; 1347 return -1;
1375 1348
1376 #elif !defined MSDOS && !defined(WIN32) 1349 #elif !defined (WINDOWSNT)
1377 /* I give up - I hope you have the BSD ioctls. */ 1350 /* I give up - I hope you have the BSD ioctls. */
1378 if (ioctl (fd, TIOCGETP, &settings->main) < 0) 1351 if (ioctl (fd, TIOCGETP, &settings->main) < 0)
1379 return -1; 1352 return -1;
1380 #endif /* HAVE_TCATTR */ 1353 #endif /* HAVE_TCATTR */
1381 1354
1444 #elif defined HAVE_TERMIO 1417 #elif defined HAVE_TERMIO
1445 /* The SYSV-style interface? */ 1418 /* The SYSV-style interface? */
1446 if (ioctl (fd, flushp ? TCSETAF : TCSETAW, &settings->main) < 0) 1419 if (ioctl (fd, flushp ? TCSETAF : TCSETAW, &settings->main) < 0)
1447 return -1; 1420 return -1;
1448 1421
1449 #elif !defined(MSDOS) && !defined(WIN32) 1422 #elif !defined (WINDOWSNT)
1450 /* I give up - I hope you have the BSD ioctls. */ 1423 /* I give up - I hope you have the BSD ioctls. */
1451 if (ioctl (fd, (flushp) ? TIOCSETP : TIOCSETN, &settings->main) < 0) 1424 if (ioctl (fd, (flushp) ? TIOCSETP : TIOCSETN, &settings->main) < 0)
1452 return -1; 1425 return -1;
1453 #endif /* HAVE_TCATTR */ 1426 #endif /* HAVE_TCATTR */
1454 1427
1627 or via TELNET or the like, but does no harm elsewhere. */ 1600 or via TELNET or the like, but does no harm elsewhere. */
1628 tty.main.c_iflag &= ~IGNBRK; 1601 tty.main.c_iflag &= ~IGNBRK;
1629 tty.main.c_iflag &= ~BRKINT; 1602 tty.main.c_iflag &= ~BRKINT;
1630 #endif /* AIX */ 1603 #endif /* AIX */
1631 #else /* if not HAVE_TERMIO */ 1604 #else /* if not HAVE_TERMIO */
1632 #if !defined(MSDOS) && !defined(WIN32) 1605 #if !defined (WINDOWSNT)
1633 con->tty_erase_char = make_char (tty.main.sg_erase); 1606 con->tty_erase_char = make_char (tty.main.sg_erase);
1634 tty.main.sg_flags &= ~(ECHO | CRMOD | XTABS); 1607 tty.main.sg_flags &= ~(ECHO | CRMOD | XTABS);
1635 if (TTY_FLAGS (con).meta_key) 1608 if (TTY_FLAGS (con).meta_key)
1636 tty.main.sg_flags |= ANYP; 1609 tty.main.sg_flags |= ANYP;
1637 /* #### should we be using RAW mode here? */ 1610 /* #### should we be using RAW mode here? */
1638 tty.main.sg_flags |= /* interrupt_input ? RAW : */ CBREAK; 1611 tty.main.sg_flags |= /* interrupt_input ? RAW : */ CBREAK;
1639 #endif /* not MSDOS or WIN32 */ 1612 #endif /* not WINDOWSNT */
1640 #endif /* not HAVE_TERMIO */ 1613 #endif /* not HAVE_TERMIO */
1641 1614
1642 /* If going to use CBREAK mode, we must request C-g to interrupt 1615 /* If going to use CBREAK mode, we must request C-g to interrupt
1643 and turn off start and stop chars, etc. If not going to use 1616 and turn off start and stop chars, etc. If not going to use
1644 CBREAK mode, do this anyway so as to turn off local flow 1617 CBREAK mode, do this anyway so as to turn off local flow
1672 #endif /* not HAVE_TERMIO */ 1645 #endif /* not HAVE_TERMIO */
1673 1646
1674 #ifdef HAVE_LTCHARS 1647 #ifdef HAVE_LTCHARS
1675 tty.ltchars = new_ltchars; 1648 tty.ltchars = new_ltchars;
1676 #endif /* HAVE_LTCHARS */ 1649 #endif /* HAVE_LTCHARS */
1677 #ifdef MSDOS
1678 internal_terminal_init ();
1679 dos_ttraw ();
1680 #endif
1681 1650
1682 EMACS_SET_TTY (input_fd, &tty, 0); 1651 EMACS_SET_TTY (input_fd, &tty, 0);
1683 1652
1684 /* This code added to insure that, if flow-control is not to be used, 1653 /* This code added to insure that, if flow-control is not to be used,
1685 we have an unlocked terminal at the start. */ 1654 we have an unlocked terminal at the start. */
1830 { 1799 {
1831 *widthp = size.ts_cols; 1800 *widthp = size.ts_cols;
1832 *heightp = size.ts_lines; 1801 *heightp = size.ts_lines;
1833 } 1802 }
1834 } 1803 }
1835 #elif defined MSDOS
1836 *widthp = FrameCols ();
1837 *heightp = FrameRows ();
1838
1839 #else /* system doesn't know size */ 1804 #else /* system doesn't know size */
1840 1805
1841 *widthp = 0; 1806 *widthp = 0;
1842 *heightp = 0; 1807 *heightp = 0;
1843 1808
1914 #endif 1879 #endif
1915 1880
1916 while (EMACS_SET_TTY (input_fd, &CONSOLE_TTY_DATA (con)->old_tty, 0) 1881 while (EMACS_SET_TTY (input_fd, &CONSOLE_TTY_DATA (con)->old_tty, 0)
1917 < 0 && errno == EINTR) 1882 < 0 && errno == EINTR)
1918 ; 1883 ;
1919
1920 #ifdef MSDOS
1921 dos_ttcooked ();
1922 #endif
1923 1884
1924 #ifdef SET_LINE_DISCIPLINE 1885 #ifdef SET_LINE_DISCIPLINE
1925 /* Ultrix's termios *ignores* any line discipline except TERMIODISC. 1886 /* Ultrix's termios *ignores* any line discipline except TERMIODISC.
1926 A different old line discipline is therefore not restored, yet. 1887 A different old line discipline is therefore not restored, yet.
1927 Restore the old line discipline by hand. */ 1888 Restore the old line discipline by hand. */
2592 /************************************************************************/ 2553 /************************************************************************/
2593 2554
2594 #define PATHNAME_CONVERT_OUT(path) \ 2555 #define PATHNAME_CONVERT_OUT(path) \
2595 GET_C_CHARPTR_EXT_FILENAME_DATA_ALLOCA ((CONST Bufbyte *) path, path) 2556 GET_C_CHARPTR_EXT_FILENAME_DATA_ALLOCA ((CONST Bufbyte *) path, path)
2596 2557
2597 /***** MSDOS versions are in msdos.c *****/
2598
2599 /***************** low-level calls ****************/ 2558 /***************** low-level calls ****************/
2600 2559
2601 /* 2560 /*
2602 * On USG systems the system calls are INTERRUPTIBLE by signals 2561 * On USG systems the system calls are INTERRUPTIBLE by signals
2603 * that the user program has elected to catch. Thus the system call 2562 * that the user program has elected to catch. Thus the system call
2626 va_start (ap, oflag); 2585 va_start (ap, oflag);
2627 mode = va_arg (ap, int); 2586 mode = va_arg (ap, int);
2628 va_end (ap); 2587 va_end (ap);
2629 2588
2630 PATHNAME_CONVERT_OUT (path); 2589 PATHNAME_CONVERT_OUT (path);
2631 #ifdef INTERRUPTIBLE_OPEN 2590 #if defined (WINDOWSNT)
2591 /* Make all handles non-inheritable */
2592 return open (path, oflag | _O_NOINHERIT, mode);
2593 #elif defined (INTERRUPTIBLE_OPEN)
2632 { 2594 {
2633 int rtnval; 2595 int rtnval;
2634 while ((rtnval = open (path, oflag, mode)) == -1 2596 while ((rtnval = open (path, oflag, mode)) == -1
2635 && (errno == EINTR)); 2597 && (errno == EINTR));
2636 return rtnval; 2598 return rtnval;
2637 } 2599 }
2638 #else 2600 #else
2639 return open (path, oflag, mode); 2601 return open (path, oflag, mode);
2640 #endif 2602 #endif
2641 } 2603 }
2642 #endif /* ENCAPSULATE_OPEN */ 2604 #endif /* ENCAPSULATE_OPEN */
2643 2605
2644 /* Like sys_open, only when open() is interrupted by EINTR, check for 2606 /* Like sys_open, only when open() is interrupted by EINTR, check for
2770 #ifdef ENCAPSULATE_FOPEN 2732 #ifdef ENCAPSULATE_FOPEN
2771 FILE * 2733 FILE *
2772 sys_fopen (CONST char *path, CONST char *type) 2734 sys_fopen (CONST char *path, CONST char *type)
2773 { 2735 {
2774 PATHNAME_CONVERT_OUT (path); 2736 PATHNAME_CONVERT_OUT (path);
2775 #ifdef INTERRUPTIBLE_OPEN 2737 #if defined (WINDOWSNT)
2738 {
2739 int fd;
2740 int oflag;
2741 const char * type_save = type;
2742
2743 /* Force all file handles to be non-inheritable. This is necessary to
2744 ensure child processes don't unwittingly inherit handles that might
2745 prevent future file access. */
2746
2747 if (type[0] == 'r')
2748 oflag = O_RDONLY;
2749 else if (type[0] == 'w' || type[0] == 'a')
2750 oflag = O_WRONLY | O_CREAT | O_TRUNC;
2751 else
2752 return 0;
2753
2754 /* Only do simplistic option parsing. */
2755 while (*++type)
2756 if (type[0] == '+')
2757 {
2758 oflag &= ~(O_RDONLY | O_WRONLY);
2759 oflag |= O_RDWR;
2760 }
2761 else if (type[0] == 'b')
2762 {
2763 oflag &= ~O_TEXT;
2764 oflag |= O_BINARY;
2765 }
2766 else if (type[0] == 't')
2767 {
2768 oflag &= ~O_BINARY;
2769 oflag |= O_TEXT;
2770 }
2771 else break;
2772
2773 fd = open (path, oflag | _O_NOINHERIT, 0644);
2774 if (fd < 0)
2775 return NULL;
2776
2777 return _fdopen (fd, type_save);
2778 }
2779 #elif defined (INTERRUPTIBLE_OPEN)
2776 { 2780 {
2777 FILE *rtnval; 2781 FILE *rtnval;
2778 while (!(rtnval = fopen (path, type)) && (errno == EINTR)); 2782 while (!(rtnval = fopen (path, type)) && (errno == EINTR));
2779 return rtnval; 2783 return rtnval;
2780 } 2784 }
2870 #ifdef ENCAPSULATE_CHDIR 2874 #ifdef ENCAPSULATE_CHDIR
2871 int 2875 int
2872 sys_chdir (CONST char *path) 2876 sys_chdir (CONST char *path)
2873 { 2877 {
2874 PATHNAME_CONVERT_OUT (path); 2878 PATHNAME_CONVERT_OUT (path);
2875 #ifdef MSDOS
2876 return dos_chdir (path);
2877 #else
2878 return chdir (path); 2879 return chdir (path);
2879 #endif
2880 } 2880 }
2881 #endif /* ENCAPSULATE_CHDIR */ 2881 #endif /* ENCAPSULATE_CHDIR */
2882 2882
2883 2883
2884 #ifdef ENCAPSULATE_MKDIR 2884 #ifdef ENCAPSULATE_MKDIR
2885 int 2885 int
2886 sys_mkdir (CONST char *path, mode_t mode) 2886 sys_mkdir (CONST char *path, mode_t mode)
2887 { 2887 {
2888 PATHNAME_CONVERT_OUT (path); 2888 PATHNAME_CONVERT_OUT (path);
2889 #ifdef WINDOWSNT
2890 return mkdir (path);
2891 #else
2889 return mkdir (path, mode); 2892 return mkdir (path, mode);
2893 #endif
2890 } 2894 }
2891 #endif /* ENCAPSULATE_MKDIR */ 2895 #endif /* ENCAPSULATE_MKDIR */
2892 2896
2893 2897
2894 #ifdef ENCAPSULATE_OPENDIR 2898 #ifdef ENCAPSULATE_OPENDIR
3078 int 3082 int
3079 sys_rename (CONST char *old, CONST char *new) 3083 sys_rename (CONST char *old, CONST char *new)
3080 { 3084 {
3081 PATHNAME_CONVERT_OUT (old); 3085 PATHNAME_CONVERT_OUT (old);
3082 PATHNAME_CONVERT_OUT (new); 3086 PATHNAME_CONVERT_OUT (new);
3087 #ifdef WINDOWSNT
3088 /* Windows rename fails if NEW exists */
3089 if (rename (old, new) == 0)
3090 return 0;
3091 if (errno != EEXIST)
3092 return -1;
3093 unlink (new);
3094 #endif /* WINDOWSNT */
3083 return rename (old, new); 3095 return rename (old, new);
3084 } 3096 }
3085 #endif /* ENCAPSULATE_RENAME */ 3097 #endif /* ENCAPSULATE_RENAME */
3086 3098
3087 3099
3345 *system_time = (((double) (curr_system_ticks - orig_system_ticks)) 3357 *system_time = (((double) (curr_system_ticks - orig_system_ticks))
3346 / ticks_per_second); 3358 / ticks_per_second);
3347 } 3359 }
3348 else 3360 else
3349 { 3361 {
3350 /* MS-DOS or equally lame OS */ 3362 /* A lame OS */
3351 *user_time = *real_time; 3363 *user_time = *real_time;
3352 *system_time = 0; 3364 *system_time = 0;
3353 } 3365 }
3354 } 3366 }
3355 3367