]> git.tuebingen.mpg.de Git - paraslash.git/blobdiff - fd.c
fd: Improve documentation of write_va_buffer().
[paraslash.git] / fd.c
diff --git a/fd.c b/fd.c
index b8d1062d1ce98628468dfd7b184f4db346ef60ee..5d23babf38c70e85765931d9ac0c0b0eb4730e37 100644 (file)
--- a/fd.c
+++ b/fd.c
@@ -6,7 +6,6 @@
 #include <sys/types.h>
 #include <dirent.h>
 #include <sys/mman.h>
-#include <poll.h>
 
 #include "para.h"
 #include "error.h"
@@ -150,12 +149,20 @@ int write_all(int fd, const char *buf, size_t len)
 }
 
 /**
- * Write a buffer given by a format string.
+ * A fprintf-like function for raw file descriptors.
+ *
+ * This function creates a string buffer according to the given format and
+ * writes this buffer to a file descriptor.
  *
  * \param fd The file descriptor.
  * \param fmt A format string.
  *
+ * The difference to fprintf(3) is that the first argument is a file
+ * descriptor, not a FILE pointer. This function does not rely on stdio.
+ *
  * \return The return value of the underlying call to \ref write_all().
+ *
+ * \sa fprintf(3), \ref xvasprintf().
  */
 __printf_2_3 int write_va_buffer(int fd, const char *fmt, ...)
 {
@@ -270,7 +277,7 @@ int read_nonblock(int fd, void *buf, size_t sz, size_t *num_bytes)
 int read_pattern(int fd, const char *pattern, size_t bufsize)
 {
        size_t n, len;
-       char *buf = para_malloc(bufsize + 1);
+       char *buf = alloc(bufsize + 1);
        int ret = read_nonblock(fd, buf, bufsize, &n);
 
        buf[n] = '\0';
@@ -309,37 +316,6 @@ bool file_exists(const char *fn)
        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 Upper bound in milliseconds.
- *
- * \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, int timeout)
-{
-       int ret;
-       struct timeval tv;
-
-       ms2tv(timeout, &tv);
-       do
-               ret = select(n, readfds, writefds, NULL, &tv);
-       while (ret < 0 && errno == EINTR);
-       if (ret < 0)
-               return -ERRNO_TO_PARA_ERROR(errno);
-       return ret;
-}
-
 /**
  * Set a file descriptor to blocking mode.
  *
@@ -599,7 +575,21 @@ int para_munmap(void *start, size_t length)
        return -ERRNO_TO_PARA_ERROR(err);
 }
 
-static int xpoll(struct pollfd *fds, nfds_t nfds, int timeout)
+/**
+ * Simple wrapper for poll(2).
+ *
+ * It calls poll(2) and starts over if the call was interrupted by a signal.
+ *
+ * \param fds See poll(2).
+ * \param nfds See poll(2).
+ * \param timeout See poll(2).
+ *
+ * \return The return value of the underlying poll() call on success, the
+ * negative paraslash error code on errors.
+ *
+ * All arguments are passed verbatim to poll(2).
+ */
+int xpoll(struct pollfd *fds, nfds_t nfds, int timeout)
 {
        int ret;