mirror of git://git.suckless.org/slstatus
simplify smprintf by using vasprintf
This commit is contained in:
parent
83e84bebb6
commit
046e273a7e
|
@ -15,7 +15,7 @@ INCS = -I. -I/usr/include -I${X11INC}
|
||||||
LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 -lasound
|
LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 -lasound
|
||||||
|
|
||||||
# flags
|
# flags
|
||||||
CPPFLAGS = -DVERSION=\"${VERSION}\"
|
CPPFLAGS = -DVERSION=\"${VERSION}\" -D_GNU_SOURCE
|
||||||
CFLAGS = -g -std=c99 -pedantic -Wall -O0 ${INCS} ${CPPFLAGS}
|
CFLAGS = -g -std=c99 -pedantic -Wall -O0 ${INCS} ${CPPFLAGS}
|
||||||
#CFLAGS = -std=c99 -pedantic -Wall -Os ${INCS} ${CPPFLAGS}
|
#CFLAGS = -std=c99 -pedantic -Wall -Os ${INCS} ${CPPFLAGS}
|
||||||
LDFLAGS = -g ${LIBS}
|
LDFLAGS = -g ${LIBS}
|
||||||
|
|
17
slstatus.c
17
slstatus.c
|
@ -40,21 +40,10 @@ char *
|
||||||
smprintf(char *fmt, ...)
|
smprintf(char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list fmtargs;
|
va_list fmtargs;
|
||||||
char *ret;
|
char *ret = NULL;
|
||||||
int len;
|
|
||||||
|
|
||||||
va_start(fmtargs, fmt);
|
va_start(fmtargs, fmt);
|
||||||
len = vsnprintf(NULL, 0, fmt, fmtargs);
|
if (vasprintf(&ret, fmt, fmtargs) < 0)
|
||||||
va_end(fmtargs);
|
return NULL;
|
||||||
|
|
||||||
ret = malloc(++len);
|
|
||||||
if (ret == NULL) {
|
|
||||||
fprintf(stderr, "Malloc error.");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
va_start(fmtargs, fmt);
|
|
||||||
vsnprintf(ret, len, fmt, fmtargs);
|
|
||||||
va_end(fmtargs);
|
va_end(fmtargs);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
Loading…
Reference in New Issue