]> git.tdb.fi Git - libs/core.git/blob - source/io/unix/seekable.cpp
Use a different diagnostic pragma for recent GCC versions
[libs/core.git] / source / io / unix / seekable.cpp
1 #define _FILE_OFFSET_BITS 64
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 /* Android libc does not recognize _FILE_OFFSET_BITS so this hack is necessary
33 to get 64-bit seeks. */
34 #ifdef __ANDROID__
35 #define off_t off64_t
36 #define lseek lseek64
37 #endif
38
39 SeekOffset sys_seek(Handle &handle, SeekOffset offset, SeekType type)
40 {
41         off_t ret = lseek(*handle, offset, sys_seek_type(type));
42         if(ret==(off_t)-1)
43         {
44                 if(errno==EINVAL)
45                         throw bad_seek(offset, type);
46                 else
47                         throw system_error("lseek64");
48         }
49
50         return ret;
51 }
52
53 } // namespace IO
54 } // namespace Msp