From 1960eb1245f321be9c471cbe2b2a4700cb3531c1 Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 20 Jul 2018 22:47:32 +0800 Subject: fix and improve to open file on windows --- core/src/tbox/src/tbox/platform/windows/file.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'core/src') 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 -- cgit v1.3.1