diff --git a/usr.bin/make/buf.c b/usr.bin/make/buf.c index 0da71e75a829..b4e86dd062b0 100644 --- a/usr.bin/make/buf.c +++ b/usr.bin/make/buf.c @@ -70,6 +70,18 @@ Buf_Size(const Buffer *buf) return (buf->end - buf->buf); } +/** + * Returns a reference to the data contained in the buffer. + * + * @note Adding data to the Buffer object may invalidate the reference. + */ +inline char * +Buf_Data(const Buffer *bp) +{ + + return (bp->buf); +} + /** * Expand the buffer to hold the number of additional bytes, plus * space to store a terminating NULL byte. @@ -222,12 +234,23 @@ Buf_Append(Buffer *bp, const char str[]) Buf_AddBytes(bp, strlen(str), str); } +/** + * Append characters in buf to Buffer object + */ +void +Buf_AppendBuf(Buffer *bp, const Buffer *buf) +{ + + Buf_AddBytes(bp, Buf_Size(buf), buf->buf); +} + /** * Append characters between str and end to Buffer object. */ void Buf_AppendRange(Buffer *bp, const char str[], const char *end) { + Buf_AddBytes(bp, end - str, str); } diff --git a/usr.bin/make/buf.h b/usr.bin/make/buf.h index 868acb783400..0ff54d9d4d6b 100644 --- a/usr.bin/make/buf.h +++ b/usr.bin/make/buf.h @@ -76,16 +76,17 @@ typedef struct Buffer { void Buf_AddByte(Buffer *, Byte); void Buf_AddBytes(Buffer *, size_t, const Byte *); -Byte *Buf_GetAll(Buffer *, size_t *); -void Buf_Clear(Buffer *); -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_AppendBuf(Buffer *, const Buffer *); void Buf_AppendRange(Buffer *, const char [], const char *); +void Buf_Clear(Buffer *); +char *Buf_Data(const Buffer *); +void Buf_Destroy(Buffer *, Boolean); +Byte *Buf_GetAll(Buffer *, size_t *); +Buffer *Buf_Init(size_t); +char *Buf_Peel(Buffer *); +void Buf_ReplaceLastByte(Buffer *, Byte); +size_t Buf_Size(const Buffer *); void Buf_StripNewlines(Buffer *); #endif /* buf_h_a61a6812 */