Update error to support getaddrinfo

This commit is contained in:
2023-01-29 11:38:48 +01:00
parent 7a3adc6ed3
commit 40310faa4b
2 changed files with 14 additions and 16 deletions

View File

@ -11,6 +11,7 @@
#include <errno.h> #include <errno.h>
#include <string.h> #include <string.h>
#include <netdb.h>
extern const char *sock_error_str(unsigned long err); extern const char *sock_error_str(unsigned long err);
extern const char *http_error_str(int err); extern const char *http_error_str(int err);
@ -29,23 +30,14 @@ static unsigned long error_decompress(int err) {
const char *error_str(int err_no, char *buf, int buf_len) { const char *error_str(int err_no, char *buf, int buf_len) {
buf[0] = 0; buf[0] = 0;
unsigned char mode = (unsigned char) (err_no >> 24);
int e = err_no & 0x00FFFFFF; int e = err_no & 0x00FFFFFF;
if (mode == 0x00) { switch (err_no >> 24) {
// normal case 0x00: return strerror_r(e, buf, buf_len);
return strerror_r(e, buf, buf_len); case 0x01: return sock_error_str(error_decompress(e));
} else if (mode == 0x01) { case 0x02: return ERR_reason_error_string(error_decompress(e));
// ssl case 0x03: return MMDB_strerror(e);
return sock_error_str(error_decompress(e)); case 0x04: return http_error_str(e);
} else if (mode == 0x02) { case 0x05: return gai_strerror(e);
// ssl err
return ERR_reason_error_string(error_decompress(e));
} else if (mode == 0x03) {
// mmdb
return MMDB_strerror(e);
} else if (mode == 0x04) {
// http
return http_error_str(e);
} }
return buf; return buf;
} }
@ -66,6 +58,10 @@ void error_http(int err) {
errno = 0x04000000 | err; errno = 0x04000000 | err;
} }
void error_gai(int err) {
errno = 0x05000000 | err;
}
static int error_get(unsigned char prefix) { static int error_get(unsigned char prefix) {
return (errno >> 24 != prefix) ? 0 : errno & 0x00FFFFFF; return (errno >> 24 != prefix) ? 0 : errno & 0x00FFFFFF;
} }

View File

@ -19,6 +19,8 @@ void error_mmdb(int err);
void error_http(int err); void error_http(int err);
void error_gai(int err);
int error_get_sys(); int error_get_sys();
int error_get_ssl(); int error_get_ssl();