]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
make read_all and write_all return ssize_t.
authorNick Mathewson <nickm@torproject.org>
Wed, 5 Nov 2008 19:29:17 +0000 (19:29 +0000)
committerNick Mathewson <nickm@torproject.org>
Wed, 5 Nov 2008 19:29:17 +0000 (19:29 +0000)
svn:r17194

src/common/torint.h
src/common/util.c
src/common/util.h

index 6f515495d159324547acf62c2fe07616ab3b721e..9004773221bc7eef9f529b91e655d3fa9ebdb523 100644 (file)
@@ -316,6 +316,16 @@ typedef uint32_t uintptr_t;
 #endif
 #endif
 
+#ifndef SSIZE_T_MAX
+#if (SIZEOF_SIZE_T == 4)
+#define SSIZE_T_MAX INT32_MAX
+#elif (SIZEOF_SIZE_T == 8)
+#define SSIZE_T_MAX INT64_MAX
+#else
+#error "Can't define SSIZE_T_MAX"
+#endif
+#endif
+
 /* Any size_t larger than this amount is likely to be an underflow. */
 #define SIZE_T_CEILING (sizeof(char)<<(sizeof(size_t)*8 - 1))
 
index 640239f97259367db029a1eda6c882e2a4d568e7..71f899c6162ba10fb16e658c0c30af55e1e0610b 100644 (file)
@@ -1357,12 +1357,12 @@ ftime_definitely_before(time_t now, time_t when)
  * must be 1 if fd was returned by socket() or accept(), and 0 if fd
  * was returned by open().  Return the number of bytes written, or -1
  * on error.  Only use if fd is a blocking fd.  */
-int
+ssize_t
 write_all(int fd, const char *buf, size_t count, int isSocket)
 {
   size_t written = 0;
   ssize_t result;
-  tor_assert(count < INT_MAX); /*XXXX021 make returnval an ssize_t */
+  tor_assert(count < SSIZE_T_MAX);
 
   while (written != count) {
     if (isSocket)
@@ -1373,7 +1373,7 @@ write_all(int fd, const char *buf, size_t count, int isSocket)
       return -1;
     written += result;
   }
-  return (int)count;
+  return (ssize_t)count;
 }
 
 /** Read from <b>fd</b> to <b>buf</b>, until we get <b>count</b> bytes
@@ -1381,14 +1381,13 @@ write_all(int fd, const char *buf, size_t count, int isSocket)
  * was returned by socket() or accept(), and 0 if fd was returned by
  * open().  Return the number of bytes read, or -1 on error. Only use
  * if fd is a blocking fd. */
-int
+ssize_t
 read_all(int fd, char *buf, size_t count, int isSocket)
 {
-  /*XXXX021 return ssize_t. */
   size_t numread = 0;
   ssize_t result;
 
-  if (count > SIZE_T_CEILING || count > INT_MAX)
+  if (count > SIZE_T_CEILING || count > SSIZE_T_MAX)
     return -1;
 
   while (numread != count) {
@@ -1402,7 +1401,7 @@ read_all(int fd, char *buf, size_t count, int isSocket)
       break;
     numread += result;
   }
-  return (int)numread;
+  return (ssize_t)numread;
 }
 
 /*
index ea890d988c78db01cd9e94bafb81392802dcb5cb..4f8182949cfe41e80df88689962d8dfe02d9bec7 100644 (file)
@@ -232,8 +232,8 @@ int ftime_definitely_after(time_t now, time_t when);
 int ftime_definitely_before(time_t now, time_t when);
 
 /* File helpers */
-int write_all(int fd, const char *buf, size_t count, int isSocket);
-int read_all(int fd, char *buf, size_t count, int isSocket);
+ssize_t write_all(int fd, const char *buf, size_t count, int isSocket);
+ssize_t read_all(int fd, char *buf, size_t count, int isSocket);
 
 /** Return values from file_status(); see that function's documentation
  * for details. */