| 4110 | } |
| 4111 | |
| 4112 | static int vasprintf(char **strp, const char *format, va_list ap) |
| 4113 | { |
| 4114 | *strp = NULL; |
| 4115 | va_list aq; |
| 4116 | va_copy(aq, ap); |
| 4117 | int result = vsnprintf(NULL, SIZE_MAX, format, ap); |
| 4118 | if (result >= 0) |
| 4119 | { |
| 4120 | char *buf = (char *)malloc(result+1); |
| 4121 | result = (buf == NULL? -1: result); |
| 4122 | if (result >= 0) |
| 4123 | result = vsnprintf(buf, result+1, format, aq); |
| 4124 | else |
| 4125 | free(buf); |
| 4126 | *strp = (result >= 0? buf: NULL); |
| 4127 | } |
| 4128 | va_end(aq); |
| 4129 | return result; |
| 4130 | } |
| 4131 | |
| 4132 | static int snprintf(char *str, size_t len, const char *format, ...) |
| 4133 | { |