xref: /netbsd-src/external/gpl3/gdb/dist/gdbsupport/gdb_obstack.cc (revision 5ba1f45f2a09259cc846f20c7c5501604d633c90)
14b169a6bSchristos /* Obstack wrapper for GDB.
24b169a6bSchristos 
3*5ba1f45fSchristos    Copyright (C) 2013-2024 Free Software Foundation, Inc.
44b169a6bSchristos 
54b169a6bSchristos    This file is part of GDB.
64b169a6bSchristos 
74b169a6bSchristos    This program is free software; you can redistribute it and/or modify
84b169a6bSchristos    it under the terms of the GNU General Public License as published by
94b169a6bSchristos    the Free Software Foundation; either version 3 of the License, or
104b169a6bSchristos    (at your option) any later version.
114b169a6bSchristos 
124b169a6bSchristos    This program is distributed in the hope that it will be useful,
134b169a6bSchristos    but WITHOUT ANY WARRANTY; without even the implied warranty of
144b169a6bSchristos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
154b169a6bSchristos    GNU General Public License for more details.
164b169a6bSchristos 
174b169a6bSchristos    You should have received a copy of the GNU General Public License
184b169a6bSchristos    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
194b169a6bSchristos 
204b169a6bSchristos #include "gdb_obstack.h"
214b169a6bSchristos 
224b169a6bSchristos /* Concatenate NULL terminated variable argument list of `const char *'
234b169a6bSchristos    strings; return the new string.  Space is found in the OBSTACKP.
244b169a6bSchristos    Argument list must be terminated by a sentinel expression `(char *)
254b169a6bSchristos    NULL'.  */
264b169a6bSchristos 
274b169a6bSchristos char *
284b169a6bSchristos obconcat (struct obstack *obstackp, ...)
294b169a6bSchristos {
304b169a6bSchristos   va_list ap;
314b169a6bSchristos 
324b169a6bSchristos   va_start (ap, obstackp);
334b169a6bSchristos   for (;;)
344b169a6bSchristos     {
354b169a6bSchristos       const char *s = va_arg (ap, const char *);
364b169a6bSchristos 
374b169a6bSchristos       if (s == NULL)
384b169a6bSchristos 	break;
394b169a6bSchristos 
404b169a6bSchristos       obstack_grow_str (obstackp, s);
414b169a6bSchristos     }
424b169a6bSchristos   va_end (ap);
434b169a6bSchristos   obstack_1grow (obstackp, 0);
444b169a6bSchristos 
454b169a6bSchristos   return (char *) obstack_finish (obstackp);
464b169a6bSchristos }
47