]> code.delx.au - gnu-emacs/blobdiff - src/mac.c
(w32_get_rdb_resource): New function.
[gnu-emacs] / src / mac.c
index 833ee5f3bdcac4b921029b6ab14b206f225b8238..a6b92db4680fe9c958d97378c0bc439dfd134c07 100644 (file)
--- a/src/mac.c
+++ b/src/mac.c
@@ -32,6 +32,7 @@ Boston, MA 02111-1307, USA.  */
 #include <pwd.h>
 #include <sys/param.h>
 #include <stdlib.h>
+#include <fcntl.h>
 #if __MWERKS__
 #include <unistd.h>
 #endif
@@ -2751,6 +2752,7 @@ and t is the same as `SECONDARY'.  */)
 #undef select
 
 extern int inhibit_window_system;
+extern int noninteractive;
 
 /* When Emacs is started from the Finder, SELECT always immediately
    returns as if input is present when file descriptor 0 is polled for
@@ -2767,8 +2769,74 @@ sys_select (n, rfds, wfds, efds, timeout)
 {
   if (!inhibit_window_system && rfds && FD_ISSET (0, rfds))
     return 1;
+  else if (inhibit_window_system || noninteractive ||
+          (timeout && (EMACS_SECS(*timeout)==0) &&
+           (EMACS_USECS(*timeout)==0)))
+    return select(n, rfds, wfds, efds, timeout);
   else
-    return select (n, rfds, wfds, efds, timeout);
+    {
+      EMACS_TIME end_time, now;
+
+      EMACS_GET_TIME (end_time);
+      if (timeout)
+       EMACS_ADD_TIME (end_time, end_time, *timeout);
+
+      do
+       {
+         int r;
+         EMACS_TIME one_second;
+         SELECT_TYPE orfds;
+
+         FD_ZERO (&orfds);
+         if (rfds)
+           {
+             orfds = *rfds;
+           }
+
+         EMACS_SET_SECS (one_second, 1);
+         EMACS_SET_USECS (one_second, 0);
+
+         if (timeout && EMACS_TIME_LT(*timeout, one_second))
+           one_second = *timeout;
+
+         if ((r = select (n, &orfds, wfds, efds, &one_second)) > 0)
+           {
+             *rfds = orfds;
+             return r;
+           }
+
+         mac_check_for_quit_char();
+
+         EMACS_GET_TIME (now);
+         EMACS_SUB_TIME (now, end_time, now);
+       }
+      while (!timeout || !EMACS_TIME_NEG_P (now));
+
+      return 0;
+    }
+}
+
+#undef read
+int sys_read (fds, buf, nbyte)
+     int fds;
+     char *buf;
+     unsigned int nbyte;
+{
+  SELECT_TYPE rfds;
+  EMACS_TIME one_second;
+  int r;
+
+  /* Use select to block on IO while still checking for quit_char */
+  if (!inhibit_window_system && !noninteractive &&
+      ! (fcntl(fds, F_GETFL, 0) & O_NONBLOCK))
+    {
+      FD_ZERO (&rfds);
+      FD_SET (fds, &rfds);
+      if (sys_select (fds+1, &rfds, 0, 0, NULL) < 0)
+       return -1;
+    }
+
+  return read (fds, buf, nbyte);
 }