X-Git-Url: http://www.dolda2000.com/gitweb/?p=ashd.git;a=blobdiff_plain;f=lib%2Fresp.c;h=52fbd4b12f8eeab0c25621810c8c6292841d1bf8;hp=2c0fa835daaf8a969f88cd36d509952a47d9f842;hb=65e8a9a08a303b49015ac21c951576f10831415d;hpb=f56b079086cb35e50697a4752b38679ae5e44679 diff --git a/lib/resp.c b/lib/resp.c index 2c0fa83..52fbd4b 100644 --- a/lib/resp.c +++ b/lib/resp.c @@ -86,16 +86,12 @@ char *htmlquote(char *text) return(ret = buf.b); } -void simpleerror(int fd, int code, char *msg, char *fmt, ...) +static void simpleerror2v(FILE *out, int code, char *msg, char *fmt, va_list args) { struct charbuf buf; char *tmp; - va_list args; - FILE *out; - va_start(args, fmt); tmp = vsprintf2(fmt, args); - va_end(args); bufinit(buf); bufcatstr(buf, "\r\n"); bufcatstr(buf, "\r\n"); @@ -108,17 +104,36 @@ void simpleerror(int fd, int code, char *msg, char *fmt, ...) bprintf(&buf, "

%s

\r\n", htmlquote(tmp)); bufcatstr(buf, "\r\n"); bufcatstr(buf, "\r\n"); - out = fdopen(dup(fd), "w"); fprintf(out, "HTTP/1.1 %i %s\n", code, msg); fprintf(out, "Content-Type: text/html\n"); fprintf(out, "Content-Length: %zi\n", buf.d); fprintf(out, "\n"); fwrite(buf.b, 1, buf.d, out); - fclose(out); buffree(buf); free(tmp); } +void simpleerror2(FILE *out, int code, char *msg, char *fmt, ...) +{ + va_list args; + + va_start(args, fmt); + simpleerror2v(out, code, msg, fmt, args); + va_end(args); +} + +void simpleerror(int fd, int code, char *msg, char *fmt, ...) +{ + va_list args; + FILE *out; + + va_start(args, fmt); + out = fdopen(dup(fd), "w"); + simpleerror2v(out, code, msg, fmt, args); + fclose(out); + va_end(args); +} + void stdredir(struct hthead *req, int fd, int code, char *dst) { FILE *out;