@@ -45,38 +45,6 @@ const char *rte_pci_get_sysfs_path(void)
return path;
}
-#ifdef RTE_EXEC_ENV_WINDOWS
-#define asprintf pci_asprintf
-
-static int
-__rte_format_printf(2, 3)
-pci_asprintf(char **buffer, const char *format, ...)
-{
- int size, ret;
- va_list arg;
-
- va_start(arg, format);
- size = vsnprintf(NULL, 0, format, arg);
- va_end(arg);
- if (size < 0)
- return -1;
- size++;
-
- *buffer = malloc(size);
- if (*buffer == NULL)
- return -1;
-
- va_start(arg, format);
- ret = vsnprintf(*buffer, size, format, arg);
- va_end(arg);
- if (ret != size - 1) {
- free(*buffer);
- return -1;
- }
- return ret;
-}
-#endif /* RTE_EXEC_ENV_WINDOWS */
-
static struct rte_devargs *
pci_devargs_lookup(const struct rte_pci_addr *pci_addr)
{
@@ -737,16 +737,6 @@ void __rte_thread_init(unsigned int lcore_id, rte_cpuset_t *cpuset);
*/
void __rte_thread_uninit(void);
-/**
- * asprintf(3) replacement for Windows.
- */
-#ifdef RTE_EXEC_ENV_WINDOWS
-__rte_format_printf(2, 3)
-int eal_asprintf(char **buffer, const char *format, ...);
-
-#define asprintf(buffer, format, ...) \
- eal_asprintf(buffer, format, ##__VA_ARGS__)
-#endif
#define EAL_LOG(level, ...) \
RTE_LOG_LINE(level, EAL, "" __VA_ARGS__)
@@ -503,34 +503,6 @@ rte_eal_init(int argc, char **argv)
return fctret;
}
-/* Don't use MinGW asprintf() to have identical code with all toolchains. */
-int
-eal_asprintf(char **buffer, const char *format, ...)
-{
- int size, ret;
- va_list arg;
-
- va_start(arg, format);
- size = vsnprintf(NULL, 0, format, arg);
- va_end(arg);
- if (size < 0)
- return -1;
- size++;
-
- *buffer = malloc(size);
- if (*buffer == NULL)
- return -1;
-
- va_start(arg, format);
- ret = vsnprintf(*buffer, size, format, arg);
- va_end(arg);
- if (ret != size - 1) {
- free(*buffer);
- return -1;
- }
- return ret;
-}
-
int
rte_vfio_container_dma_map(__rte_unused int container_fd,
__rte_unused uint64_t vaddr,
@@ -3,6 +3,7 @@
#ifndef _RTE_OS_SHIM_
#define _RTE_OS_SHIM_
+#include <stdio.h>
#include <time.h>
#include <rte_os.h>
@@ -120,4 +121,51 @@ rte_localtime_r(const time_t *timer, struct tm *buf)
}
#define localtime_r(timer, buf) rte_localtime_r(timer, buf)
+/* print to allocated string */
+__rte_format_printf(2, 0)
+static inline int
+rte_vasprintf(char **strp, const char *fmt, va_list ap)
+{
+ char *str;
+ int len, ret;
+
+ *strp = NULL;
+
+ /* determine size of buffer needed */
+ len = _vscprintf(fmt, ap);
+ if (len < 0)
+ return -1;
+
+ len += 1; /* for nul termination */
+ str = malloc(len);
+ if (str == NULL)
+ return -1;
+
+ ret = vsnprintf(str, len, fmt, ap);
+ if (ret < 0) {
+ free(str);
+ return -1;
+ } else {
+ *strp = str;
+ return ret;
+ }
+}
+#define vasprintf(strp, fmt, ap) rte_vasprintf(strp, fmt, ap)
+
+__rte_format_printf(2, 3)
+static inline int
+rte_asprintf(char **strp, const char *fmt, ...)
+{
+ int ret;
+
+ va_list ap;
+
+ va_start(ap, fmt);
+ ret = rte_vasprintf(strp, fmt, ap);
+ va_end(ap);
+
+ return ret;
+}
+
+#define asprintf(strp, fmt, ...) rte_asprintf(strp, fmt, __VA_ARGS__)
#endif /* _RTE_OS_SHIM_ */