Mercurial > hg > xemacs-beta
comparison src/sysdep.c @ 412:697ef44129c6 r21-2-14
Import from CVS: tag r21-2-14
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:20:41 +0200 |
parents | de805c49cfc1 |
children | da8ed4261e83 |
comparison
equal
deleted
inserted
replaced
411:12e008d41344 | 412:697ef44129c6 |
---|---|
29 | 29 |
30 #define DONT_ENCAPSULATE | 30 #define DONT_ENCAPSULATE |
31 | 31 |
32 #include <config.h> | 32 #include <config.h> |
33 | 33 |
34 #ifdef WIN32_NATIVE | 34 #ifdef WINDOWSNT |
35 #ifdef MINGW | 35 #include <direct.h> |
36 #include <mingw32/process.h> | 36 #ifndef __MINGW32__ |
37 #else | |
38 /* <process.h> should not conflict with "process.h", as per ANSI definition. | 37 /* <process.h> should not conflict with "process.h", as per ANSI definition. |
39 This is not true with visual c though. The trick below works with | 38 This is not true though with visual c though. The trick below works with |
40 VC4.2b, 5.0 and 6.0. It assumes that VC is installed in a kind of | 39 VC4.2b and with VC5.0. It assumes that VC is installed in a kind of |
41 standard way, so include path ends with /include. | 40 standard way, so include files get to what/ever/path/include. |
42 | 41 |
43 Unfortunately, this must go before lisp.h, since process.h defines abort() | 42 Unfortunately, this must go before lisp.h, since process.h defines abort() |
44 which will conflict with the macro defined in lisp.h | 43 which will conflict with the macro defined in lisp.h |
45 */ | 44 */ |
46 #include <../include/process.h> | 45 #include <../include/process.h> |
47 #endif /* MINGW */ | 46 #else |
48 #endif /* WIN32_NATIVE */ | 47 #include <mingw32/process.h> |
48 #endif | |
49 #endif /* WINDOWSNT */ | |
49 | 50 |
50 #include "lisp.h" | 51 #include "lisp.h" |
52 | |
53 #include <stddef.h> | |
54 #include <stdlib.h> | |
51 | 55 |
52 /* ------------------------------- */ | 56 /* ------------------------------- */ |
53 /* basic includes */ | 57 /* basic includes */ |
54 /* ------------------------------- */ | 58 /* ------------------------------- */ |
55 | 59 |
76 #endif | 80 #endif |
77 #include "sysfile.h" | 81 #include "sysfile.h" |
78 #include "syswait.h" | 82 #include "syswait.h" |
79 #include "sysdir.h" | 83 #include "sysdir.h" |
80 #include "systime.h" | 84 #include "systime.h" |
81 #if defined(WIN32_NATIVE) || defined(CYGWIN) | 85 #if defined(WINDOWSNT) || defined(__CYGWIN32__) |
82 #include "syssignal.h" | 86 #include "syssignal.h" |
83 #endif | 87 #endif |
84 | 88 #ifndef WINDOWSNT |
85 #include "sysproc.h" | |
86 | |
87 #ifndef WIN32_NATIVE | |
88 #include <sys/times.h> | 89 #include <sys/times.h> |
89 #endif | 90 #endif |
90 | 91 |
91 #ifdef WIN32_NATIVE | 92 #ifdef WINDOWSNT |
92 #include <sys/utime.h> | 93 #include <sys/utime.h> |
94 #include <windows.h> | |
93 #include "ntheap.h" | 95 #include "ntheap.h" |
94 #include "nt.h" | |
95 #endif | 96 #endif |
96 | 97 |
97 /* ------------------------------- */ | 98 /* ------------------------------- */ |
98 /* TTY definitions */ | 99 /* TTY definitions */ |
99 /* ------------------------------- */ | 100 /* ------------------------------- */ |
232 #endif /* BSD */ | 233 #endif /* BSD */ |
233 | 234 |
234 #endif /* NO_SUBPROCESSES */ | 235 #endif /* NO_SUBPROCESSES */ |
235 | 236 |
236 | 237 |
237 #ifdef WIN32_NATIVE | 238 void |
238 void wait_for_termination (HANDLE pHandle) | 239 wait_for_termination (int pid) |
239 #else | |
240 void wait_for_termination (int pid) | |
241 #endif | |
242 { | 240 { |
243 /* #### With the new improved SIGCHLD handling stuff, there is much | 241 /* #### With the new improved SIGCHLD handling stuff, there is much |
244 less danger of race conditions and some of the comments below | 242 less danger of race conditions and some of the comments below |
245 don't apply. This should be updated. */ | 243 don't apply. This should be updated. */ |
246 | 244 |
346 - EINVAL (incorrect arguments), | 344 - EINVAL (incorrect arguments), |
347 which are both program bugs. | 345 which are both program bugs. |
348 | 346 |
349 Since implementations may add their own error indicators on top, | 347 Since implementations may add their own error indicators on top, |
350 we ignore it by default. */ | 348 we ignore it by default. */ |
351 #elif defined (WIN32_NATIVE) | |
352 int ret = 0, status = 0; | |
353 if (pHandle == NULL) | |
354 { | |
355 warn_when_safe (Qprocess, Qwarning, "Cannot wait for unknown process to terminate"); | |
356 return; | |
357 } | |
358 do | |
359 { | |
360 QUIT; | |
361 ret = WaitForSingleObject(pHandle, 100); | |
362 } | |
363 while (ret == WAIT_TIMEOUT); | |
364 if (ret == WAIT_FAILED) | |
365 { | |
366 warn_when_safe (Qprocess, Qwarning, "waiting for process failed"); | |
367 } | |
368 if (ret == WAIT_ABANDONED) | |
369 { | |
370 warn_when_safe (Qprocess, Qwarning, | |
371 "process to wait for has been abandoned"); | |
372 } | |
373 if (ret == WAIT_OBJECT_0) | |
374 { | |
375 ret = GetExitCodeProcess(pHandle, &status); | |
376 if (ret) | |
377 { | |
378 synch_process_alive = 0; | |
379 synch_process_retcode = status; | |
380 } | |
381 else | |
382 { | |
383 /* GetExitCodeProcess() didn't return a valid exit status, | |
384 nothing to do. APA */ | |
385 warn_when_safe (Qprocess, Qwarning, | |
386 "failure to obtain process exit value"); | |
387 } | |
388 } | |
389 if (pHandle != NULL && !CloseHandle(pHandle)) | |
390 { | |
391 warn_when_safe (Qprocess, Qwarning, | |
392 "failure to close unknown process"); | |
393 } | |
394 #elif defined (EMACS_BLOCK_SIGNAL) && !defined (BROKEN_WAIT_FOR_SIGNAL) && defined (SIGCHLD) | 349 #elif defined (EMACS_BLOCK_SIGNAL) && !defined (BROKEN_WAIT_FOR_SIGNAL) && defined (SIGCHLD) |
395 while (1) | 350 while (1) |
396 { | 351 { |
397 static int wait_debugging = 0; /* Set nonzero to make following | 352 static int wait_debugging = 0; /* Set nonzero to make following |
398 function work under dbx (at least for bsd). */ | 353 function work under dbx (at least for bsd). */ |
420 sigpause()/sigsuspend(), then your OS doesn't implement | 375 sigpause()/sigsuspend(), then your OS doesn't implement |
421 this properly (this applies under hpux9, for example). | 376 this properly (this applies under hpux9, for example). |
422 Try defining BROKEN_WAIT_FOR_SIGNAL. */ | 377 Try defining BROKEN_WAIT_FOR_SIGNAL. */ |
423 EMACS_WAIT_FOR_SIGNAL (SIGCHLD); | 378 EMACS_WAIT_FOR_SIGNAL (SIGCHLD); |
424 } | 379 } |
425 #else /* not HAVE_WAITPID and not WIN32_NATIVE and (not EMACS_BLOCK_SIGNAL or BROKEN_WAIT_FOR_SIGNAL) */ | 380 #else /* not HAVE_WAITPID and (not EMACS_BLOCK_SIGNAL or BROKEN_WAIT_FOR_SIGNAL) */ |
426 /* This approach is kind of cheesy but is guaranteed(?!) to work | 381 /* This approach is kind of cheesy but is guaranteed(?!) to work |
427 for all systems. */ | 382 for all systems. */ |
428 while (1) | 383 while (1) |
429 { | 384 { |
430 QUIT; | 385 QUIT; |
458 and nonzero means something different. */ | 413 and nonzero means something different. */ |
459 ioctl (channel, TIOCFLUSH, &zero); | 414 ioctl (channel, TIOCFLUSH, &zero); |
460 #endif | 415 #endif |
461 } | 416 } |
462 | 417 |
463 #ifndef WIN32_NATIVE | 418 #ifndef WINDOWSNT |
464 /* Set up the terminal at the other end of a pseudo-terminal that | 419 /* Set up the terminal at the other end of a pseudo-terminal that |
465 we will be controlling an inferior through. | 420 we will be controlling an inferior through. |
466 It should not echo or do line-editing, since that is done | 421 It should not echo or do line-editing, since that is done |
467 in Emacs. No padding needed for insertion into an Emacs buffer. */ | 422 in Emacs. No padding needed for insertion into an Emacs buffer. */ |
468 | 423 |
469 void | 424 void |
470 child_setup_tty (int out) | 425 child_setup_tty (int out) |
471 { | 426 { |
472 struct emacs_tty s; | 427 struct emacs_tty s; |
473 emacs_get_tty (out, &s); | 428 EMACS_GET_TTY (out, &s); |
474 | 429 |
475 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS) | 430 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS) |
476 assert (isatty(out)); | 431 assert (isatty(out)); |
477 s.main.c_oflag |= OPOST; /* Enable output postprocessing */ | 432 s.main.c_oflag |= OPOST; /* Enable output postprocessing */ |
478 s.main.c_oflag &= ~ONLCR; /* Disable map of NL to CR-NL on output */ | 433 s.main.c_oflag &= ~ONLCR; /* Disable map of NL to CR-NL on output */ |
537 s.main.c_cc[VSUSP] = _POSIX_VDISABLE; | 492 s.main.c_cc[VSUSP] = _POSIX_VDISABLE; |
538 s.main.c_lflag &= ~ISIG; | 493 s.main.c_lflag &= ~ISIG; |
539 #endif /* no TIOCGPGRP or no TIOCGLTC or no TIOCGETC */ | 494 #endif /* no TIOCGPGRP or no TIOCGLTC or no TIOCGETC */ |
540 s.main.c_cc[VEOL] = _POSIX_VDISABLE; | 495 s.main.c_cc[VEOL] = _POSIX_VDISABLE; |
541 #if defined (CBAUD) | 496 #if defined (CBAUD) |
542 /* <mdiers> #### This is not portable. ### | 497 /* <mdiers> ### This is not portable. ### |
543 POSIX does not specify CBAUD, and 4.4BSD does not have it. | 498 POSIX does not specify CBAUD, and 4.4BSD does not have it. |
544 Instead, POSIX suggests to use cfset{i,o}speed(). | 499 Instead, POSIX suggests to use cfset{i,o}speed(). |
545 [cf. D. Lewine, POSIX Programmer's Guide, Chapter 8: Terminal | 500 [cf. D. Lewine, POSIX Programmer's Guide, Chapter 8: Terminal |
546 I/O, O'Reilly 1991] */ | 501 I/O, O'Reilly 1991] */ |
547 s.main.c_cflag = (s.main.c_cflag & ~CBAUD) | B9600; /* baud rate sanity */ | 502 s.main.c_cflag = (s.main.c_cflag & ~CBAUD) | B9600; /* baud rate sanity */ |
560 s.main.sg_erase = 0377; | 515 s.main.sg_erase = 0377; |
561 s.main.sg_kill = 0377; | 516 s.main.sg_kill = 0377; |
562 s.lmode = LLITOUT | s.lmode; /* Don't strip 8th bit */ | 517 s.lmode = LLITOUT | s.lmode; /* Don't strip 8th bit */ |
563 | 518 |
564 #endif /* not HAVE_TERMIO */ | 519 #endif /* not HAVE_TERMIO */ |
565 emacs_set_tty (out, &s, 0); | 520 EMACS_SET_TTY (out, &s, 0); |
566 | 521 |
567 #ifdef RTU | 522 #ifdef RTU |
568 { | 523 { |
569 int zero = 0; | 524 int zero = 0; |
570 ioctl (out, FIOASYNC, &zero); | 525 ioctl (out, FIOASYNC, &zero); |
571 } | 526 } |
572 #endif /* RTU */ | 527 #endif /* RTU */ |
573 } | 528 } |
574 #endif /* WIN32_NATIVE */ | 529 #endif /* WINDOWSNT */ |
575 | 530 |
576 #endif /* not NO_SUBPROCESSES */ | 531 #endif /* not NO_SUBPROCESSES */ |
577 | 532 |
578 | 533 |
579 #if !defined (SIGTSTP) && !defined (USG_JOBCTRL) | 534 #if !defined (SIGTSTP) && !defined (USG_JOBCTRL) |
610 signal (saved_handlers->code, saved_handlers->handler); | 565 signal (saved_handlers->code, saved_handlers->handler); |
611 saved_handlers++; | 566 saved_handlers++; |
612 } | 567 } |
613 } | 568 } |
614 | 569 |
615 #ifdef WIN32_NATIVE | 570 #ifdef WINDOWSNT |
616 | 571 int |
617 pid_t | |
618 sys_getpid (void) | 572 sys_getpid (void) |
619 { | 573 { |
620 return abs (getpid ()); | 574 return abs (getpid ()); |
621 } | 575 } |
622 | 576 #endif /* WINDOWSNT */ |
623 #endif /* WIN32_NATIVE */ | |
624 | 577 |
625 /* Fork a subshell. */ | 578 /* Fork a subshell. */ |
626 static void | 579 static void |
627 sys_subshell (void) | 580 sys_subshell (void) |
628 { | 581 { |
629 #ifndef WIN32_NATIVE | |
630 int pid; | 582 int pid; |
631 #endif | |
632 struct save_signal saved_handlers[5]; | 583 struct save_signal saved_handlers[5]; |
633 Lisp_Object dir; | 584 Lisp_Object dir; |
634 unsigned char *str = 0; | 585 unsigned char *str = 0; |
635 int len; | 586 int len; |
636 struct gcpro gcpro1; | 587 struct gcpro gcpro1; |
659 dir = expand_and_dir_to_file (dir, Qnil); | 610 dir = expand_and_dir_to_file (dir, Qnil); |
660 UNGCPRO; | 611 UNGCPRO; |
661 str = (unsigned char *) alloca (XSTRING_LENGTH (dir) + 2); | 612 str = (unsigned char *) alloca (XSTRING_LENGTH (dir) + 2); |
662 len = XSTRING_LENGTH (dir); | 613 len = XSTRING_LENGTH (dir); |
663 memcpy (str, XSTRING_DATA (dir), len); | 614 memcpy (str, XSTRING_DATA (dir), len); |
664 if (!IS_ANY_SEP (str[len - 1])) | 615 /* #### Unix specific */ |
665 str[len++] = DIRECTORY_SEP; | 616 if (str[len - 1] != '/') str[len++] = '/'; |
666 str[len] = 0; | 617 str[len] = 0; |
667 xyzzy: | 618 xyzzy: |
668 | 619 |
669 #ifndef WIN32_NATIVE | 620 #ifdef WINDOWSNT |
621 pid = -1; | |
622 #else /* not WINDOWSNT */ | |
623 | |
670 pid = fork (); | 624 pid = fork (); |
671 | 625 |
672 if (pid == -1) | 626 if (pid == -1) |
673 error ("Can't spawn subshell"); | 627 error ("Can't spawn subshell"); |
674 if (pid == 0) | 628 if (pid == 0) |
675 #endif /* not WIN32_NATIVE */ | 629 |
630 #endif /* not WINDOWSNT */ | |
676 { | 631 { |
677 char *sh = 0; | 632 char *sh = 0; |
678 | 633 |
679 if (sh == 0) | 634 if (sh == 0) |
680 sh = (char *) egetenv ("SHELL"); | 635 sh = (char *) egetenv ("SHELL"); |
683 | 638 |
684 /* Use our buffer's default directory for the subshell. */ | 639 /* Use our buffer's default directory for the subshell. */ |
685 if (str) | 640 if (str) |
686 sys_chdir (str); | 641 sys_chdir (str); |
687 | 642 |
688 #ifdef WIN32_NATIVE | 643 #if !defined (NO_SUBPROCESSES) && !defined (WINDOWSNT) |
689 | |
690 /* Waits for process completion */ | |
691 if (_spawnlp (_P_WAIT, sh, sh, NULL) != 0) | |
692 error ("Can't spawn subshell"); | |
693 else | |
694 return; /* we're done, no need to wait for termination */ | |
695 } | |
696 | |
697 #else | |
698 | |
699 #if !defined (NO_SUBPROCESSES) | |
700 close_process_descs (); /* Close Emacs's pipes/ptys */ | 644 close_process_descs (); /* Close Emacs's pipes/ptys */ |
701 #endif | 645 #endif |
702 | 646 |
703 #ifdef SET_EMACS_PRIORITY | 647 #ifdef SET_EMACS_PRIORITY |
704 if (emacs_priority != 0) | 648 if (emacs_priority != 0) |
705 nice (-emacs_priority); /* Give the new shell the default priority */ | 649 nice (-emacs_priority); /* Give the new shell the default priority */ |
706 #endif | 650 #endif |
707 | 651 |
652 #ifdef WINDOWSNT | |
653 /* Waits for process completion */ | |
654 pid = _spawnlp (_P_WAIT, sh, sh, NULL); | |
655 if (pid == -1) | |
656 write (1, "Can't execute subshell", 22); | |
657 | |
658 #else /* not WINDOWSNT */ | |
708 execlp (sh, sh, 0); | 659 execlp (sh, sh, 0); |
709 write (1, "Can't execute subshell", 22); | 660 write (1, "Can't execute subshell", 22); |
710 _exit (1); | 661 _exit (1); |
662 #endif /* not WINDOWSNT */ | |
711 } | 663 } |
712 | 664 |
713 save_signal_handlers (saved_handlers); | 665 save_signal_handlers (saved_handlers); |
714 synch_process_alive = 1; | 666 synch_process_alive = 1; |
715 wait_for_termination (pid); | 667 wait_for_termination (pid); |
716 restore_signal_handlers (saved_handlers); | 668 restore_signal_handlers (saved_handlers); |
717 | |
718 #endif /* not WIN32_NATIVE */ | |
719 | |
720 } | 669 } |
721 | 670 |
722 #endif /* !defined (SIGTSTP) && !defined (USG_JOBCTRL) */ | 671 #endif /* !defined (SIGTSTP) && !defined (USG_JOBCTRL) */ |
723 | 672 |
724 | 673 |
761 #endif | 710 #endif |
762 } | 711 } |
763 | 712 |
764 | 713 |
765 /* Given FD, obtain pty buffer size. When no luck, a good guess is made, | 714 /* Given FD, obtain pty buffer size. When no luck, a good guess is made, |
766 so that the function works even when fd is not a pty. */ | 715 so that the function works even fd is not a pty. */ |
767 | 716 |
768 int | 717 int |
769 get_pty_max_bytes (int fd) | 718 get_pty_max_bytes (int fd) |
770 { | 719 { |
771 /* DEC OSF 4.0 fpathconf returns 255, but xemacs hangs on long shell | 720 int pty_max_bytes; |
772 input lines if we return 253. 252 is OK!. So let's leave a bit | 721 |
773 of slack for the newline that xemacs will insert, and for those | |
774 inevitable vendor off-by-one-or-two-or-three bugs. */ | |
775 #define MAX_CANON_SLACK 10 | |
776 #define SAFE_MAX_CANON (127 - MAX_CANON_SLACK) | |
777 #if defined (HAVE_FPATHCONF) && defined (_PC_MAX_CANON) | 722 #if defined (HAVE_FPATHCONF) && defined (_PC_MAX_CANON) |
778 { | 723 pty_max_bytes = fpathconf (fd, _PC_MAX_CANON); |
779 int max_canon = fpathconf (fd, _PC_MAX_CANON); | 724 if (pty_max_bytes < 0) |
780 return (max_canon < 0 ? SAFE_MAX_CANON : | 725 #endif |
781 max_canon > SAFE_MAX_CANON ? max_canon - MAX_CANON_SLACK : | 726 pty_max_bytes = 250; |
782 max_canon); | 727 |
783 } | 728 /* Deduct one, to leave space for the eof. */ |
784 #elif defined (_POSIX_MAX_CANON) | 729 pty_max_bytes--; |
785 return (_POSIX_MAX_CANON > SAFE_MAX_CANON ? | 730 |
786 _POSIX_MAX_CANON - MAX_CANON_SLACK : | 731 return pty_max_bytes; |
787 _POSIX_MAX_CANON); | |
788 #else | |
789 return SAFE_MAX_CANON; | |
790 #endif | |
791 } | 732 } |
792 | 733 |
793 /* Figure out the eof character for the FD. */ | 734 /* Figure out the eof character for the FD. */ |
794 | 735 |
795 Bufbyte | 736 Bufbyte |
796 get_eof_char (int fd) | 737 get_eof_char (int fd) |
797 { | 738 { |
798 const Bufbyte ctrl_d = (Bufbyte) '\004'; | 739 CONST Bufbyte ctrl_d = (Bufbyte) '\004'; |
799 | 740 |
800 if (!isatty (fd)) | 741 if (!isatty (fd)) |
801 return ctrl_d; | 742 return ctrl_d; |
802 #ifdef HAVE_TERMIOS | 743 #ifdef HAVE_TERMIOS |
803 { | 744 { |
804 struct termios t; | 745 struct termios t; |
805 tcgetattr (fd, &t); | 746 tcgetattr (fd, &t); |
806 #if 0 | 747 #if 0 |
807 /* What is the following line designed to do??? -mrb */ | 748 /* What is the following line designed to do??? -mrb */ |
808 if (strlen ((const char *) t.c_cc) < (unsigned int) (VEOF + 1)) | 749 if (strlen ((CONST char *) t.c_cc) < (unsigned int) (VEOF + 1)) |
809 return ctrl_d; | 750 return ctrl_d; |
810 else | 751 else |
811 return (Bufbyte) t.c_cc[VEOF]; | 752 return (Bufbyte) t.c_cc[VEOF]; |
812 #endif | 753 #endif |
813 return t.c_cc[VEOF] == _POSIX_VDISABLE ? ctrl_d : (Bufbyte) t.c_cc[VEOF]; | 754 return t.c_cc[VEOF] == _POSIX_VDISABLE ? ctrl_d : (Bufbyte) t.c_cc[VEOF]; |
826 characters. */ | 767 characters. */ |
827 #ifdef TCGETA | 768 #ifdef TCGETA |
828 { | 769 { |
829 struct termio t; | 770 struct termio t; |
830 ioctl (fd, TCGETA, &t); | 771 ioctl (fd, TCGETA, &t); |
831 if (strlen ((const char *) t.c_cc) < (unsigned int) (VINTR + 1)) | 772 if (strlen ((CONST char *) t.c_cc) < (unsigned int) (VINTR + 1)) |
832 return ctrl_d; | 773 return ctrl_d; |
833 else | 774 else |
834 return (Bufbyte) t.c_cc[VINTR]; | 775 return (Bufbyte) t.c_cc[VINTR]; |
835 } | 776 } |
836 #else /* ! defined (TCGETA) */ | 777 #else /* ! defined (TCGETA) */ |
960 | 901 |
961 #ifdef HAVE_TTY | 902 #ifdef HAVE_TTY |
962 assert (DEVICE_TTY_P (d)); | 903 assert (DEVICE_TTY_P (d)); |
963 { | 904 { |
964 int input_fd = CONSOLE_TTY_DATA (con)->infd; | 905 int input_fd = CONSOLE_TTY_DATA (con)->infd; |
965 #if defined (WIN32_NATIVE) | 906 #if defined (WINDOWSNT) |
966 DEVICE_TTY_DATA (d)->ospeed = 15; | 907 DEVICE_TTY_DATA (d)->ospeed = 15; |
967 #elif defined (HAVE_TERMIOS) | 908 #elif defined (HAVE_TERMIOS) |
968 struct termios sg; | 909 struct termios sg; |
969 | 910 |
970 sg.c_cflag = B9600; | 911 sg.c_cflag = B9600; |
1076 static void | 1017 static void |
1077 request_sigio_on_device (struct device *d) | 1018 request_sigio_on_device (struct device *d) |
1078 { | 1019 { |
1079 int filedesc = DEVICE_INFD (d); | 1020 int filedesc = DEVICE_INFD (d); |
1080 | 1021 |
1081 #if defined (I_SETSIG) && !defined(HPUX10) && !defined(LINUX) | 1022 #if defined (I_SETSIG) && !defined(HPUX10) |
1082 { | 1023 { |
1083 int events=0; | 1024 int events=0; |
1084 ioctl (filedesc, I_GETSIG, &events); | 1025 ioctl (filedesc, I_GETSIG, &events); |
1085 ioctl (filedesc, I_SETSIG, events | S_INPUT); | 1026 ioctl (filedesc, I_SETSIG, events | S_INPUT); |
1086 } | 1027 } |
1386 /* ------------------------------------------------------ */ | 1327 /* ------------------------------------------------------ */ |
1387 | 1328 |
1388 /* It's wrong to encase these into #ifdef HAVE_TTY because we need | 1329 /* It's wrong to encase these into #ifdef HAVE_TTY because we need |
1389 them for child TTY processes. */ | 1330 them for child TTY processes. */ |
1390 /* However, this does break NT support while we don't do child TTY processes */ | 1331 /* However, this does break NT support while we don't do child TTY processes */ |
1391 #ifndef WIN32_NATIVE | 1332 #ifndef WINDOWSNT |
1392 | 1333 |
1393 /* Set *TC to the parameters associated with the terminal FD. | 1334 /* Set *TC to the parameters associated with the terminal FD. |
1394 Return zero if all's well, or -1 if we ran into an error we | 1335 Return zero if all's well, or -1 if we ran into an error we |
1395 couldn't deal with. */ | 1336 couldn't deal with. */ |
1396 int | 1337 int |
1405 #elif defined HAVE_TERMIO | 1346 #elif defined HAVE_TERMIO |
1406 /* The SYSV-style interface? */ | 1347 /* The SYSV-style interface? */ |
1407 if (ioctl (fd, TCGETA, &settings->main) < 0) | 1348 if (ioctl (fd, TCGETA, &settings->main) < 0) |
1408 return -1; | 1349 return -1; |
1409 | 1350 |
1410 #elif !defined (WIN32_NATIVE) | 1351 #elif !defined (WINDOWSNT) |
1411 /* I give up - I hope you have the BSD ioctls. */ | 1352 /* I give up - I hope you have the BSD ioctls. */ |
1412 if (ioctl (fd, TIOCGETP, &settings->main) < 0) | 1353 if (ioctl (fd, TIOCGETP, &settings->main) < 0) |
1413 return -1; | 1354 return -1; |
1414 #endif /* HAVE_TCATTR */ | 1355 #endif /* HAVE_TCATTR */ |
1415 | 1356 |
1430 return 0; | 1371 return 0; |
1431 } | 1372 } |
1432 | 1373 |
1433 /* Set the parameters of the tty on FD according to the contents of | 1374 /* Set the parameters of the tty on FD according to the contents of |
1434 *SETTINGS. If FLUSHP is non-zero, we discard input. | 1375 *SETTINGS. If FLUSHP is non-zero, we discard input. |
1435 Return 0 if all went well, and -1 if anything failed. | 1376 Return 0 if all went well, and -1 if anything failed. */ |
1436 #### All current callers use FLUSHP == 0. */ | |
1437 | 1377 |
1438 int | 1378 int |
1439 emacs_set_tty (int fd, struct emacs_tty *settings, int flushp) | 1379 emacs_set_tty (int fd, struct emacs_tty *settings, int flushp) |
1440 { | 1380 { |
1441 /* Set the primary parameters - baud rate, character size, etcetera. */ | 1381 /* Set the primary parameters - baud rate, character size, etcetera. */ |
1479 #elif defined HAVE_TERMIO | 1419 #elif defined HAVE_TERMIO |
1480 /* The SYSV-style interface? */ | 1420 /* The SYSV-style interface? */ |
1481 if (ioctl (fd, flushp ? TCSETAF : TCSETAW, &settings->main) < 0) | 1421 if (ioctl (fd, flushp ? TCSETAF : TCSETAW, &settings->main) < 0) |
1482 return -1; | 1422 return -1; |
1483 | 1423 |
1484 #elif !defined (WIN32_NATIVE) | 1424 #elif !defined (WINDOWSNT) |
1485 /* I give up - I hope you have the BSD ioctls. */ | 1425 /* I give up - I hope you have the BSD ioctls. */ |
1486 if (ioctl (fd, (flushp) ? TIOCSETP : TIOCSETN, &settings->main) < 0) | 1426 if (ioctl (fd, (flushp) ? TIOCSETP : TIOCSETN, &settings->main) < 0) |
1487 return -1; | 1427 return -1; |
1488 #endif /* HAVE_TCATTR */ | 1428 #endif /* HAVE_TCATTR */ |
1489 | 1429 |
1502 | 1442 |
1503 /* We have survived the tempest. */ | 1443 /* We have survived the tempest. */ |
1504 return 0; | 1444 return 0; |
1505 } | 1445 } |
1506 | 1446 |
1507 #endif /* WIN32_NATIVE */ | 1447 #endif /* WINDOWSNT */ |
1508 | 1448 |
1509 /* ------------------------------------------------------ */ | 1449 /* ------------------------------------------------------ */ |
1510 /* Initializing a device */ | 1450 /* Initializing a device */ |
1511 /* ------------------------------------------------------ */ | 1451 /* ------------------------------------------------------ */ |
1512 | 1452 |
1541 struct console *con = XCONSOLE (DEVICE_CONSOLE (d)); | 1481 struct console *con = XCONSOLE (DEVICE_CONSOLE (d)); |
1542 | 1482 |
1543 input_fd = CONSOLE_TTY_DATA (con)->infd; | 1483 input_fd = CONSOLE_TTY_DATA (con)->infd; |
1544 output_fd = CONSOLE_TTY_DATA (con)->outfd; | 1484 output_fd = CONSOLE_TTY_DATA (con)->outfd; |
1545 | 1485 |
1546 emacs_get_tty (input_fd, &CONSOLE_TTY_DATA (con)->old_tty); | 1486 EMACS_GET_TTY (input_fd, &CONSOLE_TTY_DATA (con)->old_tty); |
1547 tty = CONSOLE_TTY_DATA (con)->old_tty; | 1487 tty = CONSOLE_TTY_DATA (con)->old_tty; |
1548 | 1488 |
1549 con->tty_erase_char = Qnil; | 1489 con->tty_erase_char = Qnil; |
1550 | 1490 |
1551 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS) | 1491 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS) |
1662 or via TELNET or the like, but does no harm elsewhere. */ | 1602 or via TELNET or the like, but does no harm elsewhere. */ |
1663 tty.main.c_iflag &= ~IGNBRK; | 1603 tty.main.c_iflag &= ~IGNBRK; |
1664 tty.main.c_iflag &= ~BRKINT; | 1604 tty.main.c_iflag &= ~BRKINT; |
1665 #endif /* AIX */ | 1605 #endif /* AIX */ |
1666 #else /* if not HAVE_TERMIO */ | 1606 #else /* if not HAVE_TERMIO */ |
1667 #if !defined (WIN32_NATIVE) | 1607 #if !defined (WINDOWSNT) |
1668 con->tty_erase_char = make_char (tty.main.sg_erase); | 1608 con->tty_erase_char = make_char (tty.main.sg_erase); |
1669 tty.main.sg_flags &= ~(ECHO | CRMOD | XTABS); | 1609 tty.main.sg_flags &= ~(ECHO | CRMOD | XTABS); |
1670 if (TTY_FLAGS (con).meta_key) | 1610 if (TTY_FLAGS (con).meta_key) |
1671 tty.main.sg_flags |= ANYP; | 1611 tty.main.sg_flags |= ANYP; |
1672 /* #### should we be using RAW mode here? */ | 1612 /* #### should we be using RAW mode here? */ |
1673 tty.main.sg_flags |= /* interrupt_input ? RAW : */ CBREAK; | 1613 tty.main.sg_flags |= /* interrupt_input ? RAW : */ CBREAK; |
1674 #endif /* not WIN32_NATIVE */ | 1614 #endif /* not WINDOWSNT */ |
1675 #endif /* not HAVE_TERMIO */ | 1615 #endif /* not HAVE_TERMIO */ |
1676 | 1616 |
1677 /* If going to use CBREAK mode, we must request C-g to interrupt | 1617 /* If going to use CBREAK mode, we must request C-g to interrupt |
1678 and turn off start and stop chars, etc. If not going to use | 1618 and turn off start and stop chars, etc. If not going to use |
1679 CBREAK mode, do this anyway so as to turn off local flow | 1619 CBREAK mode, do this anyway so as to turn off local flow |
1708 | 1648 |
1709 #ifdef HAVE_LTCHARS | 1649 #ifdef HAVE_LTCHARS |
1710 tty.ltchars = new_ltchars; | 1650 tty.ltchars = new_ltchars; |
1711 #endif /* HAVE_LTCHARS */ | 1651 #endif /* HAVE_LTCHARS */ |
1712 | 1652 |
1713 emacs_set_tty (input_fd, &tty, 0); | 1653 EMACS_SET_TTY (input_fd, &tty, 0); |
1714 | 1654 |
1715 /* This code added to insure that, if flow-control is not to be used, | 1655 /* This code added to insure that, if flow-control is not to be used, |
1716 we have an unlocked terminal at the start. */ | 1656 we have an unlocked terminal at the start. */ |
1717 | 1657 |
1718 #ifdef TCXONC | 1658 #ifdef TCXONC |
1719 if (!TTY_FLAGS (con).flow_control) ioctl (input_fd, TCXONC, 1); | 1659 if (!TTY_FLAGS (con).flow_control) ioctl (input_fd, TCXONC, 1); |
1720 #endif | 1660 #endif |
1661 #ifndef APOLLO | |
1721 #ifdef TIOCSTART | 1662 #ifdef TIOCSTART |
1722 if (!TTY_FLAGS (con).flow_control) ioctl (input_fd, TIOCSTART, 0); | 1663 if (!TTY_FLAGS (con).flow_control) ioctl (input_fd, TIOCSTART, 0); |
1664 #endif | |
1723 #endif | 1665 #endif |
1724 | 1666 |
1725 #if defined (HAVE_TERMIOS) || defined (HPUX9) | 1667 #if defined (HAVE_TERMIOS) || defined (HPUX9) |
1726 #ifdef TCOON | 1668 #ifdef TCOON |
1727 if (!TTY_FLAGS (con).flow_control) tcflow (input_fd, TCOON); | 1669 if (!TTY_FLAGS (con).flow_control) tcflow (input_fd, TCOON); |
1813 #ifdef HAVE_TTY | 1755 #ifdef HAVE_TTY |
1814 if (DEVICE_TTY_P (d)) | 1756 if (DEVICE_TTY_P (d)) |
1815 { | 1757 { |
1816 struct emacs_tty tty; | 1758 struct emacs_tty tty; |
1817 | 1759 |
1818 emacs_get_tty (DEVICE_INFD (d), &tty); | 1760 EMACS_GET_TTY (DEVICE_INFD (d), &tty); |
1819 return EMACS_TTY_TABS_OK (&tty); | 1761 return EMACS_TTY_TABS_OK (&tty); |
1820 } | 1762 } |
1821 #endif | 1763 #endif |
1822 return 1; | 1764 return 1; |
1823 } | 1765 } |
1886 int eight_bit = 0; | 1828 int eight_bit = 0; |
1887 | 1829 |
1888 assert (DEVICE_TTY_P (d)); | 1830 assert (DEVICE_TTY_P (d)); |
1889 input_fd = DEVICE_INFD (d); | 1831 input_fd = DEVICE_INFD (d); |
1890 | 1832 |
1891 emacs_get_tty (input_fd, &s); | 1833 EMACS_GET_TTY (input_fd, &s); |
1892 | 1834 |
1893 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS) | 1835 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS) |
1894 eight_bit = (s.main.c_cflag & CSIZE) == CS8; | 1836 eight_bit = (s.main.c_cflag & CSIZE) == CS8; |
1895 #else | 1837 #else |
1896 eight_bit = 0; /* I don't know how to do it */ | 1838 eight_bit = 0; /* I don't know how to do it */ |
1936 #if defined (BSD) | 1878 #if defined (BSD) |
1937 /* Avoid possible loss of output when changing terminal modes. */ | 1879 /* Avoid possible loss of output when changing terminal modes. */ |
1938 fsync (output_fd); | 1880 fsync (output_fd); |
1939 #endif | 1881 #endif |
1940 | 1882 |
1941 while (emacs_set_tty (input_fd, &CONSOLE_TTY_DATA (con)->old_tty, 0) | 1883 while (EMACS_SET_TTY (input_fd, &CONSOLE_TTY_DATA (con)->old_tty, 0) |
1942 < 0 && errno == EINTR) | 1884 < 0 && errno == EINTR) |
1943 ; | 1885 ; |
1944 | 1886 |
1945 #ifdef SET_LINE_DISCIPLINE | 1887 #ifdef SET_LINE_DISCIPLINE |
1946 /* Ultrix's termios *ignores* any line discipline except TERMIODISC. | 1888 /* Ultrix's termios *ignores* any line discipline except TERMIODISC. |
2130 | 2072 |
2131 /************************************************************************/ | 2073 /************************************************************************/ |
2132 /* limits of text/data segments */ | 2074 /* limits of text/data segments */ |
2133 /************************************************************************/ | 2075 /************************************************************************/ |
2134 | 2076 |
2135 #if !defined(CANNOT_DUMP) && !defined(PDUMP) | 2077 #ifndef CANNOT_DUMP |
2136 #define NEED_STARTS | 2078 #define NEED_STARTS |
2137 #endif | 2079 #endif |
2138 | 2080 |
2139 #ifndef SYSTEM_MALLOC | 2081 #ifndef SYSTEM_MALLOC |
2140 #ifndef NEED_STARTS | 2082 #ifndef NEED_STARTS |
2150 * doing an unexec. After unexec the return value is undefined. | 2092 * doing an unexec. After unexec the return value is undefined. |
2151 * See crt0.c for further explanation and _start. | 2093 * See crt0.c for further explanation and _start. |
2152 * | 2094 * |
2153 */ | 2095 */ |
2154 | 2096 |
2155 #if !defined(HAVE_TEXT_START) && !defined(PDUMP) | 2097 #ifdef __cplusplus |
2156 | 2098 extern "C" int _start (); |
2157 EXTERN_C int _start (void); | 2099 #else |
2158 | 2100 extern int _start (); |
2101 #endif | |
2102 | |
2103 #ifndef HAVE_TEXT_START | |
2159 char * | 2104 char * |
2160 start_of_text (void) | 2105 start_of_text (void) |
2161 { | 2106 { |
2162 #ifdef TEXT_START | 2107 #ifdef TEXT_START |
2163 return (char *) TEXT_START; | 2108 return ((char *) TEXT_START); |
2164 #else | 2109 #else |
2165 return (char *) _start; | 2110 #ifdef GOULD |
2111 extern csrt (); | |
2112 return ((char *) csrt); | |
2113 #else /* not GOULD */ | |
2114 return ((char *) _start); | |
2115 #endif /* GOULD */ | |
2166 #endif /* TEXT_START */ | 2116 #endif /* TEXT_START */ |
2167 } | 2117 } |
2168 #endif /* !defined(HAVE_TEXT_START) && !defined(PDUMP) */ | 2118 #endif /* not HAVE_TEXT_START */ |
2169 | 2119 |
2170 /* | 2120 /* |
2171 * Return the address of the start of the data segment prior to | 2121 * Return the address of the start of the data segment prior to |
2172 * doing an unexec. After unexec the return value is undefined. | 2122 * doing an unexec. After unexec the return value is undefined. |
2173 * See crt0.c for further information and definition of data_start. | 2123 * See crt0.c for further information and definition of data_start. |
2191 * at the normal shared text boundary and the startofdata variable | 2141 * at the normal shared text boundary and the startofdata variable |
2192 * will be patched by unexec to the correct value. | 2142 * will be patched by unexec to the correct value. |
2193 * | 2143 * |
2194 */ | 2144 */ |
2195 | 2145 |
2196 #if defined(ORDINARY_LINK) && !defined(MINGW) | 2146 #ifdef ORDINARY_LINK |
2197 extern char **environ; | 2147 extern char **environ; |
2198 #endif | 2148 #endif |
2199 | 2149 |
2200 void * | 2150 void * |
2201 start_of_data (void) | 2151 start_of_data (void) |
2208 * This is a hack. Since we're not linking crt0.c or pre_crt0.c, | 2158 * This is a hack. Since we're not linking crt0.c or pre_crt0.c, |
2209 * data_start isn't defined. We take the address of environ, which | 2159 * data_start isn't defined. We take the address of environ, which |
2210 * is known to live at or near the start of the system crt0.c, and | 2160 * is known to live at or near the start of the system crt0.c, and |
2211 * we don't sweat the handful of bytes that might lose. | 2161 * we don't sweat the handful of bytes that might lose. |
2212 */ | 2162 */ |
2213 #if defined (HEAP_IN_DATA) && !defined(PDUMP) | 2163 #ifdef HEAP_IN_DATA |
2214 extern char* static_heap_base; | 2164 extern char* static_heap_base; |
2215 if (!initialized) | 2165 if (!initialized) |
2216 return static_heap_base; | 2166 return static_heap_base; |
2217 #endif | 2167 #endif |
2218 return((char *) &environ); | 2168 return((char *) &environ); |
2222 #endif /* ORDINARY_LINK */ | 2172 #endif /* ORDINARY_LINK */ |
2223 #endif /* DATA_START */ | 2173 #endif /* DATA_START */ |
2224 } | 2174 } |
2225 #endif /* NEED_STARTS (not CANNOT_DUMP or not SYSTEM_MALLOC) */ | 2175 #endif /* NEED_STARTS (not CANNOT_DUMP or not SYSTEM_MALLOC) */ |
2226 | 2176 |
2227 #if !defined(CANNOT_DUMP) && !defined(PDUMP) | 2177 #ifndef CANNOT_DUMP |
2228 /* Some systems that cannot dump also cannot implement these. */ | 2178 /* Some systems that cannot dump also cannot implement these. */ |
2229 | 2179 |
2230 /* | 2180 /* |
2231 * Return the address of the end of the text segment prior to | 2181 * Return the address of the end of the text segment prior to |
2232 * doing an unexec. After unexec the return value is undefined. | 2182 * doing an unexec. After unexec the return value is undefined. |
2257 extern int edata; | 2207 extern int edata; |
2258 return ((char *) &edata); | 2208 return ((char *) &edata); |
2259 #endif | 2209 #endif |
2260 } | 2210 } |
2261 | 2211 |
2262 #endif /* !defined(CANNOT_DUMP) && !defined(PDUMP) */ | 2212 #endif /* not CANNOT_DUMP */ |
2263 | 2213 |
2264 | 2214 |
2265 /************************************************************************/ | 2215 /************************************************************************/ |
2266 /* get the system name */ | 2216 /* get the system name */ |
2267 /************************************************************************/ | 2217 /************************************************************************/ |
2269 /* init_system_name sets up the string for the Lisp function | 2219 /* init_system_name sets up the string for the Lisp function |
2270 system-name to return. */ | 2220 system-name to return. */ |
2271 | 2221 |
2272 extern Lisp_Object Vsystem_name; | 2222 extern Lisp_Object Vsystem_name; |
2273 | 2223 |
2224 #ifdef HAVE_SOCKETS | |
2225 # include <sys/socket.h> | |
2226 # include <netdb.h> | |
2227 #endif /* HAVE_SOCKETS */ | |
2228 | |
2274 void | 2229 void |
2275 init_system_name (void) | 2230 init_system_name (void) |
2276 { | 2231 { |
2277 #if defined (WIN32_NATIVE) | 2232 #if defined (WINDOWSNT) |
2278 char hostname [MAX_COMPUTERNAME_LENGTH + 1]; | 2233 char hostname [MAX_COMPUTERNAME_LENGTH + 1]; |
2279 size_t size = sizeof (hostname); | 2234 size_t size = sizeof(hostname); |
2280 GetComputerName (hostname, &size); | 2235 GetComputerName (hostname, &size); |
2281 Vsystem_name = build_string (hostname); | 2236 Vsystem_name = build_string (hostname); |
2282 #elif !defined (HAVE_GETHOSTNAME) | 2237 #elif !defined (HAVE_GETHOSTNAME) |
2283 struct utsname uts; | 2238 struct utsname uts; |
2284 uname (&uts); | 2239 uname (&uts); |
2310 # ifndef CANNOT_DUMP | 2265 # ifndef CANNOT_DUMP |
2311 if (initialized) | 2266 if (initialized) |
2312 # endif /* not CANNOT_DUMP */ | 2267 # endif /* not CANNOT_DUMP */ |
2313 if (!strchr (hostname, '.')) | 2268 if (!strchr (hostname, '.')) |
2314 { | 2269 { |
2315 # if !(defined(HAVE_GETADDRINFO) && defined(HAVE_GETNAMEINFO)) | |
2316 struct hostent *hp = NULL; | 2270 struct hostent *hp = NULL; |
2317 int count; | 2271 int count; |
2318 # ifdef TRY_AGAIN | 2272 # ifdef TRY_AGAIN |
2319 for (count = 0; count < 10; count++) | 2273 for (count = 0; count < 10; count++) |
2320 { | 2274 { |
2321 h_errno = 0; | 2275 h_errno = 0; |
2322 # endif | 2276 # endif |
2323 /* Some systems can't handle SIGALARM/SIGIO in gethostbyname(). */ | 2277 /* Some systems can't handle SIGALARM/SIGIO in gethostbyname(). */ |
2324 stop_interrupts (); | 2278 stop_interrupts (); |
2325 hp = gethostbyname (hostname); | 2279 hp = gethostbyname (hostname); |
2326 start_interrupts (); | 2280 start_interrupts (); |
2327 # ifdef TRY_AGAIN | 2281 # ifdef TRY_AGAIN |
2328 if (! (hp == 0 && h_errno == TRY_AGAIN)) | 2282 if (! (hp == 0 && h_errno == TRY_AGAIN)) |
2329 break; | 2283 break; |
2330 Fsleep_for (make_int (1)); | 2284 Fsleep_for (make_int (1)); |
2331 } | 2285 } |
2332 # endif | 2286 # endif |
2333 if (hp) | 2287 if (hp) |
2334 { | 2288 { |
2335 const char *fqdn = (const char *) hp->h_name; | 2289 CONST char *fqdn = (CONST char *) hp->h_name; |
2336 | 2290 |
2337 if (!strchr (fqdn, '.')) | 2291 if (!strchr (fqdn, '.')) |
2338 { | 2292 { |
2339 /* We still don't have a fully qualified domain name. | 2293 /* We still don't have a fully qualified domain name. |
2340 Try to find one in the list of alternate names */ | 2294 Try to find one in the list of alternate names */ |
2345 fqdn = *alias; | 2299 fqdn = *alias; |
2346 } | 2300 } |
2347 hostname = (char *) alloca (strlen (fqdn) + 1); | 2301 hostname = (char *) alloca (strlen (fqdn) + 1); |
2348 strcpy (hostname, fqdn); | 2302 strcpy (hostname, fqdn); |
2349 } | 2303 } |
2350 # else /* !(HAVE_GETADDRINFO && HAVE_GETNAMEINFO) */ | |
2351 struct addrinfo hints, *res; | |
2352 | |
2353 xzero (hints); | |
2354 hints.ai_flags = AI_CANONNAME; | |
2355 hints.ai_family = AF_UNSPEC; | |
2356 hints.ai_socktype = SOCK_STREAM; | |
2357 hints.ai_protocol = 0; | |
2358 if (!getaddrinfo (hostname, NULL, &hints, &res)) | |
2359 { | |
2360 hostname = (char *) alloca (strlen (res->ai_canonname) + 1); | |
2361 strcpy (hostname, res->ai_canonname); | |
2362 | |
2363 freeaddrinfo (res); | |
2364 } | |
2365 # endif /* !(HAVE_GETADDRINFO && HAVE_GETNAMEINFO) */ | |
2366 } | 2304 } |
2367 # endif /* HAVE_SOCKETS */ | 2305 # endif /* HAVE_SOCKETS */ |
2368 Vsystem_name = build_string (hostname); | 2306 Vsystem_name = build_string (hostname); |
2369 #endif /* HAVE_GETHOSTNAME */ | 2307 #endif /* HAVE_GETHOSTNAME */ |
2370 { | 2308 { |
2490 | 2428 |
2491 #if !defined(NeXT) && !defined(__alpha) && !defined(MACH) && !defined(LINUX) && !defined(IRIX) && !defined(__NetBSD__) | 2429 #if !defined(NeXT) && !defined(__alpha) && !defined(MACH) && !defined(LINUX) && !defined(IRIX) && !defined(__NetBSD__) |
2492 /* Linux added here by Raymond L. Toy <toy@alydar.crd.ge.com> for XEmacs. */ | 2430 /* Linux added here by Raymond L. Toy <toy@alydar.crd.ge.com> for XEmacs. */ |
2493 /* Irix added here by gparker@sni-usa.com for XEmacs. */ | 2431 /* Irix added here by gparker@sni-usa.com for XEmacs. */ |
2494 /* NetBSD added here by James R Grinter <jrg@doc.ic.ac.uk> for XEmacs */ | 2432 /* NetBSD added here by James R Grinter <jrg@doc.ic.ac.uk> for XEmacs */ |
2495 extern const char *sys_errlist[]; | 2433 extern CONST char *sys_errlist[]; |
2496 extern int sys_nerr; | 2434 extern int sys_nerr; |
2497 #endif | 2435 #endif |
2498 | 2436 |
2499 #ifdef __NetBSD__ | 2437 #ifdef __NetBSD__ |
2500 extern char *sys_errlist[]; | 2438 extern char *sys_errlist[]; |
2501 extern int sys_nerr; | 2439 extern int sys_nerr; |
2502 #endif | 2440 #endif |
2503 | 2441 |
2504 | 2442 |
2505 const char * | 2443 CONST char * |
2506 strerror (int errnum) | 2444 strerror (int errnum) |
2507 { | 2445 { |
2508 if (errnum >= 0 && errnum < sys_nerr) | 2446 if (errnum >= 0 && errnum < sys_nerr) |
2509 return sys_errlist[errnum]; | 2447 return sys_errlist[errnum]; |
2510 return ((const char *) GETTEXT ("Unknown error")); | 2448 return ((CONST char *) GETTEXT ("Unknown error")); |
2511 } | 2449 } |
2512 | 2450 |
2513 #endif /* ! HAVE_STRERROR */ | 2451 #endif /* ! HAVE_STRERROR */ |
2514 | 2452 |
2515 #ifdef WIN32_NATIVE | 2453 #ifdef WINDOWSNT |
2516 | 2454 |
2517 struct errentry { | 2455 struct errentry { |
2518 unsigned long oscode; /* Win32 error */ | 2456 unsigned long oscode; /* Win32 error */ |
2519 int errnocode; /* unix errno */ | 2457 int errnocode; /* unix errno */ |
2520 }; | 2458 }; |
2581 mswindows_set_errno (unsigned long win32_error) | 2519 mswindows_set_errno (unsigned long win32_error) |
2582 { | 2520 { |
2583 int i; | 2521 int i; |
2584 | 2522 |
2585 /* check the table for the OS error code */ | 2523 /* check the table for the OS error code */ |
2586 for (i = 0; i < countof (errtable); ++i) | 2524 for (i = 0; i < sizeof(errtable)/sizeof(errtable[0]); ++i) |
2587 { | 2525 { |
2588 if (win32_error == errtable[i].oscode) | 2526 if (win32_error == errtable[i].oscode) |
2589 { | 2527 { |
2590 errno = errtable[i].errnocode; | 2528 errno = errtable[i].errnocode; |
2591 return; | 2529 return; |
2607 mswindows_set_last_errno (void) | 2545 mswindows_set_last_errno (void) |
2608 { | 2546 { |
2609 mswindows_set_errno (GetLastError ()); | 2547 mswindows_set_errno (GetLastError ()); |
2610 } | 2548 } |
2611 | 2549 |
2612 #endif /* WIN32_NATIVE */ | 2550 #endif /* WINDOWSNT */ |
2613 | 2551 |
2614 | 2552 |
2615 /************************************************************************/ | 2553 /************************************************************************/ |
2616 /* Encapsulations of system calls */ | 2554 /* Encapsulations of system calls */ |
2617 /************************************************************************/ | 2555 /************************************************************************/ |
2618 | 2556 |
2619 #define PATHNAME_CONVERT_OUT(path) \ | 2557 #define PATHNAME_CONVERT_OUT(path) \ |
2620 TO_EXTERNAL_FORMAT (C_STRING, (path), C_STRING_ALLOCA, (path), Qfile_name); | 2558 GET_C_CHARPTR_EXT_FILENAME_DATA_ALLOCA ((CONST Bufbyte *) path, path) |
2621 | 2559 |
2622 /***************** low-level calls ****************/ | 2560 /***************** low-level calls ****************/ |
2623 | 2561 |
2624 /* | 2562 /* |
2625 * On USG systems the system calls are INTERRUPTIBLE by signals | 2563 * On USG systems the system calls are INTERRUPTIBLE by signals |
2634 * always negligible. Fred Fish, Unisoft Systems Inc. | 2572 * always negligible. Fred Fish, Unisoft Systems Inc. |
2635 */ | 2573 */ |
2636 | 2574 |
2637 /* Ben sez: read Dick Gabriel's essay about the Worse Is Better | 2575 /* Ben sez: read Dick Gabriel's essay about the Worse Is Better |
2638 approach to programming and its connection to the silly | 2576 approach to programming and its connection to the silly |
2639 interruptible-system-call business. To find it, look on | 2577 interruptible-system-call business. To find it, look at |
2640 Jamie's home page (http://www.jwz.org/worse-is-better.html). */ | 2578 Jamie's home page (http://www.netscape.com/people/jwz). */ |
2641 | 2579 |
2642 #ifdef ENCAPSULATE_OPEN | 2580 #ifdef ENCAPSULATE_OPEN |
2643 int | 2581 int |
2644 sys_open (const char *path, int oflag, ...) | 2582 sys_open (CONST char *path, int oflag, ...) |
2645 { | 2583 { |
2646 int mode; | 2584 int mode; |
2647 va_list ap; | 2585 va_list ap; |
2648 | 2586 |
2649 va_start (ap, oflag); | 2587 va_start (ap, oflag); |
2650 mode = va_arg (ap, int); | 2588 mode = va_arg (ap, int); |
2651 va_end (ap); | 2589 va_end (ap); |
2652 | 2590 |
2653 PATHNAME_CONVERT_OUT (path); | 2591 PATHNAME_CONVERT_OUT (path); |
2654 | 2592 #if defined (WINDOWSNT) |
2655 #ifdef WIN32_NATIVE | |
2656 /* Make all handles non-inheritable */ | 2593 /* Make all handles non-inheritable */ |
2657 oflag |= _O_NOINHERIT; | 2594 return open (path, oflag | _O_NOINHERIT, mode); |
2658 #endif | 2595 #elif defined (INTERRUPTIBLE_OPEN) |
2659 | |
2660 #ifdef INTERRUPTIBLE_OPEN | |
2661 { | 2596 { |
2662 int rtnval; | 2597 int rtnval; |
2663 while ((rtnval = open (path, oflag, mode)) == -1 | 2598 while ((rtnval = open (path, oflag, mode)) == -1 |
2664 && (errno == EINTR)) | 2599 && (errno == EINTR)) |
2665 DO_NOTHING; | 2600 DO_NOTHING; |
2678 | 2613 |
2679 This function will not function as expected on systems where open() | 2614 This function will not function as expected on systems where open() |
2680 is not interrupted by C-g. However, the worst that can happen is | 2615 is not interrupted by C-g. However, the worst that can happen is |
2681 the fallback to simple open(). */ | 2616 the fallback to simple open(). */ |
2682 int | 2617 int |
2683 interruptible_open (const char *path, int oflag, int mode) | 2618 interruptible_open (CONST char *path, int oflag, int mode) |
2684 { | 2619 { |
2685 /* This function can GC */ | 2620 /* This function can GC */ |
2686 size_t len = strlen (path); | 2621 size_t len = strlen (path); |
2687 char *nonreloc = (char *) alloca (len + 1); | 2622 char *nonreloc = (char *) alloca (len + 1); |
2688 | 2623 |
2689 /* Must copy PATH, because it might be the data of a Lisp_String, | 2624 /* Must copy PATH, because it might be the data of a Lisp_String, |
2690 which could be relocated by GC when checking for QUIT. */ | 2625 which could be relocated by GC when checking for QUIT. */ |
2691 memcpy (nonreloc, path, len + 1); | 2626 memcpy (nonreloc, path, len + 1); |
2692 | 2627 |
2693 PATHNAME_CONVERT_OUT (nonreloc); | 2628 PATHNAME_CONVERT_OUT (nonreloc); |
2694 | |
2695 #ifdef WIN32_NATIVE | |
2696 /* Make all handles non-inheritable */ | |
2697 oflag |= _O_NOINHERIT; | |
2698 #endif | |
2699 | 2629 |
2700 for (;;) | 2630 for (;;) |
2701 { | 2631 { |
2702 int rtnval = open (nonreloc, oflag, mode); | 2632 int rtnval = open (nonreloc, oflag, mode); |
2703 if (!(rtnval == -1 && errno == EINTR)) | 2633 if (!(rtnval == -1 && errno == EINTR)) |
2707 } | 2637 } |
2708 } | 2638 } |
2709 | 2639 |
2710 #ifdef ENCAPSULATE_CLOSE | 2640 #ifdef ENCAPSULATE_CLOSE |
2711 int | 2641 int |
2712 sys_close (int filedes) | 2642 sys_close (int fd) |
2713 { | 2643 { |
2714 #ifdef INTERRUPTIBLE_CLOSE | 2644 #ifdef INTERRUPTIBLE_CLOSE |
2715 int did_retry = 0; | 2645 int did_retry = 0; |
2716 REGISTER int rtnval; | 2646 REGISTER int rtnval; |
2717 | 2647 |
2718 while ((rtnval = close (filedes)) == -1 | 2648 while ((rtnval = close (fd)) == -1 |
2719 && (errno == EINTR)) | 2649 && (errno == EINTR)) |
2720 did_retry = 1; | 2650 did_retry = 1; |
2721 | 2651 |
2722 /* If close is interrupted SunOS 4.1 may or may not have closed the | 2652 /* If close is interrupted SunOS 4.1 may or may not have closed the |
2723 file descriptor. If it did the second close will fail with | 2653 file descriptor. If it did the second close will fail with |
2725 if (rtnval == -1 && did_retry && errno == EBADF) | 2655 if (rtnval == -1 && did_retry && errno == EBADF) |
2726 return 0; | 2656 return 0; |
2727 | 2657 |
2728 return rtnval; | 2658 return rtnval; |
2729 #else | 2659 #else |
2730 return close (filedes); | 2660 return close (fd); |
2731 #endif | 2661 #endif |
2732 } | 2662 } |
2733 #endif /* ENCAPSULATE_CLOSE */ | 2663 #endif /* ENCAPSULATE_CLOSE */ |
2734 | 2664 |
2735 ssize_t | 2665 int |
2736 sys_read_1 (int fildes, void *buf, size_t nbyte, int allow_quit) | 2666 sys_read_1 (int fildes, void *buf, size_t nbyte, int allow_quit) |
2737 { | 2667 { |
2738 ssize_t rtnval; | 2668 int rtnval; |
2739 | 2669 |
2740 /* No harm in looping regardless of the INTERRUPTIBLE_IO setting. */ | 2670 /* No harm in looping regardless of the INTERRUPTIBLE_IO setting. */ |
2741 while ((rtnval = read (fildes, buf, nbyte)) == -1 | 2671 while ((rtnval = read (fildes, buf, nbyte)) == -1 |
2742 && (errno == EINTR)) | 2672 && (errno == EINTR)) |
2743 { | 2673 { |
2746 } | 2676 } |
2747 return rtnval; | 2677 return rtnval; |
2748 } | 2678 } |
2749 | 2679 |
2750 #ifdef ENCAPSULATE_READ | 2680 #ifdef ENCAPSULATE_READ |
2751 ssize_t | 2681 int |
2752 sys_read (int fildes, void *buf, size_t nbyte) | 2682 sys_read (int fildes, void *buf, size_t nbyte) |
2753 { | 2683 { |
2754 return sys_read_1 (fildes, buf, nbyte, 0); | 2684 return sys_read_1 (fildes, buf, nbyte, 0); |
2755 } | 2685 } |
2756 #endif /* ENCAPSULATE_READ */ | 2686 #endif /* ENCAPSULATE_READ */ |
2757 | 2687 |
2758 ssize_t | 2688 int |
2759 sys_write_1 (int fildes, const void *buf, size_t nbyte, int allow_quit) | 2689 sys_write_1 (int fildes, CONST void *buf, size_t nbyte, int allow_quit) |
2760 { | 2690 { |
2761 ssize_t bytes_written = 0; | 2691 int rtnval; |
2762 const char *b = (const char *) buf; | 2692 int bytes_written = 0; |
2693 CONST char *b = (CONST char *) buf; | |
2763 | 2694 |
2764 /* No harm in looping regardless of the INTERRUPTIBLE_IO setting. */ | 2695 /* No harm in looping regardless of the INTERRUPTIBLE_IO setting. */ |
2765 while (nbyte > 0) | 2696 while (nbyte > 0) |
2766 { | 2697 { |
2767 ssize_t rtnval = write (fildes, b, nbyte); | 2698 rtnval = write (fildes, b, nbyte); |
2768 | 2699 |
2769 if (allow_quit) | 2700 if (allow_quit) |
2770 REALLY_QUIT; | 2701 REALLY_QUIT; |
2771 | 2702 |
2772 if (rtnval == -1) | 2703 if (rtnval == -1) |
2773 { | 2704 { |
2774 if (errno == EINTR) | 2705 if (errno == EINTR) |
2775 continue; | 2706 continue; |
2776 else | 2707 else |
2777 return bytes_written ? bytes_written : -1; | 2708 return (bytes_written ? bytes_written : -1); |
2778 } | 2709 } |
2779 b += rtnval; | 2710 b += rtnval; |
2780 nbyte -= rtnval; | 2711 nbyte -= rtnval; |
2781 bytes_written += rtnval; | 2712 bytes_written += rtnval; |
2782 } | 2713 } |
2783 return bytes_written; | 2714 return (bytes_written); |
2784 } | 2715 } |
2785 | 2716 |
2786 #ifdef ENCAPSULATE_WRITE | 2717 #ifdef ENCAPSULATE_WRITE |
2787 ssize_t | 2718 int |
2788 sys_write (int fildes, const void *buf, size_t nbyte) | 2719 sys_write (int fildes, CONST void *buf, size_t nbyte) |
2789 { | 2720 { |
2790 return sys_write_1 (fildes, buf, nbyte, 0); | 2721 return sys_write_1 (fildes, buf, nbyte, 0); |
2791 } | 2722 } |
2792 #endif /* ENCAPSULATE_WRITE */ | 2723 #endif /* ENCAPSULATE_WRITE */ |
2793 | 2724 |
2801 /* #### Should also encapsulate fflush(). | 2732 /* #### Should also encapsulate fflush(). |
2802 #### Should conceivably encapsulate getchar() etc. What a pain! */ | 2733 #### Should conceivably encapsulate getchar() etc. What a pain! */ |
2803 | 2734 |
2804 #ifdef ENCAPSULATE_FOPEN | 2735 #ifdef ENCAPSULATE_FOPEN |
2805 FILE * | 2736 FILE * |
2806 sys_fopen (const char *path, const char *type) | 2737 sys_fopen (CONST char *path, CONST char *type) |
2807 { | 2738 { |
2808 PATHNAME_CONVERT_OUT (path); | 2739 PATHNAME_CONVERT_OUT (path); |
2809 #if defined (WIN32_NATIVE) | 2740 #if defined (WINDOWSNT) |
2810 { | 2741 { |
2811 int fd; | 2742 int fd; |
2812 int oflag; | 2743 int oflag; |
2813 const char * type_save = type; | 2744 const char * type_save = type; |
2814 | 2745 |
2911 #endif /* ENCAPSULATE_FREAD */ | 2842 #endif /* ENCAPSULATE_FREAD */ |
2912 | 2843 |
2913 | 2844 |
2914 #ifdef ENCAPSULATE_FWRITE | 2845 #ifdef ENCAPSULATE_FWRITE |
2915 size_t | 2846 size_t |
2916 sys_fwrite (const void *ptr, size_t size, size_t nitem, FILE *stream) | 2847 sys_fwrite (CONST void *ptr, size_t size, size_t nitem, FILE *stream) |
2917 { | 2848 { |
2918 #ifdef INTERRUPTIBLE_IO | 2849 #ifdef INTERRUPTIBLE_IO |
2919 size_t rtnval; | 2850 size_t rtnval; |
2920 size_t items_written = 0; | 2851 size_t items_written = 0; |
2921 const char *b = (const char *) ptr; | 2852 CONST char *b = (CONST char *) ptr; |
2922 | 2853 |
2923 while (nitem > 0) | 2854 while (nitem > 0) |
2924 { | 2855 { |
2925 rtnval = fwrite (b, size, nitem, stream); | 2856 rtnval = fwrite (b, size, nitem, stream); |
2926 if (rtnval == 0) | 2857 if (rtnval == 0) |
2944 | 2875 |
2945 /********************* directory calls *******************/ | 2876 /********************* directory calls *******************/ |
2946 | 2877 |
2947 #ifdef ENCAPSULATE_CHDIR | 2878 #ifdef ENCAPSULATE_CHDIR |
2948 int | 2879 int |
2949 sys_chdir (const char *path) | 2880 sys_chdir (CONST char *path) |
2950 { | 2881 { |
2951 PATHNAME_CONVERT_OUT (path); | 2882 PATHNAME_CONVERT_OUT (path); |
2952 return chdir (path); | 2883 return chdir (path); |
2953 } | 2884 } |
2954 #endif /* ENCAPSULATE_CHDIR */ | 2885 #endif /* ENCAPSULATE_CHDIR */ |
2955 | 2886 |
2956 | 2887 |
2957 #ifdef ENCAPSULATE_MKDIR | 2888 #ifdef ENCAPSULATE_MKDIR |
2958 int | 2889 int |
2959 sys_mkdir (const char *path, mode_t mode) | 2890 sys_mkdir (CONST char *path, mode_t mode) |
2960 { | 2891 { |
2961 PATHNAME_CONVERT_OUT (path); | 2892 PATHNAME_CONVERT_OUT (path); |
2962 #ifdef WIN32_NATIVE | 2893 #ifdef WINDOWSNT |
2963 return mkdir (path); | 2894 return mkdir (path); |
2964 #else | 2895 #else |
2965 return mkdir (path, mode); | 2896 return mkdir (path, mode); |
2966 #endif | 2897 #endif |
2967 } | 2898 } |
2968 #endif /* ENCAPSULATE_MKDIR */ | 2899 #endif /* ENCAPSULATE_MKDIR */ |
2969 | 2900 |
2970 | 2901 |
2971 #ifdef ENCAPSULATE_OPENDIR | 2902 #ifdef ENCAPSULATE_OPENDIR |
2972 DIR * | 2903 DIR * |
2973 sys_opendir (const char *filename) | 2904 sys_opendir (CONST char *filename) |
2974 { | 2905 { |
2975 DIR *rtnval; | 2906 DIR *rtnval; |
2976 PATHNAME_CONVERT_OUT (filename); | 2907 PATHNAME_CONVERT_OUT (filename); |
2977 | 2908 |
2978 while (!(rtnval = opendir (filename)) | 2909 while (!(rtnval = opendir (filename)) |
3000 if (rtnval == NULL) /* End of directory */ | 2931 if (rtnval == NULL) /* End of directory */ |
3001 return NULL; | 2932 return NULL; |
3002 { | 2933 { |
3003 Extcount external_len; | 2934 Extcount external_len; |
3004 int ascii_filename_p = 1; | 2935 int ascii_filename_p = 1; |
3005 const Extbyte * const external_name = (const Extbyte *) rtnval->d_name; | 2936 CONST Extbyte * CONST external_name = (CONST Extbyte *) rtnval->d_name; |
3006 | 2937 |
3007 /* Optimize for the common all-ASCII case, computing len en passant */ | 2938 /* Optimize for the common all-ASCII case, computing len en passant */ |
3008 for (external_len = 0; external_name[external_len] ; external_len++) | 2939 for (external_len = 0; external_name[external_len] ; external_len++) |
3009 { | 2940 { |
3010 if (!BYTE_ASCII_P (external_name[external_len])) | 2941 if (!BYTE_ASCII_P (external_name[external_len])) |
3013 if (ascii_filename_p) | 2944 if (ascii_filename_p) |
3014 return rtnval; | 2945 return rtnval; |
3015 | 2946 |
3016 { /* Non-ASCII filename */ | 2947 { /* Non-ASCII filename */ |
3017 static Bufbyte_dynarr *internal_DIRENTRY; | 2948 static Bufbyte_dynarr *internal_DIRENTRY; |
3018 const Bufbyte *internal_name; | 2949 CONST Bufbyte *internal_name; |
3019 Bytecount internal_len; | 2950 Bytecount internal_len; |
3020 if (!internal_DIRENTRY) | 2951 if (!internal_DIRENTRY) |
3021 internal_DIRENTRY = Dynarr_new (Bufbyte); | 2952 internal_DIRENTRY = Dynarr_new (Bufbyte); |
3022 else | 2953 else |
3023 Dynarr_reset (internal_DIRENTRY); | 2954 Dynarr_reset (internal_DIRENTRY); |
3024 | 2955 |
3025 Dynarr_add_many (internal_DIRENTRY, (Bufbyte *) rtnval, | 2956 Dynarr_add_many (internal_DIRENTRY, (Bufbyte *) rtnval, |
3026 offsetof (DIRENTRY, d_name)); | 2957 offsetof (DIRENTRY, d_name)); |
3027 | 2958 |
3028 TO_INTERNAL_FORMAT (DATA, (external_name, external_len), | 2959 internal_name = |
3029 ALLOCA, (internal_name, internal_len), | 2960 convert_from_external_format (external_name, external_len, |
3030 Qfile_name); | 2961 &internal_len, FORMAT_FILENAME); |
3031 | 2962 |
3032 Dynarr_add_many (internal_DIRENTRY, internal_name, internal_len); | 2963 Dynarr_add_many (internal_DIRENTRY, internal_name, internal_len); |
3033 Dynarr_add (internal_DIRENTRY, 0); /* zero-terminate */ | 2964 Dynarr_add (internal_DIRENTRY, 0); /* zero-terminate */ |
3034 return (DIRENTRY *) Dynarr_atp (internal_DIRENTRY, 0); | 2965 return (DIRENTRY *) Dynarr_atp (internal_DIRENTRY, 0); |
3035 } | 2966 } |
3053 #endif /* ENCAPSULATE_CLOSEDIR */ | 2984 #endif /* ENCAPSULATE_CLOSEDIR */ |
3054 | 2985 |
3055 | 2986 |
3056 #ifdef ENCAPSULATE_RMDIR | 2987 #ifdef ENCAPSULATE_RMDIR |
3057 int | 2988 int |
3058 sys_rmdir (const char *path) | 2989 sys_rmdir (CONST char *path) |
3059 { | 2990 { |
3060 PATHNAME_CONVERT_OUT (path); | 2991 PATHNAME_CONVERT_OUT (path); |
3061 return rmdir (path); | 2992 return rmdir (path); |
3062 } | 2993 } |
3063 #endif /* ENCAPSULATE_RMDIR */ | 2994 #endif /* ENCAPSULATE_RMDIR */ |
3065 | 2996 |
3066 /***************** file-information calls ******************/ | 2997 /***************** file-information calls ******************/ |
3067 | 2998 |
3068 #ifdef ENCAPSULATE_ACCESS | 2999 #ifdef ENCAPSULATE_ACCESS |
3069 int | 3000 int |
3070 sys_access (const char *path, int mode) | 3001 sys_access (CONST char *path, int mode) |
3071 { | 3002 { |
3072 PATHNAME_CONVERT_OUT (path); | 3003 PATHNAME_CONVERT_OUT (path); |
3073 return access (path, mode); | 3004 return access (path, mode); |
3074 } | 3005 } |
3075 #endif /* ENCAPSULATE_ACCESS */ | 3006 #endif /* ENCAPSULATE_ACCESS */ |
3076 | 3007 |
3077 | 3008 |
3078 #ifdef HAVE_EACCESS | 3009 #ifdef HAVE_EACCESS |
3079 #ifdef ENCAPSULATE_EACCESS | 3010 #ifdef ENCAPSULATE_EACCESS |
3080 int | 3011 int |
3081 sys_eaccess (const char *path, int mode) | 3012 sys_eaccess (CONST char *path, int mode) |
3082 { | 3013 { |
3083 PATHNAME_CONVERT_OUT (path); | 3014 PATHNAME_CONVERT_OUT (path); |
3084 return eaccess (path, mode); | 3015 return eaccess (path, mode); |
3085 } | 3016 } |
3086 #endif /* ENCAPSULATE_EACCESS */ | 3017 #endif /* ENCAPSULATE_EACCESS */ |
3087 #endif /* HAVE_EACCESS */ | 3018 #endif /* HAVE_EACCESS */ |
3088 | 3019 |
3089 | 3020 |
3090 #ifdef ENCAPSULATE_LSTAT | 3021 #ifdef ENCAPSULATE_LSTAT |
3091 int | 3022 int |
3092 sys_lstat (const char *path, struct stat *buf) | 3023 sys_lstat (CONST char *path, struct stat *buf) |
3093 { | 3024 { |
3094 PATHNAME_CONVERT_OUT (path); | 3025 PATHNAME_CONVERT_OUT (path); |
3095 return lstat (path, buf); | 3026 return lstat (path, buf); |
3096 } | 3027 } |
3097 #endif /* ENCAPSULATE_LSTAT */ | 3028 #endif /* ENCAPSULATE_LSTAT */ |
3098 | 3029 |
3099 | 3030 |
3100 #ifdef ENCAPSULATE_READLINK | 3031 #ifdef ENCAPSULATE_READLINK |
3101 int | 3032 int |
3102 sys_readlink (const char *path, char *buf, size_t bufsiz) | 3033 sys_readlink (CONST char *path, char *buf, size_t bufsiz) |
3103 { | 3034 { |
3104 PATHNAME_CONVERT_OUT (path); | 3035 PATHNAME_CONVERT_OUT (path); |
3105 /* #### currently we don't do conversions on the incoming data */ | 3036 /* #### currently we don't do conversions on the incoming data */ |
3106 return readlink (path, buf, bufsiz); | 3037 return readlink (path, buf, bufsiz); |
3107 } | 3038 } |
3108 #endif /* ENCAPSULATE_READLINK */ | 3039 #endif /* ENCAPSULATE_READLINK */ |
3109 | 3040 |
3110 #ifdef ENCAPSULATE_FSTAT | |
3111 int | |
3112 sys_fstat (int fd, struct stat *buf) | |
3113 { | |
3114 #ifdef WIN32_NATIVE | |
3115 return mswindows_fstat (fd, buf); | |
3116 #else | |
3117 return fstat (fd, buf); | |
3118 #endif | |
3119 } | |
3120 #endif /* ENCAPSULATE_FSTAT */ | |
3121 | 3041 |
3122 #ifdef ENCAPSULATE_STAT | 3042 #ifdef ENCAPSULATE_STAT |
3123 int | 3043 int |
3124 sys_stat (const char *path, struct stat *buf) | 3044 sys_stat (CONST char *path, struct stat *buf) |
3125 { | 3045 { |
3126 PATHNAME_CONVERT_OUT (path); | 3046 PATHNAME_CONVERT_OUT (path); |
3127 #ifdef WIN32_NATIVE | |
3128 return mswindows_stat (path, buf); | |
3129 #else | |
3130 return stat (path, buf); | 3047 return stat (path, buf); |
3131 #endif | |
3132 } | 3048 } |
3133 #endif /* ENCAPSULATE_STAT */ | 3049 #endif /* ENCAPSULATE_STAT */ |
3050 | |
3134 | 3051 |
3135 /****************** file-manipulation calls *****************/ | 3052 /****************** file-manipulation calls *****************/ |
3136 | 3053 |
3137 #ifdef ENCAPSULATE_CHMOD | 3054 #ifdef ENCAPSULATE_CHMOD |
3138 int | 3055 int |
3139 sys_chmod (const char *path, mode_t mode) | 3056 sys_chmod (CONST char *path, mode_t mode) |
3140 { | 3057 { |
3141 PATHNAME_CONVERT_OUT (path); | 3058 PATHNAME_CONVERT_OUT (path); |
3142 return chmod (path, mode); | 3059 return chmod (path, mode); |
3143 } | 3060 } |
3144 #endif /* ENCAPSULATE_CHMOD */ | 3061 #endif /* ENCAPSULATE_CHMOD */ |
3145 | 3062 |
3146 | 3063 |
3147 #ifdef ENCAPSULATE_CREAT | 3064 #ifdef ENCAPSULATE_CREAT |
3148 int | 3065 int |
3149 sys_creat (const char *path, mode_t mode) | 3066 sys_creat (CONST char *path, mode_t mode) |
3150 { | 3067 { |
3151 PATHNAME_CONVERT_OUT (path); | 3068 PATHNAME_CONVERT_OUT (path); |
3152 return creat (path, mode); | 3069 return creat (path, mode); |
3153 } | 3070 } |
3154 #endif /* ENCAPSULATE_CREAT */ | 3071 #endif /* ENCAPSULATE_CREAT */ |
3155 | 3072 |
3156 | 3073 |
3157 #ifdef ENCAPSULATE_LINK | 3074 #ifdef ENCAPSULATE_LINK |
3158 int | 3075 int |
3159 sys_link (const char *existing, const char *new) | 3076 sys_link (CONST char *existing, CONST char *new) |
3160 { | 3077 { |
3161 PATHNAME_CONVERT_OUT (existing); | 3078 PATHNAME_CONVERT_OUT (existing); |
3162 PATHNAME_CONVERT_OUT (new); | 3079 PATHNAME_CONVERT_OUT (new); |
3163 return link (existing, new); | 3080 return link (existing, new); |
3164 } | 3081 } |
3165 #endif /* ENCAPSULATE_LINK */ | 3082 #endif /* ENCAPSULATE_LINK */ |
3166 | 3083 |
3167 | 3084 |
3168 #ifdef ENCAPSULATE_RENAME | 3085 #ifdef ENCAPSULATE_RENAME |
3169 int | 3086 int |
3170 sys_rename (const char *old, const char *new) | 3087 sys_rename (CONST char *old, CONST char *new) |
3171 { | 3088 { |
3172 PATHNAME_CONVERT_OUT (old); | 3089 PATHNAME_CONVERT_OUT (old); |
3173 PATHNAME_CONVERT_OUT (new); | 3090 PATHNAME_CONVERT_OUT (new); |
3174 #ifdef WIN32_NATIVE | 3091 #ifdef WINDOWSNT |
3175 /* Windows rename fails if NEW exists */ | 3092 /* Windows rename fails if NEW exists */ |
3176 if (rename (old, new) == 0) | 3093 if (rename (old, new) == 0) |
3177 return 0; | 3094 return 0; |
3178 if (errno != EEXIST) | 3095 if (errno != EEXIST) |
3179 return -1; | 3096 return -1; |
3180 unlink (new); | 3097 unlink (new); |
3181 #endif /* WIN32_NATIVE */ | 3098 #endif /* WINDOWSNT */ |
3182 return rename (old, new); | 3099 return rename (old, new); |
3183 } | 3100 } |
3184 #endif /* ENCAPSULATE_RENAME */ | 3101 #endif /* ENCAPSULATE_RENAME */ |
3185 | 3102 |
3186 | 3103 |
3187 #ifdef ENCAPSULATE_SYMLINK | 3104 #ifdef ENCAPSULATE_SYMLINK |
3188 int | 3105 int |
3189 sys_symlink (const char *name1, const char *name2) | 3106 sys_symlink (CONST char *name1, CONST char *name2) |
3190 { | 3107 { |
3191 PATHNAME_CONVERT_OUT (name1); | 3108 PATHNAME_CONVERT_OUT (name1); |
3192 PATHNAME_CONVERT_OUT (name2); | 3109 PATHNAME_CONVERT_OUT (name2); |
3193 return symlink (name1, name2); | 3110 return symlink (name1, name2); |
3194 } | 3111 } |
3195 #endif /* ENCAPSULATE_SYMLINK */ | 3112 #endif /* ENCAPSULATE_SYMLINK */ |
3196 | 3113 |
3197 | 3114 |
3198 #ifdef ENCAPSULATE_UNLINK | 3115 #ifdef ENCAPSULATE_UNLINK |
3199 int | 3116 int |
3200 sys_unlink (const char *path) | 3117 sys_unlink (CONST char *path) |
3201 { | 3118 { |
3202 PATHNAME_CONVERT_OUT (path); | 3119 PATHNAME_CONVERT_OUT (path); |
3203 return unlink (path); | 3120 return unlink (path); |
3204 } | 3121 } |
3205 #endif /* ENCAPSULATE_UNLINK */ | 3122 #endif /* ENCAPSULATE_UNLINK */ |
3206 | 3123 |
3207 | 3124 |
3208 #ifdef ENCAPSULATE_EXECVP | 3125 #ifdef ENCAPSULATE_EXECVP |
3209 int | 3126 int |
3210 sys_execvp (const char *path, char * const * argv) | 3127 sys_execvp (CONST char *path, char * CONST * argv) |
3211 { | 3128 { |
3212 int i, argc; | 3129 int i, argc; |
3213 char ** new_argv; | 3130 char ** new_argv; |
3214 | 3131 |
3215 PATHNAME_CONVERT_OUT (path); | 3132 PATHNAME_CONVERT_OUT (path); |
3233 | 3150 |
3234 /***** (these are primarily required for USG, it seems) *****/ | 3151 /***** (these are primarily required for USG, it seems) *****/ |
3235 | 3152 |
3236 #ifndef HAVE_GETCWD | 3153 #ifndef HAVE_GETCWD |
3237 char * | 3154 char * |
3238 getcwd (char *pathname, size_t size) | 3155 getcwd (char *pathname, int size) |
3239 { | 3156 { |
3240 return getwd (pathname); | 3157 return getwd (pathname); |
3241 } | 3158 } |
3242 #endif /* emulate getcwd */ | 3159 #endif /* emulate getcwd */ |
3243 | 3160 |
3277 * that files be of same type (regular->regular, dir->dir, etc). | 3194 * that files be of same type (regular->regular, dir->dir, etc). |
3278 */ | 3195 */ |
3279 | 3196 |
3280 #ifndef HAVE_RENAME | 3197 #ifndef HAVE_RENAME |
3281 int | 3198 int |
3282 rename (const char *from, const char *to) | 3199 rename (CONST char *from, CONST char *to) |
3283 { | 3200 { |
3284 if (access (from, 0) == 0) | 3201 if (access (from, 0) == 0) |
3285 { | 3202 { |
3286 unlink (to); | 3203 unlink (to); |
3287 if (link (from, to) == 0) | 3204 if (link (from, to) == 0) |
3391 for increased accuracy. */ | 3308 for increased accuracy. */ |
3392 | 3309 |
3393 static int | 3310 static int |
3394 get_process_times_1 (long *user_ticks, long *system_ticks) | 3311 get_process_times_1 (long *user_ticks, long *system_ticks) |
3395 { | 3312 { |
3396 #if defined (_SC_CLK_TCK) || defined (CLK_TCK) && !defined(WIN32_NATIVE) | 3313 #if defined (_SC_CLK_TCK) || defined (CLK_TCK) && !defined(WINDOWSNT) |
3397 /* We have the POSIX times() function available. */ | 3314 /* We have the POSIX times() function available. */ |
3398 struct tms tttt; | 3315 struct tms tttt; |
3399 times (&tttt); | 3316 times (&tttt); |
3400 *user_ticks = (long) tttt.tms_utime; | 3317 *user_ticks = (long) tttt.tms_utime; |
3401 *system_ticks = (long) tttt.tms_stime; | 3318 *system_ticks = (long) tttt.tms_stime; |
3533 /* Strings corresponding to defined signals */ | 3450 /* Strings corresponding to defined signals */ |
3534 /************************************************************************/ | 3451 /************************************************************************/ |
3535 | 3452 |
3536 #if !defined (SYS_SIGLIST_DECLARED) && !defined (HAVE_SYS_SIGLIST) | 3453 #if !defined (SYS_SIGLIST_DECLARED) && !defined (HAVE_SYS_SIGLIST) |
3537 | 3454 |
3538 #if defined(WIN32_NATIVE) || defined(CYGWIN) | 3455 #if defined(WINDOWSNT) || defined(__CYGWIN32__) |
3539 const char *sys_siglist[] = | 3456 CONST char *sys_siglist[] = |
3540 { | 3457 { |
3541 "bum signal!!", | 3458 "bum signal!!", |
3542 "hangup", | 3459 "hangup", |
3543 "interrupt", | 3460 "interrupt", |
3544 "quit", | 3461 "quit", |
3567 }; | 3484 }; |
3568 #endif | 3485 #endif |
3569 | 3486 |
3570 #ifdef USG | 3487 #ifdef USG |
3571 #ifdef AIX | 3488 #ifdef AIX |
3572 const char *sys_siglist[NSIG + 1] = | 3489 CONST char *sys_siglist[NSIG + 1] = |
3573 { | 3490 { |
3574 /* AIX has changed the signals a bit */ | 3491 /* AIX has changed the signals a bit */ |
3575 DEFER_GETTEXT ("bogus signal"), /* 0 */ | 3492 DEFER_GETTEXT ("bogus signal"), /* 0 */ |
3576 DEFER_GETTEXT ("hangup"), /* 1 SIGHUP */ | 3493 DEFER_GETTEXT ("hangup"), /* 1 SIGHUP */ |
3577 DEFER_GETTEXT ("interrupt"), /* 2 SIGINT */ | 3494 DEFER_GETTEXT ("interrupt"), /* 2 SIGINT */ |
3607 DEFER_GETTEXT ("HFT input ready"), /* 31 SIGMSG */ | 3524 DEFER_GETTEXT ("HFT input ready"), /* 31 SIGMSG */ |
3608 #endif | 3525 #endif |
3609 0 | 3526 0 |
3610 }; | 3527 }; |
3611 #else /* USG, not AIX */ | 3528 #else /* USG, not AIX */ |
3612 const char *sys_siglist[NSIG + 1] = | 3529 CONST char *sys_siglist[NSIG + 1] = |
3613 { | 3530 { |
3614 DEFER_GETTEXT ("bogus signal"), /* 0 */ | 3531 DEFER_GETTEXT ("bogus signal"), /* 0 */ |
3615 DEFER_GETTEXT ("hangup"), /* 1 SIGHUP */ | 3532 DEFER_GETTEXT ("hangup"), /* 1 SIGHUP */ |
3616 DEFER_GETTEXT ("interrupt"), /* 2 SIGINT */ | 3533 DEFER_GETTEXT ("interrupt"), /* 2 SIGINT */ |
3617 DEFER_GETTEXT ("quit"), /* 3 SIGQUIT */ | 3534 DEFER_GETTEXT ("quit"), /* 3 SIGQUIT */ |
3656 0 | 3573 0 |
3657 }; | 3574 }; |
3658 #endif /* not AIX */ | 3575 #endif /* not AIX */ |
3659 #endif /* USG */ | 3576 #endif /* USG */ |
3660 #ifdef DGUX | 3577 #ifdef DGUX |
3661 const char *sys_siglist[NSIG + 1] = | 3578 CONST char *sys_siglist[NSIG + 1] = |
3662 { | 3579 { |
3663 DEFER_GETTEXT ("null signal"), /* 0 SIGNULL */ | 3580 DEFER_GETTEXT ("null signal"), /* 0 SIGNULL */ |
3664 DEFER_GETTEXT ("hangup"), /* 1 SIGHUP */ | 3581 DEFER_GETTEXT ("hangup"), /* 1 SIGHUP */ |
3665 DEFER_GETTEXT ("interrupt"), /* 2 SIGINT */ | 3582 DEFER_GETTEXT ("interrupt"), /* 2 SIGINT */ |
3666 DEFER_GETTEXT ("quit"), /* 3 SIGQUIT */ | 3583 DEFER_GETTEXT ("quit"), /* 3 SIGQUIT */ |
3761 #endif /* SYSV_SYSTEM_DIR */ | 3678 #endif /* SYSV_SYSTEM_DIR */ |
3762 | 3679 |
3763 #ifdef NONSYSTEM_DIR_LIBRARY | 3680 #ifdef NONSYSTEM_DIR_LIBRARY |
3764 | 3681 |
3765 DIR * | 3682 DIR * |
3766 opendir (const char *filename) /* name of directory */ | 3683 opendir (CONST char *filename) /* name of directory */ |
3767 { | 3684 { |
3768 DIR *dirp; /* -> malloc'ed storage */ | 3685 DIR *dirp; /* -> malloc'ed storage */ |
3769 int fd; /* file descriptor for read */ | 3686 int fd; /* file descriptor for read */ |
3770 struct stat sbuf; /* result of fstat */ | 3687 struct stat sbuf; /* result of fstat */ |
3771 | 3688 |
3863 */ | 3780 */ |
3864 #ifdef MKDIR_PROTOTYPE | 3781 #ifdef MKDIR_PROTOTYPE |
3865 MKDIR_PROTOTYPE | 3782 MKDIR_PROTOTYPE |
3866 #else | 3783 #else |
3867 int | 3784 int |
3868 mkdir (const char *dpath, int dmode) | 3785 mkdir (CONST char *dpath, int dmode) |
3869 #endif | 3786 #endif |
3870 { | 3787 { |
3871 int cpid, status, fd; | 3788 int cpid, status, fd; |
3872 struct stat statbuf; | 3789 struct stat statbuf; |
3873 | 3790 |
3923 } | 3840 } |
3924 #endif /* not HAVE_MKDIR */ | 3841 #endif /* not HAVE_MKDIR */ |
3925 | 3842 |
3926 #ifndef HAVE_RMDIR | 3843 #ifndef HAVE_RMDIR |
3927 int | 3844 int |
3928 rmdir (const char *dpath) | 3845 rmdir (CONST char *dpath) |
3929 { | 3846 { |
3930 int cpid, status, fd; | 3847 int cpid, status, fd; |
3931 struct stat statbuf; | 3848 struct stat statbuf; |
3932 | 3849 |
3933 if (stat (dpath, &statbuf) != 0) | 3850 if (stat (dpath, &statbuf) != 0) |