opnsense-src/contrib/libpcap/missing/win_asprintf.c
Joseph Mingrone 26f21a6494
libpcap: Update to 1.10.5
Changes:	https://git.tcpdump.org/libpcap/blob/bbcbc9174df3298a854daee2b3e666a4b6e5383a:/CHANGES
Reviewed by:	emaste
Obtained from:	https://www.tcpdump.org/release/libpcap-1.10.5.tar.gz
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit afdbf109c6a661a729938f68211054a0a50d38ac)
(cherry picked from commit ecb75be376a3e18d3e4836b6ee07015264784694)
(cherry picked from commit f0bcebe67ef6cf9f104535d6cd9f151c1b61dd6a)
(cherry picked from commit 34aa6f2c2db5cc9655f201a1ef01adbb9fb484d5)
2024-10-07 14:27:04 -03:00

51 lines
918 B
C

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include "portability.h"
int
pcapint_vasprintf(char **strp, const char *format, va_list args)
{
int len;
size_t str_size;
char *str;
int ret;
len = _vscprintf(format, args);
if (len == -1) {
*strp = NULL;
return (-1);
}
str_size = len + 1;
str = malloc(str_size);
if (str == NULL) {
*strp = NULL;
return (-1);
}
ret = vsnprintf(str, str_size, format, args);
if (ret == -1) {
free(str);
*strp = NULL;
return (-1);
}
*strp = str;
/*
* vsnprintf() shouldn't truncate the string, as we have
* allocated a buffer large enough to hold the string, so its
* return value should be the number of characters printed.
*/
return (ret);
}
int
pcapint_asprintf(char **strp, const char *format, ...)
{
va_list args;
int ret;
va_start(args, format);
ret = pcapint_vasprintf(strp, format, args);
va_end(args);
return (ret);
}