buffer.h File Reference

This file contains the definition of ldns_buffer, and functions to manipulate those. More...

Go to the source code of this file.

Data Structures

struct  ldns_struct_buffer
 implementation of buffers to ease operations More...

Defines

#define LDNS_MIN_BUFLEN   256
 number of initial bytes in buffer of which we cannot tell the size before hand

Typedefs

typedef struct ldns_struct_buffer ldns_buffer

Functions

ldns_bufferldns_buffer_new (size_t capacity)
 creates a new buffer with the specified capacity.
void ldns_buffer_new_frm_data (ldns_buffer *buffer, void *data, size_t size)
 creates a buffer with the specified data.
void ldns_buffer_clear (ldns_buffer *buffer)
 clears the buffer and make it ready for writing.
void ldns_buffer_flip (ldns_buffer *buffer)
 makes the buffer ready for reading the data that has been written to the buffer.
void ldns_buffer_rewind (ldns_buffer *buffer)
 make the buffer ready for re-reading the data.
bool ldns_buffer_set_capacity (ldns_buffer *buffer, size_t capacity)
 changes the buffer's capacity.
bool ldns_buffer_reserve (ldns_buffer *buffer, size_t amount)
 ensures BUFFER can contain at least AMOUNT more bytes.
int ldns_buffer_printf (ldns_buffer *buffer, const char *format,...)
 prints to the buffer, increasing the capacity if required using buffer_reserve().
void ldns_buffer_free (ldns_buffer *buffer)
 frees the buffer.
void * ldns_buffer_export (ldns_buffer *buffer)
 Makes the buffer fixed and returns a pointer to the data.


Detailed Description

This file contains the definition of ldns_buffer, and functions to manipulate those.

Definition in file buffer.h.


Define Documentation

#define LDNS_MIN_BUFLEN   256

number of initial bytes in buffer of which we cannot tell the size before hand

Definition at line 29 of file buffer.h.


Typedef Documentation

Definition at line 68 of file buffer.h.


Function Documentation

ldns_buffer* ldns_buffer_new ( size_t  capacity  ) 

creates a new buffer with the specified capacity.

Parameters:
[in] capacity the size (in bytes) to allocate for the buffer
Returns:
the created buffer

Definition at line 16 of file buffer.c.

References ldns_struct_buffer::_capacity, ldns_struct_buffer::_data, ldns_struct_buffer::_fixed, ldns_struct_buffer::_limit, ldns_struct_buffer::_position, ldns_struct_buffer::_status, LDNS_FREE, LDNS_MALLOC, LDNS_STATUS_OK, and LDNS_XMALLOC.

void ldns_buffer_new_frm_data ( ldns_buffer buffer,
void *  data,
size_t  size 
)

creates a buffer with the specified data.

The data IS copied and MEMORY allocations are done. The buffer is not fixed and can be resized using buffer_reserve().

Parameters:
[in] buffer pointer to the buffer to put the data in
[in] data the data to encapsulate in the buffer
[in] size the size of the data

Definition at line 41 of file buffer.c.

References ldns_struct_buffer::_capacity, ldns_struct_buffer::_data, ldns_struct_buffer::_fixed, ldns_struct_buffer::_limit, ldns_struct_buffer::_position, ldns_struct_buffer::_status, LDNS_STATUS_OK, and LDNS_XMALLOC.

void ldns_buffer_clear ( ldns_buffer buffer  ) 

clears the buffer and make it ready for writing.

The buffer's limit is set to the capacity and the position is set to 0.

Parameters:
[in] buffer the buffer to clear

Definition at line 56 of file buffer.c.

References ldns_struct_buffer::_capacity, ldns_struct_buffer::_limit, and ldns_struct_buffer::_position.

void ldns_buffer_flip ( ldns_buffer buffer  ) 

makes the buffer ready for reading the data that has been written to the buffer.

The buffer's limit is set to the current position and the position is set to 0.

Parameters:
[in] buffer the buffer to flip
Returns:
void

Definition at line 67 of file buffer.c.

References ldns_struct_buffer::_limit, and ldns_struct_buffer::_position.

void ldns_buffer_rewind ( ldns_buffer buffer  ) 

make the buffer ready for re-reading the data.

The buffer's position is reset to 0.

Parameters:
[in] buffer the buffer to rewind

Definition at line 76 of file buffer.c.

References ldns_struct_buffer::_position.

bool ldns_buffer_set_capacity ( ldns_buffer buffer,
size_t  capacity 
)

changes the buffer's capacity.

The data is reallocated so any pointers to the data may become invalid. The buffer's limit is set to the buffer's new capacity.

Parameters:
[in] buffer the buffer
[in] capacity the capacity to use
Returns:
whether this failed or succeeded

Definition at line 84 of file buffer.c.

References ldns_struct_buffer::_capacity, ldns_struct_buffer::_data, ldns_struct_buffer::_limit, ldns_struct_buffer::_position, ldns_struct_buffer::_status, LDNS_STATUS_MEM_ERR, and LDNS_XREALLOC.

bool ldns_buffer_reserve ( ldns_buffer buffer,
size_t  amount 
)

ensures BUFFER can contain at least AMOUNT more bytes.

The buffer's capacity is increased if necessary using buffer_set_capacity().

The buffer's limit is always set to the (possibly increased) capacity.

Parameters:
[in] buffer the buffer
[in] amount amount to use
Returns:
whether this failed or succeeded

Definition at line 103 of file buffer.c.

References ldns_struct_buffer::_capacity, ldns_struct_buffer::_fixed, ldns_struct_buffer::_limit, ldns_struct_buffer::_position, ldns_struct_buffer::_status, ldns_buffer_set_capacity(), and LDNS_STATUS_MEM_ERR.

int ldns_buffer_printf ( ldns_buffer buffer,
const char *  format,
  ... 
)

prints to the buffer, increasing the capacity if required using buffer_reserve().

The buffer's position is set to the terminating '\0'. Returns the number of characters written (not including the terminating '\0') or -1 on failure.

Definition at line 123 of file buffer.c.

References ldns_struct_buffer::_capacity, ldns_struct_buffer::_limit, ldns_struct_buffer::_position, ldns_struct_buffer::_status, ldns_buffer_reserve(), LDNS_STATUS_INTERNAL_ERR, and LDNS_STATUS_MEM_ERR.

void ldns_buffer_free ( ldns_buffer buffer  ) 

frees the buffer.

Parameters:
[in] *buffer the buffer to be freed
Returns:
void

Definition at line 161 of file buffer.c.

References ldns_struct_buffer::_data, and LDNS_FREE.

void* ldns_buffer_export ( ldns_buffer buffer  ) 

Makes the buffer fixed and returns a pointer to the data.

The caller is responsible for free'ing the result.

Parameters:
[in] *buffer the buffer to be exported
Returns:
void

Definition at line 173 of file buffer.c.

References ldns_struct_buffer::_data, and ldns_struct_buffer::_fixed.


Generated on Sat Sep 27 00:16:45 2008 for ldns by  doxygen 1.5.6