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
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
30 void *xmalloc (size_t len)
32 void *p = malloc (len);
34 if (!p) report (R_FATAL, "Out of memory.");
38 void *xrealloc (void *op, size_t len)
40 void *p = realloc (op, len);
42 if (len && !p) report (R_FATAL, "Out of memory.");
46 char *xstrdup( const char *str )
48 char *res = strdup( str );
49 if (!res) report (R_FATAL, "Out of memory.");
53 static char *vstrfmtmake (size_t *lenp, const char *fmt, va_list ap)
62 n = vsnprintf (p, size, fmt, ap);
63 if (n < 0) size *= 2; /* Windows */
64 else if ((unsigned)n >= size) size = n+1; /* glibc */
66 q = realloc (p, size);
77 char *vstrmake (size_t *lenp, va_list ap)
81 fmt = va_arg (ap, const char*);
82 return vstrfmtmake (lenp, fmt, ap);
85 char *strmake (size_t *lenp, ...)
91 p = vstrmake (lenp, ap);
92 if (!p) report (R_FATAL, "Out of memory.");
97 void xprintf (const char *fmt, ...)
105 buffer = vstrfmtmake (&size, fmt, ap);
109 if (!WriteFile( logfile, head, size, &written, NULL ))
110 report (R_FATAL, "Can't write logs: %u", GetLastError());
120 return (('a'<=c && c<='z') ||
121 ('A'<=c && c<='Z') ||
122 ('0'<=c && c<='9') ||
127 findbadtagchar (const char *tag)
130 if (goodtagchar (*tag)) tag++;