throw invalid_argument("Memory::seek");
if(new_pos<begin || new_pos>end)
- throw out_of_range("Memory::seek");
+ throw bad_seek(off, type);
pos = new_pos;
eof_flag = false;
#ifndef WIN32
#define _LARGEFILE64_SOURCE
+#include <cerrno>
#include <unistd.h>
#else
#include <windows.h>
#endif
-#include <stdexcept>
#include <msp/core/systemerror.h>
+#include <msp/strings/format.h>
#include "handle.h"
#include "handle_private.h"
#include "seekable.h"
namespace Msp {
namespace IO {
+bad_seek::bad_seek(SeekOffset offset, SeekType type):
+ runtime_error(type==S_BEG ? lexical_cast(offset) :
+ type==S_CUR ? format("CUR%+d", offset) :
+ type==S_END ? format("END%+d", offset) :
+ format("SeekType(%d)", type))
+{ }
+
+
SeekOffset sys_seek(Handle &handle, SeekOffset offset, SeekType type)
{
#ifdef WIN32
#else
off64_t ret = lseek64(*handle, offset, sys_seek_type(type));
if(ret==(off64_t)-1)
- throw system_error("lseek64");
+ {
+ if(errno==EINVAL)
+ throw bad_seek(offset, type);
+ else
+ throw system_error("lseek64");
+ }
return ret;
#endif
#ifndef MSP_IO_SEEKABLE_H_
#define MSP_IO_SEEKABLE_H_
+#include <stdexcept>
#include <msp/core/inttypes.h>
#include "base.h"
};
+class bad_seek: public std::runtime_error
+{
+public:
+ bad_seek(SeekOffset, SeekType);
+ virtual ~bad_seek() throw() { }
+};
+
+
class Seekable: public Base
{
protected: