1 /* Some commonly-used VEC types.
3 Copyright (C) 2012-2022 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/>. */
20 #include "common-defs.h"
22 #include "host-defs.h"
24 /* Worker function to split character delimiter separated string of fields
25 STR into a char pointer vector. */
28 delim_string_to_char_ptr_vec_append
29 (std::vector
<gdb::unique_xmalloc_ptr
<char>> *vecp
, const char *str
,
35 const char *next_field
;
38 next_field
= strchr (str
, delimiter
);
39 if (next_field
== NULL
)
40 this_len
= strlen (str
);
43 this_len
= next_field
- str
;
47 this_field
= (char *) xmalloc (this_len
+ 1);
48 memcpy (this_field
, str
, this_len
);
49 this_field
[this_len
] = '\0';
50 vecp
->emplace_back (this_field
);
59 std::vector
<gdb::unique_xmalloc_ptr
<char>>
60 delim_string_to_char_ptr_vec (const char *str
, char delimiter
)
62 std::vector
<gdb::unique_xmalloc_ptr
<char>> retval
;
64 delim_string_to_char_ptr_vec_append (&retval
, str
, delimiter
);
72 dirnames_to_char_ptr_vec_append
73 (std::vector
<gdb::unique_xmalloc_ptr
<char>> *vecp
, const char *dirnames
)
75 delim_string_to_char_ptr_vec_append (vecp
, dirnames
, DIRNAME_SEPARATOR
);
80 std::vector
<gdb::unique_xmalloc_ptr
<char>>
81 dirnames_to_char_ptr_vec (const char *dirnames
)
83 std::vector
<gdb::unique_xmalloc_ptr
<char>> retval
;
85 dirnames_to_char_ptr_vec_append (&retval
, dirnames
);