#include <stdbool.h>
+/* GNUC_PREREQ (V, W, X) is true if this is GNU C version V.W.X or later.
+ It can be used in a preprocessor expression. */
+#ifndef __GNUC_MINOR__
+# define GNUC_PREREQ(v, w, x) false
+#elif ! defined __GNUC_PATCHLEVEL__
+# define GNUC_PREREQ(v, w, x) ((v) < __GNUC__ + ((w) <= __GNUC_MINOR__))
+#else
+# define GNUC_PREREQ(v, w, x) \
+ ((v) < __GNUC__ + ((w) <= __GNUC_MINOR__ + ((x) <= __GNUC_PATCHLEVEL__)))
+#endif
+
/* The type of bool bitfields. Needed to compile Objective-C with
standard GCC. It was also needed to port to pre-C99 compilers,
although we don't care about that any more. */
#include TERM_HEADER
#endif /* HAVE_WINDOW_SYSTEM */
+/* Work around GCC bug 54561. */
+#if GNUC_PREREQ (4, 3, 0)
+# pragma GCC diagnostic ignored "-Wclobbered"
+#endif
+
/* Variables for blockinput.h: */
/* Positive if interrupt input is blocked right now. */
# define SOCK_CLOEXEC 0
#endif
+/* True if ERRNUM represents an error where the system call would
+ block if a blocking variant were used. */
+static bool
+would_block (int errnum)
+{
+#ifdef EWOULDBLOCK
+ if (EWOULDBLOCK != EAGAIN && errnum == EWOULDBLOCK)
+ return true;
+#endif
+ return errnum == EAGAIN;
+}
+
#ifndef HAVE_ACCEPT4
/* Emulate GNU/Linux accept4 and socket well enough for this module. */
if (s < 0)
{
int code = errno;
-
- if (code == EAGAIN)
- return;
-#ifdef EWOULDBLOCK
- if (code == EWOULDBLOCK)
- return;
-#endif
-
- if (!NILP (ps->log))
+ if (!would_block (code) && !NILP (ps->log))
call3 (ps->log, server, Qnil,
concat3 (build_string ("accept failed with code"),
Fnumber_to_string (make_number (code)),
int nread = read_process_output (proc, wait_proc->infd);
if (nread < 0)
{
- if (errno == EIO || errno == EAGAIN)
- break;
-#ifdef EWOULDBLOCK
- if (errno == EWOULDBLOCK)
- break;
-#endif
+ if (errno == EIO || would_block (errno))
+ break;
}
else
{
if (do_display)
redisplay_preserve_echo_area (12);
}
-#ifdef EWOULDBLOCK
- else if (nread == -1 && errno == EWOULDBLOCK)
- ;
-#endif
- else if (nread == -1 && errno == EAGAIN)
+ else if (nread == -1 && would_block (errno))
;
#ifdef WINDOWSNT
/* FIXME: Is this special case still needed? */
if (rv < 0)
{
- if (errno == EAGAIN
-#ifdef EWOULDBLOCK
- || errno == EWOULDBLOCK
-#endif
- )
+ if (would_block (errno))
/* Buffer is full. Wait, accepting input;
that may allow the program
to finish doing output and read more. */