]> git.tdb.fi Git - libs/core.git/blob - source/io/windows/handle.cpp
Use size_t for sizes in I/O classes
[libs/core.git] / source / io / windows / handle.cpp
1 #define NOMINMAX
2 #include <limits>
3 #include <msp/core/systemerror.h>
4 #include "handle.h"
5 #include "handle_private.h"
6
7 using namespace std;
8
9 namespace Msp {
10 namespace IO {
11
12 void sys_set_blocking(Handle &, bool)
13 {
14 }
15
16 void sys_set_inherit(Handle &, bool)
17 {
18 }
19
20 size_t sys_read(Handle &handle, char *buf, size_t size)
21 {
22         if(size>numeric_limits<DWORD>::max())
23                 throw invalid_argument("read");
24
25         DWORD ret;
26         if(ReadFile(*handle, buf, size, &ret, 0)==0)
27                 throw system_error("ReadFile");
28
29         return ret;
30 }
31
32 size_t sys_write(Handle &handle, const char *buf, size_t size)
33 {
34         if(size>numeric_limits<DWORD>::max())
35                 throw invalid_argument("write");
36
37         DWORD ret;
38         if(WriteFile(*handle, buf, size, &ret, 0)==0)
39                 throw system_error("WriteFile");
40
41         return ret;
42 }
43
44 void sys_close(Handle &handle)
45 {
46         if(handle)
47         {
48                 CloseHandle(*handle);
49                 *handle = INVALID_HANDLE_VALUE;
50         }
51 }
52
53 } // namespace IO
54 } // namespace Msp