From: Olivier Matz Date: Fri, 24 Dec 2010 12:56:06 +0000 (+0100) Subject: cmdline (merge-intel): don't limit output len of cmdline_printf() X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=c1d9d291f2bc55b98d5f25ea7c0ee2f33f16b1b6;p=libcmdline.git cmdline (merge-intel): don't limit output len of cmdline_printf() It was using a big buffer in stack. Now use vdprintf() if _GNU_SOURCE is defined, or a malloc + free if not. Signed-off-by: Olivier Matz --- diff --git a/src/lib/cmdline.c b/src/lib/cmdline.c index bafaace..6d37885 100644 --- a/src/lib/cmdline.c +++ b/src/lib/cmdline.c @@ -149,14 +149,33 @@ void cmdline_printf(const struct cmdline *cl, const char *fmt, ...) { va_list ap; - char buffer[BUFSIZ]; +#ifdef _GNU_SOURCE + if (cl->s_out < 0) + return; va_start(ap, fmt); - vsnprintf(buffer, 512, fmt, ap); + vdprintf(cl->s_out, fmt, ap); va_end(ap); - if (cl->s_out >= 0) { - write(cl->s_out, buffer, strlen(buffer)); - } +#else + int ret; + char *buf; + + if (cl->s_out < 0) + return; + + buf = malloc(BUFSIZ); + if (buf == NULL) + return; + va_start(ap, fmt); + ret = vsnprintf(buf, BUFSIZ, fmt, ap); + va_end(ap); + if (ret < 0) + return; + if (ret >= BUFSIZ) + ret = BUFSIZ - 1; + write(cl->s_out, buf, ret); + free(buf); +#endif } int