dbuf.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /* A dynamic memory buffer that expands as you write.
  2. */
  3. /*
  4. This file is part of VIPS.
  5. VIPS is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU Lesser General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  16. 02110-1301 USA
  17. */
  18. /*
  19. These files are distributed with VIPS - http://www.vips.ecs.soton.ac.uk
  20. */
  21. #ifndef VIPS_DBUF_H
  22. #define VIPS_DBUF_H
  23. #ifdef __cplusplus
  24. extern "C" {
  25. #endif /*__cplusplus*/
  26. #include <vips/vips.h>
  27. /* A buffer in the process of being written to.
  28. */
  29. typedef struct _VipsDbuf {
  30. /* All fields are private.
  31. */
  32. /*< private >*/
  33. /* The current base, and the size of the allocated memory area.
  34. */
  35. unsigned char *data;
  36. size_t allocated_size;
  37. /* The size of the actual data that's been written. This will usually
  38. * be <= allocated_size, but always >= write_point.
  39. */
  40. size_t data_size;
  41. /* The write point.
  42. */
  43. size_t write_point;
  44. } VipsDbuf;
  45. void vips_dbuf_destroy( VipsDbuf *dbuf );
  46. void vips_dbuf_init( VipsDbuf *dbuf );
  47. gboolean vips_dbuf_allocate( VipsDbuf *dbuf, size_t size );
  48. size_t vips_dbuf_read( VipsDbuf *dbuf, unsigned char *data, size_t size );
  49. unsigned char *vips_dbuf_get_write( VipsDbuf *dbuf, size_t *size );
  50. gboolean vips_dbuf_write( VipsDbuf *dbuf,
  51. const unsigned char *data, size_t size );
  52. gboolean vips_dbuf_writef( VipsDbuf *dbuf, const char *fmt, ... )
  53. __attribute__((format(printf, 2, 3)));
  54. gboolean vips_dbuf_write_amp( VipsDbuf *dbuf, const char *str );
  55. void vips_dbuf_reset( VipsDbuf *dbuf );
  56. void vips_dbuf_destroy( VipsDbuf *dbuf );
  57. gboolean vips_dbuf_seek( VipsDbuf *dbuf, off_t offset, int whence );
  58. void vips_dbuf_truncate( VipsDbuf *dbuf );
  59. off_t vips_dbuf_tell( VipsDbuf *dbuf );
  60. unsigned char *vips_dbuf_string( VipsDbuf *dbuf, size_t *size );
  61. unsigned char *vips_dbuf_steal( VipsDbuf *dbuf, size_t *size );
  62. #endif /*VIPS_DBUF_H*/
  63. #ifdef __cplusplus
  64. }
  65. #endif /*__cplusplus*/