MagickCore 6.9.11-60
Convert, Edit, Or Compose Bitmap Images
timer-private.h
Go to the documentation of this file.
1/*
2 Copyright 1999-2021 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 "magick/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
59static inline time_t ParseMagickTimeToLive(const char *time_to_live)
60{
61 char
62 *q;
63
64 time_t
65 ttl;
66
67 /*
68 Time to live, absolute or relative, e.g. 1440, 2 hours, 3 days, ...
69 */
70 ttl=(time_t) InterpretLocaleValue(time_to_live,&q);
71 if (q != time_to_live)
72 {
73 while (isspace((int) ((unsigned char) *q)) != 0)
74 q++;
75 if (LocaleNCompare(q,"second",6) == 0)
76 ttl*=1;
77 if (LocaleNCompare(q,"minute",6) == 0)
78 ttl*=60;
79 if (LocaleNCompare(q,"hour",4) == 0)
80 ttl*=3600;
81 if (LocaleNCompare(q,"day",3) == 0)
82 ttl*=86400;
83 if (LocaleNCompare(q,"week",4) == 0)
84 ttl*=604800;
85 if (LocaleNCompare(q,"month",5) == 0)
86 ttl*=2628000;
87 if (LocaleNCompare(q,"year",4) == 0)
88 ttl*=31536000;
89 }
90 return(ttl);
91}
92
93extern MagickExport time_t
94 GetMagickTime(void);
95
96#if defined(__cplusplus) || defined(c_plusplus)
97}
98#endif
99
100#endif
MagickExport double InterpretLocaleValue(const char *magick_restrict string, char **magick_restrict sentinal)
Definition: locale.c:1000
MagickExport int LocaleNCompare(const char *p, const char *q, const size_t length)
Definition: locale.c:1570
#define MagickExport
Definition: method-attribute.h:80
MagickExport time_t GetMagickTime(void)
Definition: timer.c:327
static void GetMagickUTCtime(const time_t *timep, struct tm *result)
Definition: timer-private.h:27
static time_t ParseMagickTimeToLive(const char *time_to_live)
Definition: timer-private.h:59
static void GetMagickLocaltime(const time_t *timep, struct tm *result)
Definition: timer-private.h:43