[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/master] Remove read_all and write_all



commit 40199b180e53aa36477c75782be51bd689189287
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date:   Fri Jun 29 10:16:57 2018 -0400

    Remove read_all and write_all
    
    These had become wrappers around their fd and socket variants; there
    were only a few users of the original functions still remaining.
---
 src/common/util.h       |  7 -------
 src/or/keypin.c         |  4 ++--
 src/or/microdesc.c      |  4 ++--
 src/or/routerkeys.c     |  3 +--
 src/test/test_util.c    |  5 +++--
 src/tools/tor-gencert.c |  3 +--
 src/tools/tor-resolve.c | 20 ++++++++++----------
 7 files changed, 19 insertions(+), 27 deletions(-)

diff --git a/src/common/util.h b/src/common/util.h
index 566d16d0a..9f387150a 100644
--- a/src/common/util.h
+++ b/src/common/util.h
@@ -68,11 +68,4 @@
 
 /* File helpers */
 
-#define write_all(fd, buf, count, isSock) \
-  ((isSock) ? write_all_to_socket((fd), (buf), (count)) \
-            : write_all_to_fd((int)(fd), (buf), (count)))
-#define read_all(fd, buf, count, isSock) \
-  ((isSock) ? read_all_from_socket((fd), (buf), (count)) \
-            : read_all_from_fd((int)(fd), (buf), (count)))
-
 #endif /* !defined(TOR_UTIL_H) */
diff --git a/src/or/keypin.c b/src/or/keypin.c
index 8e1ef099a..8100f3b73 100644
--- a/src/or/keypin.c
+++ b/src/or/keypin.c
@@ -309,7 +309,7 @@ keypin_open_journal(const char *fname)
   char tbuf[ISO_TIME_LEN+1];
   format_iso_time(tbuf, approx_time());
   tor_snprintf(buf, sizeof(buf), "@opened-at %s\n", tbuf);
-  if (write_all(fd, buf, strlen(buf), 0) < 0)
+  if (write_all_to_fd(fd, buf, strlen(buf)) < 0)
     goto err;
 
   keypin_journal_fd = fd;
@@ -348,7 +348,7 @@ keypin_journal_append_entry(const uint8_t *rsa_id_digest,
                       (const char*)ed25519_id_key);
   line[BASE64_DIGEST_LEN+1+BASE64_DIGEST256_LEN] = '\n';
 
