aboutsummaryrefslogtreecommitdiff
path: root/src/os/unix/ngx_errno.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/os/unix/ngx_errno.c')
-rw-r--r--src/os/unix/ngx_errno.c46
1 files changed, 45 insertions, 1 deletions
diff --git a/src/os/unix/ngx_errno.c b/src/os/unix/ngx_errno.c
index b3303bf6f..ca23b2d3f 100644
--- a/src/os/unix/ngx_errno.c
+++ b/src/os/unix/ngx_errno.c
@@ -9,6 +9,49 @@
#include <ngx_core.h>
+static ngx_str_t ngx_unknown_error = ngx_string("Unknown error");
+
+
+#if (NGX_HAVE_STRERRORDESC_NP)
+
+/*
+ * The strerrordesc_np() function, introduced in glibc 2.32, is
+ * async-signal-safe. This makes it possible to use it directly,
+ * without copying error messages.
+ */
+
+
+u_char *
+ngx_strerror(ngx_err_t err, u_char *errstr, size_t size)
+{
+ size_t len;
+ const char *msg;
+
+ msg = strerrordesc_np(err);
+
+ if (msg == NULL) {
+ msg = (char *) ngx_unknown_error.data;
+ len = ngx_unknown_error.len;
+
+ } else {
+ len = ngx_strlen(msg);
+ }
+
+ size = ngx_min(size, len);
+
+ return ngx_cpymem(errstr, msg, size);
+}
+
+
+ngx_int_t
+ngx_strerror_init(void)
+{
+ return NGX_OK;
+}
+
+
+#else
+
/*
* The strerror() messages are copied because:
*
@@ -26,7 +69,6 @@
static ngx_str_t *ngx_sys_errlist;
-static ngx_str_t ngx_unknown_error = ngx_string("Unknown error");
static ngx_err_t ngx_first_error;
static ngx_err_t ngx_last_error;
@@ -164,3 +206,5 @@ failed:
return NGX_ERROR;
}
+
+#endif