1 /* -*- Mode: C -*- */ 2 /*====================================================================== 3 FILE: icalmemory.h 4 CREATOR: eric 30 June 1999 5 6 7 $Id: icalmemory.h,v 1.6 2008-01-15 23:17:40 dothebart Exp $ 8 $Locker: $ 9 10 This program is free software; you can redistribute it and/or modify 11 it under the terms of either: 12 13 The LGPL as published by the Free Software Foundation, version 14 2.1, available at: http://www.fsf.org/copyleft/lesser.html 15 16 Or: 17 18 The Mozilla Public License Version 1.0. You may obtain a copy of 19 the License at http://www.mozilla.org/MPL/ 20 21 The Initial Developer of the Original Code is Eric Busboom 22 23 (C) COPYRIGHT 2000, Eric Busboom <eric@softwarestudio.org> 24 http://www.softwarestudio.org 25 ======================================================================*/ 26 27 #ifndef ICALMEMORY_H 28 #define ICALMEMORY_H 29 30 #ifndef WIN32 31 #include <sys/types.h> /* for size_t */ 32 #else 33 #include <stddef.h> 34 #endif 35 36 /* Tmp buffers are managed by ical. References can be returned to the 37 caller, although the caller will not own the memory. */ 38 39 void* icalmemory_tmp_buffer(size_t size); 40 char* icalmemory_tmp_copy(const char* str); 41 42 /** Add an externally allocated buffer to the ring. */ 43 void icalmemory_add_tmp_buffer(void*); 44 45 46 /** Free all memory used in the ring */ 47 void icalmemory_free_ring(void); 48 49 /* Non-tmp buffers must be freed. These are mostly wrappers around 50 * malloc, etc, but are used so the caller can change the memory 51 * allocators in a future version of the library */ 52 53 void* icalmemory_new_buffer(size_t size); 54 void* icalmemory_resize_buffer(void* buf, size_t size); 55 void icalmemory_free_buffer(void* buf); 56 57 /** 58 icalmemory_append_string will copy the string 'string' to the 59 buffer 'buf' starting at position 'pos', reallocing 'buf' if it is 60 too small. 'buf_size' is the size of 'buf' and will be changed if 61 'buf' is reallocated. 'pos' will point to the last byte of the new 62 string in 'buf', usually a '\0' */ 63 64 /* THESE ROUTINES CAN NOT BE USED ON TMP BUFFERS. Only use them on 65 normally allocated memory, or on buffers created from 66 icalmemory_new_buffer, never with buffers created by 67 icalmemory_tmp_buffer. If icalmemory_append_string has to resize a 68 buffer on the ring, the ring will loose track of it an you will 69 have memory problems. */ 70 71 void icalmemory_append_string(char** buf, char** pos, size_t* buf_size, 72 const char* string); 73 74 /** icalmemory_append_char is similar, but is appends a character instead of a string */ 75 void icalmemory_append_char(char** buf, char** pos, size_t* buf_size, 76 char ch); 77 78 /** A wrapper around strdup. Partly to trap calls to strdup, partly 79 because in -ansi, gcc on Red Hat claims that strdup is undeclared */ 80 char* icalmemory_strdup(const char *s); 81 82 #endif /* !ICALMEMORY_H */ 83 84 85 86