libc: add asprintf, fix vasprintf return value
This commit is contained in:
parent
ace0c3c2e0
commit
0621fa81b6
@ -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 fileno(FILE * stream);
|
||||||
extern int fflush(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 vasprintf(char ** buf, const char *fmt, va_list args);
|
||||||
extern int sprintf(char *buf, const char *fmt, ...);
|
extern int sprintf(char *buf, const char *fmt, ...);
|
||||||
extern int fprintf(FILE *stream, const char *fmt, ...);
|
extern int fprintf(FILE *stream, const char *fmt, ...);
|
||||||
|
@ -438,12 +438,19 @@ static int cb_asprintf(void * user, char c) {
|
|||||||
|
|
||||||
int vasprintf(char ** buf, const char * fmt, va_list args) {
|
int vasprintf(char ** buf, const char * fmt, va_list args) {
|
||||||
struct CBData data = {NULL,0,0};
|
struct CBData data = {NULL,0,0};
|
||||||
int out = xvasprintf(cb_asprintf, &data, fmt, args);
|
xvasprintf(cb_asprintf, &data, fmt, args);
|
||||||
cb_asprintf(&data, '\0');
|
cb_asprintf(&data, '\0');
|
||||||
*buf = data.str;
|
*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 */
|
/* Streams */
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user