gprofng: fix build with -mx32
[binutils-gdb/blckswan.git] / gdbsupport / gdb_vecs.cc
blob086a03e2ea44b0dbcd8abf67c4682182436141e3
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"
21 #include "gdb_vecs.h"
22 #include "host-defs.h"
24 /* Worker function to split character delimiter separated string of fields
25 STR into a char pointer vector. */
27 static void
28 delim_string_to_char_ptr_vec_append
29 (std::vector<gdb::unique_xmalloc_ptr<char>> *vecp, const char *str,
30 char delimiter)
34 size_t this_len;
35 const char *next_field;
36 char *this_field;
38 next_field = strchr (str, delimiter);
39 if (next_field == NULL)
40 this_len = strlen (str);
41 else
43 this_len = next_field - str;
44 next_field++;
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);
52 str = next_field;
54 while (str != NULL);
57 /* See gdb_vecs.h. */
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);
66 return retval;
69 /* See gdb_vecs.h. */
71 void
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);
78 /* See gdb_vecs.h. */
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);
87 return retval;