]> git.tdb.fi Git - libs/core.git/blob - source/io/windows/seekable.cpp
Check errors from CreateSemaphore
[libs/core.git] / source / io / windows / seekable.cpp
1 #include <msp/core/winapi.h>
2 #include <msp/core/systemerror.h>
3 #include "handle.h"
4 #include "handle_private.h"
5 #include "seekable.h"
6
7 using namespace std;
8
9 namespace {
10
11 using namespace Msp::IO;
12
13 int sys_seek_type(SeekType st)
14 {
15         if(st==S_BEG)
16                 return FILE_BEGIN;
17         else if(st==S_CUR)
18                 return FILE_CURRENT;
19         else if(st==S_END)
20                 return FILE_END;
21
22         throw invalid_argument("IO::sys_seek");
23 }
24
25 }
26
27 namespace Msp {
28 namespace IO {
29
30 SeekOffset sys_seek(Handle &handle, SeekOffset offset, SeekType type)
31 {
32         LONG high = offset>>32;
33         DWORD ret = SetFilePointer(*handle, offset, &high, sys_seek_type(type));
34         if(ret==INVALID_SET_FILE_POINTER)
35         {
36                 DWORD err = GetLastError();
37                 if(err!=NO_ERROR)
38                         throw system_error("SetFilePointer");
39         }
40
41         return (SeekOffset(high)<<32) | ret;
42 }
43
44 } // namespace IO
45 } // namespace Msp