libc: add asprintf, fix vasprintf return value

This commit is contained in:
K. Lange 2023-04-21 15:55:17 +09:00
parent ace0c3c2e0
commit 0621fa81b6
2 changed files with 10 additions and 2 deletions

View File

@ -34,6 +34,7 @@ extern size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE * stream);
extern int fileno(FILE * stream);
extern int fflush(FILE * stream);
extern int asprintf(char ** ret, const char * fmt, ...);
extern int vasprintf(char ** buf, const char *fmt, va_list args);
extern int sprintf(char *buf, const char *fmt, ...);
extern int fprintf(FILE *stream, const char *fmt, ...);

View File

@ -438,12 +438,19 @@ static int cb_asprintf(void * user, char c) {
int vasprintf(char ** buf, const char * fmt, va_list args) {
struct CBData data = {NULL,0,0};
int out = xvasprintf(cb_asprintf, &data, fmt, args);
xvasprintf(cb_asprintf, &data, fmt, args);
cb_asprintf(&data, '\0');
*buf = data.str;
return out;
return 0;
}
int asprintf(char ** ret, const char * fmt, ...) {
va_list args;
va_start(args, fmt);
int out = vasprintf(ret,fmt,args);
va_end(args);
return out;
}
/* Streams */