summaryrefslogtreecommitdiffstats
path: root/tmpbuffer.c
diff options
context:
space:
mode:
authorSimon Rettberg2014-03-15 01:49:50 +0100
committerSimon Rettberg2014-03-15 01:49:50 +0100
commitbedd2e7ccb1595c23e159eaa952ae1b0b5a3d2ad (patch)
treec7d1995a09f6ed0c4e6873252e957d72f5d07d07 /tmpbuffer.c
downloadldadp-bedd2e7ccb1595c23e159eaa952ae1b0b5a3d2ad.tar.gz
ldadp-bedd2e7ccb1595c23e159eaa952ae1b0b5a3d2ad.tar.xz
ldadp-bedd2e7ccb1595c23e159eaa952ae1b0b5a3d2ad.zip
Lean and mean initial commit
Not much functionality yet
Diffstat (limited to 'tmpbuffer.c')
-rw-r--r--tmpbuffer.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/tmpbuffer.c b/tmpbuffer.c
new file mode 100644
index 0000000..4f2c632
--- /dev/null
+++ b/tmpbuffer.c
@@ -0,0 +1,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;
+}
+