wmii

git clone git://oldgit.suckless.org/wmii/
Log | Files | Refs | README | LICENSE

strlistdup.c (470B)


      1 /* Copyright ©2007-2010 Kris Maglione <maglione.k at Gmail>
      2  * See LICENSE file for license details.
      3  */
      4 #include <string.h>
      5 #include "../x11.h"
      6 
      7 char**
      8 strlistdup(char *list[]) {
      9 	char **p;
     10 	char *q;
     11 	int i, m, n;
     12 
     13 	n = 0;
     14 	m = 0;
     15 	for(p=list; *p; p++, n++)
     16 		m += strlen(*p) + 1;
     17 
     18 	p = malloc((n+1) * sizeof(*p) + m);
     19 	q = (char*)&p[n+1];
     20 
     21 	for(i=0; i < n; i++) {
     22 		p[i] = q;
     23 		m = strlen(list[i]) + 1;
     24 		memcpy(q, list[i], m);
     25 		q += m;
     26 	}
     27 	p[n] = nil;
     28 	return p;
     29 }