libUPnP  1.6.17
Data Structures | Defines | Functions
membuffer.h File Reference
#include <stdlib.h>
#include "upnputil.h"
Include dependency graph for membuffer.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  memptr
struct  membuffer

Defines

#define MINVAL(a, b)   ( (a) < (b) ? (a) : (b) )
#define MAXVAL(a, b)   ( (a) > (b) ? (a) : (b) )
#define MEMBUF_DEF_SIZE_INC   (size_t)5

Functions

char * str_alloc (const char *str, size_t str_len)
 Allocate memory and copy information from the input string to the newly allocated memory.
int memptr_cmp (memptr *m, const char *s)
 Compares characters of strings passed for number of bytes. If equal for the number of bytes, the length of the bytes determines which buffer is shorter.
int memptr_cmp_nocase (memptr *m, const char *s)
 Compares characters of 2 strings irrespective of the case for a specific count of bytes.
int membuffer_set_size (membuffer *m, size_t new_length)
 Increases or decreases buffer cap so that at least 'new_length' bytes can be stored.
void membuffer_init (membuffer *m)
 Wrapper to membuffer_initialize().
void membuffer_destroy (membuffer *m)
 Free's memory allocated for membuffer* m.
int membuffer_assign (membuffer *m, const void *buf, size_t buf_len)
 Allocate memory to membuffer *m and copy the contents of the in parameter const void *buf.
int membuffer_assign_str (membuffer *m, const char *c_str)
 Wrapper function for membuffer_assign().
int membuffer_append (membuffer *m, const void *buf, size_t buf_len)
 Invokes function to appends data from a constant buffer to the buffer.
int membuffer_append_str (membuffer *m, const char *c_str)
 Invokes function to appends data from a constant string to the buffer.
int membuffer_insert (membuffer *m, const void *buf, size_t buf_len, size_t index)
 Allocates memory for the new data to be inserted. Does memory management by moving the data from the existing memory to the newly allocated memory and then appending the new data.
void membuffer_delete (membuffer *m, size_t index, size_t num_bytes)
 Shrink the size of the buffer depending on the current size of the bufer and te input parameters. Move contents from the old buffer to the new sized buffer.
char * membuffer_detach (membuffer *m)
void membuffer_attach (membuffer *m, char *new_buf, size_t buf_len)

Detailed Description


Define Documentation

#define MEMBUF_DEF_SIZE_INC   (size_t)5

default value of size_inc.

Referenced by ixml_membuf_init(), and membuffer_init().


Function Documentation

int membuffer_append ( membuffer m,
const void *  buf,
size_t  buf_len 
)

Invokes function to appends data from a constant buffer to the buffer.

Returns:
int.
Parameters:
[in,out]mBuffer whose memory is to be appended.
[in]bufSource buffer whose contents will be copied.
[in]buf_lenLength of the source buffer.

References membuffer::length.

int membuffer_append_str ( membuffer m,
const char *  c_str 
)

Invokes function to appends data from a constant string to the buffer.

Returns:
int.
Parameters:
[in,out]mBuffer whose memory is to be appended.
[in]c_strSource buffer whose contents will be copied.

References membuffer::length.

int membuffer_assign ( membuffer m,
const void *  buf,
size_t  buf_len 
)

Allocate memory to membuffer *m and copy the contents of the in parameter const void *buf.

Returns:
  • UPNP_E_SUCCESS
  • UPNP_E_OUTOF_MEMORY
Parameters:
[in,out]mBuffer whose memory is to be allocated and assigned.
[in]bufSource buffer whose contents will be copied.
[in]buf_lenLength of the source buffer.

References membuffer::buf, and membuffer::length.

int membuffer_assign_str ( membuffer m,
const char *  c_str 
)

Wrapper function for membuffer_assign().

Returns:
  • UPNP_E_SUCCESS
  • UPNP_E_OUTOF_MEMORY
