summaryrefslogtreecommitdiff
path: root/tools/win32/compat.c
blob: b70d74015472d554d58db03ebcaaa51d6e7cd9ba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// Copyright 2007 - 2021, Alan Antonuk and the rabbitmq-c contributors.
// SPDX-License-Identifier: mit

#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>

#include "compat.h"

int asprintf(char **strp, const char *fmt, ...) {
  va_list ap;
  int len;

  va_start(ap, fmt);
  len = _vscprintf(fmt, ap);
  va_end(ap);

  *strp = malloc(len + 1);
  if (!*strp) {
    return -1;
  }

  va_start(ap, fmt);
  _vsnprintf(*strp, len + 1, fmt, ap);
  va_end(ap);

  (*strp)[len] = 0;
  return len;
}