opnsense-src/contrib/libpcap/missing/win_asprintf.c
Joseph Mingrone 6f9cba8f8b
libpcap: Update to 1.10.3
Local changes:

- In contrib/libpcap/pcap/bpf.h, do not include pcap/dlt.h.  Our system
  net/dlt.h is pulled in from net/bpf.h.
- sys/net/dlt.h: Incorporate changes from libpcap 1.10.3.
- lib/libpcap/Makefile: Update for libpcap 1.10.3.

Changelog:	https://git.tcpdump.org/libpcap/blob/95691ebe7564afa3faa5c6ba0dbd17e351be455a:/CHANGES
Reviewed by:	emaste
Obtained from:	https://www.tcpdump.org/release/libpcap-1.10.3.tar.gz
Sponsored by:	The FreeBSD Foundation
2023-03-31 16:02:22 -03:00

51 lines
909 B
C

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include "portability.h"
int
pcap_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
pcap_asprintf(char **strp, const char *format, ...)
{
va_list args;
int ret;
va_start(args, format);
ret = pcap_vasprintf(strp, format, args);
va_end(args);
return (ret);
}