]> git.tdb.fi Git - libs/core.git/blob - source/io/windows/handle.cpp
Close duplicated handles after starting a new process
[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 void sys_set_blocking(Handle &, bool)
9 {
10 }
11
12 void sys_set_inherit(Handle &, bool)
13 {
14 }
15
16 unsigned sys_read(Handle &handle, char *buf, unsigned size)
17 {
18         DWORD ret;
19         if(ReadFile(*handle, buf, size, &ret, 0)==0)
20                 throw system_error("ReadFile");
21
22         return ret;
23 }
24
25 unsigned sys_write(Handle &handle, const char *buf, unsigned size)
26 {
27         DWORD ret;
28         if(WriteFile(*handle, buf, size, &ret, 0)==0)
29                 throw system_error("WriteFile");
30
31         return ret;
32 }
33
34 void sys_close(Handle &handle)
35 {
36         if(handle)
37         {
38                 CloseHandle(*handle);
39                 *handle = INVALID_HANDLE_VALUE;
40         }
41 }
42
43 } // namespace IO
44 } // namespace Msp