src/os/win32/ngx_errno.c - nginx source code

Functions defined

Source code


  1. /*
  2. * Copyright (C) Igor Sysoev
  3. * Copyright (C) Nginx, Inc.
  4. */


  5. #include <ngx_config.h>
  6. #include <ngx_core.h>


  7. u_char *
  8. ngx_strerror(ngx_err_t err, u_char *errstr, size_t size)
  9. {
  10.     u_int          len;
  11.     static u_long  lang = MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US);

  12.     if (size == 0) {
  13.         return errstr;
  14.     }

  15.     len = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,
  16.                         NULL, err, lang, (char *) errstr, size, NULL);

  17.     if (len == 0 && lang) {

  18.         /*
  19.          * Try to use English messages first and fallback to a language,
  20.          * based on locale: non-English Windows have no English messages
  21.          * at all.  This way allows to use English messages at least on
  22.          * Windows with MUI.
  23.          */

  24.         lang = 0;

  25.         len = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,
  26.                             NULL, err, lang, (char *) errstr, size, NULL);
  27.     }

  28.     if (len == 0) {
  29.         return ngx_snprintf(errstr, size,
  30.                             "FormatMessage() error:(%d)", GetLastError());
  31.     }

  32.     /* remove ".\r\n\0" */
  33.     while (errstr[len] == '\0' || errstr[len] == CR
  34.            || errstr[len] == LF || errstr[len] == '.')
  35.     {
  36.         --len;
  37.     }

  38.     return &errstr[++len];
  39. }


  40. ngx_int_t
  41. ngx_strerror_init(void)
  42. {
  43.     return NGX_OK;
  44. }