Commit 936275c9 authored by Geoff Simmons's avatar Geoff Simmons

strfTIM() gets its temp buffer from the stack, rather than using a VSB

parent e5cb895e
...@@ -33,11 +33,11 @@ ...@@ -33,11 +33,11 @@
#include <sys/types.h> #include <sys/types.h>
#include <errno.h> #include <errno.h>
#include <math.h> #include <math.h>
#include <stdio.h>
#include "strfTIM.h" #include "strfTIM.h"
#include "vas.h" #include "vas.h"
#include "vsb.h"
/* /*
* cf. vtim.c/VTIM:timespec in libvarnish * cf. vtim.c/VTIM:timespec in libvarnish
...@@ -55,38 +55,39 @@ double2timeval(double t) ...@@ -55,38 +55,39 @@ double2timeval(double t)
size_t size_t
strfTIM(char *s, size_t max, const char *fmt, struct tm *tm, unsigned usec) strfTIM(char *s, size_t max, const char *fmt, struct tm *tm, unsigned usec)
{ {
struct vsb *vsb = VSB_new(NULL, NULL, max, VSB_FIXEDLEN);
const char *p; const char *p;
size_t n; char newfmt[max], *f = newfmt;
size_t n, len = 0;
assert(usec < 1000000); assert(usec < 1000000);
for (p = fmt; *p; p++) { for (p = fmt; *p; p++) {
if (*p != '%') { if (*p != '%') {
VSB_putc(vsb, *p); len++;
if (len > max)
return 0;
*f++ = *p;
continue; continue;
} }
p++; p++;
if (*p == '%') {
VSB_cat(vsb, "%%");
continue;
}
if (*p != 'i') { if (*p != 'i') {
VSB_putc(vsb, '%'); len += 2;
VSB_putc(vsb, *p); if (len > max)
return 0;
*f++ = '%';
*f++ = *p;
continue; continue;
} }
len += 6;
VSB_printf(vsb, "%06u", usec); if (len > max)
} return 0;
VSB_finish(vsb); sprintf(f, "%06u", usec);
f += 6;
if (VSB_error(vsb)) {
VSB_delete(vsb);
return 0;
} }
if (len + 1 > max)
return 0;
*f = '\0';
n = strftime(s, max, VSB_data(vsb), tm); n = strftime(s, max, newfmt, tm);
VSB_delete(vsb);
return n; return n;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment