Skip to content

Commit

Permalink
Backport O_APPEND implementation fix (#321)
Browse files Browse the repository at this point in the history
  • Loading branch information
toots authored Sep 4, 2024
1 parent 0574aaa commit 54d7cd0
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
diff --git a/otherlibs/win32unix/open.c b/otherlibs/win32unix/open.c
index 5a56d92dc5..c324ce0ea2 100644
--- a/otherlibs/win32unix/open.c
+++ b/otherlibs/win32unix/open.c
@@ -24,7 +24,7 @@

static int open_access_flags[15] = {
GENERIC_READ, GENERIC_WRITE, GENERIC_READ|GENERIC_WRITE,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+ 0, FILE_APPEND_DATA, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};

static int open_create_flags[15] = {
@@ -46,6 +46,7 @@ CAMLprim value unix_open(value path, value flags, value perm)
int fileaccess, createflags, fileattrib, filecreate, sharemode, cloexec;
SECURITY_ATTRIBUTES attr;
HANDLE h;
+ DWORD dwMoved;
wchar_t * wpath;

caml_unix_check_path(path, "open");
@@ -87,5 +88,15 @@ CAMLprim value unix_open(value path, value flags, value perm)
win32_maperr(GetLastError());
uerror("open", path);
}
+
+ if (fileaccess & FILE_APPEND_DATA) {
+ dwMoved = SetFilePointer(h, 0, NULL, FILE_END);
+ if (dwMoved == INVALID_SET_FILE_POINTER) {
+ win32_maperr(GetLastError());
+ CloseHandle(h);
+ uerror("open", path);
+ }
+ }
+
return win_alloc_handle(h);
}
2 changes: 2 additions & 0 deletions packages/ocaml-windows32/ocaml-windows32.4.14.1/opam
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ maintainer: "whitequark@whitequark.org"
patches: [
"patches/ostype-fix.patch"
"patches/configure.patch"
"patches/windows-append.patch"
]
substs: [
"windows.conf"
Expand Down Expand Up @@ -34,6 +35,7 @@ extra-files: [
["install.sh" "md5=48972538ab93f9a8452af2ddaff38f03"]
["patches/ostype-fix.patch" "md5=05919aebf4e0894bf8f0bc60a6932b46"]
["patches/configure.patch" "md5=2947eb1d16daec3d35f769093574249f"]
["patches/windows-append.patch" "md5=524e3cd11717d838d6b7a1bd1e3150cf"]
]
url {
src: "https://github.com/ocaml/ocaml/archive/4.14.1.tar.gz"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
diff --git a/otherlibs/win32unix/open.c b/otherlibs/win32unix/open.c
index 5a56d92dc5..c324ce0ea2 100644
--- a/otherlibs/win32unix/open.c
+++ b/otherlibs/win32unix/open.c
@@ -24,7 +24,7 @@

static int open_access_flags[15] = {
GENERIC_READ, GENERIC_WRITE, GENERIC_READ|GENERIC_WRITE,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+ 0, FILE_APPEND_DATA, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};

static int open_create_flags[15] = {
@@ -46,6 +46,7 @@ CAMLprim value unix_open(value path, value flags, value perm)
int fileaccess, createflags, fileattrib, filecreate, sharemode, cloexec;
SECURITY_ATTRIBUTES attr;
HANDLE h;
+ DWORD dwMoved;
wchar_t * wpath;

caml_unix_check_path(path, "open");
@@ -87,5 +88,15 @@ CAMLprim value unix_open(value path, value flags, value perm)
win32_maperr(GetLastError());
uerror("open", path);
}
+
+ if (fileaccess & FILE_APPEND_DATA) {
+ dwMoved = SetFilePointer(h, 0, NULL, FILE_END);
+ if (dwMoved == INVALID_SET_FILE_POINTER) {
+ win32_maperr(GetLastError());
+ CloseHandle(h);
+ uerror("open", path);
+ }
+ }
+
return win_alloc_handle(h);
}
2 changes: 2 additions & 0 deletions packages/ocaml-windows64/ocaml-windows64.4.14.1/opam
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ maintainer: "whitequark@whitequark.org"
patches: [
"patches/ostype-fix.patch"
"patches/configure.patch"
"patches/windows-append.patch"
]
substs: [
"windows.conf"
Expand Down Expand Up @@ -33,6 +34,7 @@ extra-files: [
["install.sh" "md5=48972538ab93f9a8452af2ddaff38f03"]
["patches/ostype-fix.patch" "md5=05919aebf4e0894bf8f0bc60a6932b46"]
["patches/configure.patch" "md5=2947eb1d16daec3d35f769093574249f"]
["patches/windows-append.patch" "md5=524e3cd11717d838d6b7a1bd1e3150cf"]
]
url {
src: "https://github.com/ocaml/ocaml/archive/4.14.1.tar.gz"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
diff --git a/otherlibs/unix/open_win32.c b/otherlibs/unix/open_win32.c
index b4e02aefe9..726080d6b1 100644
--- a/otherlibs/unix/open_win32.c
+++ b/otherlibs/unix/open_win32.c
@@ -24,7 +24,7 @@

static int open_access_flags[15] = {
GENERIC_READ, GENERIC_WRITE, GENERIC_READ|GENERIC_WRITE,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+ 0, FILE_APPEND_DATA, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};

static int open_create_flags[15] = {
@@ -46,6 +46,7 @@ CAMLprim value caml_unix_open(value path, value flags, value perm)
int fileaccess, createflags, fileattrib, filecreate, sharemode, cloexec;
SECURITY_ATTRIBUTES attr;
HANDLE h;
+ DWORD dwMoved;
wchar_t * wpath;

caml_unix_check_path(path, "open");
@@ -87,5 +88,15 @@ CAMLprim value caml_unix_open(value path, value flags, value perm)
caml_win32_maperr(GetLastError());
caml_uerror("open", path);
}
+
+ if (fileaccess & FILE_APPEND_DATA) {
+ dwMoved = SetFilePointer(h, 0, NULL, FILE_END);
+ if (dwMoved == INVALID_SET_FILE_POINTER) {
+ caml_win32_maperr(GetLastError());
+ CloseHandle(h);
+ caml_uerror("open", path);
+ }
+ }
+
return caml_win32_alloc_handle(h);
}
2 changes: 2 additions & 0 deletions packages/ocaml-windows64/ocaml-windows64.5.1.1/opam
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ maintainer: "whitequark@whitequark.org"
patches: [
"patches/ostype-fix.patch"
"patches/configure.patch"
"patches/windows-append.patch"
]
substs: [
"windows.conf"
Expand Down Expand Up @@ -33,6 +34,7 @@ extra-files: [
["install.sh" "md5=166b007726c8a1de4a172eb2ae5a4355"]
["patches/ostype-fix.patch" "md5=57404edca01e9a353f28d3b3c0139f55"]
["patches/configure.patch" "md5=11532eb26b881d38db59a00341823b99"]
["patches/windows-append.patch" "md5=137c69d696dc857d663f49df7385923b"]
]
url {
src: "https://github.com/ocaml/ocaml/archive/5.1.1.tar.gz"
Expand Down

0 comments on commit 54d7cd0

Please sign in to comment.