Parameters:
[in,out]mBuffer to be allocated and assigned.
[in]c_strSource buffer whose contents will be copied.
void membuffer_attach ( membuffer m,
char *  new_buf,
size_t  buf_len 
)
Parameters:
[in,out]mBuffer to be updated.
[in]new_bufSource buffer which will be assigned to the buffer to be updated.
[in]buf_lenLength of the source buffer.

References membuffer::buf, membuffer::capacity, and membuffer::length.

void membuffer_delete ( membuffer m,
size_t  index,
size_t  num_bytes 
)

Shrink the size of the buffer depending on the current size of the bufer and te input parameters. Move contents from the old buffer to the new sized buffer.

Parameters:
[in,out]mBuffer whose memory size is to be decreased and copied to the modified location.
[in]indexIndex to determine bounds while moving data.
[in]num_bytesNumber of bytes that the data needs to shrink by.

References membuffer::buf, and membuffer::length.

Free's memory allocated for membuffer* m.

Parameters:
[in,out]mBuffer to be destroyed.

References membuffer::buf.

char* membuffer_detach ( membuffer m)
Parameters:
[in,out]mBuffer to be returned and updated.

References membuffer::buf.

void membuffer_init ( membuffer m)

Wrapper to membuffer_initialize().

Set the size of the buffer to MEMBUF_DEF_SIZE_INC and Initializes m->buf to NULL, length = 0.

Parameters:
[in,out]mBuffer to be initialized.

References MEMBUF_DEF_SIZE_INC, and membuffer::size_inc.

int membuffer_insert ( membuffer m,
const void *  buf,
size_t  buf_len,
size_t  index 
)

Allocates memory for the new data to be inserted. Does memory management by moving the data from the existing memory to the newly allocated memory and then appending the new data.

Returns:
0 if successful, error code if error.
Parameters:
[in,out]mBuffer whose memory size is to be increased and appended.
[in]bufsource buffer whose contents will be copied.
[in]buf_lensize of the source buffer.
[in]indexindex to determine the bounds while movinf the data.

References membuffer::buf, and membuffer::length.

int membuffer_set_size ( membuffer m,
size_t  new_length 
)

Increases or decreases buffer cap so that at least 'new_length' bytes can be stored.

Returns:
  • UPNP_E_SUCCESS - On Success
  • UPNP_E_OUTOF_MEMORY - On failure to allocate memory.
Parameters:
[in,out]mbuffer whose size is to be modified.
[in]new_lengthnew size to which the buffer will be modified.

References membuffer::buf, membuffer::capacity, membuffer::length, membuffer::size_inc, and UPNP_E_OUTOF_MEMORY.

int memptr_cmp ( memptr m,
const char *  s 
)

Compares characters of strings passed for number of bytes. If equal for the number of bytes, the length of the bytes determines which buffer is shorter.

Returns:
  • < 0 string1 substring less than string2 substring
  • == 0 string1 substring identical to string2 substring
  • > 0 string1 substring greater than string2 substring
Parameters:
[in]mInput memory object.
[in]sConstatnt string for the memory object to be compared with.

References memptr::buf, and memptr::length.

int memptr_cmp_nocase ( memptr m,
const char *  s 
)

Compares characters of 2 strings irrespective of the case for a specific count of bytes.

If the character comparison is the same the length of the 2 srings determines the shorter of the 2 strings.

Returns:
  • < 0 string1 substring less than string2 substring
  • == 0 string1 substring identical to string2 substring
  • > 0 string1 substring greater than string2 substring
Parameters:
[in]mInput memory object.
[in]sConstatnt string for the memory object to be compared with.

References memptr::buf, and memptr::length.

char* str_alloc ( const char *  str,
size_t  str_len 
)

Allocate memory and copy information from the input string to the newly allocated memory.

Returns:
Pointer to the newly allocated memory. NULL if memory cannot be allocated.
Parameters:
[in]strInput string object.
[in]str_lenInput string length.