18dffb485Schristos /* Some commonly-used VEC types. 28dffb485Schristos 3*5ba1f45fSchristos Copyright (C) 2012-2024 Free Software Foundation, Inc. 48dffb485Schristos 58dffb485Schristos This file is part of GDB. 68dffb485Schristos 78dffb485Schristos This program is free software; you can redistribute it and/or modify 88dffb485Schristos it under the terms of the GNU General Public License as published by 98dffb485Schristos the Free Software Foundation; either version 3 of the License, or 108dffb485Schristos (at your option) any later version. 118dffb485Schristos 128dffb485Schristos This program is distributed in the hope that it will be useful, 138dffb485Schristos but WITHOUT ANY WARRANTY; without even the implied warranty of 148dffb485Schristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 158dffb485Schristos GNU General Public License for more details. 168dffb485Schristos 178dffb485Schristos You should have received a copy of the GNU General Public License 188dffb485Schristos along with this program. If not, see <http://www.gnu.org/licenses/>. */ 198dffb485Schristos 208dffb485Schristos #include "gdb_vecs.h" 218dffb485Schristos #include "host-defs.h" 228dffb485Schristos 238dffb485Schristos /* Worker function to split character delimiter separated string of fields 248dffb485Schristos STR into a char pointer vector. */ 258dffb485Schristos 268dffb485Schristos static void 278dffb485Schristos delim_string_to_char_ptr_vec_append 288dffb485Schristos (std::vector<gdb::unique_xmalloc_ptr<char>> *vecp, const char *str, 298dffb485Schristos char delimiter) 308dffb485Schristos { 318dffb485Schristos do 328dffb485Schristos { 338dffb485Schristos size_t this_len; 348dffb485Schristos const char *next_field; 358dffb485Schristos char *this_field; 368dffb485Schristos 378dffb485Schristos next_field = strchr (str, delimiter); 388dffb485Schristos if (next_field == NULL) 398dffb485Schristos this_len = strlen (str); 408dffb485Schristos else 418dffb485Schristos { 428dffb485Schristos this_len = next_field - str; 438dffb485Schristos next_field++; 448dffb485Schristos } 458dffb485Schristos 468dffb485Schristos this_field = (char *) xmalloc (this_len + 1); 478dffb485Schristos memcpy (this_field, str, this_len); 488dffb485Schristos this_field[this_len] = '\0'; 498dffb485Schristos vecp->emplace_back (this_field); 508dffb485Schristos 518dffb485Schristos str = next_field; 528dffb485Schristos } 538dffb485Schristos while (str != NULL); 548dffb485Schristos } 558dffb485Schristos 568dffb485Schristos /* See gdb_vecs.h. */ 578dffb485Schristos 588dffb485Schristos std::vector<gdb::unique_xmalloc_ptr<char>> 598dffb485Schristos delim_string_to_char_ptr_vec (const char *str, char delimiter) 608dffb485Schristos { 618dffb485Schristos std::vector<gdb::unique_xmalloc_ptr<char>> retval; 628dffb485Schristos 638dffb485Schristos delim_string_to_char_ptr_vec_append (&retval, str, delimiter); 648dffb485Schristos 658dffb485Schristos return retval; 668dffb485Schristos } 678dffb485Schristos 688dffb485Schristos /* See gdb_vecs.h. */ 698dffb485Schristos 708dffb485Schristos void 718dffb485Schristos dirnames_to_char_ptr_vec_append 728dffb485Schristos (std::vector<gdb::unique_xmalloc_ptr<char>> *vecp, const char *dirnames) 738dffb485Schristos { 748dffb485Schristos delim_string_to_char_ptr_vec_append (vecp, dirnames, DIRNAME_SEPARATOR); 758dffb485Schristos } 768dffb485Schristos 778dffb485Schristos /* See gdb_vecs.h. */ 788dffb485Schristos 798dffb485Schristos std::vector<gdb::unique_xmalloc_ptr<char>> 808dffb485Schristos dirnames_to_char_ptr_vec (const char *dirnames) 818dffb485Schristos { 828dffb485Schristos std::vector<gdb::unique_xmalloc_ptr<char>> retval; 838dffb485Schristos 848dffb485Schristos dirnames_to_char_ptr_vec_append (&retval, dirnames); 858dffb485Schristos 868dffb485Schristos return retval; 878dffb485Schristos } 88