wmii

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

util.c (585B)


      1 #include <ctype.h>
      2 #include <stdio.h>
      3 #include <string.h>
      4 
      5 static char*
      6 vsmprint(const char *fmt, va_list ap) {
      7 	va_list al;
      8 	char *buf = "";
      9 	int n;
     10 
     11 	va_copy(al, ap);
     12 	n = vsnprintf(buf, 0, fmt, al);
     13 	va_end(al);
     14 
     15 	buf = malloc(++n);
     16 	if(buf)
     17 		vsnprintf(buf, n, fmt, ap);
     18 	return buf;
     19 }
     20 
     21 static char*
     22 smprint(const char *fmt, ...) {
     23 	va_list ap;
     24 	char *ret;
     25 
     26 	va_start(ap, fmt);
     27 	ret = vsmprint(fmt, ap);
     28 	va_end(ap);
     29 	return ret;
     30 }
     31 
     32 static char*
     33 strdup(const char *s) {
     34 	char *ret;
     35 	int len;
     36 
     37 	len = strlen(s)+1;
     38 	ret = malloc(len);
     39 	if(ret)
     40 		memcpy(ret, s, len);
     41 	return ret;
     42 }
     43