trafficserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bc...@apache.org
Subject [trafficserver] 02/03: Upgrade API I/O functions to consistently use s/size_t.
Date Thu, 07 Jun 2018 23:01:40 GMT
This is an automated email from the ASF dual-hosted git repository.

bcall pushed a commit to branch 8.0.x
in repository https://gitbox.apache.org/repos/asf/trafficserver.git

commit 94a56fdcaa73896ed2527a994aa1a2f4a0d27963
Author: Chris Lemmons <alficles@gmail.com>
AuthorDate: Thu May 10 09:21:09 2018 +0000

    Upgrade API I/O functions to consistently use s/size_t.
    
    These functions were returning -1 on error, but in an unsigned type.
    Internally, ints were being used inconsistently. This cleans it up.
    
    (cherry picked from commit 58623ec707dc07cf53fcd0268d9f49f2e23894c9)
---
 proxy/InkAPI.cc        | 34 ++++++++++++++++++----------------
 proxy/InkAPIInternal.h | 12 ++++++------
 proxy/api/ts/ts.h      |  4 ++--
 3 files changed, 26 insertions(+), 24 deletions(-)

diff --git a/proxy/InkAPI.cc b/proxy/InkAPI.cc
index c971f88..13bb88e 100644
--- a/proxy/InkAPI.cc
+++ b/proxy/InkAPI.cc
@@ -802,11 +802,11 @@ FileImpl::fclose()
   }
 }
 
-int
-FileImpl::fread(void *buf, int length)
+ssize_t
+FileImpl::fread(void *buf, size_t length)
 {
-  int64_t amount;
-  int64_t err;
+  size_t amount;
+  ssize_t err;
 
   if ((m_mode != READ) || (m_fd == -1)) {
     return -1;
@@ -855,11 +855,11 @@ FileImpl::fread(void *buf, int length)
   }
 }
 
-int
-FileImpl::fwrite(const void *buf, int length)
+ssize_t
+FileImpl::fwrite(const void *buf, size_t length)
 {
   const char *p, *e;
-  int64_t avail;
+  size_t avail;
 
   if ((m_mode != WRITE) || (m_fd == -1)) {
     return -1;
@@ -895,11 +895,11 @@ FileImpl::fwrite(const void *buf, int length)
   return (p - (const char *)buf);
 }
 
-int
+ssize_t
 FileImpl::fflush()
 {
   char *p, *e;
-  int err = 0;
+  ssize_t err = 0;
 
   if ((m_mode != WRITE) || (m_fd == -1)) {
     return -1;
@@ -930,10 +930,10 @@ FileImpl::fflush()
 }
 
 char *
-FileImpl::fgets(char *buf, int length)
+FileImpl::fgets(char *buf, size_t length)
 {
   char *e;
-  int pos;
+  size_t pos;
 
   if (length == 0) {
     return nullptr;
@@ -954,13 +954,15 @@ FileImpl::fgets(char *buf, int length)
   e = (char *)memchr(m_buf, '\n', m_bufpos);
   if (e) {
     e += 1;
-    if (length > (e - m_buf + 1)) {
+    if (length > (size_t)(e - m_buf + 1)) {
       length = e - m_buf + 1;
     }
   }
 
-  pos      = fread(buf, length - 1);
-  buf[pos] = '\0';
+  ssize_t rlen = fread(buf, length - 1);
+  if (rlen >= 0) {
+    buf[rlen] = '\0';
+  }
 
   return buf;
 }
@@ -1888,14 +1890,14 @@ TSfclose(TSFile filep)
   delete file;
 }
 
-size_t
+ssize_t
 TSfread(TSFile filep, void *buf, size_t length)
 {
   FileImpl *file = (FileImpl *)filep;
   return file->fread(buf, length);
 }
 
-size_t
+ssize_t
 TSfwrite(TSFile filep, const void *buf, size_t length)
 {
   FileImpl *file = (FileImpl *)filep;
diff --git a/proxy/InkAPIInternal.h b/proxy/InkAPIInternal.h
index 47f8c93..05e5794 100644
--- a/proxy/InkAPIInternal.h
+++ b/proxy/InkAPIInternal.h
@@ -83,17 +83,17 @@ public:
 
   int fopen(const char *filename, const char *mode);
   void fclose();
-  int fread(void *buf, int length);
-  int fwrite(const void *buf, int length);
-  int fflush();
-  char *fgets(char *buf, int length);
+  ssize_t fread(void *buf, size_t length);
+  ssize_t fwrite(const void *buf, size_t length);
+  ssize_t fflush();
+  char *fgets(char *buf, size_t length);
 
 public:
   int m_fd;
   int m_mode;
   char *m_buf;
-  int m_bufsize;
-  int m_bufpos;
+  size_t m_bufsize;
+  size_t m_bufpos;
 };
 
 struct INKConfigImpl : public ConfigInfo {
diff --git a/proxy/api/ts/ts.h b/proxy/api/ts/ts.h
index 4ab8be0..4347255 100644
--- a/proxy/api/ts/ts.h
+++ b/proxy/api/ts/ts.h
@@ -203,7 +203,7 @@ tsapi void TSfclose(TSFile filep);
       while reading the file, it returns -1.
 
  */
-tsapi size_t TSfread(TSFile filep, void *buf, size_t length);
+tsapi ssize_t TSfread(TSFile filep, void *buf, size_t length);
 
 /**
     Attempts to write length bytes of data from the buffer buf
@@ -220,7 +220,7 @@ tsapi size_t TSfread(TSFile filep, void *buf, size_t length);
       writing, it returns the number of bytes successfully written.
 
  */
-tsapi size_t TSfwrite(TSFile filep, const void *buf, size_t length);
+tsapi ssize_t TSfwrite(TSFile filep, const void *buf, size_t length);
 
 /**
     Flushes pending data that has been buffered up in memory from

-- 
To stop receiving notification emails like this one, please contact
bcall@apache.org.

Mime
View raw message