[PATCH 3/3] examples: Work around lack of mingw localtime_r()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



mingw lacks localtime_r(); we were getting it from gnulib. But since
commit acf522e8 stopped linking examples against gnulib, we are
getting a build failure. Keep the examples standalone, and work
around mingw by using the non-reentrant localtime() (safe since our
examples are single-threaded), and add a necessary exemption to our
syntax check.

Signed-off-by: Eric Blake <eblake@xxxxxxxxxx>
---
 cfg.mk                        | 2 +-
 examples/admin/client_info.c  | 6 +++++-
 examples/admin/list_clients.c | 6 +++++-
 3 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/cfg.mk b/cfg.mk
index d9a8a44dc4..a75bfef86e 100644
--- a/cfg.mk
+++ b/cfg.mk
@@ -1233,7 +1233,7 @@ exclude_file_name_regexp--sc_prohibit_newline_at_end_of_diagnostic = \
   ^src/rpc/gendispatch\.pl$$

 exclude_file_name_regexp--sc_prohibit_nonreentrant = \
-  ^((po|tests)/|docs/.*(py|js|html\.in)|run.in$$|tools/wireshark/util/genxdrstub\.pl$$)
+  ^((po|tests|examples/admin)/|docs/.*(py|js|html\.in)|run.in$$|tools/wireshark/util/genxdrstub\.pl$$)

 exclude_file_name_regexp--sc_prohibit_select = \
 	^cfg\.mk$$
diff --git a/examples/admin/client_info.c b/examples/admin/client_info.c
index 2c46ccf514..f3f62a656b 100644
--- a/examples/admin/client_info.c
+++ b/examples/admin/client_info.c
@@ -30,9 +30,13 @@ exampleGetTimeStr(time_t then)
 {
     char *ret = NULL;
     struct tm timeinfo;
+    struct tm *timeinfop;

-    if (!localtime_r(&then, &timeinfo))
+    /* localtime_r() is smarter, but since mingw lacks it and this
+     * example is single-threaded, we can get away with localtime */
+    if (!(timeinfop = localtime(&then)))
         return NULL;
+    timeinfo = *timeinfop;

     if (!(ret = calloc(64, sizeof(char))))
         return NULL;
diff --git a/examples/admin/list_clients.c b/examples/admin/list_clients.c
index 15205a7bd1..5cf8e4c2a6 100644
--- a/examples/admin/list_clients.c
+++ b/examples/admin/list_clients.c
@@ -28,9 +28,13 @@ exampleGetTimeStr(time_t then)
 {
     char *ret = NULL;
     struct tm timeinfo;
+    struct tm *timeinfop;

-    if (!localtime_r(&then, &timeinfo))
+    /* localtime_r() is smarter, but since mingw lacks it and this
+     * example is single-threaded, we can get away with localtime */
+    if (!(timeinfop = localtime(&then)))
         return NULL;
+    timeinfo = *timeinfop;

     if (!(ret = calloc(64, sizeof(char))))
         return NULL;
-- 
2.20.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux