+/* warning: EOF is also an error. */
+static size_t
+xread (int fd, void *buf, size_t count)
+{
+ ssize_t retval = read (fd, buf, count);
+
+ if (retval <= 0)
+ error (EXIT_FAILURE, errno, _("Error reading data"));
+
+ return retval;
+}
+
+/* warning: No events are also an error. */
+static void
+xpoll (struct pollfd *fds, nfds_t nfds, int timeout)
+{
+ if (poll (fds, nfds, timeout) != 1)
+ error (EXIT_FAILURE, errno, _("poll returned error"));
+}
+
+static pid_t
+xfork (void)
+{
+ pid_t retval = fork ();
+
+ if (retval == -1)
+ error (EXIT_FAILURE, errno, _("Error calling fork"));
+
+ return retval;
+}
+
+static void
+xsnprintf (char *str, size_t size, const char *format, ...)
+{
+ int i;
+ va_list ap;
+
+ va_start (ap, format);
+ i = vsnprintf (str, size, format, ap);
+ va_end (ap);
+ if (i <= 0 || strlen (str) >= size - 1)
+ error (EXIT_FAILURE, errno, _("Error calling sprintf"));
+}
+
+static void
+xfflush (FILE *stream)
+{
+ if (fflush (stream) != 0)
+ error (EXIT_FAILURE, errno, _("Error calling fflush"));
+}
+
+static void
+xdup2 (int oldfd, int newfd)
+{
+ if (dup2 (oldfd, newfd) != newfd)
+ error (EXIT_FAILURE, errno, _("Error calling dup2 (%d, %d)"), oldfd,
+ newfd);
+}
+
+static void
+xclose (int fd)
+{
+ if (close (fd) != 0)
+ error (EXIT_FAILURE, errno, _("Error calling close (%d)"), fd);
+}
+
+static void
+xpipe (int pipefd[2])
+{
+ if (pipe (pipefd) != 0)
+ error (EXIT_FAILURE, errno, _("Error creating internal pipe"));
+}
+
+static void
+xraise (int sig)
+{
+ if (raise (sig) != 0)
+ error (EXIT_FAILURE, errno, _("Error calling raise (%d)"), sig);
+}
+
+static void
+xfcntl_setfl (int fd, int cmdarg)
+{
+ if (fcntl (fd, F_SETFL, cmdarg) != 0)
+ error (EXIT_FAILURE, errno,
+ _("Error calling fcntl (%d, F_SETFL, 0%o)"), fd, cmdarg);
+}
+
+static void
+xwrite (int fd, const void *buf, size_t count)
+{
+ if (!count)
+ return;
+
+ if ((ssize_t) count < 0 || write (fd, buf, count) != (ssize_t) count)
+ error (EXIT_FAILURE, errno,
+ _("Error calling write (%d, ..., %zu)"), fd, count);
+}
+
+static int
+xopen (const char *pathname, int flags, mode_t mode)
+{
+ int retval = open (pathname, flags, mode);
+
+ if (retval == -1)
+ error (EXIT_FAILURE, errno,
+ _("Error %s file \"%s\" (flags 0x%x, mode 0%o)"),
+ flags & O_APPEND ? _("appending")
+ : (flags & O_CREAT ? _("creating")
+ : _("opening")),
+ pathname, flags, mode);
+
+ return retval;
+}
+