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