summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--kern/cbuf.c11
-rw-r--r--kern/cbuf.h20
2 files changed, 17 insertions, 14 deletions
diff --git a/kern/cbuf.c b/kern/cbuf.c
index 5c636e56..ef5c7e33 100644
--- a/kern/cbuf.c
+++ b/kern/cbuf.c
@@ -16,16 +16,17 @@
*/
#include <assert.h>
+#include <stddef.h>
#include <kern/cbuf.h>
#include <kern/error.h>
#include <kern/macros.h>
/* Negative close to 0 so that an overflow occurs early */
-#define CBUF_INIT_INDEX ((unsigned long)-500)
+#define CBUF_INIT_INDEX ((size_t)-500)
void
-cbuf_init(struct cbuf *cbuf, char *buf, unsigned long capacity)
+cbuf_init(struct cbuf *cbuf, char *buf, size_t capacity)
{
assert(ISP2(capacity));
@@ -35,8 +36,8 @@ cbuf_init(struct cbuf *cbuf, char *buf, unsigned long capacity)
cbuf->end = cbuf->start;
}
-static unsigned long
-cbuf_index(const struct cbuf *cbuf, unsigned long abs_index)
+static size_t
+cbuf_index(const struct cbuf *cbuf, size_t abs_index)
{
return abs_index & (cbuf->capacity - 1);
}
@@ -66,7 +67,7 @@ cbuf_pop(struct cbuf *cbuf, char *bytep)
}
int
-cbuf_read(const struct cbuf *cbuf, unsigned long index, char *bytep)
+cbuf_read(const struct cbuf *cbuf, size_t index, char *bytep)
{
/* Mind integer overflows */
if ((cbuf->end - index - 1) >= cbuf_size(cbuf)) {
diff --git a/kern/cbuf.h b/kern/cbuf.h
index 3ea38418..b675fd5d 100644
--- a/kern/cbuf.h
+++ b/kern/cbuf.h
@@ -21,6 +21,8 @@
#ifndef _KERN_CBUF_H
#define _KERN_CBUF_H
+#include <stddef.h>
+
/*
* Circular buffer descriptor.
*
@@ -29,30 +31,30 @@
*/
struct cbuf {
char *buf;
- unsigned long capacity;
- unsigned long start;
- unsigned long end;
+ size_t capacity;
+ size_t start;
+ size_t end;
};
-static inline unsigned long
+static inline size_t
cbuf_capacity(const struct cbuf *cbuf)
{
return cbuf->capacity;
}
-static inline unsigned long
+static inline size_t
cbuf_start(const struct cbuf *cbuf)
{
return cbuf->start;
}
-static inline unsigned long
+static inline size_t
cbuf_end(const struct cbuf *cbuf)
{
return cbuf->end;
}
-static inline unsigned long
+static inline size_t
cbuf_size(const struct cbuf *cbuf)
{
return cbuf->end - cbuf->start;
@@ -70,7 +72,7 @@ cbuf_clear(struct cbuf *cbuf)
* The descriptor is set to use the given buffer for storage. Capacity
* must be a power-of-two.
*/
-void cbuf_init(struct cbuf *cbuf, char *buf, unsigned long capacity);
+void cbuf_init(struct cbuf *cbuf, char *buf, size_t capacity);
/*
* Append a byte to a circular buffer.
@@ -96,6 +98,6 @@ int cbuf_pop(struct cbuf *cbuf, char *bytep);
* Otherwise the byte is stored at the bytep address and 0 is returned.
* The buffer isn't changed by this operation.
*/
-int cbuf_read(const struct cbuf *cbuf, unsigned long index, char *bytep);
+int cbuf_read(const struct cbuf *cbuf, size_t index, char *bytep);
#endif /* _KERN_CBUF_H */