X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=blobdiff_plain;f=source%2Fio%2Fwindows%2Ffile.cpp;fp=source%2Fio%2Fwindows%2Ffile.cpp;h=b973375475abe3554296969bb5a19ed836fbbe2f;hp=0000000000000000000000000000000000000000;hb=609c9a508cfdc7b42c46c4f21d17639204165a00;hpb=b4806214e905752617691f851717033fd3f266c2 diff --git a/source/io/windows/file.cpp b/source/io/windows/file.cpp new file mode 100644 index 0000000..b973375 --- /dev/null +++ b/source/io/windows/file.cpp @@ -0,0 +1,54 @@ +#include +#include +#include "file.h" +#include "handle_private.h" + +using namespace std; + +namespace Msp { +namespace IO { + +void File::platform_init(const string &fn, CreateMode cm) +{ + int flags = 0; + int share_flags = 0; + int create_flags = OPEN_EXISTING; + + if(mode&M_READ) + flags |= GENERIC_READ; + + if(mode&M_WRITE) + { + flags |= GENERIC_WRITE; + + switch(static_cast(cm)) + { + case C_NONE: create_flags = OPEN_EXISTING; break; + case C_CREATE: create_flags = OPEN_ALWAYS; break; + case C_TRUNCATE: create_flags = TRUNCATE_EXISTING; break; + case C_OVERWRITE: create_flags = CREATE_ALWAYS; break; + case C_NEW: create_flags = CREATE_NEW; break; + } + } + else + share_flags = FILE_SHARE_READ; + + *handle = CreateFile(fn.c_str(), flags, share_flags, 0, create_flags, FILE_ATTRIBUTE_NORMAL, 0); + if(!handle) + { + int err = GetLastError(); + if(err==ERROR_FILE_NOT_FOUND) + throw file_not_found(fn); + else if(err==ERROR_FILE_EXISTS) + throw file_already_exists(fn); + else + throw system_error(format("CreateFile(%s)", fn), err); + } +} + +void File::sync() +{ +} + +} // namespace IO +} // namespace Msp