Skip to content

Commit

Permalink
Fix substitutions for Windows OS
Browse files Browse the repository at this point in the history
  • Loading branch information
dmlloyd committed Sep 1, 2023
1 parent 7bcaf5c commit 1415f1a
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion net/src/main/java/io/smallrye/common/net/Substitutions.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import java.util.Collections;
import java.util.List;

import org.graalvm.nativeimage.Platform;
import org.graalvm.nativeimage.Platforms;
import org.graalvm.nativeimage.StackValue;
import org.graalvm.nativeimage.c.CContext;
import org.graalvm.nativeimage.c.function.CFunction;
Expand All @@ -17,6 +19,7 @@

final class Substitutions {
@TargetClass(className = "io.smallrye.common.net.GetHostInfoAction")
@Platforms({ Platform.DARWIN.class, Platform.LINUX.class })
static final class Target_io_smallrye_common_net_GetHostInfoAction {
@Substitute
public String[] run() {
Expand All @@ -31,7 +34,7 @@ public String[] run() {
// query the operating system
CCharPointer nameBuf = StackValue.get(ProcessSubstitutions.SIZE); // should be more than enough
int res = NativeInfo.gethostname(nameBuf, WordFactory.unsigned(ProcessSubstitutions.SIZE));
if (res != -1 && res > 0) {
if (res > 0) {
if (res == ProcessSubstitutions.SIZE) {
// null-terminate a really long name
nameBuf.write(ProcessSubstitutions.SIZE - 1, (byte) 0);
Expand Down Expand Up @@ -83,6 +86,7 @@ public String[] run() {
}

@CContext(NativeInfoDirectives.class)
@Platforms({ Platform.DARWIN.class, Platform.LINUX.class })
static final class NativeInfo {
@CFunction
static native int gethostname(CCharPointer nameBuf, UnsignedWord /* size_t */ len);
Expand Down

0 comments on commit 1415f1a

Please sign in to comment.