/*******************************************************************
  OCERA CAN Communication - C interface library

  ul_dbuff.c	- dynamic buffer

  (C) Copyright 2003 by Frantisek Vacek

  The OCERA CAN Communication is distributed under 
  the Gnu General Public License. 
  See file COPYING for details.
 *******************************************************************/

#ifndef _UL_DBUFF_H
#define _UL_DBUFF_H

#ifdef __cplusplus
extern "C" {
#endif

#define UL_DBUFF_SLEN 32

#define UL_DBUFF_IS_STATIC 1 
/* use only sbuf (no dynamic allocation) */

typedef struct ul_dbuff {	/* generic buffer for dynamic data */
  unsigned long len;		/* actual length of stored data */
  unsigned long capacity;	/* capacity of allocated buffer */
  int flags;                /* only one flag (UL_DBUFF_IS_STATIC) exists*/
  unsigned char *data;		/* pointer to dynamically allocated buffer */
  unsigned char	sbuff[UL_DBUFF_SLEN]; /* static buffer */
} ul_dbuff_t;

int ul_dbuff_init(ul_dbuff_t *buf, int flags);
__inline__ void ul_dbuff_destroy(ul_dbuff_t *buf);
int ul_dbuff_set_capacity(ul_dbuff_t *buf, int new_capacity);
int ul_dbuff_set_len(ul_dbuff_t *buf, int new_len);
int ul_dbuff_cat(ul_dbuff_t *buf, const void *b, int len);
int ul_dbuff_strcpy(ul_dbuff_t *buf, const char *str);
int ul_dbuff_strcat(ul_dbuff_t *buf, const char *str);
int ul_dbuff_append_byte(ul_dbuff_t *buf, unsigned char b);

int ul_dbuff_ltrim(ul_dbuff_t *buf);
int ul_dbuff_rtrim(ul_dbuff_t *buf);
int ul_dbuff_trim(ul_dbuff_t *buf);

#ifdef __cplusplus
} /* extern "C"*/
#endif

#endif /* _UL_NETBASE_H */
