aboutsummaryrefslogtreecommitdiffstats
path: root/src/mac.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/mac.c')
-rw-r--r--src/mac.c145
1 files changed, 81 insertions, 64 deletions
diff --git a/src/mac.c b/src/mac.c
index 9f3455ab5dc..9740b3bf3f4 100644
--- a/src/mac.c
+++ b/src/mac.c
@@ -2769,6 +2769,8 @@ and t is the same as `SECONDARY'. */)
2769extern int inhibit_window_system; 2769extern int inhibit_window_system;
2770extern int noninteractive; 2770extern int noninteractive;
2771 2771
2772#include "blockinput.h"
2773
2772/* When Emacs is started from the Finder, SELECT always immediately 2774/* When Emacs is started from the Finder, SELECT always immediately
2773 returns as if input is present when file descriptor 0 is polled for 2775 returns as if input is present when file descriptor 0 is polled for
2774 input. Strangely, when Emacs is run as a GUI application from the 2776 input. Strangely, when Emacs is run as a GUI application from the
@@ -2776,85 +2778,100 @@ extern int noninteractive;
2776 the system call SELECT corrects this discrepancy. */ 2778 the system call SELECT corrects this discrepancy. */
2777int 2779int
2778sys_select (n, rfds, wfds, efds, timeout) 2780sys_select (n, rfds, wfds, efds, timeout)
2779 int n; 2781 int n;
2780 SELECT_TYPE *rfds; 2782 SELECT_TYPE *rfds;
2781 SELECT_TYPE *wfds; 2783 SELECT_TYPE *wfds;
2782 SELECT_TYPE *efds; 2784 SELECT_TYPE *efds;
2783 struct timeval *timeout; 2785 struct timeval *timeout;
2784{ 2786{
2785 if (!inhibit_window_system && rfds && FD_ISSET (0, rfds)) 2787 OSErr err;
2786 return 1; 2788 EMACS_TIME end_time, now, remaining_time;
2787 else if (inhibit_window_system || noninteractive || 2789
2788 (timeout && (EMACS_SECS(*timeout)==0) && 2790 if (inhibit_window_system || noninteractive
2789 (EMACS_USECS(*timeout)==0))) 2791 || rfds == NULL || !FD_ISSET (0, rfds))
2790 return select(n, rfds, wfds, efds, timeout); 2792 return select (n, rfds, wfds, efds, timeout);
2791 else 2793
2792 { 2794 if (wfds == NULL && efds == NULL)
2793 EMACS_TIME end_time, now; 2795 {
2794 2796 int i;
2795 EMACS_GET_TIME (end_time); 2797
2796 if (timeout) 2798 for (i = 1; i < n; i++)
2797 EMACS_ADD_TIME (end_time, end_time, *timeout); 2799 if (FD_ISSET (i, rfds))
2798 2800 break;
2799 do 2801 if (i == n)
2800 { 2802 {
2801 int r; 2803 EventTimeout timeout_sec =
2802 EMACS_TIME one_second; 2804 (timeout
2803 SELECT_TYPE orfds; 2805 ? (EMACS_SECS (*timeout) * kEventDurationSecond
2804 2806 + EMACS_USECS (*timeout) * kEventDurationMicrosecond)
2805 FD_ZERO (&orfds); 2807 : kEventDurationForever);
2806 if (rfds) 2808
2809 BLOCK_INPUT;
2810 err = ReceiveNextEvent (0, NULL, timeout_sec,
2811 kEventLeaveInQueue, NULL);
2812 UNBLOCK_INPUT;
2813 if (err == noErr)
2807 { 2814 {
2808 orfds = *rfds; 2815 FD_ZERO (rfds);
2816 FD_SET (0, rfds);
2817 return 1;
2809 } 2818 }
2819 else
2820 return 0;
2821 }
2822 }
2810 2823
2811 EMACS_SET_SECS (one_second, 1); 2824 if (timeout)
2812 EMACS_SET_USECS (one_second, 0); 2825 {
2826 remaining_time = *timeout;
2827 EMACS_GET_TIME (now);
2828 EMACS_ADD_TIME (end_time, now, remaining_time);
2829 }
2830 FD_CLR (0, rfds);
2831 do
2832 {
2833 EMACS_TIME select_timeout;
2834 SELECT_TYPE orfds = *rfds;
2835 int r;
2813 2836
2814 if (timeout && EMACS_TIME_LT(*timeout, one_second)) 2837 EMACS_SET_SECS_USECS (select_timeout, 0, 20000);
2815 one_second = *timeout;
2816 2838
2817 if ((r = select (n, &orfds, wfds, efds, &one_second)) > 0) 2839 if (timeout && EMACS_TIME_LT (remaining_time, select_timeout))
2840 select_timeout = remaining_time;
2841
2842 r = select (n, &orfds, wfds, efds, &select_timeout);
2843 BLOCK_INPUT;
2844 err = ReceiveNextEvent (0, NULL, kEventDurationNoWait,
2845 kEventLeaveInQueue, NULL);
2846 UNBLOCK_INPUT;
2847 if (r > 0)
2848 {
2849 *rfds = orfds;
2850 if (err == noErr)
2818 { 2851 {
2819 *rfds = orfds; 2852 FD_SET (0, rfds);
2820 return r; 2853 r++;
2821 } 2854 }
2855 return r;
2856 }
2857 else if (err == noErr)
2858 {
2859 FD_ZERO (rfds);
2860 FD_SET (0, rfds);
2861 return 1;
2862 }
2822 2863
2823 mac_check_for_quit_char(); 2864 if (timeout)
2824 2865 {
2825 EMACS_GET_TIME (now); 2866 EMACS_GET_TIME (now);
2826 EMACS_SUB_TIME (now, end_time, now); 2867 EMACS_SUB_TIME (remaining_time, end_time, now);
2827 } 2868 }
2828 while (!timeout || !EMACS_TIME_NEG_P (now));
2829
2830 return 0;
2831 }
2832}
2833
2834#undef read
2835int sys_read (fds, buf, nbyte)
2836 int fds;
2837 char *buf;
2838 unsigned int nbyte;
2839{
2840 SELECT_TYPE rfds;
2841 EMACS_TIME one_second;
2842 int r;
2843
2844 /* Use select to block on IO while still checking for quit_char */
2845 if (!inhibit_window_system && !noninteractive &&
2846 ! (fcntl(fds, F_GETFL, 0) & O_NONBLOCK))
2847 {
2848 FD_ZERO (&rfds);
2849 FD_SET (fds, &rfds);
2850 if (sys_select (fds+1, &rfds, 0, 0, NULL) < 0)
2851 return -1;
2852 } 2869 }
2870 while (!timeout || EMACS_TIME_LT (now, end_time));
2853 2871
2854 return read (fds, buf, nbyte); 2872 return 0;
2855} 2873}
2856 2874
2857
2858/* Set up environment variables so that Emacs can correctly find its 2875/* Set up environment variables so that Emacs can correctly find its
2859 support files when packaged as an application bundle. Directories 2876 support files when packaged as an application bundle. Directories
2860 placed in /usr/local/share/emacs/<emacs-version>/, /usr/local/bin, 2877 placed in /usr/local/share/emacs/<emacs-version>/, /usr/local/bin,