]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdbsupport/gdb_vecs.cc
Automatic date update in version.in
[thirdparty/binutils-gdb.git] / gdbsupport / gdb_vecs.cc
CommitLineData
48faced0
DE
1/* Some commonly-used VEC types.
2
1d506c26 3 Copyright (C) 2012-2024 Free Software Foundation, Inc.
48faced0
DE
4
5 This file is part of GDB.
6
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.
11
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.
16
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/>. */
19
48faced0
DE
20#include "gdb_vecs.h"
21#include "host-defs.h"
22
749234e5 23/* Worker function to split character delimiter separated string of fields
e80aaf61 24 STR into a char pointer vector. */
48faced0 25
749234e5 26static void
e80aaf61
SM
27delim_string_to_char_ptr_vec_append
28 (std::vector<gdb::unique_xmalloc_ptr<char>> *vecp, const char *str,
29 char delimiter)
48faced0
DE
30{
31 do
32 {
33 size_t this_len;
e6a959d6
PA
34 const char *next_field;
35 char *this_field;
48faced0 36
749234e5
DE
37 next_field = strchr (str, delimiter);
38 if (next_field == NULL)
39 this_len = strlen (str);
48faced0
DE
40 else
41 {
749234e5
DE
42 this_len = next_field - str;
43 next_field++;
48faced0
DE
44 }
45
224c3ddb 46 this_field = (char *) xmalloc (this_len + 1);
749234e5
DE
47 memcpy (this_field, str, this_len);
48 this_field[this_len] = '\0';
e80aaf61 49 vecp->emplace_back (this_field);
48faced0 50
749234e5 51 str = next_field;
48faced0 52 }
749234e5
DE
53 while (str != NULL);
54}
55
e80aaf61 56/* See gdb_vecs.h. */
749234e5 57
e80aaf61 58std::vector<gdb::unique_xmalloc_ptr<char>>
749234e5
DE
59delim_string_to_char_ptr_vec (const char *str, char delimiter)
60{
e80aaf61 61 std::vector<gdb::unique_xmalloc_ptr<char>> retval;
749234e5
DE
62
63 delim_string_to_char_ptr_vec_append (&retval, str, delimiter);
64
65 return retval;
66}
67
e80aaf61 68/* See gdb_vecs.h. */
749234e5
DE
69
70void
e80aaf61
SM
71dirnames_to_char_ptr_vec_append
72 (std::vector<gdb::unique_xmalloc_ptr<char>> *vecp, const char *dirnames)
749234e5
DE
73{
74 delim_string_to_char_ptr_vec_append (vecp, dirnames, DIRNAME_SEPARATOR);
48faced0
DE
75}
76
e80aaf61 77/* See gdb_vecs.h. */
48faced0 78
e80aaf61 79std::vector<gdb::unique_xmalloc_ptr<char>>
48faced0
DE
80dirnames_to_char_ptr_vec (const char *dirnames)
81{
e80aaf61 82 std::vector<gdb::unique_xmalloc_ptr<char>> retval;
48faced0
DE
83
84 dirnames_to_char_ptr_vec_append (&retval, dirnames);
85
86 return retval;
87}