mxcl
mxcl2y 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
ioB2y ago
@aapoalas, as the local ffi wizard, do you have any input here?
AapoAlas
AapoAlas2y 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
mxclOP2y ago
thanks both!
Deno.dlopen("",
{
errno: {
type: "int32"
}
});
Deno.dlopen("",
{
errno: {
type: "int32"
}
});
works (darwin/vanilla linux)
AapoAlas
AapoAlas2y 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
ioB2y ago
Pretty sure this is for tea curious what this is for specifically though
AapoAlas
AapoAlas2y ago
Like brewing?
ioB
ioB2y 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
ioB2y ago
TLDR; package manager written in Deno https://github.com/teaxyz/cli/pull/621/files oh wow this is a cursed PR
mxcl
mxclOP2y ago
thanks for the help here both. This use of ffi is now live!
ioB
ioB2y ago
Happy to help as always Max

Did you find this page helpful?