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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 void *xmalloc (size_t len
)
29 void *p
= malloc (len
);
31 if (!p
) report (R_FATAL
, "Out of memory.");
35 void *xrealloc (void *op
, size_t len
)
37 void *p
= realloc (op
, len
);
39 if (len
&& !p
) report (R_FATAL
, "Out of memory.");
43 static char *vstrfmtmake (size_t *lenp
, const char *fmt
, va_list ap
)
52 n
= vsnprintf (p
, size
, fmt
, ap
);
53 if (n
< 0) size
*= 2; /* Windows */
54 else if ((unsigned)n
>= size
) size
= n
+1; /* glibc */
56 q
= realloc (p
, size
);
67 char *vstrmake (size_t *lenp
, va_list ap
)
71 fmt
= va_arg (ap
, const char*);
72 return vstrfmtmake (lenp
, fmt
, ap
);
75 char *strmake (size_t *lenp
, ...)
81 p
= vstrmake (lenp
, ap
);
82 if (!p
) report (R_FATAL
, "Out of memory.");
87 void xprintf (const char *fmt
, ...)
95 buffer
= vstrfmtmake (&size
, fmt
, ap
);
98 while ((written
= write (1, head
, size
)) != size
) {
100 report (R_FATAL
, "Can't write logs: %d", errno
);
110 return (('a'<=c
&& c
<='z') ||
111 ('A'<=c
&& c
<='Z') ||
112 ('0'<=c
&& c
<='9') ||
117 findbadtagchar (const char *tag
)
120 if (goodtagchar (*tag
)) tag
++;