diff options
author | Ali H. Fardan <raiz@firemail.cc> | 2016-08-28 19:27:01 +0300 |
---|---|---|
committer | Ali H. Fardan <raiz@firemail.cc> | 2016-08-28 19:27:01 +0300 |
commit | 5829cee24ea0e40cbe402728d1ca2f0bfb630182 (patch) | |
tree | e77087814683ea21e0dd7601150628e5fcc3cdf1 /slstatus.c | |
parent | 94a62b864b56d8bad1fb68925dcee7c71015bc54 (diff) |
used a different implementation of smprintf() imported from dwmstatus
Diffstat (limited to 'slstatus.c')
-rw-r--r-- | slstatus.c | 18 |
1 files changed, 12 insertions, 6 deletions
@@ -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; } |