]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
fd: Make write_all() receive the length by value.
authorAndre Noll <maan@systemlinux.org>
Tue, 6 Dec 2011 19:46:17 +0000 (20:46 +0100)
committerAndre Noll <maan@systemlinux.org>
Fri, 20 Jan 2012 21:57:06 +0000 (22:57 +0100)
Not a single caller actually checked the value of the passed
len pointer after the call, which is a sure sign for a bad API.
Just return the number of bytes written.

afh.c
audioc.c
crypt.c
fd.c
fd.h
gcrypt.c
net.c

diff --git a/afh.c b/afh.c
index f2745b61b47e67310ce89dd78d9b95944021a7a4..8810a28b8dacc83731c40a57f014b2190a3b81ab 100644 (file)
--- a/afh.c
+++ b/afh.c
@@ -152,7 +152,7 @@ static int cat_file(struct afh_info *afhi, int audio_format_id,
                if (!size)
                        continue;
                PARA_INFO_LOG("writing chunk %lu\n", i);
                if (!size)
                        continue;
                PARA_INFO_LOG("writing chunk %lu\n", i);
-               ret = write_all(STDOUT_FILENO, buf, &size);
+               ret = write_all(STDOUT_FILENO, buf, size);
                if (ret < 0)
                        return ret;
        }
                if (ret < 0)
                        return ret;
        }
index 7435a86919a9cf745282c2d75d77471231d45e54..84c2a39472f6fcf58f7c6fecf62e752d35d1a098 100644 (file)
--- a/audioc.c
+++ b/audioc.c
@@ -339,7 +339,7 @@ int main(int argc, char *argv[])
                size_t n = ret = recv_bin_buffer(fd, buf, bufsize);
                if (ret <= 0)
                        break;
                size_t n = ret = recv_bin_buffer(fd, buf, bufsize);
                if (ret <= 0)
                        break;
-               ret = write_all(STDOUT_FILENO, buf, &n);
+               ret = write_all(STDOUT_FILENO, buf, n);
        } while (ret >= 0);
 out:
        if (ret < 0)
        } while (ret >= 0);
 out:
        if (ret < 0)
diff --git a/crypt.c b/crypt.c
index 69e4a3140a1599f971dbd641dd99e3461af40ff1..7161e626119b5052689b03f161117c53004f6729 100644 (file)
--- a/crypt.c
+++ b/crypt.c
@@ -298,7 +298,7 @@ int sc_send_bin_buffer(struct stream_cipher_context *scc, char *buf,
                memcpy(remainder, buf + l1, len - l1);
                RC4(&scc->send->key, len - l1, remainder, tmp + l1);
        }
                memcpy(remainder, buf + l1, len - l1);
                RC4(&scc->send->key, len - l1, remainder, tmp + l1);
        }
-       ret = write_all(scc->fd, (char *)tmp, &len);
+       ret = write_all(scc->fd, (char *)tmp, len);
        free(tmp);
        return ret;
 }
        free(tmp);
        return ret;
 }
diff --git a/fd.c b/fd.c
index 2e05313ea26ece1fd65315e80561fdd626f45fe1..429960cc0ab3d822811a1702c56c99a9e4c1ff10 100644 (file)
--- a/fd.c
+++ b/fd.c
  * \param buf The buffer to be sent.
  * \param len The length of \a buf.
  *
  * \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.
+ * \return Standard.
  */
  */
-int write_all(int fd, const char *buf, size_t *len)
+int write_all(int fd, const char *buf, size_t len)
 {
 {
-       size_t total = *len;
+       size_t total = len;
 
        assert(total);
 
        assert(total);
-       *len = 0;
-       while (*len < total) {
-               int ret = write(fd, buf + *len, total - *len);
+       len = 0;
+       while (len < total) {
+               int ret = write(fd, buf + len, total - len);
                if (ret == -1)
                        return -ERRNO_TO_PARA_ERROR(errno);
                if (ret == -1)
                        return -ERRNO_TO_PARA_ERROR(errno);
-               *len += ret;
+               len += ret;
        }
        }
-       return 1;
+       return len;
 }
 
 /**
 }
 
 /**
diff --git a/fd.h b/fd.h
index c87c0ea6d1c419f45d4894303fdbf1e73f8a56d4..b12067ec404976f9c6f96345c1a4bd4b21cb2d13 100644 (file)
--- a/fd.h
+++ b/fd.h
@@ -6,7 +6,7 @@
 
 /** \file fd.h exported symbols from fd.c */
 
 
 /** \file fd.h exported symbols from fd.c */
 
-int write_all(int fd, const char *buf, size_t *len);
+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);
 int file_exists(const char *);
 int para_select(int n, fd_set *readfds, fd_set *writefds,
                struct timeval *timeout_tv);
index 2f38f1a6cab16e606e3a5704cef61b7cad252b50..467e7399da721c5cb7ac6c0ea628f007052fea10 100644 (file)
--- a/gcrypt.c
+++ b/gcrypt.c
@@ -951,7 +951,7 @@ int sc_send_bin_buffer(struct stream_cipher_context *scc, char *buf,
        gret = gcry_cipher_encrypt(scc->send->handle, tmp, size,
                (unsigned char *)buf, size);
        assert(gret == 0);
        gret = gcry_cipher_encrypt(scc->send->handle, tmp, size,
                (unsigned char *)buf, size);
        assert(gret == 0);
-       ret = write_all(scc->fd, (char *)tmp, &size);
+       ret = write_all(scc->fd, (char *)tmp, size);
        free(tmp);
        return ret;
 }
        free(tmp);
        return ret;
 }
diff --git a/net.c b/net.c
index 3ce98ea4bc5ebf34b16d1191a83e396ae854e1e4..d32cc7eeb611279d936ef8cfd98dda644f06d799 100644 (file)
--- a/net.c
+++ b/net.c
@@ -705,7 +705,7 @@ int send_bin_buffer(int fd, const char *buf, size_t len)
 {
        if (!len)
                PARA_CRIT_LOG("len == 0\n");
 {
        if (!len)
                PARA_CRIT_LOG("len == 0\n");
-       return write_all(fd, buf, &len);
+       return write_all(fd, buf, len);
 }
 
 /**
 }
 
 /**