[Gambas-user] Get last errno from external function call
Matheus Castello
matheus at castello.eng.br
Wed Oct 5 05:46:13 CEST 2022
For example some calls from libgpiod return structs, if the return is a
null pointer then you have an error. For this cases libgpiod set the
error code to the `errno` and you need to read it as soon the function
returns the null pointer.
Reference:
https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/tree/include/gpiod.h#n28
On 10/5/2022 12:25 AM, Jussi Lahtinen wrote:
> You mean an error occurring inside the library? I don't think there is
> any other way, than the library itself reporting the error code.
> I don't see why using __errno_location inside the library would fail.
> Are you calling it from the Gambas code?
Yeah, I add an `External` declaration to it to try to get the errno, but
as I said "surely the runtime (I mean the Gambas3 runtime) must be
making other calls that are overwriting the errno" and I'm always
getting `errno = 0` that means success.
.NET for example have an annotation to store the errno from an external
function the `SetLastError`:
https://github.com/dotnet/iot/blob/main/src/System.Device.Gpio/Interop/Unix/libgpiod/Interop.libgpiod.cs#L49
I was looking for something similar in Gambas3.
BR,
Matheus Castello
> If this is about a missing error message, then are you reading it from
> stderr?
> You need to give more details and/or some code to see.
>
> Jussi
>
>
>
>
> On Wed, Oct 5, 2022 at 5:54 AM Matheus Castello <matheus at castello.eng.br
> <mailto:matheus at castello.eng.br>> wrote:
>
> Hi guys,
>
> I'm new to Gambas3, I'm trying to use it for embedded devices and I'm
> doing some external function calls. There is some way in Gambas3 to
> get,
> or Gambas runtime stores, the last errno from a external function call?
>
> I tried to get it directly from libc `__errno_location` but surely the
> runtime must be making other calls that are overwriting the errno.
>
> Thanks in advance,
> Matheus Castello
>
> ----[ http://gambaswiki.org/wiki/doc/netiquette
> <http://gambaswiki.org/wiki/doc/netiquette> ]----
>
>
>
> ----[ http://gambaswiki.org/wiki/doc/netiquette ]----
More information about the User
mailing list