Skip to content

Commit

Permalink
Refactor asprintf.c formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Neved4 committed Nov 18, 2024
1 parent 768a206 commit 8dbe46a
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions asprintf.c
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
#include <stdio.h>
#include <stdlib.h>

#include "asprintf.h"

int vasprintf(char **strp, const char *fmt, va_list ap) {
int size, res;

va_list cp;

va_copy(cp, ap);
size = vsnprintf(NULL, 0, fmt, cp);
va_end(cp);
if (size < 0)

if (size < 0) {
return -1;
}

*strp = malloc(size + 1);
if (*strp == NULL)
if (*strp == NULL) {
return -1;
}

res = vsnprintf(*strp, size + 1, fmt, ap);
if (res < 0) {
Expand All @@ -33,5 +35,6 @@ int asprintf(char **s, const char *fmt, ...) {
va_start(ap, fmt);
ret = vasprintf(s, fmt, ap);
va_end(ap);

return ret;
}

0 comments on commit 8dbe46a

Please sign in to comment.