Apply and read errors
This commit is contained in:
+6
-1
@@ -22,13 +22,18 @@ LispVal *make_lisp_string(const char *data, size_t length, bool take,
|
||||
LispVal *lisp_sprintf(const char *format, ...) {
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
LispVal *s = lisp_vsprintf(format, args);
|
||||
va_end(args);
|
||||
return s;
|
||||
}
|
||||
|
||||
LispVal *lisp_vsprintf(const char *format, va_list args) {
|
||||
va_list args2;
|
||||
va_copy(args2, args);
|
||||
int needed = vsnprintf(NULL, 0, format, args2);
|
||||
va_end(args2);
|
||||
char *buffer = lisp_malloc(needed + 1);
|
||||
int printed = vsnprintf(buffer, needed + 1, format, args);
|
||||
va_end(args);
|
||||
assert(printed == needed);
|
||||
return make_lisp_string(buffer, printed, true, false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user