]> git.tdb.fi Git - libs/core.git/blobdiff - source/io/unix/seekable.cpp
Move most platform-specific code into overlay directories
[libs/core.git] / source / io / unix / seekable.cpp
diff --git a/source/io/unix/seekable.cpp b/source/io/unix/seekable.cpp
new file mode 100644 (file)
index 0000000..2c17114
--- /dev/null
@@ -0,0 +1,47 @@
+#define _LARGEFILE64_SOURCE
+#include <cerrno>
+#include <unistd.h>
+#include <msp/core/systemerror.h>
+#include "handle.h"
+#include "handle_private.h"
+#include "seekable.h"
+
+using namespace std;
+
+namespace {
+
+using namespace Msp::IO;
+
+int sys_seek_type(SeekType st)
+{
+       if(st==S_BEG)
+               return SEEK_SET;
+       else if(st==S_CUR)
+               return SEEK_CUR;
+       else if(st==S_END)
+               return SEEK_END;
+
+       throw invalid_argument("sys_seek_type");
+}
+
+}
+
+namespace Msp {
+namespace IO {
+
+SeekOffset sys_seek(Handle &handle, SeekOffset offset, SeekType type)
+{
+       off64_t ret = lseek64(*handle, offset, sys_seek_type(type));
+       if(ret==(off64_t)-1)
+       {
+               if(errno==EINVAL)
+                       throw bad_seek(offset, type);
+               else
+                       throw system_error("lseek64");
+       }
+
+       return ret;
+}
+
+} // namespace IO
+} // namespace Msp