]> git.tdb.fi Git - libs/core.git/blob - source/io/windows/handle.cpp
Move most platform-specific code into overlay directories
[libs/core.git] / source / io / windows / handle.cpp
1 #include <msp/core/systemerror.h>
2 #include "handle.h"
3 #include "handle_private.h"
4
5 namespace Msp {
6 namespace IO {
7
8 Handle::operator const void *() const
9 {
10         return priv->handle!=INVALID_HANDLE_VALUE ? this : 0;
11 }
12
13
14 void sys_set_blocking(Handle &, bool)
15 {
16 }
17
18 unsigned sys_read(Handle &handle, char *buf, unsigned size)
19 {
20         DWORD ret;
21         if(ReadFile(*handle, buf, size, &ret, 0)==0)
22                 throw system_error("ReadFile");
23
24         return ret;
25 }
26
27 unsigned sys_write(Handle &handle, const char *buf, unsigned size)
28 {
29         DWORD ret;
30         if(WriteFile(*handle, buf, size, &ret, 0)==0)
31                 throw system_error("WriteFile");
32
33         return ret;
34 }
35
36 void sys_close(Handle &handle)
37 {
38         CloseHandle(*handle);
39 }
40
41 } // namespace IO
42 } // namespace Msp