Further bugfixes in tools.c
[dwm-status.git] / tools.c
blob7c697cc096786bef8f1cc69453f39da738e706ee
1 /*-
2 * "THE BEER-WARE LICENSE" (Revision 42):
3 * <tobias.rehbein@web.de> wrote this file. As long as you retain this notice
4 * you can do whatever you want with this stuff. If we meet some day, and you
5 * think this stuff is worth it, you can buy me a beer in return.
6 * Tobias Rehbein
7 */
9 #define _POSIX_C_SOURCE 199506
11 #include <assert.h>
12 #include <stdarg.h>
13 #include <stdlib.h>
15 #include "tools.h"
17 int
18 tools_catitems(char *outbuf, size_t outbuflen,...)
20 va_list ap;
21 char *op, *ip, *ep;
22 size_t ccount;
24 assert(outbuf != NULL);
26 if (outbuflen == 0)
27 return (0);
29 op = outbuf;
30 ep = op + outbuflen - 1;
32 va_start(ap, outbuflen);
33 while ((ip = va_arg(ap, char *)) != NULL) {
34 while (*ip != '\0' && op < ep) {
35 *(op++) = *(ip++);
38 *op = '\0';
39 va_end(ap);
41 ccount = op - outbuf + 1;
42 assert(ccount <= outbuflen);
44 return (ccount);