| 1 |
joko |
1.2 |
/* $Id: utils_misc.c,v 1.1 2006/06/15 22:58:58 joko Exp $ */ |
| 2 |
joko |
1.1 |
|
| 3 |
|
|
#include <stdio.h> |
| 4 |
|
|
#include <windows.h> |
| 5 |
|
|
|
| 6 |
|
|
// if last char is newline, "strip" it |
| 7 |
|
|
void chomp(char * string) { |
| 8 |
|
|
int string_length = strlen(string); |
| 9 |
|
|
if (string[string_length-1] == '\n') { |
| 10 |
|
|
string[string_length-1] = '\0'; |
| 11 |
|
|
} |
| 12 |
|
|
} |
| 13 |
|
|
|
| 14 |
|
|
// checks for errors and writes its message to stderr |
| 15 |
|
|
BOOL check_alert_error(const char * error_source) { |
| 16 |
|
|
DWORD dwError = GetLastError(); |
| 17 |
|
|
|
| 18 |
|
|
HLOCAL message = NULL; |
| 19 |
|
|
BOOL fOk; |
| 20 |
|
|
|
| 21 |
|
|
if (dwError == 0) |
| 22 |
|
|
return FALSE; |
| 23 |
|
|
|
| 24 |
|
|
fOk = FormatMessage( |
| 25 |
|
|
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER, |
| 26 |
|
|
NULL, |
| 27 |
|
|
dwError, |
| 28 |
|
|
MAKELANGID(LANG_NEUTRAL, SUBLANG_SYS_DEFAULT), |
| 29 |
|
|
(PTSTR)&message, |
| 30 |
|
|
0, |
| 31 |
|
|
NULL |
| 32 |
|
|
); |
| 33 |
|
|
|
| 34 |
|
|
if (message != NULL) { |
| 35 |
joko |
1.2 |
fprintf(stderr, "ERROR with '%s': %s (Code %i)\n", error_source, message, dwError); |
| 36 |
joko |
1.1 |
LocalFree(message); |
| 37 |
|
|
} |
| 38 |
|
|
|
| 39 |
|
|
return TRUE; |
| 40 |
|
|
|
| 41 |
|
|
} |