mirror of
https://github.com/radareorg/radare2.git
synced 2024-12-02 18:27:18 +00:00
* Fix append to file on Windows * Test from @ret2libc
This commit is contained in:
parent
a08337f7c7
commit
f46b1749b3
@ -369,7 +369,7 @@ R_API int r_sandbox_open(const char *path, int perm, int mode) {
|
||||
if (perm & O_EXCL) {
|
||||
creation = CREATE_NEW;
|
||||
} else {
|
||||
creation = CREATE_ALWAYS;
|
||||
creation = OPEN_ALWAYS;
|
||||
}
|
||||
if (mode & S_IREAD && !(mode & S_IWRITE)) {
|
||||
flags = FILE_ATTRIBUTE_READONLY;
|
||||
@ -389,6 +389,9 @@ R_API int r_sandbox_open(const char *path, int perm, int mode) {
|
||||
} else {
|
||||
permission = GENERIC_READ;
|
||||
}
|
||||
if (perm & O_APPEND) {
|
||||
permission |= FILE_APPEND_DATA;
|
||||
}
|
||||
|
||||
wchar_t *wepath = r_utf8_to_utf16 (epath);
|
||||
if (!wepath) {
|
||||
@ -397,7 +400,7 @@ R_API int r_sandbox_open(const char *path, int perm, int mode) {
|
||||
}
|
||||
HANDLE h = CreateFileW (wepath, permission, FILE_SHARE_READ | (read_only ? 0 : FILE_SHARE_WRITE), NULL, creation, flags, NULL);
|
||||
if (h != INVALID_HANDLE_VALUE) {
|
||||
ret = _open_osfhandle ((intptr_t)h, 0);
|
||||
ret = _open_osfhandle ((intptr_t)h, perm);
|
||||
}
|
||||
free (wepath);
|
||||
}
|
||||
|
@ -24,3 +24,16 @@ EXPECT=<<EOF
|
||||
EOF
|
||||
RUN
|
||||
|
||||
NAME=append to file
|
||||
FILE=-
|
||||
CMDS=<<EOF
|
||||
echo Hello > .r2-append-to-file.test
|
||||
echo World >> .r2-append-to-file.test
|
||||
cat .r2-append-to-file.test
|
||||
rm -f .r2-append-to-file.test
|
||||
EOF
|
||||
EXPECT=<<EOF
|
||||
Hello
|
||||
World
|
||||
EOF
|
||||
RUN
|
||||
|
Loading…
Reference in New Issue
Block a user