diff options
author | Brad Smith <brad@cvs.openbsd.org> | 2006-01-23 20:18:21 +0000 |
---|---|---|
committer | Brad Smith <brad@cvs.openbsd.org> | 2006-01-23 20:18:21 +0000 |
commit | c6db55f30e62c11f27aa2b28558f522418c033a1 (patch) | |
tree | d45a8eb7b86bdd1a6bc153aee1d332d9fb076633 /lib | |
parent | de4e4ee4d247b36840d0978c437808595bdc3c99 (diff) |
add evbuffer_add_vprintf interface from artur grabowski
From libevent CVS
ok markus@
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libevent/Makefile | 6 | ||||
-rw-r--r-- | lib/libevent/buffer.c | 62 | ||||
-rw-r--r-- | lib/libevent/event.3 | 5 | ||||
-rw-r--r-- | lib/libevent/event.h | 7 | ||||
-rw-r--r-- | lib/libevent/shlib_version | 2 |
5 files changed, 48 insertions, 34 deletions
diff --git a/lib/libevent/Makefile b/lib/libevent/Makefile index 57a02afe35c..cd1f36ba6f5 100644 --- a/lib/libevent/Makefile +++ b/lib/libevent/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.18 2006/01/21 19:34:56 brad Exp $ +# $OpenBSD: Makefile,v 1.19 2006/01/23 20:18:20 brad Exp $ LIB= event WANTLINT= @@ -19,8 +19,8 @@ MLINKS= event.3 event_init.3 event.3 event_dispatch.3 event.3 event_loop.3 \ bufferevent_enable.3 event.3 bufferevent_disable.3 event.3 \ bufferevent_settimeout.3 event.3 evbuffer_new.3 event.3 evbuffer_free.3 \ event.3 evbuffer_add.3 event.3 evbuffer_add_buffer.3 event.3 \ - evbuffer_add_printf.3 event.3 evbuffer_drain.3 event.3 evbuffer_write.3 \ - event.3 evbuffer_read.3 event.3 evbuffer_find.3 \ + evbuffer_add_printf.3 event.3 evbuffer_add_vprintf.3 event.3 evbuffer_drain.3 \ + event.3 evbuffer_write.3 event.3 evbuffer_read.3 event.3 evbuffer_find.3 \ event.3 evbuffer_readline.3 CFLAGS+= -I${.CURDIR} \ diff --git a/lib/libevent/buffer.c b/lib/libevent/buffer.c index de04f0bf079..3ec3f444385 100644 --- a/lib/libevent/buffer.c +++ b/lib/libevent/buffer.c @@ -1,4 +1,4 @@ -/* $OpenBSD: buffer.c,v 1.7 2005/07/02 07:15:13 grunk Exp $ */ +/* $OpenBSD: buffer.c,v 1.8 2006/01/23 20:18:20 brad Exp $ */ /* * Copyright (c) 2002, 2003 Niels Provos <provos@citi.umich.edu> @@ -126,38 +126,46 @@ evbuffer_add_buffer(struct evbuffer *outbuf, struct evbuffer *inbuf) } int -evbuffer_add_printf(struct evbuffer *buf, char *fmt, ...) +evbuffer_add_vprintf(struct evbuffer *buf, const char *fmt, va_list ap) { - int res = -1; - char *msg; -#ifndef HAVE_VASPRINTF - static char buffer[4096]; -#endif - va_list ap; + char *buffer; + size_t space; + size_t oldoff = buf->off; + int sz; - va_start(ap, fmt); + for (;;) { + buffer = buf->buffer + buf->off; + space = buf->totallen - buf->misalign - buf->off; -#ifdef HAVE_VASPRINTF - if (vasprintf(&msg, fmt, ap) == -1) - goto end; +#ifdef WIN32 + sz = vsnprintf(buffer, space - 1, fmt, ap); + buffer[space - 1] = '\0'; #else -# ifdef WIN32 - _vsnprintf(buffer, sizeof(buffer) - 1, fmt, ap); - buffer[sizeof(buffer)-1] = '\0'; -# else /* ! WIN32 */ - vsnprintf(buffer, sizeof(buffer), fmt, ap); -# endif - msg = buffer; + sz = vsnprintf(buffer, space, fmt, ap); #endif - - res = strlen(msg); - if (evbuffer_add(buf, msg, res) == -1) - res = -1; -#ifdef HAVE_VASPRINTF - free(msg); + if (sz == -1) + return (-1); + if (sz < space) { + buf->off += sz; + if (buf->cb != NULL) + (*buf->cb)(buf, oldoff, buf->off, buf->cbarg); + return (sz); + } + if (evbuffer_expand(buf, sz) == -1) + return (-1); + + } + /* NOTREACHED */ +} -end: -#endif +int +evbuffer_add_printf(struct evbuffer *buf, const char *fmt, ...) +{ + int res = -1; + va_list ap; + + va_start(ap, fmt); + res = evbuffer_add_vprintf(buf, fmt, ap); va_end(ap); return (res); diff --git a/lib/libevent/event.3 b/lib/libevent/event.3 index d10b8def705..da0149692d3 100644 --- a/lib/libevent/event.3 +++ b/lib/libevent/event.3 @@ -1,4 +1,4 @@ -.\" $OpenBSD: event.3,v 1.22 2006/01/21 19:15:09 brad Exp $ +.\" $OpenBSD: event.3,v 1.23 2006/01/23 20:18:20 brad Exp $ .\" .\" Copyright (c) 2000 Artur Grabowski <art@openbsd.org> .\" All rights reserved. @@ -66,6 +66,7 @@ .Nm evbuffer_add , .Nm evbuffer_add_buffer , .Nm evbuffer_add_printf , +.Nm evbuffer_add_vprintf , .Nm evbuffer_drain , .Nm evbuffer_write , .Nm evbuffer_read , @@ -153,6 +154,8 @@ .Fn "evbuffer_add_buffer" "struct evbuffer *dst" "struct evbuffer *src" .Ft int .Fn "evbuffer_add_printf" "struct evbuffer *buf" "char *fmt" "..." +.Ft int +.Fn "evbuffer_add_vprintf" "struct evbuffer *buf" "const char *fmt" "va_list ap" .Ft void .Fn "evbuffer_drain" "struct evbuffer *buf" "size_t size" .Ft int diff --git a/lib/libevent/event.h b/lib/libevent/event.h index 2b3332f9fc5..f20fd4ecb48 100644 --- a/lib/libevent/event.h +++ b/lib/libevent/event.h @@ -1,4 +1,4 @@ -/* $OpenBSD: event.h,v 1.12 2005/06/18 01:52:22 brad Exp $ */ +/* $OpenBSD: event.h,v 1.13 2006/01/23 20:18:20 brad Exp $ */ /* * Copyright (c) 2000-2004 Niels Provos <provos@citi.umich.edu> @@ -33,6 +33,8 @@ extern "C" { #endif +#include <stdarg.h> + #ifdef WIN32 #define WIN32_LEAN_AND_MEAN #include <windows.h> @@ -261,7 +263,8 @@ int evbuffer_add(struct evbuffer *, void *, size_t); int evbuffer_remove(struct evbuffer *, void *, size_t); char *evbuffer_readline(struct evbuffer *); int evbuffer_add_buffer(struct evbuffer *, struct evbuffer *); -int evbuffer_add_printf(struct evbuffer *, char *fmt, ...); +int evbuffer_add_printf(struct evbuffer *, const char *fmt, ...); +int evbuffer_add_vprintf(struct evbuffer *, const char *fmt, va_list ap); void evbuffer_drain(struct evbuffer *, size_t); int evbuffer_write(struct evbuffer *, int); int evbuffer_read(struct evbuffer *, int, int); diff --git a/lib/libevent/shlib_version b/lib/libevent/shlib_version index 1edea46de91..893819d18ff 100644 --- a/lib/libevent/shlib_version +++ b/lib/libevent/shlib_version @@ -1,2 +1,2 @@ major=1 -minor=0 +minor=1 |