summaryrefslogtreecommitdiffstats
path: root/lib/libpcap/libpcap/missing/win_asprintf.c
diff options
context:
space:
mode:
authorCameron Katri <me@cameronkatri.com>2021-05-10 14:55:20 -0400
committerCameron Katri <me@cameronkatri.com>2021-05-10 14:55:20 -0400
commitd88d199f23088ac1c3d7696374b0a1c1c1c18358 (patch)
tree977307e478f76c5de5ca141268cf8ce0309a09eb /lib/libpcap/libpcap/missing/win_asprintf.c
parent5fd83771641d15c418f747bd343ba6738d3875f7 (diff)
downloadapple_cmds-d88d199f23088ac1c3d7696374b0a1c1c1c18358.tar.gz
apple_cmds-d88d199f23088ac1c3d7696374b0a1c1c1c18358.tar.zst
apple_cmds-d88d199f23088ac1c3d7696374b0a1c1c1c18358.zip
libpcap-98.40.1
Diffstat (limited to 'lib/libpcap/libpcap/missing/win_asprintf.c')
-rw-r--r--lib/libpcap/libpcap/missing/win_asprintf.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/lib/libpcap/libpcap/missing/win_asprintf.c b/lib/libpcap/libpcap/missing/win_asprintf.c
new file mode 100644
index 0000000..cce6296
--- /dev/null
+++ b/lib/libpcap/libpcap/missing/win_asprintf.c
@@ -0,0 +1,51 @@
+#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 = pcap_vsnprintf(str, str_size, format, args);
+ if (ret == -1) {
+ free(str);
+ *strp = NULL;
+ return (-1);
+ }
+ *strp = str;
+ /*
+ * pcap_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);
+}