1 #include <msp/core/systemerror.h>
2 #include <msp/strings/format.h>
4 #include "handle_private.h"
11 void File::platform_init(const string &fn, CreateMode cm)
15 int create_flags = OPEN_EXISTING;
18 flags |= GENERIC_READ;
22 flags |= GENERIC_WRITE;
24 switch(static_cast<int>(cm))
26 case C_NONE: create_flags = OPEN_EXISTING; break;
27 case C_CREATE: create_flags = OPEN_ALWAYS; break;
28 case C_TRUNCATE: create_flags = TRUNCATE_EXISTING; break;
29 case C_OVERWRITE: create_flags = CREATE_ALWAYS; break;
30 case C_NEW: create_flags = CREATE_NEW; break;
34 share_flags = FILE_SHARE_READ;
36 *handle = CreateFile(fn.c_str(), flags, share_flags, 0, create_flags, FILE_ATTRIBUTE_NORMAL, 0);
39 int err = GetLastError();
40 if(err==ERROR_FILE_NOT_FOUND)
41 throw file_not_found(fn);
42 else if(err==ERROR_FILE_EXISTS)
43 throw file_already_exists(fn);
45 throw system_error(format("CreateFile(%s)", fn), err);