GDB (API)
|
00001 /* Some commonly-used VEC types. 00002 00003 Copyright (C) 2012-2013 Free Software Foundation, Inc. 00004 00005 This file is part of GDB. 00006 00007 This program is free software; you can redistribute it and/or modify 00008 it under the terms of the GNU General Public License as published by 00009 the Free Software Foundation; either version 3 of the License, or 00010 (at your option) any later version. 00011 00012 This program is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 00019 00020 #ifdef GDBSERVER 00021 #include "server.h" 00022 #else 00023 #include "defs.h" 00024 #endif 00025 00026 #include "gdb_vecs.h" 00027 #include "host-defs.h" 00028 00029 /* Call xfree for each element of CHAR_PTR_VEC and final VEC_free for 00030 CHAR_PTR_VEC itself. 00031 00032 You must not modify CHAR_PTR_VEC after it got registered with this function 00033 by make_cleanup as the CHAR_PTR_VEC base address may change on its updates. 00034 Contrary to VEC_free this function does not (cannot) clear the pointer. */ 00035 00036 void 00037 free_char_ptr_vec (VEC (char_ptr) *char_ptr_vec) 00038 { 00039 int ix; 00040 char *name; 00041 00042 for (ix = 0; VEC_iterate (char_ptr, char_ptr_vec, ix, name); ++ix) 00043 xfree (name); 00044 VEC_free (char_ptr, char_ptr_vec); 00045 } 00046 00047 /* Extended version of dirnames_to_char_ptr_vec - additionally if *VECP is 00048 non-NULL the new list elements from DIRNAMES are appended to the existing 00049 *VECP list of entries. *VECP address will be updated by this call. */ 00050 00051 void 00052 dirnames_to_char_ptr_vec_append (VEC (char_ptr) **vecp, const char *dirnames) 00053 { 00054 do 00055 { 00056 size_t this_len; 00057 char *next_dir, *this_dir; 00058 00059 next_dir = strchr (dirnames, DIRNAME_SEPARATOR); 00060 if (next_dir == NULL) 00061 this_len = strlen (dirnames); 00062 else 00063 { 00064 this_len = next_dir - dirnames; 00065 next_dir++; 00066 } 00067 00068 this_dir = xmalloc (this_len + 1); 00069 memcpy (this_dir, dirnames, this_len); 00070 this_dir[this_len] = '\0'; 00071 VEC_safe_push (char_ptr, *vecp, this_dir); 00072 00073 dirnames = next_dir; 00074 } 00075 while (dirnames != NULL); 00076 } 00077 00078 /* Split DIRNAMES by DIRNAME_SEPARATOR delimiter and return a list of all the 00079 elements in their original order. For empty string ("") DIRNAMES return 00080 list of one empty string ("") element. 00081 00082 You may modify the returned strings. 00083 Read free_char_ptr_vec for its cleanup. */ 00084 00085 VEC (char_ptr) * 00086 dirnames_to_char_ptr_vec (const char *dirnames) 00087 { 00088 VEC (char_ptr) *retval = NULL; 00089 00090 dirnames_to_char_ptr_vec_append (&retval, dirnames); 00091 00092 return retval; 00093 }