[PATCH v30 03/13] windows: update os shim

Stephen Hemminger stephen at networkplumber.org
Sun Oct 27 18:24:33 CET 2024


Windows does not have localtime_r but it does have a similar
function that can be used instead.

Use rte_os_shim.h in lib/log instead of redefine of strdup.

Add fileno() and isatty() to the wrapper.

Signed-off-by: Stephen Hemminger <stephen at networkplumber.org>
Acked-by: Tyler Retzlaff <roretzla at linux.microsoft.com>
Acked-by: Morten Brørup <mb at smartsharesystems.com>
Acked-by: Bruce Richardson <bruce.richardson at intel.com>
Acked-by: Chengwen Feng <fengchengwen at huawei.com>
---
 lib/eal/windows/include/rte_os_shim.h | 12 ++++++++++++
 lib/log/log.c                         |  7 +++----
 2 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/lib/eal/windows/include/rte_os_shim.h b/lib/eal/windows/include/rte_os_shim.h
index eda8113662..0e74eb19c7 100644
--- a/lib/eal/windows/include/rte_os_shim.h
+++ b/lib/eal/windows/include/rte_os_shim.h
@@ -30,6 +30,8 @@
 #define write(fd, buf, n) _write(fd, buf, n)
 #define close(fd) _close(fd)
 #define unlink(path) _unlink(path)
+#define fileno(f) _fileno(f)
+#define isatty(fd) _isatty(fd)
 
 #define IPVERSION	4
 
@@ -110,4 +112,14 @@ rte_clock_gettime(clockid_t clock_id, struct timespec *tp)
 }
 #define clock_gettime(clock_id, tp) rte_clock_gettime(clock_id, tp)
 
+static inline struct tm *
+rte_localtime_r(const time_t *timep, struct tm *result)
+{
+	if (localtime_s(result, timep) == 0)
+		return result;
+	else
+		return NULL;
+}
+#define localtime_r(timep, result) rte_localtime_r(timep, result)
+
 #endif /* _RTE_OS_SHIM_ */
diff --git a/lib/log/log.c b/lib/log/log.c
index 255f757d94..7416c82b34 100644
--- a/lib/log/log.c
+++ b/lib/log/log.c
@@ -14,13 +14,12 @@
 
 #include <rte_log.h>
 #include <rte_per_lcore.h>
-
-#include "log_internal.h"
-
 #ifdef RTE_EXEC_ENV_WINDOWS
-#define strdup _strdup
+#include <rte_os_shim.h>
 #endif
 
+#include "log_internal.h"
+
 struct rte_log_dynamic_type {
 	const char *name;
 	uint32_t loglevel;
-- 
2.45.2



More information about the dev mailing list