]> git.tdb.fi Git - libs/core.git/blobdiff - source/io/windows/handle.cpp
Move most platform-specific code into overlay directories
[libs/core.git] / source / io / windows / handle.cpp
diff --git a/source/io/windows/handle.cpp b/source/io/windows/handle.cpp
new file mode 100644 (file)
index 0000000..5b1d933
--- /dev/null
@@ -0,0 +1,42 @@
+#include <msp/core/systemerror.h>
+#include "handle.h"
+#include "handle_private.h"
+
+namespace Msp {
+namespace IO {
+
+Handle::operator const void *() const
+{
+       return priv->handle!=INVALID_HANDLE_VALUE ? this : 0;
+}
+
+
+void sys_set_blocking(Handle &, bool)
+{
+}
+
+unsigned sys_read(Handle &handle, char *buf, unsigned size)
+{
+       DWORD ret;
+       if(ReadFile(*handle, buf, size, &ret, 0)==0)
+               throw system_error("ReadFile");
+
+       return ret;
+}
+
+unsigned sys_write(Handle &handle, const char *buf, unsigned size)
+{
+       DWORD ret;
+       if(WriteFile(*handle, buf, size, &ret, 0)==0)
+               throw system_error("WriteFile");
+
+       return ret;
+}
+
+void sys_close(Handle &handle)
+{
+       CloseHandle(*handle);
+}
+
+} // namespace IO
+} // namespace Msp