compat: MUSL implementation of strptime()
On Windows there's no strptime(). A similar functionality is available
from C++11's `std::get_time` in `<iomanip>`, but there are subtle
differences, including actual behavioral differences when parsing
invalid dates such as "January 41st" (which is invalid everywhere, and
could become "January 4th", eating one char less), or Feb 29th, 2018
(which does not exist).
Let's just import the MIT-licensed implementation from the MUSL C
library because it's reasonably self-contained and appears to work the
same as the glibc one.
diff --git a/CMakeModules/UseCompat.cmake b/CMakeModules/UseCompat.cmake
index d81f28c..ac330e5 100644
--- a/CMakeModules/UseCompat.cmake
+++ b/CMakeModules/UseCompat.cmake
@@ -53,6 +53,7 @@
check_symbol_exists(realpath "stdlib.h" HAVE_REALPATH)
check_symbol_exists(localtime_r "time.h" HAVE_LOCALTIME_R)
+ check_symbol_exists(strptime "time.h" HAVE_STRPTIME)
unset(CMAKE_REQUIRED_DEFINITIONS)
unset(CMAKE_REQUIRED_LIBRARIES)
@@ -64,4 +65,7 @@
if(WIN32)
include_directories(${PROJECT_SOURCE_DIR}/compat/posix-shims)
endif()
+ if(NOT HAVE_STRPTIME)
+ set(compatsrc ${compatsrc} ${PROJECT_SOURCE_DIR}/compat/strptime.c)
+ endif()
endmacro()