#include "akerror.h" #include "err_capture.h" #include /* * The library imports system errno codes and their descriptions at build time * (scripts/generrno.sh -> akerr_init_errno). Verify: * - a system errno (EACCES) has a registered, non-empty name; * - an unregistered status returns the "Unknown Error" sentinel; * - a system errno can be raised, propagated and handled like any AKERR_* code. */ static int handled = 0; akerr_ErrorContext *boom(void) { PREPARE_ERROR(e); FAIL_RETURN(e, EACCES, "permission denied"); } int main(void) { akerr_capture_install(); akerr_init(); char *nm = akerr_name_for_status(EACCES, NULL); AKERR_CHECK(nm != NULL); AKERR_CHECK(nm[0] != '\0'); #if AKERR_USE_STDLIB /* akerr_init_errno() -- the only thing that registers a name for a host * errno -- is not called when AKERR_USE_STDLIB is OFF (see * akerr_init_state() in src/error.c), so EACCES deliberately reads back * as "Unknown Error" in that configuration. */ AKERR_CHECK(strcmp(nm, "Unknown Error") != 0); #endif AKERR_CHECK(strcmp(akerr_name_for_status(1000000, NULL), "Unknown Error") == 0); PREPARE_ERROR(e); ATTEMPT { CATCH(e, boom()); } CLEANUP { } PROCESS(e) { } HANDLE(e, EACCES) { AKERR_CHECK_STATUS(e, EACCES); handled = 1; } FINISH_NORETURN(e); AKERR_CHECK(handled == 1); AKERR_CHECK(akerr_slots_in_use() == 0); fprintf(stderr, "err_errno ok (EACCES name: \"%s\")\n", nm); return 0; }