From: Mikko Rasa Date: Sun, 31 Oct 2021 11:29:59 +0000 (+0200) Subject: Use size_t to represent sizes X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=03862ac4f38db0799872850dc4ab43b88688e4eb;p=libs%2Fcore.git Use size_t to represent sizes --- diff --git a/source/io/android/asset.cpp b/source/io/android/asset.cpp index 1b97eae..3e03034 100644 --- a/source/io/android/asset.cpp +++ b/source/io/android/asset.cpp @@ -34,8 +34,9 @@ Asset::~Asset() 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"); diff --git a/source/io/asset.cpp b/source/io/asset.cpp index 526133e..9284f97 100644 --- a/source/io/asset.cpp +++ b/source/io/asset.cpp @@ -15,7 +15,7 @@ void Asset::set_inherit(bool) 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); } diff --git a/source/io/asset.h b/source/io/asset.h index e83355e..23a110e 100644 --- a/source/io/asset.h +++ b/source/io/asset.h @@ -26,8 +26,8 @@ public: 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); diff --git a/source/io/generic/asset.cpp b/source/io/generic/asset.cpp index 7971f1b..b5cad9a 100644 --- a/source/io/generic/asset.cpp +++ b/source/io/generic/asset.cpp @@ -28,7 +28,7 @@ Asset::~Asset() 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); } diff --git a/source/io/serial.cpp b/source/io/serial.cpp index 09a9768..b256b11 100644 --- a/source/io/serial.cpp +++ b/source/io/serial.cpp @@ -106,7 +106,7 @@ void Serial::set_parameters(const string ¶ms) 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; @@ -114,12 +114,12 @@ unsigned Serial::do_write(const char *buf, unsigned 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; - unsigned ret = reader.read(buf, size); + size_t ret = reader.read(buf, size); if(ret==0) set_eof(); diff --git a/source/io/serial.h b/source/io/serial.h index dbc7a77..1e93f10 100644 --- a/source/io/serial.h +++ b/source/io/serial.h @@ -45,8 +45,8 @@ public: 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); diff --git a/source/io/utils.cpp b/source/io/utils.cpp index eee51cc..2b80cc7 100644 --- a/source/io/utils.cpp +++ b/source/io/utils.cpp @@ -4,9 +4,9 @@ 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 + 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. */ -unsigned read_all(Base &, char *, unsigned); +std::size_t read_all(Base &, char *, std::size_t); } // namespace IO } // namespace Msp diff --git a/source/io/windows/eventreader.cpp b/source/io/windows/eventreader.cpp index 7406524..8c41020 100644 --- a/source/io/windows/eventreader.cpp +++ b/source/io/windows/eventreader.cpp @@ -13,9 +13,9 @@ struct EventReader::Private { OVERLAPPED overlapped; Handle event; - unsigned buf_size = 0; + size_t buf_size = 0; char *buffer = 0; - unsigned buf_avail = 0; + size_t buf_avail = 0; char *buf_next = 0; bool pending = false; bool eof = false;