2 #define _LARGEFILE64_SOURCE
8 #include <msp/core/systemerror.h>
9 #include <msp/strings/format.h>
11 #include "handle_private.h"
18 using namespace Msp::IO;
20 int sys_seek_type(SeekType st)
38 throw invalid_argument("sys_seek_type");
47 bad_seek::bad_seek(SeekOffset offset, SeekType type):
48 runtime_error(type==S_BEG ? lexical_cast<string>(offset) :
49 type==S_CUR ? format("CUR%+d", offset) :
50 type==S_END ? format("END%+d", offset) :
51 format("SeekType(%d)", type))
55 SeekOffset sys_seek(Handle &handle, SeekOffset offset, SeekType type)
58 LONG high = offset>>32;
59 DWORD ret = SetFilePointer(*handle, offset, &high, sys_seek_type(type));
60 if(ret==INVALID_SET_FILE_POINTER)
62 DWORD err = GetLastError();
64 throw system_error("SetFilePointer");
67 return (SeekOffset(high)<<32) | ret;
69 off64_t ret = lseek64(*handle, offset, sys_seek_type(type));
73 throw bad_seek(offset, type);
75 throw system_error("lseek64");