What a good, thread-safe way to pass error strings from a C shared library

I am writing a C library for internal use (I will be dlopen () in a C ++ application, if that matters). The shared library loads (among other things) some Java code through the JNI module, which means that all the manners of nightmare error modes that I need to handle intelligently in the application can arise from the JVM mode. In addition, this library must be repeated. Is there idiom for passing error strings in this case, or am I looping integer matching errors and using printfs to debug things?

Thank!

+3
source share
7 answers

. , .

  • API C , API , , , . errno.h ; , ( , , ), .
    • errno. , , . , GetLastError() . , ?
  • ( errno.h ), , strerror, .
  • , , , . .
    • , , , errno, , ( ), . waaay - , SQLite, API, errno , " : " " ".

EDIT: : :

  • API (, out-parameters), , , , - , .
  • , , . ( . , .)
  • . , .
  • . .

, API . , :

  • , , , , Booleans.
  • , . ( API- UNIX: close munmap . , _exit .)
  • , abort, malloc , , . ( ++ RAII - , ++, .)

: , , XPCOM.

+3

static const char []. . , , .

+2

C, (I18N) (L10N), - . , , ( , ), - .

I18N/L10N, , mmap(), "" , . ( PROT_READ mmap()).

.

, , . , :

int get_error(int errnum, char *buffer, size_t buflen);

, ; , , , , (, ) .

++ ( ) ; , , . , , , ( ) - , ++. mmap() .

, , , . ( , I18N/L10N, , 'n$, , / , .)

+1

, PWideChars, Windows. . , PwideChar, Dll . PWideChar .

0

R. ( static const char []), , Enum . , #define int.

0
  • , - (, errno - TLSed ); Linux return -ENOENT;.
  • , strerror, const. I18N, , , gettext, .
0

, : error_code_t function (, char ** err_msg). : void free_error_message (char * err_msg). , . , , , , , .

, . ...

0

Source: https://habr.com/ru/post/1781760/


All Articles