Add obstack_printf function.

This commit is contained in:
Aric Belsito 2017-01-13 16:23:18 -08:00 committed by Jürgen Buchmüller
parent 32262ffdc0
commit c6599f0200
3 changed files with 21 additions and 1 deletions

View file

@ -1,6 +1,6 @@
## Makefile.am - procress this file with automake to produce Makefile.in
lib_LTLIBRARIES = libobstack.la
libobstack_la_SOURCES = obstack.c
libobstack_la_SOURCES = obstack.c obstack_printf.c
libobstack_la_HEADERS = obstack.h
libobstack_ladir = $(includedir)
ACLOCAL_AMFLAGS = -Im4

View file

@ -235,6 +235,8 @@ int obstack_alignment_mask (struct obstack *obstack);
int obstack_chunk_size (struct obstack *obstack);
int obstack_memory_used (struct obstack *obstack);
int obstack_printf(struct obstack *obstack, const char *__restrict fmt, ...);
/* Error handler called when `obstack_chunk_alloc' failed to allocate
more memory. This can be set to a user defined function. The
default action is to print a message and abort. */

18
obstack_printf.c Normal file
View file

@ -0,0 +1,18 @@
#include <stdarg.h>
#include <stdio.h>
#include <strings.h>
#include "obstack.h"
int obstack_printf(struct obstack *obstack, const char *__restrict fmt, ...)
{
char buf[1024];
va_list ap;
int len;
va_start(ap, fmt);
len = vsnprintf(buf, sizeof(buf), fmt, ap);
obstack_grow(obstack, buf, len);
va_end(ap);
return len;
}