mxcl
mxcl13mo ago

getting errno with ffi

I am using ffi to call execv and need to get the value of errno for failures, but can’t see how I can do that.
10 Replies
ioB
ioB13mo ago
@aapoalas, as the local ffi wizard, do you have any input here?
AapoAlas
AapoAlas12mo ago
Seems like errno is defined by a macro so I'm not sure it's exactly readable directly with Deno FFI but if it is then it's something like this:
Deno.dlopen("",
{
errno: {
type: "int32"
}
});
Deno.dlopen("",
{
errno: {
type: "int32"
}
});
Hm yeah, seems to be somewhat platform specific. Here's how it'd work for Android:
const lib = Deno.dlopen("",
{
__geterrno: {
parameters: [],
result: "pointer",
},
});

const errnoPointer = lib.symbols.__geterrno();
const errno = new Deno.UnsafePointerView(errnoPointer).getInt32();
const lib = Deno.dlopen("",
{
__geterrno: {
parameters: [],
result: "pointer",
},
});

const errnoPointer = lib.symbols.__geterrno();
const errno = new Deno.UnsafePointerView(errnoPointer).getInt32();
mxcl
mxcl12mo ago
thanks both!
Deno.dlopen("",
{
errno: {
type: "int32"
}
});
Deno.dlopen("",
{
errno: {
type: "int32"
}
});
works (darwin/vanilla linux)
AapoAlas
AapoAlas12mo ago
Happy to help! If you have your code up somewhere or put it up later, let me know, I'm interested in seeing all the wonderful and wacky things people come up with using FFI 🙂
ioB
ioB12mo ago
Pretty sure this is for tea curious what this is for specifically though
AapoAlas
AapoAlas12mo ago
Like brewing?
ioB
ioB12mo ago
GitHub
GitHub - teaxyz/cli: the next-generation, cross‐platform package ma...
the next-generation, cross‐platform package manager - GitHub - teaxyz/cli: the next-generation, cross‐platform package manager
ioB
ioB12mo ago
TLDR; package manager written in Deno https://github.com/teaxyz/cli/pull/621/files oh wow this is a cursed PR
mxcl
mxcl12mo ago
thanks for the help here both. This use of ffi is now live!
ioB
ioB12mo ago
Happy to help as always Max