summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--rb.h20
-rw-r--r--rb_str.h10
-rw-r--r--src/rb.c16
-rw-r--r--src/rb_str.c10
4 files changed, 30 insertions, 26 deletions
diff --git a/rb.h b/rb.h
index 5b1e0e1..8a8eb0e 100644
--- a/rb.h
+++ b/rb.h
@@ -13,9 +13,13 @@ typedef struct t_ring_buffer {
size_t size_filled;
} t_ring_buffer;
+/* do not remove for backward compatibility */
typedef t_ring_buffer t_rb;
-static inline size_t rb_get_size(const t_rb *rb)
+typedef t_ring_buffer ring_buffer_t;
+typedef t_ring_buffer rb_t;
+
+static inline size_t rb_get_size(const rb_t *rb)
{
return sizeof(rb->buffer);
}
@@ -24,33 +28,33 @@ static inline size_t rb_get_size(const t_rb *rb)
* initializes rb with default values.
* returns 0 on success
*/
-int rb_init(t_rb *rb);
+int rb_init(rb_t *rb);
/* returns an initialized newly allocated ring buffer */
-__attribute((malloc)) t_rb *rb_new(void);
+__attribute((malloc)) rb_t *rb_new(void);
-void rb_delete(t_rb **);
+void rb_delete(rb_t **);
/* put n bytes of src into the ring buffer pointed by rb */
-t_rb *rb_put(t_rb *rb, const void *src, size_t n);
+rb_t *rb_put(rb_t *rb, const void *src, size_t n);
/*
* take at most n bytes from the ring buffer pointed by rb and
* put them into dest
*/
-size_t rb_get(t_rb *rb, void *dest, size_t n);
+size_t rb_get(rb_t *rb, void *dest, size_t n);
/*
* like rb_get but does not modify the ring_buffer (the bytes are kept
* in the ring_buffer)
*/
-size_t rb_peek(const t_rb *ring_buffer, void *dest, size_t size);
+size_t rb_peek(const rb_t *ring_buffer, void *dest, size_t size);
/*
* remove a maximum of n bytes from the ring buffer pointed to by rb
* the functions returns the number of bytes actually removed
*/
-static inline size_t rb_remove(t_rb *rb, size_t n)
+static inline size_t rb_remove(rb_t *rb, size_t n)
{
return rb_get(rb, NULL, n);
}
diff --git a/rb_str.h b/rb_str.h
index bbfef5e..bebca5e 100644
--- a/rb_str.h
+++ b/rb_str.h
@@ -17,7 +17,7 @@
* common use case:
* request = rb_gets(rb, "\r\n")
*/
-char *rb_gets(t_rb *rb, const char *delim);
+char *rb_gets(rb_t *rb, const char *delim);
/*
* same as the above function but takes a null terminated array of delimiters
@@ -29,19 +29,19 @@ char *rb_gets(t_rb *rb, const char *delim);
* request = rb_gets(rb, (const char *[]){"\n", "\r", "\r\n", NULL})
* which will return a request disregarding whether netcat or telnet is used
*/
-char *rb_gets2(t_rb *rb, const char *const *delim);
+char *rb_gets2(rb_t *rb, const char *const *delim);
/*
* this functions writes str to the ring buffer pointed by rb. If the ring
* buffer is not large enough to contain all the data, the beginning will be
* overriden. However, a buffer overflow is not susceptible to happen.
*/
-static inline t_rb *rb_puts(t_rb *rb, const char *str)
+static inline rb_t *rb_puts(rb_t *rb, const char *str)
{
return rb_put(rb, str, strlen(str));
}
-t_rb *rb_vprintf(t_rb *rb, const char *fmt, va_list list);
+rb_t *rb_vprintf(rb_t *rb, const char *fmt, va_list list);
/*
* function which behaves like sprintf but which writes into a ring buffer
@@ -49,6 +49,6 @@ t_rb *rb_vprintf(t_rb *rb, const char *fmt, va_list list);
* the beginning will be overriden. However, a buffer overflow will not occur
*/
__attribute__((format(printf, 2, 3)))
-t_rb *rb_printf(t_rb *rb, const char *fmt, ...);
+rb_t *rb_printf(rb_t *rb, const char *fmt, ...);
#endif /* RB_STR_H */
diff --git a/src/rb.c b/src/rb.c
index a04d0cf..d8a801c 100644
--- a/src/rb.c
+++ b/src/rb.c
@@ -6,7 +6,7 @@
#define MAX(_x1, _x2) (((_x1) > (_x2)) ? (_x1) : (_x2))
#define MIN(_x1, _x2) (((_x1) < (_x2)) ? (_x1) : (_x2))
-int rb_init(t_rb *rb)
+int rb_init(rb_t *rb)
{
rb->off_r = 0;
rb->off_w = 0;
@@ -15,11 +15,11 @@ int rb_init(t_rb *rb)
return 0;
}
-t_rb *rb_new(void)
+rb_t *rb_new(void)
{
- t_rb *rb;
+ rb_t *rb;
- if ((rb = malloc(sizeof(t_rb))) == NULL) {
+ if ((rb = malloc(sizeof(rb_t))) == NULL) {
return NULL;
}
@@ -28,13 +28,13 @@ t_rb *rb_new(void)
return rb;
}
-void rb_delete(t_rb **rb)
+void rb_delete(rb_t **rb)
{
free(*rb);
*rb = NULL;
}
-t_rb *rb_put(t_rb *rb, const void *src, size_t n)
+rb_t *rb_put(rb_t *rb, const void *src, size_t n)
{
size_t size;
@@ -83,7 +83,7 @@ t_rb *rb_put(t_rb *rb, const void *src, size_t n)
return rb;
}
-size_t rb_get(t_rb *rb, void *dest, size_t n)
+size_t rb_get(rb_t *rb, void *dest, size_t n)
{
size_t size = rb_peek(rb, dest, n);
@@ -98,7 +98,7 @@ size_t rb_get(t_rb *rb, void *dest, size_t n)
return size;
}
-size_t rb_peek(const t_rb *rb, void *dest, size_t n)
+size_t rb_peek(const rb_t *rb, void *dest, size_t n)
{
uint16_t offset;
size_t size;
diff --git a/src/rb_str.c b/src/rb_str.c
index 07b2844..f6b3878 100644
--- a/src/rb_str.c
+++ b/src/rb_str.c
@@ -4,7 +4,7 @@
typedef uint8_t byte;
-static char *__rb_gets2(t_rb *rb, const char *const *delim,
+static char *__rb_gets2(rb_t *rb, const char *const *delim,
const byte *data, size_t size)
{
char *ret = NULL;
@@ -37,7 +37,7 @@ static char *__rb_gets2(t_rb *rb, const char *const *delim,
return ret;
}
-char *rb_gets2(t_rb *rb, const char *const *delim)
+char *rb_gets2(rb_t *rb, const char *const *delim)
{
size_t size;
char *ret;
@@ -58,7 +58,7 @@ char *rb_gets2(t_rb *rb, const char *const *delim)
return ret;
}
-char *rb_gets(t_rb *rb, const char *delimit)
+char *rb_gets(rb_t *rb, const char *delimit)
{
char *data = malloc((rb->size_filled) * sizeof(char));
@@ -81,7 +81,7 @@ char *rb_gets(t_rb *rb, const char *delimit)
return ret;
}
-t_rb *rb_vprintf(t_rb *rb, const char *fmt, va_list ap)
+rb_t *rb_vprintf(rb_t *rb, const char *fmt, va_list ap)
{
char *buffer;
@@ -102,7 +102,7 @@ t_rb *rb_vprintf(t_rb *rb, const char *fmt, va_list ap)
}
__attribute__((format(printf, 2, 3)))
-t_rb *rb_printf(t_rb *rb, const char *fmt, ...)
+rb_t *rb_printf(rb_t *rb, const char *fmt, ...)
{
va_list ap;