From aa435fbee3630b078e0168a8444f93bd073c8ced Mon Sep 17 00:00:00 2001 From: leitner Date: Tue, 9 Oct 2007 13:49:26 +0000 Subject: [PATCH] add fmt_strm --- CHANGES | 1 + fmt.h | 3 +++ fmt/fmt_strm_internal.c | 17 +++++++++++++++++ test/fmt.c | 14 ++++++++++++++ 4 files changed, 35 insertions(+) create mode 100644 fmt/fmt_strm_internal.c create mode 100644 test/fmt.c diff --git a/CHANGES b/CHANGES index 3c49c0e..78a4058 100644 --- a/CHANGES +++ b/CHANGES @@ -1,4 +1,5 @@ 0.27: + add fmt_strm 0.26: fix really pathological case where io_timeouted would never diff --git a/fmt.h b/fmt.h index 2be0f90..458b34a 100644 --- a/fmt.h +++ b/fmt.h @@ -90,4 +90,7 @@ size_t fmt_httpdate(char* dest,time_t t); /* internal functions, may be independently useful */ char fmt_tohex(char c); +#define fmt_strm(b,...) fmt_strm_internal(b,__VA_ARGS__,(char*)0) +size_t fmt_strm_internal(char* dest,...); + #endif diff --git a/fmt/fmt_strm_internal.c b/fmt/fmt_strm_internal.c new file mode 100644 index 0000000..75dcbfb --- /dev/null +++ b/fmt/fmt_strm_internal.c @@ -0,0 +1,17 @@ +#include +#include "fmt.h" + +size_t fmt_strm_internal(char* dest, ...) { + size_t n; + va_list a; + const char* s; + va_start(a,dest); + for (n=0; s=va_arg(a,const char*); ) { + size_t inc=fmt_str(dest,s); + if (n+inc +#include +#include + +int main() { + char buf[100]; + buf[5]='x'; + assert(fmt_str(buf,"fnord")==5); + assert(buf[5]=='x'); + buf[5]=0; + assert(!strcmp(buf,"fnord")); + assert(fmt_strm(buf,"Fn","0rd")==5); + assert(!strcmp(buf,"Fn0rd")); +}