diff options
author | YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org> | 2012-11-25 13:07:19 +0900 |
---|---|---|
committer | YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org> | 2012-11-25 15:19:10 +0900 |
commit | f47b9b2e4b0e22497a4badb1d0193c10008d308c (patch) | |
tree | a2808339c19720db434094bea3ca98b286ffce39 /ninfod | |
parent | e74b9a2ef7a1714c6007c48ffeaffc8455ea9a9b (diff) | |
download | iputils-f47b9b2e4b0e22497a4badb1d0193c10008d308c.tar.gz |
ninfod: Employ internal buffer in stderrlog() for common case.
Signed-off-by: YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>
Diffstat (limited to 'ninfod')
-rw-r--r-- | ninfod/ninfod.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/ninfod/ninfod.c b/ninfod/ninfod.c index c8a581d..51f6e2a 100644 --- a/ninfod/ninfod.c +++ b/ninfod/ninfod.c @@ -152,14 +152,15 @@ static const __inline__ char * log_level(int priority) { void stderrlog(int pri, char *fmt, ...) { va_list ap; - char *buf = NULL; - size_t buflen = 1; + char ebuf[512]; + char *buf; + size_t buflen; va_start(ap, fmt); - for (buf = NULL, buflen = 1024; + for (buf = ebuf, buflen = sizeof(ebuf); buflen < SIZE_MAX / 2; - free(buf), buf = NULL, buflen *= 2) { + free(buf != ebuf ? buf : NULL), buf = NULL, buflen *= 2) { size_t rem; size_t res; @@ -183,7 +184,7 @@ void stderrlog(int pri, char *fmt, ...) if (buf) { fputs(buf, stderr); - free(buf); + free(buf != ebuf ? buf : NULL); } va_end(ap); |