]> git.tdb.fi Git - libs/core.git/blob - source/io/unix/seekable.cpp
Move most platform-specific code into overlay directories
[libs/core.git] / source / io / unix / seekable.cpp
1 #define _LARGEFILE64_SOURCE
2 #include <cerrno>
3 #include <unistd.h>
4 #include <msp/core/systemerror.h>
5 #include "handle.h"
6 #include "handle_private.h"
7 #include "seekable.h"
8
9 using namespace std;
10
11 namespace {
12
13 using namespace Msp::IO;
14
15 int sys_seek_type(SeekType st)
16 {
17         if(st==S_BEG)
18                 return SEEK_SET;
19         else if(st==S_CUR)
20                 return SEEK_CUR;
21         else if(st==S_END)
22                 return SEEK_END;
23
24         throw invalid_argument("sys_seek_type");
25 }
26
27 }
28
29 namespace Msp {
30 namespace IO {
31
32 SeekOffset sys_seek(Handle &handle, SeekOffset offset, SeekType type)
33 {
34         off64_t ret = lseek64(*handle, offset, sys_seek_type(type));
35         if(ret==(off64_t)-1)
36         {
37                 if(errno==EINVAL)
38                         throw bad_seek(offset, type);
39                 else
40                         throw system_error("lseek64");
41         }
42
43         return ret;
44 }
45
46 } // namespace IO
47 } // namespace Msp