Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

strptime() on Cygwin requires _XOPEN_SOURCE



When building on the latest Cygwin, I get the following warning:

datetime.c:62:12: warning: implicit declaration of function 'strptime'

and if I use the newly built zsh to run
zsh% zmodload zsh/datetime
zsh% strftime -r '%Y' 2016
then the zsh coredumps.

Cygwin uses not glib but newlib, and feature test macros have been
overhauled in newlib-2.4 (a few months ago I guess).
It now requires _XOPEN_SOURCE to use strptime(3) in time.h.

A possible fix is to define _XOPEN_SOURCE in datetime.c (patch1 below).
Another possibility is to define _GNU_SOURCE in zsh_system.h (patch2).

Both work OK on the latest Cygwin, but I can't test on older Cygwin.
Maybe patch1 is better since it would have minimum side effects?

patch1:
diff --git a/Src/Modules/datetime.c b/Src/Modules/datetime.c
index bb82c54..b924392 100644
--- a/Src/Modules/datetime.c
+++ b/Src/Modules/datetime.c
@@ -27,6 +27,9 @@
  *
  */
 
+#ifdef __CYGWIN__
+#define _XOPEN_SOURCE
+#endif
 #include "datetime.mdh"
 #include "datetime.pro"
 #include <time.h>


patch2:
diff --git a/Src/zsh_system.h b/Src/zsh_system.h
index 17c4c64..8e48a51 100644
--- a/Src/zsh_system.h
+++ b/Src/zsh_system.h
@@ -37,7 +37,7 @@
 #endif
 #endif
 
-#if defined(__linux) || defined(__GNU__) || defined(__GLIBC__) || defined(LIBC_MUSL)
+#if defined(__linux) || defined(__GNU__) || defined(__GLIBC__) || defined(LIBC_MUSL) || defined(__CYGWIN__)
 /*
  * Turn on numerous extensions.
  * This is in order to get the functions for manipulating /dev/ptmx.





Messages sorted by: Reverse Date, Date, Thread, Author