Skip to content

Commit

Permalink
sim/win/hostfs: set O_BINARY for windows hostfs as default
Browse files Browse the repository at this point in the history
Since the initial default setting in MSVC is text mode ( O_TEXT ):

https://learn.microsoft.com/en-us/cpp/c-runtime-library/text-and-binary-mode-file-i-o?view=msvc-170

In order to unify the translation behavior with unix,
1. set O_BINARY for hostfs as default
2. enable default text mode if the application specifies flag O_TEXT

Signed-off-by: chao an <anchao@xiaomi.com>
  • Loading branch information
anchao committed Apr 13, 2023
1 parent 41f1044 commit b9a6910
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions arch/sim/src/sim/win/sim_hostfs.c
Expand Up @@ -120,6 +120,22 @@ int host_open(const char *pathname, int flags, nuttx_mode_t mode)
mapflags |= O_TRUNC;
}

/* Since the initial default setting in MSVC is text mode ( O_TEXT ):
*
* https://learn.microsoft.com/en-us/cpp/c-runtime-library/ \
* text-and-binary-mode-file-i-o?view=msvc-170
*
* In order to unify the translation behavior with unix,
* 1. set O_BINARY for hostfs as default
* 2. enable default text mode if the application specifies flag O_TEXT
*
*/

if ((flags & NUTTX_O_TEXT) == 0)
{
mapflags |= O_BINARY;
}

ret = _open(pathname, mapflags, mode);
if (ret == -1)
{
Expand Down

0 comments on commit b9a6910

Please sign in to comment.