From: guy Date: Wed, 28 Apr 2004 22:09:23 +0000 (+0000) Subject: From Gisle Vanem: give "tok2str()" 4 static buffers it can fill in, so X-Git-Url: https://git.tcpdump.org/tcpdump/commitdiff_plain/4ce4b393d3f800eef8c04fcf8b13c9cdcb014b9c From Gisle Vanem: give "tok2str()" 4 static buffers it can fill in, so that it can be called up to 4 times in a given "printf()". --- diff --git a/util.c b/util.c index 4e3d61fc..005824e3 100644 --- a/util.c +++ b/util.c @@ -21,7 +21,7 @@ #ifndef lint static const char rcsid[] _U_ = - "@(#) $Header: /tcpdump/master/tcpdump/util.c,v 1.87.2.3 2003-12-29 22:42:23 hannes Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/util.c,v 1.87.2.4 2004-04-28 22:09:23 guy Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -212,7 +212,9 @@ const char * tok2str(register const struct tok *lp, register const char *fmt, register int v) { - static char buf[128]; + static char buf[4][128]; + static int idx = 0; + char *ret; while (lp->s != NULL) { if (lp->v == v) @@ -221,8 +223,10 @@ tok2str(register const struct tok *lp, register const char *fmt, } if (fmt == NULL) fmt = "#%d"; - (void)snprintf(buf, sizeof(buf), fmt, v); - return (buf); + ret = buf[idx]; + (void)snprintf(ret, sizeof(buf[0]), fmt, v); + idx = (idx+1) & 3; + return (ret); } /*