view common/logging.c @ 456:37a97621b466

Added label for current and updated list date.
author Raimund Renkert <rrenkert@intevation.de>
date Wed, 23 Apr 2014 14:00:10 +0200
parents 17e1c8f37d72
children 2a4f7364ab81
line wrap: on
line source
/* Copyright (C) 2014 by Bundesamt für Sicherheit in der Informationstechnik
 * Software engineering by Intevation GmbH
 *
 * This file is Free Software under the GNU GPL (v>=2)
 * and comes with ABSOLUTELY NO WARRANTY!
 * See LICENSE.txt for details.
 */
#include "logging.h"
#include "strhelp.h"

#include <stdio.h>

#ifdef WIN32
char *
getLastErrorMsg()
{
  LPWSTR bufPtr = NULL;
  DWORD err = GetLastError();
  char *retval = NULL;
  FormatMessageW (FORMAT_MESSAGE_ALLOCATE_BUFFER |
                  FORMAT_MESSAGE_FROM_SYSTEM |
                  FORMAT_MESSAGE_IGNORE_INSERTS,
                  NULL, err, 0, (LPWSTR) &bufPtr, 0, NULL);
  if (!bufPtr)
    {
      HMODULE hWinhttp = GetModuleHandleW (L"crypt32");
      if (hWinhttp)
        {
          FormatMessageW (FORMAT_MESSAGE_ALLOCATE_BUFFER |
                          FORMAT_MESSAGE_FROM_HMODULE |
                          FORMAT_MESSAGE_IGNORE_INSERTS,
                          hWinhttp, HRESULT_CODE (err), 0,
                          (LPWSTR) &bufPtr, 0, NULL);
        }
    }
  if (!bufPtr) {
    fprintf (stderr, "Error getting last error for code: %lx \n", err);
    return NULL;
  }

  retval = wchar_to_utf8(bufPtr, wcslen(bufPtr));
  LocalFree (bufPtr);

  return retval;
}

#endif

http://wald.intevation.org/projects/trustbridge/