Browse Source

used a different implementation of smprintf() imported from dwmstatus

Ali H. Fardan 9 years ago
parent
commit
5829cee24e
1 changed files with 12 additions and 6 deletions
  1. 12 6
      slstatus.c

+ 12 - 6
slstatus.c

@@ -79,17 +79,23 @@ static char *
 smprintf(const char *fmt, ...)
 {
 	va_list ap;
-	char tmp[120];
-	char *ret = NULL;
+	char *ret;
+	int len;
 
 	va_start(ap, fmt);
-	vsnprintf(tmp, sizeof(tmp)-1, fmt, ap);
-	tmp[strlen(tmp)+1] = '\0';
+	len = vsnprintf(NULL, 0, fmt, ap);
+	va_end(ap);
 
-	if (asprintf(&ret, "%s", tmp) < 0)
-		return NULL;
+	ret = malloc(++len);
+	if (ret == NULL) {
+		perror("malloc");
+		exit(1);
+	}
 
+	va_start(ap, fmt);
+	vsnprintf(ret, len, fmt, ap);
 	va_end(ap);
+
 	return ret;
 }