* elf32-spu.c (build_stub): Fix malloc under-allocation.
[binutils.git] / include / dyn-string.h
blob2b147271e5f85b52ac2bc07f6696dbb08fb0e80b
1 /* An abstract string datatype.
2 Copyright (C) 1998, 1999, 2000, 2002, 2004, 2005, 2009
3 Free Software Foundation, Inc.
4 Contributed by Mark Mitchell (mark@markmitchell.com).
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
11 any later version.
13 GCC 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 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING. If not, write to
20 the Free Software Foundation, 51 Franklin Street - Fifth Floor,
21 Boston, MA 02110-1301, USA. */
23 #ifndef DYN_STRING_H
24 #define DYN_STRING_H
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
30 typedef struct dyn_string
32 int allocated; /* The amount of space allocated for the string. */
33 int length; /* The actual length of the string. */
34 char *s; /* The string itself, NUL-terminated. */
35 }* dyn_string_t;
37 /* The length STR, in bytes, not including the terminating NUL. */
38 #define dyn_string_length(STR) \
39 ((STR)->length)
41 /* The NTBS in which the contents of STR are stored. */
42 #define dyn_string_buf(STR) \
43 ((STR)->s)
45 /* Compare DS1 to DS2 with strcmp. */
46 #define dyn_string_compare(DS1, DS2) \
47 (strcmp ((DS1)->s, (DS2)->s))
50 extern int dyn_string_init (struct dyn_string *, int);
51 extern dyn_string_t dyn_string_new (int);
52 extern void dyn_string_delete (dyn_string_t);
53 extern char *dyn_string_release (dyn_string_t);
54 extern dyn_string_t dyn_string_resize (dyn_string_t, int);
55 extern void dyn_string_clear (dyn_string_t);
56 extern int dyn_string_copy (dyn_string_t, dyn_string_t);
57 extern int dyn_string_copy_cstr (dyn_string_t, const char *);
58 extern int dyn_string_prepend (dyn_string_t, dyn_string_t);
59 extern int dyn_string_prepend_cstr (dyn_string_t, const char *);
60 extern int dyn_string_insert (dyn_string_t, int, dyn_string_t);
61 extern int dyn_string_insert_cstr (dyn_string_t, int, const char *);
62 extern int dyn_string_insert_char (dyn_string_t, int, int);
63 extern int dyn_string_append (dyn_string_t, dyn_string_t);
64 extern int dyn_string_append_cstr (dyn_string_t, const char *);
65 extern int dyn_string_append_char (dyn_string_t, int);
66 extern int dyn_string_substring (dyn_string_t, dyn_string_t, int, int);
67 extern int dyn_string_eq (dyn_string_t, dyn_string_t);
69 #ifdef __cplusplus
71 #endif
73 #endif /* !defined (DYN_STRING_H) */