X-Git-Url: http://git.silcnet.org/gitweb/?a=blobdiff_plain;f=lib%2Fsilcutil%2Fsilcbuffer.h;h=5ce671175b628994820e5edd63a20efb026cb504;hb=52e57c880aba9c5e89f59d962eb9af75670b76e0;hp=673c4a7ff0608da0bd421c4f42be134060c5c313;hpb=8fd8212bcd16f2b53fbedff2a9b9a4e8c15b9695;p=silc.git diff --git a/lib/silcutil/silcbuffer.h b/lib/silcutil/silcbuffer.h index 673c4a7f..5ce67117 100644 --- a/lib/silcutil/silcbuffer.h +++ b/lib/silcutil/silcbuffer.h @@ -4,7 +4,7 @@ Author: Pekka Riikonen - Copyright (C) 1998 - 2006 Pekka Riikonen + Copyright (C) 1998 - 2007 Pekka Riikonen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -110,7 +110,7 @@ * * SOURCE */ -typedef struct { +typedef struct SilcBufferObject { unsigned char *head; unsigned char *data; unsigned char *tail; @@ -120,106 +120,114 @@ typedef struct { /* Macros */ -/****d* silcutil/SilcBufferAPI/silc_buffer_truelen +/****f* silcutil/SilcBufferAPI/silc_buffer_data * * NAME * - * SilcUInt32 silc_buffer_truelen(SilcBuffer sb) + * unsigned char *silc_buffer_data(SilcBuffer sb) * * DESCRIPTION * - * Returns the true length of the buffer. + * Returns pointer to the data area of the buffer. * * SOURCE */ -#define silc_buffer_truelen(x) (SilcUInt32)((x)->end - (x)->head) +#define silc_buffer_data(x) (x)->data /***/ -/****d* silcutil/SilcBufferAPI/silc_buffer_len +/****f* silcutil/SilcBufferAPI/silc_buffer_datalen * * NAME * - * SilcUInt32 silc_buffer_len(SilcBuffer sb) + * #define silc_buffer_datalen ... * * DESCRIPTION * - * Returns the current length of the data area of the buffer. + * Macro that can be used in function argument list to give the data + * pointer and the data length, instead of calling both silc_buffer_data + * and silc_buffer_len separately. + * + * EXAMPLE + * + * // Following are the same thing + * silc_foo_function(foo, silc_buffer_datalen(buf)); + * silc_foo_function(foo, silc_buffer_data(buf), silc_buffer_len(buf)); * * SOURCE */ -#define silc_buffer_len(x) (SilcUInt32)((x)->tail - (x)->data) +#define silc_buffer_datalen(x) (x) ? silc_buffer_data((x)) : NULL, \ + (x) ? silc_buffer_len((x)) : 0 /***/ -/****d* silcutil/SilcBufferAPI/silc_buffer_headlen +/* Inline functions */ + +/****d* silcutil/SilcBufferAPI/silc_buffer_truelen * * NAME * - * SilcUInt32 silc_buffer_headlen(SilcBuffer sb) + * SilcUInt32 silc_buffer_truelen(SilcBuffer sb) * * DESCRIPTION * - * Returns the current length of the head data area of the buffer. + * Returns the true length of the buffer. * - * SOURCE - */ -#define silc_buffer_headlen(x) (SilcUInt32)((x)->data - (x)->head) -/***/ + ***/ +static inline +SilcUInt32 silc_buffer_truelen(SilcBuffer x) +{ + return (SilcUInt32)(x->end - x->head); +} -/****d* silcutil/SilcBufferAPI/silc_buffer_taillen +/****d* silcutil/SilcBufferAPI/silc_buffer_len * * NAME * - * SilcUInt32 silc_buffer_taillen(SilcBuffer sb) + * SilcUInt32 silc_buffer_len(SilcBuffer sb) * * DESCRIPTION * - * Returns the current length of the tail data area of the buffer. + * Returns the current length of the data area of the buffer. * - * SOURCE - */ -#define silc_buffer_taillen(x) (SilcUInt32)((x)->end - (x)->tail) -/***/ + ***/ +static inline +SilcUInt32 silc_buffer_len(SilcBuffer x) +{ + return (SilcUInt32)(x->tail - x->data); +} -/****f* silcutil/SilcBufferAPI/silc_buffer_data +/****d* silcutil/SilcBufferAPI/silc_buffer_headlen * * NAME * - * unsigned char *silc_buffer_data(SilcBuffer sb) + * SilcUInt32 silc_buffer_headlen(SilcBuffer sb) * * DESCRIPTION * - * Returns pointer to the data area of the buffer. + * Returns the current length of the head data area of the buffer. * - * SOURCE - */ -#define silc_buffer_data(x) (x)->data -/***/ + ***/ +static inline +SilcUInt32 silc_buffer_headlen(SilcBuffer x) +{ + return (SilcUInt32)(x->data - x->head); +} -/****f* silcutil/SilcBufferAPI/silc_buffer_datalen +/****d* silcutil/SilcBufferAPI/silc_buffer_taillen * * NAME * - * #define silc_buffer_datalen ... + * SilcUInt32 silc_buffer_taillen(SilcBuffer sb) * * DESCRIPTION * - * Macro that can be used in function argument list to give the data - * pointer and the data length, instead of calling both silc_buffer_data - * and silc_buffer_len separately. - * - * EXAMPLE - * - * // Following are the same thing - * silc_foo_function(foo, silc_buffer_datalen(buf)); - * silc_foo_function(foo, silc_buffer_data(buf), silc_buffer_len(buf)); + * Returns the current length of the tail data area of the buffer. * - * SOURCE - */ -#define silc_buffer_datalen(x) (x) ? silc_buffer_data((x)) : NULL, \ - (x) ? silc_buffer_len((x)) : 0 -/***/ - -/* Inline functions */ + ***/ +static inline +SilcUInt32 silc_buffer_taillen(SilcBuffer x) +{ + return (SilcUInt32)(x->end - x->tail); +} /****f* silcutil/SilcBufferAPI/silc_buffer_alloc * @@ -969,7 +977,7 @@ SilcBuffer silc_buffer_salloc(SilcStack stack, SilcUInt32 len) return NULL; /* Allocate the actual data area */ - sb->head = (unsigned char *)silc_smalloc_ua(stack, len); + sb->head = (unsigned char *)silc_smalloc(stack, len); if (silc_unlikely(!sb->head)) return NULL; @@ -1046,12 +1054,12 @@ SilcBuffer silc_buffer_srealloc(SilcStack stack, hlen = silc_buffer_headlen(sb); dlen = silc_buffer_len(sb); - h = (unsigned char *)silc_srealloc_ua(stack, silc_buffer_truelen(sb), - sb->head, newsize); + h = (unsigned char *)silc_srealloc(stack, silc_buffer_truelen(sb), + sb->head, newsize); if (!h) { /* Do slow and stack wasting realloc. The old sb->head is lost and is freed eventually. */ - h = (unsigned char *)silc_smalloc_ua(stack, newsize); + h = (unsigned char *)silc_smalloc(stack, newsize); if (silc_unlikely(!h)) return NULL; memcpy(h, sb->head, silc_buffer_truelen(sb));