Fix missing execve; add .* printf support for s

This commit is contained in:
K. Lange 2018-06-29 10:42:56 +09:00
parent bc104fe5d9
commit 03ab5b9f78
2 changed files with 11 additions and 5 deletions

View File

@ -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);

View File

@ -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++;