- * \return Standard. In any case, the number of bytes that have been written is
- * stored in \a len.
- */
-int write_all(int fd, const char *buf, size_t *len)
-{
- size_t total = *len;
-
- assert(total);
- *len = 0;
- while (*len < total) {
- int ret = write(fd, buf + *len, total - *len);
- if (ret == -1)
- return -ERRNO_TO_ERROR(errno);
- *len += ret;
- }
- return 1;
-}
-
-/**
- * Check whether a file exists.
- *
- * \param fn The file name.
- *
- * \return Non-zero iff file exists.
- */
-int file_exists(const char *fn)
-{
- struct stat statbuf;
-
- return !stat(fn, &statbuf);
-}
-
-/**
- * Paraslash's wrapper for select(2).
- *
- * It calls select(2) (with no exceptfds) and starts over if select() was
- * interrupted by a signal.
- *
- * \param n The highest-numbered descriptor in any of the two sets, plus 1.
- * \param readfds fds that should be checked for readability.
- * \param writefds fds that should be checked for writablility.
- * \param timeout_tv upper bound on the amount of time elapsed before select()
- * returns.
- *
- * \return The return value of the underlying select() call on success, the
- * negative system error code on errors.
- *
- * All arguments are passed verbatim to select(2).
- * \sa select(2) select_tut(2).
- */
-int para_select(int n, fd_set *readfds, fd_set *writefds,
- struct timeval *timeout_tv)
-{
- int ret, err;
- do {
- ret = select(n, readfds, writefds, NULL, timeout_tv);
- err = errno;
- } while (ret < 0 && err == EINTR);
- if (ret < 0)
- return -ERRNO_TO_ERROR(errno);
- return ret;
-}
-
-/**
- * Set a file descriptor to blocking mode.
- *
- * \param fd The file descriptor.