buf.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /* A static string buffer, with overflow protection.
  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_BUF_H
  22. #define VIPS_BUF_H
  23. #ifdef __cplusplus
  24. extern "C" {
  25. #endif /*__cplusplus*/
  26. #include <vips/vips.h>
  27. /* A string in the process of being written to ... multiple calls to
  28. * vips_buf_append add to it. On overflow append "..." and block further
  29. * writes.
  30. */
  31. typedef struct _VipsBuf {
  32. /* All fields are private.
  33. */
  34. /*< private >*/
  35. char *base; /* String base */
  36. int mx; /* Maximum length */
  37. int i; /* Current write point */
  38. gboolean full; /* String has filled, block writes */
  39. int lasti; /* For read-recent */
  40. gboolean dynamic; /* We own the string with malloc() */
  41. } VipsBuf;
  42. #define VIPS_BUF_STATIC( TEXT ) \
  43. { &TEXT[0], sizeof( TEXT ), 0, FALSE, 0, FALSE }
  44. /* Init and append to one of the above.
  45. */
  46. void vips_buf_rewind( VipsBuf *buf );
  47. void vips_buf_destroy( VipsBuf *buf );
  48. void vips_buf_init( VipsBuf *buf );
  49. void vips_buf_set_static( VipsBuf *buf, char *base, int mx );
  50. void vips_buf_set_dynamic( VipsBuf *buf, int mx );
  51. void vips_buf_init_static( VipsBuf *buf, char *base, int mx );
  52. void vips_buf_init_dynamic( VipsBuf *buf, int mx );
  53. gboolean vips_buf_appendns( VipsBuf *buf, const char *str, int sz );
  54. gboolean vips_buf_appends( VipsBuf *buf, const char *str );
  55. gboolean vips_buf_appendf( VipsBuf *buf, const char *fmt, ... )
  56. __attribute__((format(printf, 2, 3)));
  57. gboolean vips_buf_vappendf( VipsBuf *buf, const char *fmt, va_list ap );
  58. gboolean vips_buf_appendc( VipsBuf *buf, char ch );
  59. gboolean vips_buf_appendsc( VipsBuf *buf, gboolean quote, const char *str );
  60. gboolean vips_buf_appendgv( VipsBuf *buf, GValue *value );
  61. gboolean vips_buf_append_size( VipsBuf *buf, size_t n );
  62. gboolean vips_buf_removec( VipsBuf *buf, char ch );
  63. gboolean vips_buf_change( VipsBuf *buf, const char *o, const char *n );
  64. gboolean vips_buf_is_empty( VipsBuf *buf );
  65. gboolean vips_buf_is_full( VipsBuf *buf );
  66. const char *vips_buf_all( VipsBuf *buf );
  67. const char *vips_buf_firstline( VipsBuf *buf );
  68. gboolean vips_buf_appendg( VipsBuf *buf, double g );
  69. gboolean vips_buf_appendd( VipsBuf *buf, int d );
  70. int vips_buf_len( VipsBuf *buf );
  71. #endif /*VIPS_BUF_H*/
  72. #ifdef __cplusplus
  73. }
  74. #endif /*__cplusplus*/