Add obstack_printf function.
This commit is contained in:
parent
32262ffdc0
commit
c6599f0200
3 changed files with 21 additions and 1 deletions
|
@ -1,6 +1,6 @@
|
||||||
## Makefile.am - procress this file with automake to produce Makefile.in
|
## Makefile.am - procress this file with automake to produce Makefile.in
|
||||||
lib_LTLIBRARIES = libobstack.la
|
lib_LTLIBRARIES = libobstack.la
|
||||||
libobstack_la_SOURCES = obstack.c
|
libobstack_la_SOURCES = obstack.c obstack_printf.c
|
||||||
libobstack_la_HEADERS = obstack.h
|
libobstack_la_HEADERS = obstack.h
|
||||||
libobstack_ladir = $(includedir)
|
libobstack_ladir = $(includedir)
|
||||||
ACLOCAL_AMFLAGS = -Im4
|
ACLOCAL_AMFLAGS = -Im4
|
||||||
|
|
|
@ -235,6 +235,8 @@ int obstack_alignment_mask (struct obstack *obstack);
|
||||||
int obstack_chunk_size (struct obstack *obstack);
|
int obstack_chunk_size (struct obstack *obstack);
|
||||||
int obstack_memory_used (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
|
/* Error handler called when `obstack_chunk_alloc' failed to allocate
|
||||||
more memory. This can be set to a user defined function. The
|
more memory. This can be set to a user defined function. The
|
||||||
default action is to print a message and abort. */
|
default action is to print a message and abort. */
|
||||||
|
|
18
obstack_printf.c
Normal file
18
obstack_printf.c
Normal 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;
|
||||||
|
}
|
Loading…
Reference in a new issue