Move write_all() from net.c to fd.c.
authorAndre Noll <maan@systemlinux.org>
Sat, 15 Mar 2008 18:09:53 +0000 (19:09 +0100)
committerAndre Noll <maan@systemlinux.org>
Sat, 15 Mar 2008 18:09:53 +0000 (19:09 +0100)
This way it can be used also for programs that don't need
networking.

fd.c
fd.h
net.c

diff --git a/fd.c b/fd.c
index abad80a86ce368660c1ed3b88a1c0e088488a422..48e2faf97c6d3e2bcb1616ebef04db48e2003d9e 100644 (file)
--- a/fd.c
+++ b/fd.c
 #include "para.h"
 #include "error.h"
 
+/*
+ * Write a buffer to a file descriptor, re-write on short writes.
+ *
+ * \param fd The file descriptor.
+ * \param buf The buffer to be sent.
+ * \param len The length of \a buf.
+ *
+ * \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_PARA_ERROR(errno);
+               *len += ret;
+       }
+       return 1;
+}
+
 /**
  * Check whether a file exists.
  *
diff --git a/fd.h b/fd.h
index 6472c137e7d0a86007e2161b0f6691740c9f6fe3..22141be2d79a7451188f0d6986b772368248ff71 100644 (file)
--- a/fd.h
+++ b/fd.h
@@ -6,6 +6,7 @@
 
 /** \file fd.h exported symbols from fd.c */
 
+int write_all(int fd, const char *buf, size_t *len);
 int file_exists(const char *);
 int para_select(int n, fd_set *readfds, fd_set *writefds,
                struct timeval *timeout_tv);
diff --git a/net.c b/net.c
index 427ab0f0d2a3ebe3873eeff603422742b66a94b1..b2c9c43a81ad356ec021373c12d5c764fa5b76f4 100644 (file)
--- a/net.c
+++ b/net.c
 #define AI_ADDRCONFIG 0
 #endif
 
+#include <dirent.h>
 
 #include "para.h"
 #include "error.h"
 #include "net.h"
 #include "string.h"
+#include "fd.h"
 
 
 /** Information about one encrypted connection. */
@@ -345,31 +347,6 @@ struct in_addr extract_v4_addr(const struct sockaddr_storage *ss)
        return ia;
 }
 
-/*
- * Write a buffer to a file descriptor, re-write on short writes.
- *
- * \param fd The file descriptor.
- * \param buf The buffer to be sent.
- * \param len The length of \a buf.
- *
- * \return Standard. In any case, the number of bytes that have been written is
- * stored in \a len.
- */
-static 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_PARA_ERROR(errno);
-               *len += ret;
-       }
-       return 1;
-}
-
 /**
  * Encrypt and send a binary buffer.
  *