2002-08-07 00:39:45 +08:00
|
|
|
|
|
|
|
/*
|
2004-09-30 00:00:49 +08:00
|
|
|
* Copyright (C) Igor Sysoev
|
2004-09-28 16:34:51 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
2002-08-07 00:39:45 +08:00
|
|
|
#include <ngx_config.h>
|
2003-05-30 22:27:59 +08:00
|
|
|
#include <ngx_core.h>
|
|
|
|
|
2002-08-07 00:39:45 +08:00
|
|
|
|
2008-11-25 19:26:32 +08:00
|
|
|
u_char *
|
2010-11-25 19:04:03 +08:00
|
|
|
ngx_strerror(ngx_err_t err, u_char *errstr, size_t size)
|
2002-08-07 00:39:45 +08:00
|
|
|
{
|
2009-04-28 23:06:29 +08:00
|
|
|
u_int len;
|
|
|
|
static u_long lang = MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US);
|
2002-08-07 00:39:45 +08:00
|
|
|
|
2004-11-11 22:07:14 +08:00
|
|
|
if (size == 0) {
|
|
|
|
return errstr;
|
|
|
|
}
|
|
|
|
|
2009-04-28 23:06:29 +08:00
|
|
|
len = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,
|
|
|
|
NULL, err, lang, (char *) errstr, size, NULL);
|
|
|
|
|
|
|
|
if (len == 0 && lang && GetLastError() == ERROR_RESOURCE_LANG_NOT_FOUND) {
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Try to use English messages first and fallback to a language,
|
|
|
|
* based on locale: non-English Windows have no English messages
|
|
|
|
* at all. This way allows to use English messages at least on
|
|
|
|
* Windows with MUI.
|
|
|
|
*/
|
|
|
|
|
|
|
|
lang = 0;
|
|
|
|
|
|
|
|
len = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,
|
|
|
|
NULL, err, lang, (char *) errstr, size, NULL);
|
|
|
|
}
|
2002-08-07 00:39:45 +08:00
|
|
|
|
|
|
|
if (len == 0) {
|
2004-11-11 22:07:14 +08:00
|
|
|
return ngx_snprintf(errstr, size,
|
2009-04-22 19:25:12 +08:00
|
|
|
"FormatMessage() error:(%d)", GetLastError());
|
2002-08-07 00:39:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* remove ".\r\n\0" */
|
|
|
|
while (errstr[len] == '\0' || errstr[len] == CR
|
|
|
|
|| errstr[len] == LF || errstr[len] == '.')
|
2004-11-11 22:07:14 +08:00
|
|
|
{
|
2002-08-07 00:39:45 +08:00
|
|
|
--len;
|
2004-11-11 22:07:14 +08:00
|
|
|
}
|
2002-08-07 00:39:45 +08:00
|
|
|
|
2004-11-11 22:07:14 +08:00
|
|
|
return &errstr[++len];
|
2002-08-07 00:39:45 +08:00
|
|
|
}
|
2010-11-25 19:04:03 +08:00
|
|
|
|
|
|
|
|
|
|
|
ngx_uint_t
|
|
|
|
ngx_strerror_init(void)
|
|
|
|
{
|
|
|
|
return NGX_OK;
|
|
|
|
}
|