[Gambas-user] Get last errno from external function call
vuott at tutanota.com
vuott at tutanota.com
Thu Oct 6 16:35:51 CEST 2022
I did a test...
Looking at the sources of the libgpiod functions, I see that in many of them a value is assigned to the "errno" symbol.
For example in the "int gpiod_line_bulk_add_line ()" function:
errno = EINVAL;
https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/tree/lib/core.c#n147
Not having installed the "libgpiod" library on my system, I tried to create "ex novo" a similar function, and to test it with Gambas:
' void simula_errore()
Private Extern simula_errore() In "/tmp/liberror"
Public Sub Main()
Dim p As Pointer
' Go to create the external shared library, that will simulate the "EINVAL" error:
Creaso()
' Calls then External function:
simula_errore()
' Catch the error:
p = System.GetExternSymbol("/tmp/liberror", "errno")
Print Int@(p)
End
Private Procedure Creaso()
File.Save("/tmp/liberror.c", "#include <errno.h>\n\n" &
"void simula_errore() {\n" &
" errno = EINVAL;\n}")
Shell "gcc -o /tmp/liberror.so /tmp/liberror.c -shared" Wait
End
------
Maybe I'm thinking wrong, in any case it works for me.
-----------------------------------------------------------------------------------
6 ott 2022, 10:43 da benoit.minisini at gambas-basic.org:
> Le 06/10/2022 à 01:30, vuott--- via User a écrit :
>
>> Out of curiosity, maybe you could also try "System.GetExternSymbol ()":
>>
>> Dim p As Pointer
>>
>> p = System.GetExternSymbol("libgpiod", "errno")
>>
>> Print Int@(p)
>>
>
> Don't do that, as 'errno' is not a global variable anymore according to the glibc manual ('man errno' says it's a C macro).
>
> Regards,
>
> --
> Benoît Minisini.
>
>
> ----[ http://gambaswiki.org/wiki/doc/netiquette ]----
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20221006/d4269e55/attachment.htm>
More information about the User
mailing list