icalmemory.h 2.8 KB

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