123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607 |
- #ifndef __PJ_ERRNO_H__
- #define __PJ_ERRNO_H__
- #include <pj/types.h>
- #include <pj/compat/errno.h>
- #include <stdarg.h>
- PJ_BEGIN_DECL
- #ifndef PJ_ERR_MSG_SIZE
- # define PJ_ERR_MSG_SIZE 80
- #endif
- #ifndef PJ_PERROR_TITLE_BUF_SIZE
- # define PJ_PERROR_TITLE_BUF_SIZE 120
- #endif
- #ifndef PJ_STRERROR_USE_WIN_GET_THREAD_LOCALE
- # define PJ_STRERROR_USE_WIN_GET_THREAD_LOCALE 0
- #endif
- PJ_DECL(pj_status_t) pj_get_os_error(void);
- PJ_DECL(void) pj_set_os_error(pj_status_t code);
- PJ_DECL(pj_status_t) pj_get_netos_error(void);
- PJ_DECL(void) pj_set_netos_error(pj_status_t code);
- PJ_DECL(pj_str_t) pj_strerror( pj_status_t statcode,
- char *buf, pj_size_t bufsize);
- #define PJ_PERROR(level,arg) do { \
- pj_perror_wrapper_##level(arg); \
- } while (0)
- PJ_DECL(void) pj_perror(int log_level, const char *sender, pj_status_t status,
- const char *title_fmt, ...)
- PJ_PRINT_FUNC_DECOR(4);
- typedef pj_str_t (*pj_error_callback)(pj_status_t e, char *msg, pj_size_t max);
- PJ_DECL(pj_status_t) pj_register_strerror(pj_status_t start_code,
- pj_status_t err_space,
- pj_error_callback f);
- #ifndef PJ_RETURN_OS_ERROR
- # define PJ_RETURN_OS_ERROR(os_code) (os_code ? \
- PJ_STATUS_FROM_OS(os_code) : -1)
- #endif
- #if PJ_NATIVE_ERR_POSITIVE
- # define PJ_STATUS_FROM_OS(e) (e == 0 ? PJ_SUCCESS : e + PJ_ERRNO_START_SYS)
- #else
- # define PJ_STATUS_FROM_OS(e) (e == 0 ? PJ_SUCCESS : PJ_ERRNO_START_SYS - e)
- #endif
- #if PJ_NATIVE_ERR_POSITIVE
- # define PJ_STATUS_TO_OS(e) (e == 0 ? PJ_SUCCESS : e - PJ_ERRNO_START_SYS)
- #else
- # define PJ_STATUS_TO_OS(e) (e == 0 ? PJ_SUCCESS : PJ_ERRNO_START_SYS - e)
- #endif
- #ifndef PJ_BUILD_ERR
- # define PJ_BUILD_ERR(code,msg) { code, msg " (" #code ")" }
- #endif
- #define PJ_EUNKNOWN (PJ_ERRNO_START_STATUS + 1)
- #define PJ_EPENDING (PJ_ERRNO_START_STATUS + 2)
- #define PJ_ETOOMANYCONN (PJ_ERRNO_START_STATUS + 3)
- #define PJ_EINVAL (PJ_ERRNO_START_STATUS + 4)
- #define PJ_ENAMETOOLONG (PJ_ERRNO_START_STATUS + 5)
- #define PJ_ENOTFOUND (PJ_ERRNO_START_STATUS + 6)
- #define PJ_ENOMEM (PJ_ERRNO_START_STATUS + 7)
- #define PJ_EBUG (PJ_ERRNO_START_STATUS + 8)
- #define PJ_ETIMEDOUT (PJ_ERRNO_START_STATUS + 9)
- #define PJ_ETOOMANY (PJ_ERRNO_START_STATUS + 10)
- #define PJ_EBUSY (PJ_ERRNO_START_STATUS + 11)
- #define PJ_ENOTSUP (PJ_ERRNO_START_STATUS + 12)
- #define PJ_EINVALIDOP (PJ_ERRNO_START_STATUS + 13)
- #define PJ_ECANCELLED (PJ_ERRNO_START_STATUS + 14)
- #define PJ_EEXISTS (PJ_ERRNO_START_STATUS + 15)
- #define PJ_EEOF (PJ_ERRNO_START_STATUS + 16)
- #define PJ_ETOOBIG (PJ_ERRNO_START_STATUS + 17)
- #define PJ_ERESOLVE (PJ_ERRNO_START_STATUS + 18)
- #define PJ_ETOOSMALL (PJ_ERRNO_START_STATUS + 19)
- #define PJ_EIGNORED (PJ_ERRNO_START_STATUS + 20)
- #define PJ_EIPV6NOTSUP (PJ_ERRNO_START_STATUS + 21)
- #define PJ_EAFNOTSUP (PJ_ERRNO_START_STATUS + 22)
- #define PJ_EGONE (PJ_ERRNO_START_STATUS + 23)
- #define PJ_ESOCKETSTOP (PJ_ERRNO_START_STATUS + 24)
-
-
- #define PJ_ERRNO_START 20000
- #define PJ_ERRNO_SPACE_SIZE 50000
- #define PJ_ERRNO_START_STATUS (PJ_ERRNO_START + PJ_ERRNO_SPACE_SIZE)
- #define PJ_ERRNO_START_SYS (PJ_ERRNO_START_STATUS + PJ_ERRNO_SPACE_SIZE)
- #define PJ_ERRNO_START_USER (PJ_ERRNO_START_SYS + PJ_ERRNO_SPACE_SIZE)
- void pj_errno_clear_handlers(void);
- #if PJ_LOG_MAX_LEVEL >= 1
- #define pj_perror_wrapper_1(arg) pj_perror_1 arg
-
- PJ_DECL(void) pj_perror_1(const char *sender, pj_status_t status,
- const char *title_fmt, ...)
- PJ_PRINT_FUNC_DECOR(3);
- #else
- #define pj_perror_wrapper_1(arg)
- #endif
- #if PJ_LOG_MAX_LEVEL >= 2
- #define pj_perror_wrapper_2(arg) pj_perror_2 arg
-
- PJ_DECL(void) pj_perror_2(const char *sender, pj_status_t status,
- const char *title_fmt, ...)
- PJ_PRINT_FUNC_DECOR(3);
- #else
- #define pj_perror_wrapper_2(arg)
- #endif
- #if PJ_LOG_MAX_LEVEL >= 3
- #define pj_perror_wrapper_3(arg) pj_perror_3 arg
-
- PJ_DECL(void) pj_perror_3(const char *sender, pj_status_t status,
- const char *title_fmt, ...)
- PJ_PRINT_FUNC_DECOR(3);
- #else
- #define pj_perror_wrapper_3(arg)
- #endif
- #if PJ_LOG_MAX_LEVEL >= 4
- #define pj_perror_wrapper_4(arg) pj_perror_4 arg
-
- PJ_DECL(void) pj_perror_4(const char *sender, pj_status_t status,
- const char *title_fmt, ...)
- PJ_PRINT_FUNC_DECOR(3);
- #else
- #define pj_perror_wrapper_4(arg)
- #endif
- #if PJ_LOG_MAX_LEVEL >= 5
- #define pj_perror_wrapper_5(arg) pj_perror_5 arg
-
- PJ_DECL(void) pj_perror_5(const char *sender, pj_status_t status,
- const char *title_fmt, ...)
- PJ_PRINT_FUNC_DECOR(3);
- #else
- #define pj_perror_wrapper_5(arg)
- #endif
- #if PJ_LOG_MAX_LEVEL >= 6
- #define pj_perror_wrapper_6(arg) pj_perror_6 arg
-
- PJ_DECL(void) pj_perror_6(const char *sender, pj_status_t status,
- const char *title_fmt, ...)
- PJ_PRINT_FUNC_DECOR(3);
- #else
- #define pj_perror_wrapper_6(arg)
- #endif
- PJ_END_DECL
- #endif
|