Debian Codegraph @

win/c-source/errors.c

raw
1 #define UNICODE
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <windows.h>
5 #include "errors.h"
6
7 /* Copied from the Win32-2.13.4.0 package, but renamed `getErrorMessage` to
8 * `_ansi_terminal_getErrorMessage`, in order to avoid problems with duplicate
9 * symbols in GHC's object files. See:
10 * https://gitlab.haskell.org/ghc/ghc/-/issues/23365.
11 */
12
13 /* There's two ways we can generate error messages - with different tradeoffs:
14 * If we do a function call, we have to use a static buffer.
15 * If we use a macro and ANSI C's string splicing, we have to use constant
16 * strings - and accept a certain amount of overhead from inserting the
17 * boilerplate text.
18 *
19 * Why the concern about performance? Error messages are only generated
20 * in exceptional situations -- sof 9/98
21 *
22 * sof 9/98 : Removed use of non-standard (and wimpy :-) snprintf().
23 */
24
25 LPTSTR _ansi_terminal_getErrorMessage(DWORD err)
26 {
27 LPTSTR what;
28
29 FormatMessage(
30 (FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER) ,
31 NULL,
32 err,
33 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */
34 (LPTSTR) &what,
35 0,
36 NULL
37 );
38 return what;
39 }