aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2016-06-09 16:30:17 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2016-06-18 15:05:38 +0300
commitd326f16dd40013e8bea639ff95c2b249e7867e5e (patch)
treee4330b63b6aed86434fb49edd54bf4f3d452c9e4
parent8e069039aaa63fab272971920212864da67a0720 (diff)
Eliminate the use of *_s() functions on Windows
-rw-r--r--butl/timestamp.cxx23
-rw-r--r--tests/process/driver.cxx4
2 files changed, 23 insertions, 4 deletions
diff --git a/butl/timestamp.cxx b/butl/timestamp.cxx
index bf02829..4c226fe 100644
--- a/butl/timestamp.cxx
+++ b/butl/timestamp.cxx
@@ -71,13 +71,27 @@ using namespace details;
// original function is absent. However, MinGW GCC can sometimes provide them.
// And so to avoid name clashes we hide them in the details namespace.
//
+// Previously we have used gmtime_s() and localtime_s() for gmtime() and
+// localtime() implementations for Windows, but that required Security-Enhanced
+// version of CRT to be present, which is not always the case. In particular if
+// MinGW is configured with --disable-secure-api option then declarations of
+// *_s() functions are not available. So we use ::gmtime() and ::localtime()
+// for that purpose. Note that according to MSDN "gmtime and localtime all use
+// one common tm structure per thread for the conversion", which mean that they
+// are thread-safe.
+//
namespace details
{
static tm*
gmtime (const time_t* t, tm* r)
{
#ifdef _WIN32
- return gmtime_s (r, t) != 0 ? nullptr : r;
+ const tm* gt (::gmtime (t));
+ if (gt == nullptr)
+ return nullptr;
+
+ *r = *gt;
+ return r;
#else
return gmtime_r (t, r);
#endif
@@ -87,7 +101,12 @@ namespace details
localtime (const time_t* t, tm* r)
{
#ifdef _WIN32
- return localtime_s (r, t) != 0 ? nullptr : r;
+ const tm* lt (::localtime (t));
+ if (lt == nullptr)
+ return nullptr;
+
+ *r = *lt;
+ return r;
#else
return localtime_r (t, r);
#endif
diff --git a/tests/process/driver.cxx b/tests/process/driver.cxx
index efb4ca3..741340c 100644
--- a/tests/process/driver.cxx
+++ b/tests/process/driver.cxx
@@ -2,7 +2,7 @@
// copyright : Copyright (c) 2014-2016 Code Synthesis Ltd
// license : MIT; see accompanying LICENSE file
-#include <stdlib.h> // getenv(), setenv(), _putenv_s()
+#include <stdlib.h> // getenv(), setenv(), _putenv()
#include <ios>
#include <string>
@@ -306,7 +306,7 @@ try
#ifndef _WIN32
assert (setenv ("PATH", paths.c_str (), 1) == 0);
#else
- assert (_putenv_s ("PATH", paths.c_str ()) == 0);
+ assert (_putenv (("PATH=" + paths).c_str ()) == 0);
#endif
dir_path::current (fp.directory () / dir_path (".."));