summaryrefslogtreecommitdiffstats
path: root/tmpbuffer.c
blob: 4f2c6321bddb0733c9c5f7cd13ac88a29d5acdb5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include "tmpbuffer.h"
#include "asn1.h"
#include <stdio.h>

#define COUNT 40

static char buffer[TMPLEN * COUNT];
static int pos = 0;

inline char* tmpbuffer_get()
{
	pos = (pos + 1) % COUNT;
	return buffer + TMPLEN * pos;
}

void tmpbuffer_format(struct string *dest, const char *format, ...)
{
	va_list args;
	va_start(args, format);
	tmpbuffer_formatva(dest, format, args);
	va_end(args);
}

void tmpbuffer_formatva(struct string *dest, const char *format, va_list args)
{
	char *b = tmpbuffer_get();
	const int ret = vsnprintf(b, TMPLEN, format, args);
	dest->l = (ret >= TMPLEN ? TMPLEN - 1 : ret);
	dest->s = b;
}