From 119e54daa6aef3e1de1a9de4d8e3ae2faf44dfa1 Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter Date: Tue, 4 Jan 2022 17:38:43 -0600 Subject: [PATCH 1/5] Use jnr-ffi from HEAD --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index dbbe787..eea9407 100644 --- a/pom.xml +++ b/pom.xml @@ -79,7 +79,7 @@ com.github.jnr jnr-ffi - 2.2.10 + 2.2.11-SNAPSHOT com.github.jnr From 03a4a3feaa2475c0125d4fa4046bcb2d80d29ce2 Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter Date: Wed, 5 Jan 2022 12:23:50 -0600 Subject: [PATCH 2/5] Use Variadic annotation for open and fcntl --- src/main/java/jnr/posix/LibC.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/jnr/posix/LibC.java b/src/main/java/jnr/posix/LibC.java index 6df0ffd..8e8287e 100644 --- a/src/main/java/jnr/posix/LibC.java +++ b/src/main/java/jnr/posix/LibC.java @@ -85,10 +85,14 @@ public interface LibC { int dup(int fd); int dup2(int oldFd, int newFd); + @Variadic(fixedCount = 2) int fcntl(int fd, int fnctl, Flock arg); + @Variadic(fixedCount = 2) int fcntl(int fd, int fnctl, Pointer arg); + @Variadic(fixedCount = 2) int fcntl(int fd, int fnctl); - int fcntl(int fd, int fnctl, int arg); + @Variadic(fixedCount = 2) + int fcntl(int fd, int fnctl, @u_int64_t int arg); @Deprecated int fcntl(int fd, int fnctl, int... arg); int access(CharSequence path, int amode); @@ -164,6 +168,7 @@ public interface LibCSignalHandler { int flock(int fd, int mode); int unlink(CharSequence path); + @Variadic(fixedCount = 2) int open(CharSequence path, int flags, int perm); int pipe(@Out int[] fds); int truncate(CharSequence path, long length); From 73813cc9c9f5b395f7b0b87dac82e7114ee7e38d Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter Date: Wed, 5 Jan 2022 14:34:15 -0600 Subject: [PATCH 3/5] Add test for open with mode --- src/test/java/jnr/posix/FileTest.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/test/java/jnr/posix/FileTest.java b/src/test/java/jnr/posix/FileTest.java index 98981b3..a5940d9 100644 --- a/src/test/java/jnr/posix/FileTest.java +++ b/src/test/java/jnr/posix/FileTest.java @@ -380,6 +380,15 @@ public void openTest() throws Throwable { result = posix.close(fd); assertEquals(-1, result); + + fd = posix.open("jnr-posix-filetest.txt", OpenFlags.O_CREAT.intValue() | OpenFlags.O_RDWR.intValue(), 0666); + + assertEquals(0666, posix.stat("jnr-posix-filetest.txt").mode() & 0777); + + result = posix.close(fd); + assertEquals(0, result); + + new File("jnr-posix-filetest.txt").delete(); } @Test From 99c3b56fdaa33199637fc0a72f95bccd12dd81c4 Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter Date: Wed, 5 Jan 2022 15:21:03 -0600 Subject: [PATCH 4/5] Specify type for strict vararg platforms This fix is primarily to get this function working on Apple M1. --- src/main/java/jnr/posix/LibC.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/jnr/posix/LibC.java b/src/main/java/jnr/posix/LibC.java index 8e8287e..fb384e7 100644 --- a/src/main/java/jnr/posix/LibC.java +++ b/src/main/java/jnr/posix/LibC.java @@ -169,7 +169,7 @@ public interface LibCSignalHandler { int flock(int fd, int mode); int unlink(CharSequence path); @Variadic(fixedCount = 2) - int open(CharSequence path, int flags, int perm); + int open(CharSequence path, int flags, @u_int32_t int perm); int pipe(@Out int[] fds); int truncate(CharSequence path, long length); int ftruncate(int fd, long offset); From ce6e2b7a5bc5e05ff1f488ca9d0790527cac0e5b Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter Date: Wed, 5 Jan 2022 17:44:26 -0600 Subject: [PATCH 5/5] Patch this test to avoid umask interference Typical umask on Darwin of 022 interferes with requested 0666 mode, so we use 0600 instead. --- src/test/java/jnr/posix/FileTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/jnr/posix/FileTest.java b/src/test/java/jnr/posix/FileTest.java index a5940d9..afadb07 100644 --- a/src/test/java/jnr/posix/FileTest.java +++ b/src/test/java/jnr/posix/FileTest.java @@ -381,9 +381,9 @@ public void openTest() throws Throwable { result = posix.close(fd); assertEquals(-1, result); - fd = posix.open("jnr-posix-filetest.txt", OpenFlags.O_CREAT.intValue() | OpenFlags.O_RDWR.intValue(), 0666); + fd = posix.open("jnr-posix-filetest.txt", OpenFlags.O_CREAT.intValue() | OpenFlags.O_RDWR.intValue(), 0600); - assertEquals(0666, posix.stat("jnr-posix-filetest.txt").mode() & 0777); + assertEquals(0600, posix.stat("jnr-posix-filetest.txt").mode() & 0777); result = posix.close(fd); assertEquals(0, result);