2004-09-28 16:34:51 +08:00
|
|
|
|
|
|
|
/*
|
2004-09-30 00:00:49 +08:00
|
|
|
* Copyright (C) Igor Sysoev
|
2004-09-28 16:34:51 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
2003-12-15 04:10:27 +08:00
|
|
|
#include <ngx_config.h>
|
|
|
|
#include <ngx_core.h>
|
|
|
|
|
|
|
|
|
2004-10-25 23:29:23 +08:00
|
|
|
#if (NGX_STRERROR_R)
|
2003-12-15 21:57:13 +08:00
|
|
|
|
2003-12-15 04:10:27 +08:00
|
|
|
ngx_int_t ngx_strerror_r(int err, char *errstr, size_t size)
|
|
|
|
{
|
|
|
|
size_t len;
|
|
|
|
|
|
|
|
if (size == 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
errstr[0] = '\0';
|
|
|
|
|
|
|
|
strerror_r(err, errstr, size);
|
|
|
|
|
|
|
|
for (len = 0; len < size; len++) {
|
|
|
|
if (errstr[len] == '\0') {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
2003-12-15 21:57:13 +08:00
|
|
|
|
2004-10-25 23:29:23 +08:00
|
|
|
#elif (NGX_GNU_STRERROR_R)
|
2004-02-11 00:23:38 +08:00
|
|
|
|
|
|
|
/* Linux strerror_r() */
|
|
|
|
|
|
|
|
ngx_int_t ngx_strerror_r(int err, char *errstr, size_t size)
|
|
|
|
{
|
|
|
|
char *str;
|
|
|
|
size_t len;
|
|
|
|
|
|
|
|
if (size == 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
errstr[0] = '\0';
|
|
|
|
|
|
|
|
str = strerror_r(err, errstr, size);
|
|
|
|
|
|
|
|
if (str != errstr) {
|
2004-10-11 23:07:03 +08:00
|
|
|
return ngx_cpystrn((u_char *) errstr, (u_char *) str, size)
|
|
|
|
- (u_char *) errstr;
|
2004-02-11 00:23:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for (len = 0; len < size; len++) {
|
|
|
|
if (errstr[len] == '\0') {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2003-12-15 21:57:13 +08:00
|
|
|
#endif
|