From 1ec1562ecab38de7b55fdc2c4e52effcfc0371fb Mon Sep 17 00:00:00 2001 From: Cristy Date: Mon, 15 Apr 2019 11:46:52 -0400 Subject: [PATCH] https://github.com/ImageMagick/ImageMagick/pull/1496 --- ChangeLog | 2 ++ MagickCore/timer-private.h | 38 +++++++++++++++++++++++++++++++++++--- MagickCore/timer.c | 30 ++---------------------------- coders/cin.c | 8 ++------ coders/mat.c | 6 +----- coders/pdf.c | 6 +----- coders/png.c | 3 ++- 7 files changed, 45 insertions(+), 48 deletions(-) diff --git a/ChangeLog b/ChangeLog index 992cdb4ed..3243fff2d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6,6 +6,8 @@ https://imagemagick.org/discourse-server/viewforum.php?f=3). * Fixed a number of issues (reference https://github.com/ImageMagick/ImageMagick/issues). + * Honor SOURCE_DATE_EPOCH environment variable (reference + https://github.com/ImageMagick/ImageMagick/pull/1496/). 2019-04-07 7.0.8-39 Cristy * Release ImageMagick version 7.0.8-39, GIT revision 15489:6120f8bc1:20190406 diff --git a/MagickCore/timer-private.h b/MagickCore/timer-private.h index e8af5cd69..b823cfeff 100644 --- a/MagickCore/timer-private.h +++ b/MagickCore/timer-private.h @@ -1,12 +1,12 @@ /* Copyright 1999-2019 ImageMagick Studio LLC, a non-profit organization dedicated to making software imaging solutions freely available. - + You may not use this file except in compliance with the License. You may obtain a copy of the License at - + https://imagemagick.org/script/license.php - + Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -22,6 +22,38 @@ extern "C" { #endif +static inline void GetUTCTime(const time_t *timep,struct tm *result) +{ +#if defined(MAGICKCORE_HAVE_GMTIME_R) + (void) gmtime_r(timep,result); +#else + { + struct tm + *my_time; + + my_time=gmtime(timep); + if (my_time != (struct tm *) NULL) + (void) memcpy(result,my_time,sizeof(gm_time)); + } +#endif +} + +static inline void GetLocalTime(const time_t *timep,struct tm *result) +{ +#if defined(MAGICKCORE_HAVE_GMTIME_R) + (void) localtime_r(timep,result); +#else + { + struct tm + *my_time; + + my_time=localtime(timep); + if (my_time != (struct tm *) NULL) + (void) memcpy(result,my_time,sizeof(gm_time)); + } +#endif +} + extern MagickPrivate time_t GetMagickTime(void); diff --git a/MagickCore/timer.c b/MagickCore/timer.c index 7d77d2683..57f69b04e 100644 --- a/MagickCore/timer.c +++ b/MagickCore/timer.c @@ -259,36 +259,10 @@ MagickExport ssize_t FormatMagickTime(const time_t time,const size_t length, count; struct tm - gm_time, - local_time; + gm_time; assert(timestamp != (char *) NULL); - (void) memset(&local_time,0,sizeof(local_time)); - (void) memset(&gm_time,0,sizeof(gm_time)); -#if defined(MAGICKCORE_HAVE_LOCALTIME_R) - (void) localtime_r(&time,&local_time); -#else - { - struct tm - *my_time; - - my_time=localtime(&time); - if (my_time != (struct tm *) NULL) - (void) memcpy(&local_time,my_time,sizeof(local_time)); - } -#endif -#if defined(MAGICKCORE_HAVE_GMTIME_R) - (void) gmtime_r(&time,&gm_time); -#else - { - struct tm - *my_time; - - my_time=gmtime(&time); - if (my_time != (struct tm *) NULL) - (void) memcpy(&gm_time,my_time,sizeof(gm_time)); - } -#endif + GetUTCTime(&time,&gm_time); count=FormatLocaleString(timestamp,length, "%04d-%02d-%02dT%02d:%02d:%02d%+03d:00",gm_time.tm_year+1900, gm_time.tm_mon+1,gm_time.tm_mday,gm_time.tm_hour,gm_time.tm_min, diff --git a/coders/cin.c b/coders/cin.c index d79f1c3bf..202f89730 100644 --- a/coders/cin.c +++ b/coders/cin.c @@ -992,13 +992,9 @@ static MagickBooleanType WriteCINImage(const ImageInfo *image_info,Image *image, offset+=WriteBlob(image,sizeof(cin.file.filename),(unsigned char *) cin.file.filename); seconds=GetMagickTime(); -#if defined(MAGICKCORE_HAVE_LOCALTIME_R) - (void) localtime_r(&seconds,&local_time); -#else - (void) memcpy(&local_time,localtime(&seconds),sizeof(local_time)); -#endif + GetUTCTime(&seconds,&local_time); (void) memset(timestamp,0,sizeof(timestamp)); - (void) strftime(timestamp,MagickPathExtent,"%Y:%m:%d:%H:%M:%S%Z",&local_time); + (void) strftime(timestamp,MaxTextExtent,"%Y:%m:%d:%H:%M:%SUTC",&local_time); (void) memset(cin.file.create_date,0,sizeof(cin.file.create_date)); (void) CopyMagickString(cin.file.create_date,timestamp,11); offset+=WriteBlob(image,sizeof(cin.file.create_date),(unsigned char *) diff --git a/coders/mat.c b/coders/mat.c index 3eb4571e2..7c71fa643 100644 --- a/coders/mat.c +++ b/coders/mat.c @@ -1607,11 +1607,7 @@ static MagickBooleanType WriteMATImage(const ImageInfo *image_info,Image *image, image->depth=8; current_time=GetMagickTime(); -#if defined(MAGICKCORE_HAVE_LOCALTIME_R) - (void) localtime_r(¤t_time,&local_time); -#else - (void) memcpy(&local_time,localtime(¤t_time),sizeof(local_time)); -#endif + GetUTCTime(¤t_time,&local_time); (void) memset(MATLAB_HDR,' ',MagickMin(sizeof(MATLAB_HDR),124)); FormatLocaleString(MATLAB_HDR,sizeof(MATLAB_HDR), "MATLAB 5.0 MAT-file, Platform: %s, Created on: %s %s %2d %2d:%2d:%2d %d", diff --git a/coders/pdf.c b/coders/pdf.c index 26938afe2..5a5750f94 100644 --- a/coders/pdf.c +++ b/coders/pdf.c @@ -3009,11 +3009,7 @@ RestoreMSCWarning } (void) WriteBlobString(image,buffer); seconds=GetMagickTime(); -#if defined(MAGICKCORE_HAVE_LOCALTIME_R) - (void) localtime_r(&seconds,&local_time); -#else - (void) memcpy(&local_time,localtime(&seconds),sizeof(local_time)); -#endif + GetUTCTime(&seconds,&local_time); (void) FormatLocaleString(date,MagickPathExtent,"D:%04d%02d%02d%02d%02d%02d", local_time.tm_year+1900,local_time.tm_mon+1,local_time.tm_mday, local_time.tm_hour,local_time.tm_min,local_time.tm_sec); diff --git a/coders/png.c b/coders/png.c index c3e522184..84b95c234 100644 --- a/coders/png.c +++ b/coders/png.c @@ -87,6 +87,7 @@ #include "MagickCore/statistic.h" #include "MagickCore/string_.h" #include "MagickCore/string-private.h" +#include "MagickCore/timer-private.h" #include "MagickCore/transform.h" #include "MagickCore/utility.h" #if defined(MAGICKCORE_PNG_DELEGATE) @@ -8366,7 +8367,7 @@ static void write_tIME_chunk(Image *image,png_struct *ping,png_info *info, ptime.hour = hour; ptime.minute = minute; ptime.second = second; - + png_convert_from_time_t(&ptime,GetMagickTime()); LogMagickEvent(CoderEvent,GetMagickModule(), " png_set_tIME: y=%d, m=%d, d=%d, h=%d, m=%d, s=%d, ah=%d, am=%d", ptime.year, ptime.month, ptime.day, ptime.hour, ptime.minute, -- 2.40.0