summaryrefslogtreecommitdiff
path: root/devel/bmake/files/buf.h
diff options
context:
space:
mode:
authorjoerg <joerg@pkgsrc.org>2009-09-18 21:27:25 +0000
committerjoerg <joerg@pkgsrc.org>2009-09-18 21:27:25 +0000
commit0e4ebdb6f74d932373911427665f276e2f31a73d (patch)
tree9f85b0675b6430d91feb47f1fcbbe95577efbec7 /devel/bmake/files/buf.h
parenta19d1d1f1d169614d1222f6021835c928ad0aa0f (diff)
downloadpkgsrc-0e4ebdb6f74d932373911427665f276e2f31a73d.tar.gz
Update to bmake-20090909
Diffstat (limited to 'devel/bmake/files/buf.h')
-rw-r--r--devel/bmake/files/buf.h45
1 files changed, 26 insertions, 19 deletions
diff --git a/devel/bmake/files/buf.h b/devel/bmake/files/buf.h
index a2c04560af3..9bf4033092f 100644
--- a/devel/bmake/files/buf.h
+++ b/devel/bmake/files/buf.h
@@ -1,4 +1,4 @@
-/* $NetBSD: buf.h,v 1.2 2008/03/09 19:54:29 joerg Exp $ */
+/* $NetBSD: buf.h,v 1.3 2009/09/18 21:27:25 joerg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -80,32 +80,39 @@
#ifndef _BUF_H
#define _BUF_H
-#include "sprite.h"
-
typedef char Byte;
typedef struct Buffer {
int size; /* Current size of the buffer */
- int left; /* Space left (== size - (inPtr - buffer)) */
- Byte *buffer; /* The buffer itself */
- Byte *inPtr; /* Place to write to */
- Byte *outPtr; /* Place to read from */
-} *Buffer;
+ int count; /* Number of bytes in buffer */
+ Byte *buffer; /* The buffer itself (zero terminated) */
+} Buffer;
+
+/* If we aren't on netbsd, __predict_false() might not be defined. */
+#ifndef __predict_false
+#define __predict_false(x) (x)
+#endif
/* Buf_AddByte adds a single byte to a buffer. */
-#define Buf_AddByte(bp, byte) \
- (void) (--(bp)->left <= 0 ? Buf_OvAddByte(bp, byte), 1 : \
- (*(bp)->inPtr++ = (byte), *(bp)->inPtr = 0), 1)
+#define Buf_AddByte(bp, byte) do { \
+ int _count = ++(bp)->count; \
+ char *_ptr; \
+ if (__predict_false(_count >= (bp)->size)) \
+ Buf_Expand_1(bp); \
+ _ptr = (bp)->buffer + _count; \
+ _ptr[-1] = (byte); \
+ _ptr[0] = 0; \
+ } while (0)
#define BUF_ERROR 256
-void Buf_OvAddByte(Buffer, int);
-void Buf_AddBytes(Buffer, int, const Byte *);
-Byte *Buf_GetAll(Buffer, int *);
-void Buf_Discard(Buffer, int);
-int Buf_Size(Buffer);
-Buffer Buf_Init(int);
-void Buf_Destroy(Buffer, Boolean);
-void Buf_ReplaceLastByte(Buffer, int);
+#define Buf_Size(bp) ((bp)->count)
+
+void Buf_Expand_1(Buffer *);
+void Buf_AddBytes(Buffer *, int, const Byte *);
+Byte *Buf_GetAll(Buffer *, int *);
+void Buf_Empty(Buffer *);
+void Buf_Init(Buffer *, int);
+Byte *Buf_Destroy(Buffer *, Boolean);
#endif /* _BUF_H */