1 /*******************************************************************
2 uLan Utilities Library - C library of basic reusable constructions
4 ul_cbuff.c - circular buffer
6 (C) Copyright 2005-2006 by Pavel Pisa - Originator
8 The uLan utilities library can be used, copied and modified under
10 - GPL - GNU General Public License
11 - LGPL - GNU Lesser General Public License
12 - MPL - Mozilla Public License
13 - and other licenses added by project originators
14 Code can be modified and re-distributed under any combination
15 of the above listed licenses. If contributor does not agree with
16 some of the licenses, he/she can delete appropriate line.
17 Warning, if you delete all lines, you are not allowed to
18 distribute source code and/or binaries utilizing code.
20 See files COPYING and README for details.
22 *******************************************************************/
25 #include "ul_utmalloc.h"
27 #define UL_CBUFF_INCLUDE_INTERNAL
31 int ul_cbuff_init(ul_cbuff_t *buff, ul_cbuff_state_t *state,
32 void *buff_start, ul_cbuff_loc_t size)
34 ul_cbuff_msg_head_t *msg_head;
35 int state_alloc=(state==NULL);
38 state=(ul_cbuff_state_t *)malloc(sizeof(ul_cbuff_state_t));
44 size=ul_cbuff_align(size+1)-ul_cbuff_align(1);
46 size=ul_cbuff_align(size);
47 buff_start=malloc(size);
55 state->buff_size=size;
63 buff->buff_start=(unsigned char *)buff_start;
65 msg_head=(ul_cbuff_msg_head_t *)buff_start;