Skip to content

Commit

Permalink
try not passing mode
Browse files Browse the repository at this point in the history
  • Loading branch information
rjernst committed Jul 10, 2024
1 parent f97bfe1 commit 73854bf
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,11 @@ public int ftruncate(int fd, long length) {
return functions.ftruncate(fd, new NativeLong(length));
}

@Override
public int open(String pathname, int flags) {
return functions.open(pathname, flags);
}

@Override
public int open(String pathname, int flags, int mode) {
return functions.open(pathname, flags, mode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public OptionalLong allocatedSizeInBytes(Path path) {
assert Files.isRegularFile(path) : path;
var stats = libc.newStat64(constants.statStructSize(), constants.statStructSizeOffset(), constants.statStructBlocksOffset());

int fd = libc.open(path.toAbsolutePath().toString(), O_RDONLY, 0);
int fd = libc.open(path.toAbsolutePath().toString(), O_RDONLY);
if (fd == -1) {
logger.warn("Could not open file [" + path + "] to get allocated size: " + libc.strerror(libc.errno()));
return OptionalLong.empty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ interface Stat64 {

int open(String pathname, int flags, int mode);

int open(String pathname, int flags);

int close(int fd);

int fstat64(int fd, Stat64 stats);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,16 @@ public int ftruncate(int fd, long length) {
}
}

@Override
public int open(String pathname, int flags) {
try (Arena arena = Arena.ofConfined()) {
MemorySegment nativePathname = MemorySegmentUtil.allocateString(arena, pathname);
return (int) open$mh.invokeExact(errnoState, nativePathname, flags);
} catch (Throwable t) {
throw new AssertionError(t);
}
}

@Override
public int open(String pathname, int flags, int mode) {
try (Arena arena = Arena.ofConfined()) {
Expand Down

0 comments on commit 73854bf

Please sign in to comment.