MagickCore  7.1.2-29
Convert, Edit, Or Compose Bitmap Images
timer-private.h
1 /*
2  Copyright @ 1999 ImageMagick Studio LLC, a non-profit organization
3  dedicated to making software imaging solutions freely available.
4 
5  You may not use this file except in compliance with the License. You may
6  obtain a copy of the License at
7 
8  https://imagemagick.org/license/
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15 
16  MagickCore private timer methods.
17 */
18 #ifndef MAGICKCORE_TIMER_PRIVATE_H
19 #define MAGICKCORE_TIMER_PRIVATE_H
20 
21 #if defined(__cplusplus) || defined(c_plusplus)
22 extern "C" {
23 #endif
24 
25 #include "MagickCore/locale_.h"
26 
27 static inline void GetMagickUTCTime(const time_t *timep,struct tm *result)
28 {
29 #if defined(MAGICKCORE_HAVE_GMTIME_R)
30  (void) gmtime_r(timep,result);
31 #elif defined(_MSC_VER)
32  (void) gmtime_s(result,timep);
33 #else
34  {
35  struct tm
36  *my_time;
37 
38  my_time=gmtime(timep);
39  if (my_time != (struct tm *) NULL)
40  (void) memcpy(result,my_time,sizeof(*my_time));
41  }
42 #endif
43 }
44 
45 static inline void GetMagickLocaltime(const time_t *timep,struct tm *result)
46 {
47 #if defined(MAGICKCORE_HAVE_GMTIME_R)
48  (void) localtime_r(timep,result);
49 #elif defined(_MSC_VER)
50  (void) localtime_s(result,timep);
51 #else
52  {
53  struct tm
54  *my_time;
55 
56  my_time=localtime(timep);
57  if (my_time != (struct tm *) NULL)
58  (void) memcpy(result,my_time,sizeof(*my_time));
59  }
60 #endif
61 }
62 
63 extern MagickExport MagickBooleanType
64  IsSourceDataEpochSet(void);
65 
66 extern MagickExport time_t
67  GetMagickTime(void);
68 
69 static inline MagickBooleanType IsImageTTLExpired(const Image* image)
70 {
71  if (image->ttl == (time_t) 0)
72  return(MagickFalse);
73  return(image->ttl < time((time_t *) NULL) ? MagickTrue : MagickFalse);
74 }
75 
76 static inline time_t ParseMagickTimeToLive(const char *time_to_live)
77 {
78  char
79  *q;
80 
81  time_t
82  ttl;
83 
84  /*
85  Time to live, absolute or relative, e.g. 1440, 2 hours, 3 days, ...
86  */
87  ttl=(time_t) InterpretLocaleValue(time_to_live,&q);
88  if (q != time_to_live)
89  {
90  while (isspace((int) ((unsigned char) *q)) != 0)
91  q++;
92  if (LocaleNCompare(q,"second",6) == 0)
93  ttl*=1;
94  if (LocaleNCompare(q,"minute",6) == 0)
95  ttl*=60;
96  if (LocaleNCompare(q,"hour",4) == 0)
97  ttl*=3600;
98  if (LocaleNCompare(q,"day",3) == 0)
99  ttl*=86400;
100  if (LocaleNCompare(q,"week",4) == 0)
101  ttl*=604800;
102  if (LocaleNCompare(q,"month",5) == 0)
103  ttl*=2628000;
104  if (LocaleNCompare(q,"year",4) == 0)
105  ttl*=31536000;
106  }
107  return(ttl);
108 }
109 
110 extern MagickPrivate void
111  SetMagickDatePrecision(const unsigned long);
112 
113 #if defined(__cplusplus) || defined(c_plusplus)
114 }
115 #endif
116 
117 #endif
Definition: image.h:132