summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarti Maria <marti.maria@littlecms.com>2021-06-05 16:11:53 +0200
committerGitHub <noreply@github.com>2021-06-05 16:11:53 +0200
commit7f83b09711204dd8166e72544c0178e70d107ad0 (patch)
tree445a3614ace12736d12fc1486b3b99c3d71faf39
parent08768f06683a843d79fa4f9a0ba3784bd0059876 (diff)
parent45a7fea828e1fbaca3c11d1110eec65890231fd8 (diff)
downloadlcms2-7f83b09711204dd8166e72544c0178e70d107ad0.tar.gz
Merge pull request #263 from kleisauke/use-threadsafe-gmtime
Ensure threadsafe alternative of gmtime is used. Looks great, thank you!
-rw-r--r--configure.ac3
-rw-r--r--src/cmsio0.c19
2 files changed, 21 insertions, 1 deletions
diff --git a/configure.ac b/configure.ac
index eec188b..5e49b35 100644
--- a/configure.ac
+++ b/configure.ac
@@ -80,6 +80,9 @@ AX_APPEND_COMPILE_FLAGS(["-fvisibility=hidden"])
# Motorola and SPARC CPUs), define `WORDS_BIGENDIAN'.
AC_C_BIGENDIAN
+# Check for functions that some compilers lack (or name differently)
+AC_CHECK_FUNCS([gmtime_r _gmtime64_s])
+
# Point to JPEG installed in DIR or disable JPEG with --without-jpeg.
AC_ARG_WITH(jpeg,
AS_HELP_STRING([--with-jpeg=DIR],[use jpeg installed in DIR]),
diff --git a/src/cmsio0.c b/src/cmsio0.c
index 19ccbeb..8dafe57 100644
--- a/src/cmsio0.c
+++ b/src/cmsio0.c
@@ -488,6 +488,10 @@ cmsIOHANDLER* CMSEXPORT cmsGetProfileIOhandler(cmsHPROFILE hProfile)
// Creates an empty structure holding all required parameters
cmsHPROFILE CMSEXPORT cmsCreateProfilePlaceholder(cmsContext ContextID)
{
+ struct tm *t;
+#if defined(HAVE_GMTIME_R) || defined(HAVE__GMTIME64_S)
+ struct tm tm;
+#endif
time_t now = time(NULL);
_cmsICCPROFILE* Icc = (_cmsICCPROFILE*) _cmsMallocZero(ContextID, sizeof(_cmsICCPROFILE));
if (Icc == NULL) return NULL;
@@ -500,14 +504,27 @@ cmsHPROFILE CMSEXPORT cmsCreateProfilePlaceholder(cmsContext ContextID)
// Set default version
Icc ->Version = 0x02100000;
+#ifdef HAVE_GMTIME_R
+ t = gmtime_r(&now, &tm);
+#elif defined(HAVE__GMTIME64_S)
+ t = _gmtime64_s(&tm, &now) == 0 ? &tm : NULL;
+#else
+ t = gmtime(&now);
+#endif
+ if (t == NULL) goto Error;
+
// Set creation date/time
- memmove(&Icc ->Created, gmtime(&now), sizeof(Icc ->Created));
+ memmove(&Icc ->Created, t, sizeof(Icc ->Created));
// Create a mutex if the user provided proper plugin. NULL otherwise
Icc ->UsrMutex = _cmsCreateMutex(ContextID);
// Return the handle
return (cmsHPROFILE) Icc;
+
+Error:
+ _cmsFree(ContextID, Icc);
+ return NULL;
}
cmsContext CMSEXPORT cmsGetProfileContextID(cmsHPROFILE hProfile)