From 475e526a487c81a74f9eb6915de53db8d89261fa Mon Sep 17 00:00:00 2001 From: Robert James Kaes Date: Mon, 24 Dec 2001 00:01:02 +0000 Subject: Moved write_message() into sock.c because I'm using it in other places. --- src/reqs.c | 54 +----------------------------------------------------- 1 file changed, 1 insertion(+), 53 deletions(-) (limited to 'src') diff --git a/src/reqs.c b/src/reqs.c index da7f72e..d9c7496 100644 --- a/src/reqs.c +++ b/src/reqs.c @@ -1,4 +1,4 @@ -/* $Id: reqs.c,v 1.51 2001-12-23 21:55:08 rjkaes Exp $ +/* $Id: reqs.c,v 1.52 2001-12-24 00:01:02 rjkaes Exp $ * * This is where all the work in tinyproxy is actually done. Incoming * connections have a new thread created for them. The thread then @@ -199,58 +199,6 @@ extract_ssl_url(const char *url, struct request_s *request) return 0; } -/* - * Send a "message" to the file descriptor provided. This handles the - * differences between the various implementations of vsnprintf. This code - * was basically stolen from the snprintf() man page of Debian Linux - * (although I did fix a memory leak. :) - */ -static int -write_message(int fd, const char *fmt, ...) -{ - ssize_t n; - size_t size = (1024 * 2); /* start with 2 KB and go from there */ - char *buf, *tmpbuf; - va_list ap; - - if ((buf = safemalloc(size)) == NULL) - return -1; - - while (1) { - va_start(ap, fmt); - n = vsnprintf(buf, size, fmt, ap); - va_end(ap); - - /* If that worked, break out so we can send the buffer */ - if (n > -1 && n < size) - break; - - /* Else, try again with more space */ - if (n > -1) - /* precisely what is needed (glibc2.1) */ - size = n + 1; - else - /* twice the old size (glibc2.0) */ - size *= 2; - - if ((tmpbuf = saferealloc(buf, size)) == NULL) { - safefree(buf); - return -1; - } else - buf = tmpbuf; - } - - if (safe_write(fd, buf, n) < 0) { - DEBUG2("Error in write_message(): %d", fd); - - safefree(buf); - return -1; - } - - safefree(buf); - return 0; -} - /* * Create a connection for HTTP connections. */ -- cgit v1.2.3