From ab578ff5dbdc19b9647e3535e7d41306e46fab5d Mon Sep 17 00:00:00 2001 From: Fu Juntang <StrongTiger_001@163.com> Date: 星期一, 30 八月 2021 19:32:58 +0800 Subject: [PATCH] Fix the return stat check. --- src/bus_error.cpp | 55 ++++++++++++++++++++++++++++++++++++++++++------------- 1 files changed, 42 insertions(+), 13 deletions(-) diff --git a/src/bus_error.cpp b/src/bus_error.cpp index 6cee508..49244cd 100644 --- a/src/bus_error.cpp +++ b/src/bus_error.cpp @@ -11,11 +11,20 @@ static pthread_key_t strerrorKey; -static char *_bus_errlist[_bus_nerr] = { +static const char *_bus_errlist[_bus_nerr] = { "\0", - "timeout", + "Timed out", "The other end is not inline", - "Key already in use" + "Key already in use", + "Network fault", + "Send to self error", + "Receive from wrong end", + "Service stoped", + "Exceed resource limit", + "Service not supported", + "Resource busy", + "Resource not provide", + "Invalid parameters" }; @@ -41,10 +50,13 @@ char * bus_strerror(int err) { - int s, eindex; + int s; char *buf; - eindex = err - 10000; /* Make first caller allocate key for thread-specific data */ + + if (err == 0) { + err = EBUS_BASE; + } s = pthread_once(&once, createKey); if (s != 0) @@ -64,14 +76,31 @@ err_exit(s, "pthread_setspecific"); } - if (eindex < 0 || eindex >= _bus_nerr || _bus_errlist[eindex] == NULL) - { - snprintf(buf, MAX_ERROR_LEN, "Unknown error %d", eindex); - } - else - { - strncpy(buf, _bus_errlist[eindex], MAX_ERROR_LEN - 1); - buf[MAX_ERROR_LEN - 1] = '\0'; /* Ensure null termination */ + + if(err < EBUS_BASE) { + // libc閿欒 + if (err < 0 || err >= _sys_nerr || _sys_errlist[err] == NULL) + { + snprintf(buf, MAX_ERROR_LEN, "Unknown error %d", err); + } + else + { + strncpy(buf, _sys_errlist[err], MAX_ERROR_LEN - 1); + buf[MAX_ERROR_LEN - 1] = '\0'; /* Ensure null termination */ + } + } else { + //鑷畾涔夐敊璇� + err -= EBUS_BASE; + if (err < 0 || err >= _bus_nerr || _bus_errlist[err] == NULL) + { + snprintf(buf, MAX_ERROR_LEN, "Unknown error %d", err); + } + else + { + strncpy(buf, _bus_errlist[err], MAX_ERROR_LEN - 1); + buf[MAX_ERROR_LEN - 1] = '\0'; /* Ensure null termination */ + } + } return buf; -- Gitblit v1.8.0