1 /* A static string buffer, with overflow protection. 2 */ 3 4 /* 5 6 This file is part of VIPS. 7 8 VIPS is free software; you can redistribute it and/or modify 9 it under the terms of the GNU Lesser General Public License as published by 10 the Free Software Foundation; either version 2 of the License, or 11 (at your option) any later version. 12 13 This program is distributed in the hope that it will be useful, 14 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 GNU Lesser General Public License for more details. 17 18 You should have received a copy of the GNU Lesser General Public License 19 along with this program; if not, write to the Free Software 20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 21 02110-1301 USA 22 23 */ 24 25 /* 26 27 These files are distributed with VIPS - http://www.vips.ecs.soton.ac.uk 28 29 */ 30 31 #ifndef VIPS_BUF_H 32 #define VIPS_BUF_H 33 34 #ifdef __cplusplus 35 extern "C" { 36 #endif /*__cplusplus*/ 37 38 #include <vips/vips.h> 39 40 /* A string in the process of being written to ... multiple calls to 41 * vips_buf_append add to it. On overflow append "..." and block further 42 * writes. 43 */ 44 45 typedef struct _VipsBuf { 46 /* All fields are private. 47 */ 48 /*< private >*/ 49 char *base; /* String base */ 50 int mx; /* Maximum length */ 51 int i; /* Current write point */ 52 gboolean full; /* String has filled, block writes */ 53 int lasti; /* For read-recent */ 54 gboolean dynamic; /* We own the string with malloc() */ 55 } VipsBuf; 56 57 #define VIPS_BUF_STATIC( TEXT ) \ 58 { &TEXT[0], sizeof( TEXT ), 0, FALSE, 0, FALSE } 59 60 /* Init and append to one of the above. 61 */ 62 void vips_buf_rewind( VipsBuf *buf ); 63 void vips_buf_destroy( VipsBuf *buf ); 64 void vips_buf_init( VipsBuf *buf ); 65 void vips_buf_set_static( VipsBuf *buf, char *base, int mx ); 66 void vips_buf_set_dynamic( VipsBuf *buf, int mx ); 67 void vips_buf_init_static( VipsBuf *buf, char *base, int mx ); 68 void vips_buf_init_dynamic( VipsBuf *buf, int mx ); 69 gboolean vips_buf_appendns( VipsBuf *buf, const char *str, int sz ); 70 gboolean vips_buf_appends( VipsBuf *buf, const char *str ); 71 gboolean vips_buf_appendf( VipsBuf *buf, const char *fmt, ... ) 72 __attribute__((format(printf, 2, 3))); 73 gboolean vips_buf_vappendf( VipsBuf *buf, const char *fmt, va_list ap ); 74 gboolean vips_buf_appendc( VipsBuf *buf, char ch ); 75 gboolean vips_buf_appendsc( VipsBuf *buf, gboolean quote, const char *str ); 76 gboolean vips_buf_appendgv( VipsBuf *buf, GValue *value ); 77 gboolean vips_buf_append_size( VipsBuf *buf, size_t n ); 78 gboolean vips_buf_removec( VipsBuf *buf, char ch ); 79 gboolean vips_buf_change( VipsBuf *buf, const char *o, const char *n ); 80 gboolean vips_buf_is_empty( VipsBuf *buf ); 81 gboolean vips_buf_is_full( VipsBuf *buf ); 82 const char *vips_buf_all( VipsBuf *buf ); 83 const char *vips_buf_firstline( VipsBuf *buf ); 84 gboolean vips_buf_appendg( VipsBuf *buf, double g ); 85 gboolean vips_buf_appendd( VipsBuf *buf, int d ); 86 int vips_buf_len( VipsBuf *buf ); 87 88 #endif /*VIPS_BUF_H*/ 89 90 #ifdef __cplusplus 91 } 92 #endif /*__cplusplus*/ 93