]> git.tdb.fi Git - libs/core.git/blobdiff - source/io/windows/handle.cpp
Use size_t for sizes in I/O classes
[libs/core.git] / source / io / windows / handle.cpp
index e59de273a65ea07d3d42712f1d2394cdc0db018d..1cdf8ce208ed881d0d5510bc0efb3a93122640ca 100644 (file)
@@ -1,7 +1,11 @@
+#define NOMINMAX
+#include <limits>
 #include <msp/core/systemerror.h>
 #include "handle.h"
 #include "handle_private.h"
 
+using namespace std;
+
 namespace Msp {
 namespace IO {
 
@@ -13,8 +17,11 @@ void sys_set_inherit(Handle &, bool)
 {
 }
 
-unsigned sys_read(Handle &handle, char *buf, unsigned size)
+size_t sys_read(Handle &handle, char *buf, size_t size)
 {
+       if(size>numeric_limits<DWORD>::max())
+               throw invalid_argument("read");
+
        DWORD ret;
        if(ReadFile(*handle, buf, size, &ret, 0)==0)
                throw system_error("ReadFile");
@@ -22,8 +29,11 @@ unsigned sys_read(Handle &handle, char *buf, unsigned size)
        return ret;
 }
 
-unsigned sys_write(Handle &handle, const char *buf, unsigned size)
+size_t sys_write(Handle &handle, const char *buf, size_t size)
 {
+       if(size>numeric_limits<DWORD>::max())
+               throw invalid_argument("write");
+
        DWORD ret;
        if(WriteFile(*handle, buf, size, &ret, 0)==0)
                throw system_error("WriteFile");