diff options
| author | ruki <[email protected]> | 2018-07-20 22:47:32 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2018-07-20 10:45:15 +0800 |
| commit | 1960eb1245f321be9c471cbe2b2a4700cb3531c1 (patch) | |
| tree | 1364597c29ba07e48898743f9a10cf53ad6f344b /core/src | |
| parent | 9bf2dfab4b53cb2b804bdb599b13b25e104d4b3f (diff) | |
fix and improve to open file on windows
Diffstat (limited to 'core/src')
| -rw-r--r-- | core/src/tbox/src/tbox/platform/windows/file.c | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/core/src/tbox/src/tbox/platform/windows/file.c b/core/src/tbox/src/tbox/platform/windows/file.c index 67d055f86..62ba7b86d 100644 --- a/core/src/tbox/src/tbox/platform/windows/file.c +++ b/core/src/tbox/src/tbox/platform/windows/file.c @@ -83,9 +83,18 @@ tb_file_ref_t tb_file_init(tb_char_t const* path, tb_size_t mode) // init flag DWORD cflag = 0; - if (mode & (TB_FILE_MODE_CREAT | TB_FILE_MODE_TRUNC)) cflag |= CREATE_ALWAYS; - else if (mode & TB_FILE_MODE_CREAT) cflag |= CREATE_NEW; + if (mode & TB_FILE_MODE_CREAT) + { + // always create a new empty file + if (mode & TB_FILE_MODE_TRUNC) cflag |= CREATE_ALWAYS; + // create or open and append file + else if (mode & TB_FILE_MODE_APPEND) cflag |= OPEN_ALWAYS; + // create a new file only if file not exists + else cflag |= CREATE_NEW; + } + // open and truncate an existing file else if (mode & TB_FILE_MODE_TRUNC) cflag |= TRUNCATE_EXISTING; + // open an existing file if (!cflag) cflag |= OPEN_EXISTING; // init attr |
