nginx/src/os/unix/ngx_errno.c

60 lines
842 B
C
Raw Normal View History

/*
* Copyright (C) Igor Sysoev
*/
2003-12-15 04:10:27 +08:00
#include <ngx_config.h>
#include <ngx_core.h>
#if (NGX_HAVE_STRERROR_R)
2003-12-15 21:57:13 +08:00
u_char *ngx_strerror_r(int err, u_char *errstr, size_t size)
2003-12-15 04:10:27 +08:00
{
if (size == 0) {
return 0;
}
errstr[0] = '\0';
strerror_r(err, (char *) errstr, size);
2003-12-15 04:10:27 +08:00
while (*errstr && size) {
errstr++;
size--;
2003-12-15 04:10:27 +08:00
}
return errstr;
2003-12-15 04:10:27 +08:00
}
2003-12-15 21:57:13 +08:00
#elif (NGX_HAVE_GNU_STRERROR_R)
2004-02-11 00:23:38 +08:00
/* Linux strerror_r() */
u_char *ngx_strerror_r(int err, u_char *errstr, size_t size)
2004-02-11 00:23:38 +08:00
{
char *str;
2004-02-11 00:23:38 +08:00
if (size == 0) {
return 0;
}
errstr[0] = '\0';
str = strerror_r(err, (char *) errstr, size);
2004-02-11 00:23:38 +08:00
if (str != (char *) errstr) {
return ngx_cpystrn(errstr, (u_char *) str, size);
2004-02-11 00:23:38 +08:00
}
while (*errstr && size) {
errstr++;
size--;
2004-02-11 00:23:38 +08:00
}
return errstr;
2004-02-11 00:23:38 +08:00
}
2003-12-15 21:57:13 +08:00
#endif