Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix substitutions for Windows OS #242

Merged
merged 1 commit into from
Sep 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading