Fix building Loongarch BFD with a 32-bit compiler
[binutils-gdb.git] / gdbsupport / gdb_vecs.cc
blob71c730876d6e7dbbfe0c6d97ac20c3153fd2ec0f
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/>. */
20 #include "gdb_vecs.h"
21 #include "host-defs.h"
23 /* Worker function to split character delimiter separated string of fields
24 STR into a char pointer vector. */
26 static void
27 delim_string_to_char_ptr_vec_append
28 (std::vector<gdb::unique_xmalloc_ptr<char>> *vecp, const char *str,
29 char delimiter)
33 size_t this_len;
34 const char *next_field;
35 char *this_field;
37 next_field = strchr (str, delimiter);
38 if (next_field == NULL)
39 this_len = strlen (str);
40 else
42 this_len = next_field - str;
43 next_field++;
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);
51 str = next_field;
53 while (str != NULL);
56 /* See gdb_vecs.h. */
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);
65 return retval;
68 /* See gdb_vecs.h. */
70 void
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);
77 /* See gdb_vecs.h. */
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);
86 return retval;