-  if (write_all(keypin_journal_fd, line, JOURNAL_LINE_LEN, 0)<0) {
+  if (write_all_to_fd(keypin_journal_fd, line, JOURNAL_LINE_LEN)<0) {
     log_warn(LD_DIRSERV, "Error while adding a line to the key-pinning "
              "journal: %s", strerror(errno));
     keypin_close_journal();
diff --git a/src/or/microdesc.c b/src/or/microdesc.c
index bbe5ead6b..838c966a2 100644
--- a/src/or/microdesc.c
+++ b/src/or/microdesc.c
@@ -197,7 +197,7 @@ dump_microdescriptor(int fd, microdesc_t *md, size_t *annotation_len_out)
     char annotation[ISO_TIME_LEN+32];
     format_iso_time(buf, md->last_listed);
     tor_snprintf(annotation, sizeof(annotation), "@last-listed %s\n", buf);
-    if (write_all(fd, annotation, strlen(annotation), 0) < 0) {
+    if (write_all_to_fd(fd, annotation, strlen(annotation)) < 0) {
       log_warn(LD_DIR,
                "Couldn't write microdescriptor annotation: %s",
                strerror(errno));
@@ -210,7 +210,7 @@ dump_microdescriptor(int fd, microdesc_t *md, size_t *annotation_len_out)
   }
 
   md->off = tor_fd_getpos(fd);
-  written = write_all(fd, md->body, md->bodylen, 0);
+  written = write_all_to_fd(fd, md->body, md->bodylen);
   if (written != (ssize_t)md->bodylen) {
     written = written < 0 ? 0 : written;
     log_warn(LD_DIR,
diff --git a/src/or/routerkeys.c b/src/or/routerkeys.c
index 9f4def0e6..1e0a6fc65 100644
--- a/src/or/routerkeys.c
+++ b/src/or/routerkeys.c
@@ -44,7 +44,7 @@ do_getpass(const char *prompt, char *buf, size_t buflen,
   if (options->use_keygen_passphrase_fd) {
     twice = 0;
     fd = options->keygen_passphrase_fd;
-    length = read_all(fd, buf, buflen-1, 0);
+    length = read_all_from_fd(fd, buf, buflen-1);
     if (length >= 0)
       buf[length] = 0;
     goto done_reading;
@@ -1403,4 +1403,3 @@ routerkeys_free_all(void)
   rsa_ed_crosscert = NULL; // redundant
   rsa_ed_crosscert_len = 0;
 }
-
diff --git a/src/test/test_util.c b/src/test/test_util.c
index 49c8ce359..105de2911 100644
--- a/src/test/test_util.c
+++ b/src/test/test_util.c
@@ -4099,7 +4099,8 @@ test_util_ftruncate(void *ptr)
   tt_int_op(fd, OP_GE, 0);
 
   /* Make the file be there. */
-  tt_int_op(strlen(message), OP_EQ, write_all(fd, message, strlen(message),0));
+  tt_int_op(strlen(message), OP_EQ,
+            write_all_to_fd(fd, message, strlen(message)));
   tt_int_op((int)tor_fd_getpos(fd), OP_EQ, strlen(message));
   tt_int_op(0, OP_EQ, fstat(fd, &st));
   tt_int_op((int)st.st_size, OP_EQ, strlen(message));
@@ -4112,7 +4113,7 @@ test_util_ftruncate(void *ptr)
 
   /* Replace, and see if it got replaced */
   tt_int_op(strlen(message2), OP_EQ,
-            write_all(fd, message2, strlen(message2), 0));
+            write_all_to_fd(fd, message2, strlen(message2)));
   tt_int_op((int)tor_fd_getpos(fd), OP_EQ, strlen(message2));
   tt_int_op(0, OP_EQ, fstat(fd, &st));
   tt_int_op((int)st.st_size, OP_EQ, strlen(message2));
diff --git a/src/tools/tor-gencert.c b/src/tools/tor-gencert.c
index 2fda1cd8f..dd2a3ea63 100644
--- a/src/tools/tor-gencert.c
+++ b/src/tools/tor-gencert.c
@@ -84,7 +84,7 @@ load_passphrase(void)
   char *cp;
   char buf[1024]; /* "Ought to be enough for anybody." */
   memset(buf, 0, sizeof(buf)); /* should be needless */
-  ssize_t n = read_all(passphrase_fd, buf, sizeof(buf), 0);
+  ssize_t n = read_all_from_fd(passphrase_fd, buf, sizeof(buf));
   if (n < 0) {
     log_err(LD_GENERAL, "Couldn't read from passphrase fd: %s",
             strerror(errno));
@@ -575,4 +575,3 @@ main(int argc, char **argv)
   crypto_global_cleanup();
   return r;
 }
-
diff --git a/src/tools/tor-resolve.c b/src/tools/tor-resolve.c
index f307f6a91..15be12af8 100644
--- a/src/tools/tor-resolve.c
+++ b/src/tools/tor-resolve.c
@@ -224,11 +224,11 @@ do_resolve(const char *hostname, uint32_t sockshost, uint16_t socksport,
 
   if (version == 5) {
     char method_buf[2];
-    if (write_all(s, "\x05\x01\x00", 3, 1) != 3) {
+    if (write_all_to_socket(s, "\x05\x01\x00", 3) != 3) {
       log_err(LD_NET, "Error sending SOCKS5 method list.");
       goto err;
     }
-    if (read_all(s, method_buf, 2, 1) != 2) {
+    if (read_all_from_socket(s, method_buf, 2) != 2) {
       log_err(LD_NET, "Error reading SOCKS5 methods.");
       goto err;
     }
@@ -250,7 +250,7 @@ do_resolve(const char *hostname, uint32_t sockshost, uint16_t socksport,
     tor_assert(!req);
     goto err;
   }
-  if (write_all(s, req, len, 1) != len) {
+  if (write_all_to_socket(s, req, len) != len) {
     log_sock_error("sending SOCKS request", s);
     tor_free(req);
     goto err;
@@ -259,7 +259,7 @@ do_resolve(const char *hostname, uint32_t sockshost, uint16_t socksport,
 
   if (version == 4) {
     char reply_buf[RESPONSE_LEN_4];
-    if (read_all(s, reply_buf, RESPONSE_LEN_4, 1) != RESPONSE_LEN_4) {
+    if (read_all_from_socket(s, reply_buf, RESPONSE_LEN_4) != RESPONSE_LEN_4) {
       log_err(LD_NET, "Error reading SOCKS4 response.");
       goto err;
     }
@@ -270,7 +270,7 @@ do_resolve(const char *hostname, uint32_t sockshost, uint16_t socksport,
     }
   } else {
     char reply_buf[16];
-    if (read_all(s, reply_buf, 4, 1) != 4) {
+    if (read_all_from_socket(s, reply_buf, 4) != 4) {
       log_err(LD_NET, "Error reading SOCKS5 response.");
       goto err;
     }
@@ -290,14 +290,14 @@ do_resolve(const char *hostname, uint32_t sockshost, uint16_t socksport,
     }
     if (reply_buf[3] == 1) {
       /* IPv4 address */
-      if (read_all(s, reply_buf, 4, 1) != 4) {
+      if (read_all_from_socket(s, reply_buf, 4) != 4) {
         log_err(LD_NET, "Error reading address in socks5 response.");
         goto err;
       }
       tor_addr_from_ipv4n(result_addr, get_uint32(reply_buf));
     } else if (reply_buf[3] == 4) {
       /* IPv6 address */
-      if (read_all(s, reply_buf, 16, 1) != 16) {
+      if (read_all_from_socket(s, reply_buf, 16) != 16) {
         log_err(LD_NET, "Error reading address in socks5 response.");
         goto err;
       }
@@ -305,13 +305,14 @@ do_resolve(const char *hostname, uint32_t sockshost, uint16_t socksport,
     } else if (reply_buf[3] == 3) {
       /* Domain name */
       size_t result_len;
-      if (read_all(s, reply_buf, 1, 1) != 1) {
+      if (read_all_from_socket(s, reply_buf, 1) != 1) {
         log_err(LD_NET, "Error reading address_length in socks5 response.");
         goto err;
       }
       result_len = *(uint8_t*)(reply_buf);
       *result_hostname = tor_malloc(result_len+1);
-      if (read_all(s, *result_hostname, result_len, 1) != (int) result_len) {
+      if (read_all_from_socket(s, *result_hostname, result_len)
+          != (int) result_len) {
         log_err(LD_NET, "Error reading hostname in socks5 response.");
         goto err;
       }
@@ -450,4 +451,3 @@ main(int argc, char **argv)
   }
   return 0;
 }
-



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits