4 * Copyright 2003 Dimitrie O. Paun
5 * Copyright 2003 Ferenc Wagner
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
25 void fatal (const char* msg)
27 MessageBox (NULL, msg, "Fatal Error", MB_ICONERROR | MB_OK);
31 void warning (const char* msg)
33 MessageBox (NULL, msg, "Warning", MB_ICONWARNING | MB_OK);
36 void *xmalloc (size_t len)
38 void *p = malloc (len);
40 if (!p) fatal ("Out of memory.");
44 void *xrealloc (void *op, size_t len)
46 void *p = realloc (op, len);
48 if (!p) fatal ("Out of memory.");
52 void xprintf (const char *fmt, ...)
57 if (vprintf (fmt, ap) < 0) fatal ("Can't write logs.");
61 char *vstrmake (size_t *lenp, const char *fmt, va_list ap)
70 n = vsnprintf (p, size, fmt, ap);
71 if (n < 0) size *= 2; /* Windows */
72 else if ((unsigned)n >= size) size = n+1; /* glibc */
74 q = realloc (p, size);
85 char *strmake (size_t *lenp, const char *fmt, ...)
91 p = vstrmake (lenp, fmt, ap);
92 if (!p) fatal ("Out of memory.");