1 /* fn.h: arbitrarily long filenames (or just strings).
3 Copyright 2001, 2005 Olaf Weber.
4 Copyright 1993, 2008 Karl Berry.
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with this library; if not, see <http://www.gnu.org/licenses/>. */
22 #include <kpathsea/c-proto.h>
23 #include <kpathsea/types.h>
25 /* Arbitrarily long filenames; it's inconvenient to use obstacks here,
26 because we want to maintain a null terminator. Also used for
27 dynamically growing strings even when the null byte isn't necessary,
28 e.g., in `variable.c', since I don't want to pass obstacks around
29 everywhere, and one can't free parts of an obstack arbitrarily. */
35 unsigned length; /* includes the terminating null byte, if any */
38 #define FN_STRING(fn) ((fn).str)
39 #define FN_ALLOCATED(fn) ((fn).allocated)
40 #define FN_LENGTH(fn) ((fn).length)
43 /* Create a new empty fn. */
44 extern KPSEDLL fn_type fn_init P1H(void);
46 /* Create a new fn from the first LEN characters from S and a null. */
47 extern KPSEDLL fn_type fn_copy0 P2H(const_string s, unsigned len);
49 /* Free what's been allocated. Can also just free the string if it's
50 been extracted out. Fatal error if nothing allocated in F. */
51 extern KPSEDLL void fn_free P1H(fn_type *f);
53 /* Append the character C to the fn F. Don't append trailing null. */
54 extern KPSEDLL void fn_1grow P2H(fn_type *f, char c);
56 /* Append LENGTH bytes from SOURCE to F. */
57 extern KPSEDLL void fn_grow P3H(fn_type *f, const_string source, unsigned length);
59 /* Concatenate the component S to the fn F. Assumes string currently in
60 F is null terminated. */
61 extern KPSEDLL void fn_str_grow P2H(fn_type *f, const_string s);
63 /* Add a null to F's string at position LOC, and update its length.
64 Fatal error if LOC is past the end of the string. */
65 extern KPSEDLL void fn_shrink_to P2H(fn_type *f, unsigned loc);
67 #endif /* not KPATHSEA_FN_H */