X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=blobdiff_plain;f=source%2Ffile.cpp;h=6ef338888b24b610b0d61f7bcaa06d9fec2594fa;hp=9b1e433662c63e9fddfa8295fd7719789d471522;hb=5ed3d4f2ff489d02661aaabb24d4182f76499926;hpb=c0861d1f8e3869f058bc8b152cd35a08e5b03e73 diff --git a/source/file.cpp b/source/file.cpp index 9b1e433..6ef3388 100644 --- a/source/file.cpp +++ b/source/file.cpp @@ -10,7 +10,7 @@ Distributed under the LGPL #include #endif #include -#include "error.h" +#include "except.h" #include "file.h" using namespace std; @@ -57,7 +57,13 @@ File::File(const string &fn, Mode m, CreateMode cm) handle=CreateFile(fn.c_str(), flags, 0, 0, create_flags, FILE_ATTRIBUTE_NORMAL, 0); if(handle==INVALID_HANDLE_VALUE) - throw SystemError(format("Can't open file '%s'", fn), GetLastError()); + { + int err=GetLastError(); + if(err==ERROR_FILE_NOT_FOUND) + throw FileNotFound("Can't find file "+fn, fn); + else + throw SystemError(format("Can't open file '%s'", fn), GetLastError()); + } #else int flags=0; switch(mode&M_RDWR) @@ -105,7 +111,7 @@ void File::close() set_events(P_NONE); - signal_closing.emit(); + signal_flush_required.emit(); #ifdef WIN32 CloseHandle(handle); @@ -134,6 +140,15 @@ void File::set_block(bool b) #endif } +void File::sync() +{ +#ifndef WIN32 + signal_flush_required.emit(); + + fsync(handle); +#endif +} + /** Seeks the file to the given byte offset. @@ -146,6 +161,8 @@ int File::seek(int off, SeekType st) { check_access(M_NONE); + signal_flush_required.emit(); + int type=sys_seek_type(st); #ifdef WIN32 DWORD ret=SetFilePointer(handle, off, 0, type); @@ -232,13 +249,6 @@ unsigned File::do_write(const char *buf, unsigned size) return ret; } -void File::sync() -{ -#ifndef WIN32 - fsync(handle); -#endif -} - /** Reads data from the file.