Kannel: Open Source WAP and SMS gateway  $Revision: 5037 $
wsbuffer.h File Reference

Go to the source code of this file.

Data Structures

struct  WsBufferRec
 

Typedefs

typedef struct WsBufferRec WsBuffer
 

Functions

void ws_buffer_init (WsBuffer *buffer)
 
void ws_buffer_uninit (WsBuffer *buffer)
 
WsBufferws_buffer_alloc (void)
 
void ws_buffer_free (WsBuffer *buffer)
 
WsBool ws_buffer_append (WsBuffer *buffer, unsigned char *data, size_t len)
 
WsBool ws_buffer_append_space (WsBuffer *buffer, unsigned char **p, size_t size)
 
unsigned char * ws_buffer_ptr (WsBuffer *buffer)
 
size_t ws_buffer_len (WsBuffer *buffer)
 
unsigned char * ws_buffer_steal (WsBuffer *buffer)
 

Typedef Documentation

typedef struct WsBufferRec WsBuffer

Definition at line 83 of file wsbuffer.h.

Function Documentation

WsBuffer* ws_buffer_alloc ( void  )

Definition at line 89 of file wsbuffer.c.

References ws_calloc().

90 {
91  return ws_calloc(1, sizeof(WsBuffer));
92 }
void * ws_calloc(size_t num, size_t size)
Definition: wsalloc.c:83
WsBool ws_buffer_append ( WsBuffer buffer,
unsigned char *  data,
size_t  len 
)

Definition at line 102 of file wsbuffer.c.

References ws_buffer_append_space(), WS_FALSE, and WS_TRUE.

103 {
104  unsigned char *p;
105 
106  if (!ws_buffer_append_space(buffer, &p, len))
107  return WS_FALSE;
108 
109  memcpy(p, data, len);
110 
111  return WS_TRUE;
112 }
Definition: wsint.h:131
WsBool ws_buffer_append_space(WsBuffer *buffer, unsigned char **p, size_t size)
Definition: wsbuffer.c:115
WsBool ws_buffer_append_space ( WsBuffer buffer,
unsigned char **  p,
size_t  size 
)

Definition at line 115 of file wsbuffer.c.

References WsBufferRec::data, WsBufferRec::len, size, WS_FALSE, ws_realloc(), and WS_TRUE.

Referenced by buffer_to_int(), read_float_from_exp(), read_float_from_point(), ws_bc_encode(), ws_buffer_append(), ws_encode_buffer(), and ws_yy_lex().

116 {
117  unsigned char *ndata = ws_realloc(buffer->data, buffer->len + size);
118 
119  if (ndata == NULL)
120  return WS_FALSE;
121 
122  buffer->data = ndata;
123 
124  if (p)
125  *p = buffer->data + buffer->len;
126 
127  buffer->len += size;
128 
129  return WS_TRUE;
130 }
int size
Definition: wsasm.c:84
Definition: wsint.h:131
void * ws_realloc(void *ptr, size_t size)
Definition: wsalloc.c:89
size_t len
Definition: wsbuffer.h:79
unsigned char * data
Definition: wsbuffer.h:80
void ws_buffer_free ( WsBuffer buffer)

Definition at line 95 of file wsbuffer.c.

References WsBufferRec::data, and ws_free().

96 {
97  ws_free(buffer->data);
98  ws_free(buffer);
99 }
void ws_free(void *ptr)
Definition: wsalloc.c:139
unsigned char * data
Definition: wsbuffer.h:80
void ws_buffer_init ( WsBuffer buffer)

Definition at line 74 of file wsbuffer.c.

References WsBufferRec::data, and WsBufferRec::len.

Referenced by compile_stream(), ws_bc_encode(), and ws_yy_lex().

75 {
76  buffer->len = 0;
77  buffer->data = NULL;
78 }
size_t len
Definition: wsbuffer.h:79
unsigned char * data
Definition: wsbuffer.h:80
size_t ws_buffer_len ( WsBuffer buffer)

Definition at line 139 of file wsbuffer.c.

References WsBufferRec::len.

Referenced by compile_stream(), ws_asm_linearize(), ws_bc_encode(), and ws_yy_lex().

140 {
141  return buffer->len;
142 }
size_t len
Definition: wsbuffer.h:79
unsigned char* ws_buffer_ptr ( WsBuffer buffer)

Definition at line 133 of file wsbuffer.c.

References WsBufferRec::data.

Referenced by buffer_to_int(), compile_stream(), read_float_from_exp(), and ws_bc_encode().

134 {
135  return buffer->data;
136 }
unsigned char * data
Definition: wsbuffer.h:80
unsigned char* ws_buffer_steal ( WsBuffer buffer)

Definition at line 145 of file wsbuffer.c.

References WsBufferRec::data, and WsBufferRec::len.

146 {
147  unsigned char *p = buffer->data;
148 
149  buffer->data = NULL;
150  buffer->len = 0;
151 
152  return p;
153 }
size_t len
Definition: wsbuffer.h:79
unsigned char * data
Definition: wsbuffer.h:80
void ws_buffer_uninit ( WsBuffer buffer)

Definition at line 81 of file wsbuffer.c.

References WsBufferRec::data, WsBufferRec::len, and ws_free().

Referenced by compile_stream(), ws_bc_encode(), and ws_yy_lex().

82 {
83  ws_free(buffer->data);
84  buffer->len = 0;
85  buffer->data = NULL;
86 }
void ws_free(void *ptr)
Definition: wsalloc.c:139
size_t len
Definition: wsbuffer.h:79
unsigned char * data
Definition: wsbuffer.h:80
See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.