2 ashd - A Sane HTTP Daemon
3 Copyright (C) 2008 Fredrik Tolf <fredrik@dolda2000.com>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
29 void _sizebuf(struct buffer *buf, size_t wanted, size_t el)
41 buf->b = srealloc(buf->b, n * el);
43 buf->b = smalloc(n * el);
47 char *decstr(char **p, size_t *len)
51 for(p2 = *p; (p2 - *p) < *len; p2++) {
64 char *vsprintf2(char *format, va_list al)
71 ret = vsnprintf(NULL, 0, format, al2);
73 buf = smalloc(ret + 1);
75 vsnprintf(buf, ret + 1, format, al2);
80 char *sprintf2(char *format, ...)
85 va_start(args, format);
86 buf = vsprintf2(format, args);
91 char *sprintf3(char *format, ...)
93 static char *buf = NULL;
98 va_start(args, format);
99 buf = vsprintf2(format, args);
106 return((off_t)strtoll(n, NULL, 10));
109 char **tokenize(char *src)
134 else if(isspace(*p) || !*p)
142 n = memcpy(malloc(cl + 1), p2, cl);
144 for(p2 = n; *p2; cl--) {
146 memmove(p2, p2 + 1, cl--);
148 } else if(*p2 == '\"') {
149 memmove(p2, p2 + 1, cl);
154 ret = realloc(ret, sizeof(char *) * (++s));
157 ret = realloc(ret, sizeof(char *) * (++s));
162 void freeca(char **ca)
175 for(i = 0; *a; a++, i++);
179 void bvprintf(struct charbuf *buf, char *format, va_list al)
186 ret = vsnprintf(buf->b + buf->d, buf->s - buf->d, format, al2);
188 if(ret < buf->s - buf->d) {
192 sizebuf(*buf, buf->d + ret + 1);
196 void bprintf(struct charbuf *buf, char *format, ...)
200 va_start(args, format);
201 bvprintf(buf, format, args);
205 void replstr(char **p, char *n)