1 /* mastring.h -- Implement auto-allocating string functions.
2  *
3  * (C) 2001 - 2002 by Matthias Andree <matthias.andree@gmx.de>
4  *
5  * This library is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU Lesser General Public License as
7  * published by the Free Software Foundation; either version 2 or 2.1 of
8  * the License. See the file COPYING.LGPL for details.
9  *
10  * This library is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18  * USA
19  */
20 #ifndef MASTRING_H
21 #define MASTRING_H
22 
23 #include "version.h"
24 
25 #include <sys/types.h>		/* for size_t */
26 #include <stdio.h>
27 
28 struct mastr {
29     char *PRIVATE__dat;
30     size_t PRIVATE__bufsize;
31     size_t PRIVATE__len;
32 };
33 
34 typedef struct mastr mastr;
35 
36 #define MASTR_OOM_ABORT 1
37 
38 /*@only@*/ mastr *mastr_new(size_t);
39 /*@only@*/ mastr *mastr_newstr(const char *);
40 int mastr_cpy(mastr *, const char *);
41 int mastr_cat(mastr *, /*@unique@*/ /*@observer@*/ const char *const);
42 int mastr_vcat(mastr *, ...);
43 int mastr_resizekeep(mastr *, size_t);
44 int mastr_resizekill(mastr *, size_t);
45 size_t mastr_size(mastr *);
46 #if LEAFNODE_VERSION > 1
47 ssize_t mastr_getln(mastr *, FILE *, ssize_t maxbytes);
48 #endif
49 #define mastr_autosize(m) do { (void)mastr_resizekeep(m, m->len); } while(0)
50 void mastr_delete(/*@only@*/ mastr *);
51 void mastr_clear(mastr *);
52 void mastr_triml(mastr * m);
53 void mastr_trimr(mastr * m);
54 void mastr_chop(mastr * m);
55 size_t mastr_len(mastr *);
56 #define mastr_trim(m) do { mastr_triml(m); mastr_trimr(m); } while(0)
57 #define mastr_str(m) ((const char *)(m->PRIVATE__dat))
58 #define mastr_modifyable_str(m) (m->PRIVATE__dat)
59 #endif
60