1 /* Some commonly-used VEC types.
3 Copyright (C) 2012 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
27 #include "host-defs.h"
29 /* Call xfree for each element of CHAR_PTR_VEC and final VEC_free for
32 You must not modify CHAR_PTR_VEC after it got registered with this function
33 by make_cleanup as the CHAR_PTR_VEC base address may change on its updates.
34 Contrary to VEC_free this function does not (cannot) clear the pointer. */
37 free_char_ptr_vec (VEC (char_ptr
) *char_ptr_vec
)
42 for (ix
= 0; VEC_iterate (char_ptr
, char_ptr_vec
, ix
, name
); ++ix
)
44 VEC_free (char_ptr
, char_ptr_vec
);
47 /* Extended version of dirnames_to_char_ptr_vec - additionally if *VECP is
48 non-NULL the new list elements from DIRNAMES are appended to the existing
49 *VECP list of entries. *VECP address will be updated by this call. */
52 dirnames_to_char_ptr_vec_append (VEC (char_ptr
) **vecp
, const char *dirnames
)
57 char *next_dir
, *this_dir
;
59 next_dir
= strchr (dirnames
, DIRNAME_SEPARATOR
);
61 this_len
= strlen (dirnames
);
64 this_len
= next_dir
- dirnames
;
68 this_dir
= xmalloc (this_len
+ 1);
69 memcpy (this_dir
, dirnames
, this_len
);
70 this_dir
[this_len
] = '\0';
71 VEC_safe_push (char_ptr
, *vecp
, this_dir
);
75 while (dirnames
!= NULL
);
78 /* Split DIRNAMES by DIRNAME_SEPARATOR delimiter and return a list of all the
79 elements in their original order. For empty string ("") DIRNAMES return
80 list of one empty string ("") element.
82 You may modify the returned strings.
83 Read free_char_ptr_vec for its cleanup. */
86 dirnames_to_char_ptr_vec (const char *dirnames
)
88 VEC (char_ptr
) *retval
= NULL
;
90 dirnames_to_char_ptr_vec_append (&retval
, dirnames
);