Back to index

lightning-sunbird  0.9+nobinonly
Functions
icalmemory.h File Reference
#include <sys/types.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

voidicalmemory_tmp_buffer (size_t size)
 Create a new temporary buffer on the ring.
char * icalmemory_tmp_copy (const char *str)
 Like strdup, but the buffer is on the ring.
void icalmemory_add_tmp_buffer (void *)
 Add an externally allocated buffer to the ring.
void icalmemory_free_ring (void)
 Free all memory used in the ring.
voidicalmemory_new_buffer (size_t size)
voidicalmemory_resize_buffer (void *buf, size_t size)
void icalmemory_free_buffer (void *buf)
void icalmemory_append_string (char **buf, char **pos, size_t *buf_size, const char *string)
 icalmemory_append_string will copy the string 'string' to the buffer 'buf' starting at position 'pos', reallocing 'buf' if it is too small.
void icalmemory_append_char (char **buf, char **pos, size_t *buf_size, char ch)
 icalmemory_append_char is similar, but is appends a character instead of a string
char * icalmemory_strdup (const char *s)
 A wrapper around strdup.

Function Documentation

Add an externally allocated buffer to the ring.

Definition at line 153 of file icalmemory.c.

{
    buffer_ring *br = get_buffer_ring();


    /* Wrap around the ring */
    if(++(br->pos) == BUFFER_RING_SIZE){
       br->pos = 0;
    }

    /* Free buffers as their slots are overwritten */
    if ( br->ring[br->pos] != 0){
       free( br->ring[br->pos]);
    }

    /* Assign the buffer to a slot */
    br->ring[br->pos] = buf; 
}

Here is the call graph for this function:

void icalmemory_append_char ( char **  buf,
char **  pos,
size_t *  buf_size,
char  ch 
)

icalmemory_append_char is similar, but is appends a character instead of a string

Definition at line 330 of file icalmemory.c.

{
    char *new_buf;
    char *new_pos;

    size_t data_length, final_length;

#ifndef ICAL_NO_INTERNAL_DEBUG
    icalerror_check_arg_rv( (buf!=0),"buf");
    icalerror_check_arg_rv( (*buf!=0),"*buf");
    icalerror_check_arg_rv( (pos!=0),"pos");
    icalerror_check_arg_rv( (*pos!=0),"*pos");
    icalerror_check_arg_rv( (buf_size!=0),"buf_size");
    icalerror_check_arg_rv( (*buf_size!=0),"*buf_size");
#endif

    data_length = (size_t)*pos - (size_t)*buf;

    final_length = data_length + 2; 

    if ( final_length > (size_t) *buf_size ) {

       
       *buf_size  = (*buf_size) * 2  + final_length +1;

       new_buf = realloc(*buf,*buf_size);

       new_pos = (void*)((size_t)new_buf + data_length);
       
       *pos = new_pos;
       *buf = new_buf;
    }

    **pos = ch;
    *pos += 1;
    **pos = 0;
}

Here is the call graph for this function:

void icalmemory_append_string ( char **  buf,
char **  pos,
size_t *  buf_size,
const char *  string 
)

icalmemory_append_string will copy the string 'string' to the buffer 'buf' starting at position 'pos', reallocing 'buf' if it is too small.

'buf_size' is the size of 'buf' and will be changed if 'buf' is reallocated. 'pos' will point to the last byte of the new string in 'buf', usually a '\0'

Definition at line 288 of file icalmemory.c.

{
    char *new_buf;
    char *new_pos;

    size_t data_length, final_length, string_length;

#ifndef ICAL_NO_INTERNAL_DEBUG
    icalerror_check_arg_rv( (buf!=0),"buf");
    icalerror_check_arg_rv( (*buf!=0),"*buf");
    icalerror_check_arg_rv( (pos!=0),"pos");
    icalerror_check_arg_rv( (*pos!=0),"*pos");
    icalerror_check_arg_rv( (buf_size!=0),"buf_size");
    icalerror_check_arg_rv( (*buf_size!=0),"*buf_size");
    icalerror_check_arg_rv( (string!=0),"string");
#endif 

    string_length = strlen(string);
    data_length = (size_t)*pos - (size_t)*buf;    
    final_length = data_length + string_length; 

    if ( final_length >= (size_t) *buf_size) {

       
       *buf_size  = (*buf_size) * 2  + final_length;

       new_buf = realloc(*buf,*buf_size);

       new_pos = (void*)((size_t)new_buf + data_length);
       
       *pos = new_pos;
       *buf = new_buf;
    }
    
    strcpy(*pos, string);

    *pos += string_length;
}

Here is the call graph for this function:

Definition at line 282 of file icalmemory.c.

{
    free(buf);
}

Free all memory used in the ring.

Definition at line 212 of file icalmemory.c.

Here is the call graph for this function:

void* icalmemory_new_buffer ( size_t  size)

Definition at line 256 of file icalmemory.c.

{
    void *b = malloc(size);

    if( b == 0){
       icalerror_set_errno(ICAL_NEWFAILED_ERROR);
       return 0;
    }

    memset(b,0,size); 

    return b;
}

Here is the call graph for this function:

void* icalmemory_resize_buffer ( void buf,
size_t  size 
)

Definition at line 270 of file icalmemory.c.

{
    void *b = realloc(buf, size);

    if( b == 0){
       icalerror_set_errno(ICAL_NEWFAILED_ERROR);
       return 0;
    }

   return b;
}

Here is the call graph for this function:

char* icalmemory_strdup ( const char *  s)

A wrapper around strdup.

Partly to trap calls to strdup, partly because in -ansi, gcc on Red Hat claims that strdup is undeclared

Definition at line 234 of file icalmemory.c.

{
    return strdup(s);
}
void* icalmemory_tmp_buffer ( size_t  size)

Create a new temporary buffer on the ring.

Libical owns these and will deallocate them.

Definition at line 179 of file icalmemory.c.

{
    char *buf;

    if (size < MIN_BUFFER_SIZE){
       size = MIN_BUFFER_SIZE;
    }
    
    buf = (void*)malloc(size);

    if( buf == 0){
       icalerror_set_errno(ICAL_NEWFAILED_ERROR);
       return 0;
    }

    memset(buf,0,size); 

    icalmemory_add_tmp_buffer(buf);

    return buf;
}

Here is the call graph for this function:

char* icalmemory_tmp_copy ( const char *  str)

Like strdup, but the buffer is on the ring.

Definition at line 224 of file icalmemory.c.

{
    char* b = icalmemory_tmp_buffer(strlen(str)+1);

    strcpy(b,str);

    return b;
}

Here is the call graph for this function: