Skip to content

Commit

Permalink
handle UnsatisfiedLinkError in LinuxPOSIX constructor, resolves #187
Browse files Browse the repository at this point in the history
  • Loading branch information
betalb committed Feb 6, 2024
1 parent 3b3e32f commit 75bb232
Showing 1 changed file with 25 additions and 15 deletions.
40 changes: 25 additions & 15 deletions src/main/java/jnr/posix/LinuxPOSIX.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,26 @@ final class LinuxPOSIX extends BaseNativePOSIX implements Linux {
LinuxPOSIX(LibCProvider libcProvider, POSIXHandler handler) {
super(libcProvider, handler);

statVersion = getStatVersion();
if (statVersion == -1) {
use_fxstat64 = false;
use_lxstat64 = false;
use_xstat64 = false;
}
}

private int getStatVersion() {
if (Platform.IS_32_BIT || "sparcv9".equals(Platform.ARCH) || Platform.ARCH.contains("mips64")) {
statVersion = 3;
return 3;
} else {
FileStat stat = allocateStat();

if (((LinuxLibC) libc()).__xstat64(0, "/dev/null", stat) < 0) {
statVersion = 1;
} else {
statVersion = 0;
try {
if (((LinuxLibC) libc()).__xstat64(0, "/dev/null", stat) < 0) {
return 1;
}
return 0;
} catch (UnsatisfiedLinkError ex) {
return -1;
}
}
}
Expand All @@ -44,16 +54,16 @@ public FileStat allocateStat() {
if ("aarch64".equals(Platform.ARCH)) {
return new LinuxFileStatAARCH64(this);
} else if ("sparcv9".equals(Platform.ARCH)) {
return new LinuxFileStatSPARCV9(this);
} else if ("loongarch64".equals(Platform.ARCH)) {
return new LinuxFileStatLOONGARCH64(this);
} else {
if (Platform.ARCH.contains("mips64")) {
return new LinuxFileStatMIPS64(this);
}
return new LinuxFileStatSPARCV9(this);
} else if ("loongarch64".equals(Platform.ARCH)) {
return new LinuxFileStatLOONGARCH64(this);
} else {
if (Platform.ARCH.contains("mips64")) {
return new LinuxFileStatMIPS64(this);
}
return new LinuxFileStat64(this);
}
}
}
}
}

public MsgHdr allocateMsgHdr() {
Expand Down

0 comments on commit 75bb232

Please sign in to comment.