MagickCore 7.1.1
Convert, Edit, Or Compose Bitmap Images
Loading...
Searching...
No Matches
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/script/license.php
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)
22extern "C" {
23#endif
24
25#include "MagickCore/locale_.h"
26
27static 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#else
32 {
33 struct tm
34 *my_time;
35
36 my_time=gmtime(timep);
37 if (my_time != (struct tm *) NULL)
38 (void) memcpy(result,my_time,sizeof(*my_time));
39 }
40#endif
41}
42
43static inline void GetMagickLocaltime(const time_t *timep,struct tm *result)
44{
45#if defined(MAGICKCORE_HAVE_GMTIME_R)
46 (void) localtime_r(timep,result);
47#else
48 {
49 struct tm
50 *my_time;
51
52 my_time=localtime(timep);
53 if (my_time != (struct tm *) NULL)
54 (void) memcpy(result,my_time,sizeof(*my_time));
55 }
56#endif
57}
58
59extern MagickExport time_t
60 GetMagickTime(void);
61
62static inline MagickBooleanType IsImageTTLExpired(const Image* image)
63{
64 if (image->ttl == (time_t) 0)
65 return(MagickFalse);
66 return(image->ttl < GetMagickTime() ? MagickTrue : MagickFalse);
67}
68
69static inline time_t ParseMagickTimeToLive(const char *time_to_live)
70{
71 char
72 *q;
73
74 time_t
75 ttl;
76
77 /*
78 Time to live, absolute or relative, e.g. 1440, 2 hours, 3 days, ...
79 */
80 ttl=(time_t) InterpretLocaleValue(time_to_live,&q);
81 if (q != time_to_live)
82 {
83 while (isspace((int) ((unsigned char) *q)) != 0)
84 q++;
85 if (LocaleNCompare(q,"second",6) == 0)
86 ttl*=1;
87 if (LocaleNCompare(q,"minute",6) == 0)
88 ttl*=60;
89 if (LocaleNCompare(q,"hour",4) == 0)
90 ttl*=3600;
91 if (LocaleNCompare(q,"day",3) == 0)
92 ttl*=86400;
93 if (LocaleNCompare(q,"week",4) == 0)
94 ttl*=604800;
95 if (LocaleNCompare(q,"month",5) == 0)
96 ttl*=2628000;
97 if (LocaleNCompare(q,"year",4) == 0)
98 ttl*=31536000;
99 }
100 return(ttl);
101}
102
103extern MagickPrivate void
104 SetMagickDatePrecision(const unsigned long);
105
106#if defined(__cplusplus) || defined(c_plusplus)
107}
108#endif
109
110#endif