1 /* Some commonly-used VEC types.
3 Copyright (C) 2012-2024 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/>. */
21 #include "host-defs.h"
23 /* Worker function to split character delimiter separated string of fields
24 STR into a char pointer vector. */
27 delim_string_to_char_ptr_vec_append
28 (std::vector
<gdb::unique_xmalloc_ptr
<char>> *vecp
, const char *str
,
34 const char *next_field
;
37 next_field
= strchr (str
, delimiter
);
38 if (next_field
== NULL
)
39 this_len
= strlen (str
);
42 this_len
= next_field
- str
;
46 this_field
= (char *) xmalloc (this_len
+ 1);
47 memcpy (this_field
, str
, this_len
);
48 this_field
[this_len
] = '\0';
49 vecp
->emplace_back (this_field
);
58 std::vector
<gdb::unique_xmalloc_ptr
<char>>
59 delim_string_to_char_ptr_vec (const char *str
, char delimiter
)
61 std::vector
<gdb::unique_xmalloc_ptr
<char>> retval
;
63 delim_string_to_char_ptr_vec_append (&retval
, str
, delimiter
);
71 dirnames_to_char_ptr_vec_append
72 (std::vector
<gdb::unique_xmalloc_ptr
<char>> *vecp
, const char *dirnames
)
74 delim_string_to_char_ptr_vec_append (vecp
, dirnames
, DIRNAME_SEPARATOR
);
79 std::vector
<gdb::unique_xmalloc_ptr
<char>>
80 dirnames_to_char_ptr_vec (const char *dirnames
)
82 std::vector
<gdb::unique_xmalloc_ptr
<char>> retval
;
84 dirnames_to_char_ptr_vec_append (&retval
, dirnames
);