1 /* str/catns.c - Append N C strings to a dynamic str
2  * Copyright (C) 2004,2005  Bruce Guenter <bruce@untroubled.org>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
17  */
18 #include <stdarg.h>
19 #include <string.h>
20 #include "str.h"
21 
22 /** Append N C strings */
str_catns(str * s,unsigned int count,...)23 int str_catns(str* s, unsigned int count, ...)
24 {
25   const char* ptr;
26   va_list ap;
27   va_start(ap, count);
28   while (count-- > 0) {
29     if ((ptr = va_arg(ap, const char*)) != 0)
30       if (!str_cats(s, ptr))
31 	return 0;
32   }
33   va_end(ap);
34   return 1;
35 }
36 
37 #ifdef SELFTEST_MAIN
38 MAIN
39 {
40   static str s;
41   str_copyb(&s, "abc", 3);
42   debugstrfn(str_catns(&s, 7, "1", "2", 0, "3", "4", "5", "6"), &s);
43 }
44 #endif
45 #ifdef SELFTEST_EXP
46 result=1 len=9 size=16 s=abc123456
47 #endif
48