diff options
author | Glenn Strauss <gstrauss@gluelogic.com> | 2021-05-21 22:42:09 -0400 |
---|---|---|
committer | Glenn Strauss <gstrauss@gluelogic.com> | 2021-08-27 02:16:52 -0400 |
commit | 0286bdef0c503bfccd658e0cca1101d51947fdaa (patch) | |
tree | d9d24e67330656c2264fc14d6ed6f6520ba39b85 /src/log.c | |
parent | 86c39754f215ec00186a649c09cf0b2eea21c872 (diff) | |
download | lighttpd-git-0286bdef0c503bfccd658e0cca1101d51947fdaa.tar.gz |
[multiple] use thread-safe strerror where avail
use ck_strerror_s() to use strerror_s() or strerror_r() thread-safe and
constraint-checking interfaces, where available.
Diffstat (limited to 'src/log.c')
-rw-r--r-- | src/log.c | 17 |
1 files changed, 13 insertions, 4 deletions
@@ -5,6 +5,7 @@ #include "first.h" +#include "ck.h" #include "log.h" #include <sys/types.h> @@ -166,6 +167,16 @@ log_buffer_vprintf (buffer * const b, } +__attribute_noinline__ +static void +log_error_append_strerror (buffer * const b, const int errnum) +{ + char buf[1024]; + errno_t rc = ck_strerror_s(buf, sizeof(buf), errnum); + if (0 == rc || rc == ERANGE) + buffer_append_str2(b, CONST_STR_LEN(": "), buf, strlen(buf)); +} + __attribute_format__((__printf__, 4, 0)) static void log_error_va_list_impl (log_error_st * const errh, @@ -178,10 +189,8 @@ log_error_va_list_impl (log_error_st * const errh, buffer * const b = &errh->b; if (-1 == log_buffer_prepare(errh, filename, line, b)) return; log_buffer_vprintf(b, fmt, ap); - if (perr) { - buffer_append_string_len(b, CONST_STR_LEN(": ")); - buffer_append_string(b, strerror(errnum)); - } + if (perr) + log_error_append_strerror(b, errnum); log_write(errh, b); errno = errnum; } |