From 3509f4d713e525c5434286783add85df080c329f Mon Sep 17 00:00:00 2001 From: Hartmut Brandt Date: Tue, 8 Mar 2005 13:15:18 +0000 Subject: [PATCH] Create a new function Buf_Peel that returns the string from inside a Buffer and frees the Buffer. --- usr.bin/make/buf.c | 19 +++++++++++++++++++ usr.bin/make/buf.h | 1 + 2 files changed, 20 insertions(+) diff --git a/usr.bin/make/buf.c b/usr.bin/make/buf.c index dc192827d93e..0da71e75a829 100644 --- a/usr.bin/make/buf.c +++ b/usr.bin/make/buf.c @@ -135,6 +135,25 @@ Buf_GetAll(Buffer *bp, size_t *len) return (bp->buf); } +/** + * Get the contents of a buffer and destroy the buffer. If the buffer + * is NULL, return NULL. + * + * Returns: + * the pointer to the data. + */ +char * +Buf_Peel(Buffer *bp) +{ + char *ret; + + if (bp == NULL) + return (NULL); + ret = bp->buf; + free(bp); + return (ret); +} + /** * Initialize a buffer. If no initial size is given, a reasonable * default is used. diff --git a/usr.bin/make/buf.h b/usr.bin/make/buf.h index 6b7ea493ab6c..868acb783400 100644 --- a/usr.bin/make/buf.h +++ b/usr.bin/make/buf.h @@ -82,6 +82,7 @@ size_t Buf_Size(const Buffer *); Buffer *Buf_Init(size_t); void Buf_Destroy(Buffer *, Boolean); void Buf_ReplaceLastByte(Buffer *, Byte); +char *Buf_Peel(Buffer *); void Buf_Append(Buffer *, const char []); void Buf_AppendRange(Buffer *, const char [], const char *);