Did I use it incorrectly or does uv_fs_open with O_TRUNC have a bug? #4291
Replies: 3 comments 8 replies
-
Does |
Beta Was this translation helpful? Give feedback.
-
I did some research on this issue. First I looked at the source code of libuv and found that uv_fs_open actually calls the CreateFileW function on the Window platform. The libuv function fs__open will set the local variable disposition to TRUNCATE_EXISTING and use it as the dwCreationDisposition (5th) parameter of the CreateFileW function when the flags (4th) parameter of uv_fs_open specifies O_WRONLY | O_TRUNC. Then I took a look at the WinAPI manual, and the description of TRUNCATE_EXISTING pointed out:
So I tried adding a few lines of code here, as follows:
Eventually it worked, the existing file was opened and the file was truncated to 0 bytes. But I'm not sure whether this modification will affect other working modes. |
Beta Was this translation helpful? Give feedback.
-
The fs__open function has used FILE_GENERIC_WRITE. I took a look and FILE_GENERIC_WRITE and GENERIC_WRITE are two completely different macros. This CreateFileW function is really complicated. Until now, I haven't figured out why there are two macros and their differences. |
Beta Was this translation helpful? Give feedback.
-
The uv_fs_open(libuv1.47.0) always return parameter error when I use uv_fs_open to open an existing file and want to truncate it to 0 bytes on the Windows platform (Windows 10 19045.3930), as shown in the following code:
the error is always UV_EINVAL(-4071). Did I use it incorrectly or does uv_fs_open with O_TRUNC have a bug?
Beta Was this translation helpful? Give feedback.
All reactions