1221828Sgrehan/* Obstack wrapper for GDB.
2221828Sgrehan
3221828Sgrehan   Copyright (C) 2013-2020 Free Software Foundation, Inc.
4221828Sgrehan
5221828Sgrehan   This file is part of GDB.
6221828Sgrehan
7221828Sgrehan   This program is free software; you can redistribute it and/or modify
8221828Sgrehan   it under the terms of the GNU General Public License as published by
9221828Sgrehan   the Free Software Foundation; either version 3 of the License, or
10221828Sgrehan   (at your option) any later version.
11221828Sgrehan
12221828Sgrehan   This program is distributed in the hope that it will be useful,
13221828Sgrehan   but WITHOUT ANY WARRANTY; without even the implied warranty of
14221828Sgrehan   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15221828Sgrehan   GNU General Public License for more details.
16221828Sgrehan
17221828Sgrehan   You should have received a copy of the GNU General Public License
18221828Sgrehan   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
19221828Sgrehan
20221828Sgrehan#include "defs.h"
21221828Sgrehan#include "gdb_obstack.h"
22221828Sgrehan
23221828Sgrehan/* Concatenate NULL terminated variable argument list of `const char *'
24221828Sgrehan   strings; return the new string.  Space is found in the OBSTACKP.
25221828Sgrehan   Argument list must be terminated by a sentinel expression `(char *)
26221828Sgrehan   NULL'.  */
27221828Sgrehan
28221828Sgrehanchar *
29221828Sgrehanobconcat (struct obstack *obstackp, ...)
30221828Sgrehan{
31221828Sgrehan  va_list ap;
32221828Sgrehan
33221828Sgrehan  va_start (ap, obstackp);
34221828Sgrehan  for (;;)
35221828Sgrehan    {
36221828Sgrehan      const char *s = va_arg (ap, const char *);
37244013Sgrehan
38221828Sgrehan      if (s == NULL)
39221828Sgrehan	break;
40221828Sgrehan
41221828Sgrehan      obstack_grow_str (obstackp, s);
42221828Sgrehan    }
43221828Sgrehan  va_end (ap);
44221828Sgrehan  obstack_1grow (obstackp, 0);
45221828Sgrehan
46221828Sgrehan  return (char *) obstack_finish (obstackp);
47221828Sgrehan}
48221828Sgrehan