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 *xmalloc (size_t len)
27 void *p = malloc (len);
29 if (!p) report (R_FATAL, "Out of memory.");
33 void *xrealloc (void *op, size_t len)
35 void *p = realloc (op, len);
37 if (!p) report (R_FATAL, "Out of memory.");
41 void xprintf (const char *fmt, ...)
46 if (vprintf (fmt, ap) < 0) report (R_FATAL, "Can't write logs.");
50 char *vstrmake (size_t *lenp, va_list ap)
59 fmt = va_arg (ap, char*);
61 n = vsnprintf (p, size, fmt, ap);
62 if (n < 0) size *= 2; /* Windows */
63 else if ((unsigned)n >= size) size = n+1; /* glibc */
65 q = realloc (p, size);
76 char *strmake (size_t *lenp, ...)
82 p = vstrmake (lenp, ap);
83 if (!p) report (R_FATAL, "Out of memory.");
89 badtagchar (char *tag)
92 if (('a'<=*tag && *tag<='z') ||
93 ('A'<=*tag && *tag<='Z') ||
94 ('0'<=*tag && *tag<='9') ||
95 *tag=='-' || *tag=='.')