]> git.tdb.fi Git - libs/core.git/commitdiff
Use size_t to represent sizes
authorMikko Rasa <tdb@tdb.fi>
Sun, 31 Oct 2021 11:29:59 +0000 (13:29 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sun, 31 Oct 2021 18:27:42 +0000 (20:27 +0200)
source/io/android/asset.cpp
source/io/asset.cpp
source/io/asset.h
source/io/generic/asset.cpp
source/io/serial.cpp
source/io/serial.h
source/io/utils.cpp
source/io/utils.h
source/io/windows/eventreader.cpp

index 1b97eae3d1f7a5177575043521d893feaa4ff894..3e03034760f03bf75fb87190933406b336d19ced 100644 (file)
@@ -34,8 +34,9 @@ Asset::~Asset()
        delete priv;
 }
 
        delete priv;
 }
 
-unsigned Asset::do_read(char *buf, unsigned size)
+size_t Asset::do_read(char *buf, size_t size)
 {
 {
+       // The function actually returns an int, despite taking size_t
        int ret = AAsset_read(priv->asset, buf, size);
        if(ret<0)
                throw runtime_error("Asset::do_read");
        int ret = AAsset_read(priv->asset, buf, size);
        if(ret<0)
                throw runtime_error("Asset::do_read");
index 526133e3c383a95a49a6438676fb025c2e0981c3..9284f97107f9e19a2eacfb121ddcd43c0c09e3b3 100644 (file)
@@ -15,7 +15,7 @@ void Asset::set_inherit(bool)
        throw logic_error("Asset::set_inherit");
 }
 
        throw logic_error("Asset::set_inherit");
 }
 
-unsigned Asset::do_write(const char *, unsigned)
+size_t Asset::do_write(const char *, size_t)
 {
        throw invalid_access(M_WRITE);
 }
 {
        throw invalid_access(M_WRITE);
 }
index e83355ed72981fc33228c0c4c04d48a76d069780..23a110e8c3b084a1d37242beda4ee032b2ac2285 100644 (file)
@@ -26,8 +26,8 @@ public:
        virtual void set_inherit(bool);
 
 private:
        virtual void set_inherit(bool);
 
 private:
-       virtual unsigned do_write(const char *, unsigned);
-       virtual unsigned do_read(char *, unsigned);
+       virtual std::size_t do_write(const char *, std::size_t);
+       virtual std::size_t do_read(char *, std::size_t);
 
 public:
        virtual const Handle &get_handle(Mode);
 
 public:
        virtual const Handle &get_handle(Mode);
index 7971f1b0346eeff7d848ca1a2c7f67183e4a3d03..b5cad9a47ce1b34097a8f716009aa972fda7e74d 100644 (file)
@@ -28,7 +28,7 @@ Asset::~Asset()
        delete priv;
 }
 
        delete priv;
 }
 
-unsigned Asset::do_read(char *buf, unsigned size)
+size_t Asset::do_read(char *buf, size_t size)
 {
        return priv->file->read(buf, size);
 }
 {
        return priv->file->read(buf, size);
 }
index 09a9768023bad9e1fa00be0d398ac45a6933442c..b256b117098b96a64f337c5c73b5f28818f77627 100644 (file)
@@ -106,7 +106,7 @@ void Serial::set_parameters(const string &params)
        state.apply_to(handle);
 }
 
        state.apply_to(handle);
 }
 
-unsigned Serial::do_write(const char *buf, unsigned size)
+size_t Serial::do_write(const char *buf, size_t size)
 {
        if(size==0)
                return 0;
 {
        if(size==0)
                return 0;
@@ -114,12 +114,12 @@ unsigned Serial::do_write(const char *buf, unsigned size)
        return sys_write(handle, buf, size);
 }
 
        return sys_write(handle, buf, size);
 }
 
-unsigned Serial::do_read(char *buf, unsigned size)
+size_t Serial::do_read(char *buf, size_t size)
 {
        if(size==0)
                return 0;
 
 {
        if(size==0)
                return 0;
 
-       unsigned ret = reader.read(buf, size);
+       size_t ret = reader.read(buf, size);
        if(ret==0)
                set_eof();
 
        if(ret==0)
                set_eof();
 
index dbc7a77bd0578159d12a8ae3b0d202290a604162..1e93f10879d2659756a2e33824e68eeb9aa870ab 100644 (file)
@@ -45,8 +45,8 @@ public:
        void set_parameters(const std::string &);
 
 private:
        void set_parameters(const std::string &);
 
 private:
-       virtual unsigned do_write(const char *, unsigned);
-       virtual unsigned do_read(char *, unsigned);
+       virtual std::size_t do_write(const char *, std::size_t);
+       virtual std::size_t do_read(char *, std::size_t);
 
 public:
        virtual const Handle &get_handle(Mode);
 
 public:
        virtual const Handle &get_handle(Mode);
index eee51cc57d28a6b365fb2e7da57fedeb358c32e5..2b80cc71a6c8ad20dd267b188de5bec7993d974f 100644 (file)
@@ -4,9 +4,9 @@
 namespace Msp {
 namespace IO {
 
 namespace Msp {
 namespace IO {
 
-unsigned read_all(Base &obj, char *buf, unsigned size)
+size_t read_all(Base &obj, char *buf, size_t size)
 {
 {
-       unsigned pos = 0;
+       size_t pos = 0;
        while(pos<size)
                pos += obj.read(buf+pos, size-pos);
 
        while(pos<size)
                pos += obj.read(buf+pos, size-pos);
 
index 8d4f9dd692c769f86b2a2aea71d4522eec9b7bbf..f73383d94ba9dc29b78d17aaa0c2a1e4912afec7 100644 (file)
@@ -1,6 +1,8 @@
 #ifndef MSP_IO_UTILS_H_
 #define MSP_IO_UTILS_H_
 
 #ifndef MSP_IO_UTILS_H_
 #define MSP_IO_UTILS_H_
 
+#include <cstddef>
+
 namespace Msp {
 namespace IO {
 
 namespace Msp {
 namespace IO {
 
@@ -12,7 +14,7 @@ data is read, regardless of the blocking mode of the object.
 Note: If the data is not immediately available and the object is in non-blocking
 mode, this function effectively becomes a busyloop until it can get more
 data. */
 Note: If the data is not immediately available and the object is in non-blocking
 mode, this function effectively becomes a busyloop until it can get more
 data. */
-unsigned read_all(Base &, char *, unsigned);
+std::size_t read_all(Base &, char *, std::size_t);
 
 } // namespace IO
 } // namespace Msp
 
 } // namespace IO
 } // namespace Msp
index 74065244bd11444a65b865c35ccbc7d0a9b0f189..8c4102067854eb0c9096ff92ab4277c1e3cf6441 100644 (file)
@@ -13,9 +13,9 @@ struct EventReader::Private
 {
        OVERLAPPED overlapped;
        Handle event;
 {
        OVERLAPPED overlapped;
        Handle event;
-       unsigned buf_size = 0;
+       size_t buf_size = 0;
        char *buffer = 0;
        char *buffer = 0;
-       unsigned buf_avail = 0;
+       size_t buf_avail = 0;
        char *buf_next = 0;
        bool pending = false;
        bool eof = false;
        char *buf_next = 0;
        bool pending = false;
        bool eof = false;