Skip to content

Commit

Permalink
fix and improve to open file on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
waruqi committed Jul 20, 2018
1 parent 280f827 commit dba5e5a
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/tbox/platform/windows/file.c
Expand Up @@ -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
Expand Down

0 comments on commit dba5e5a

Please sign in to comment.