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
26 void *xmalloc (size_t len)
28 void *p = malloc (len);
30 if (!p) report (R_FATAL, "Out of memory.");
34 void *xrealloc (void *op, size_t len)
36 void *p = realloc (op, len);
38 if (!p) report (R_FATAL, "Out of memory.");
42 void xprintf (const char *fmt, ...)
47 if (vprintf (fmt, ap) < 0)
48 report (R_FATAL, "Can't write logs: %d", errno);
52 char *vstrmake (size_t *lenp, va_list ap)
61 fmt = va_arg (ap, char*);
63 n = vsnprintf (p, size, fmt, ap);
64 if (n < 0) size *= 2; /* Windows */
65 else if ((unsigned)n >= size) size = n+1; /* glibc */
67 q = realloc (p, size);
78 char *strmake (size_t *lenp, ...)
84 p = vstrmake (lenp, ap);
85 if (!p) report (R_FATAL, "Out of memory.");
91 badtagchar (char *tag)
94 if (('a'<=*tag && *tag<='z') ||
95 ('A'<=*tag && *tag<='Z') ||
96 ('0'<=*tag && *tag<='9') ||
97 *tag=='-' || *tag=='.')