--- /dev/null
+#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