From 03ab5b9f78c26a833de7c594db5186f94e6f003d Mon Sep 17 00:00:00 2001 From: "K. Lange" Date: Fri, 29 Jun 2018 10:42:56 +0900 Subject: [PATCH] Fix missing execve; add .* printf support for s --- base/usr/include/unistd.h | 1 + libc/stdio/printf.c | 15 ++++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/base/usr/include/unistd.h b/base/usr/include/unistd.h index 9b297ebe..586e7314 100644 --- a/base/usr/include/unistd.h +++ b/base/usr/include/unistd.h @@ -18,6 +18,7 @@ extern int execle(const char *path, const char *arg, ...); extern int execv(const char *path, char *const argv[]); extern int execvp(const char *file, char *const argv[]); extern int execvpe(const char *file, char *const argv[], char *const envp[]); +extern int execve(const char *name, char * const argv[], char * const envp[]); extern void _exit(int status); extern int setuid(uid_t uid); diff --git a/libc/stdio/printf.c b/libc/stdio/printf.c index d250958d..90fc35d0 100644 --- a/libc/stdio/printf.c +++ b/libc/stdio/printf.c @@ -100,7 +100,7 @@ size_t xvasprintf(char * buf, const char * fmt, va_list args) { int i = 0; char * s; char * b = buf; - int precision = 0; + int precision = -1; for (const char *f = fmt; *f; f++) { if (*f != '%') { *b++ = *f; @@ -131,10 +131,15 @@ size_t xvasprintf(char * buf, const char * fmt, va_list args) { if (*f == '.') { ++f; precision = 0; - while (*f >= '0' && *f <= '9') { - precision *= 10; - precision += *f - '0'; + if (*f == '*') { + precision = (int)va_arg(args, int); ++f; + } else { + while (*f >= '0' && *f <= '9') { + precision *= 10; + precision += *f - '0'; + ++f; + } } } if (*f == 'l') { @@ -162,7 +167,7 @@ size_t xvasprintf(char * buf, const char * fmt, va_list args) { if (s == NULL) { s = "(null)"; } - if (precision > 0) { + if (precision >= 0) { while (*s && precision > 0) { *b++ = *s++; count++;