Apache Portable Runtime
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
apr_time.h
Go to the documentation of this file.
1 /* Licensed to the Apache Software Foundation (ASF) under one or more
2  * contributor license agreements. See the NOTICE file distributed with
3  * this work for additional information regarding copyright ownership.
4  * The ASF licenses this file to You under the Apache License, Version 2.0
5  * (the "License"); you may not use this file except in compliance with
6  * the License. You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
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 
17 #ifndef APR_TIME_H
18 #define APR_TIME_H
19 
20 /**
21  * @file apr_time.h
22  * @brief APR Time Library
23  */
24 
25 #include "apr.h"
26 #include "apr_pools.h"
27 #include "apr_errno.h"
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif /* __cplusplus */
32 
33 /**
34  * @defgroup apr_time Time Routines
35  * @ingroup APR
36  * @{
37  */
38 
39 /** month names */
40 APR_DECLARE_DATA extern const char apr_month_snames[12][4];
41 /** day names */
42 APR_DECLARE_DATA extern const char apr_day_snames[7][4];
43 
44 
45 /** number of microseconds since 00:00:00 january 1, 1970 UTC */
46 typedef apr_int64_t apr_time_t;
47 
48 
49 /** mechanism to properly type apr_time_t literals */
50 #define APR_TIME_C(val) APR_INT64_C(val)
51 
52 /** mechanism to properly print apr_time_t values */
53 #define APR_TIME_T_FMT APR_INT64_T_FMT
54 
55 /** intervals for I/O timeouts, in microseconds */
56 typedef apr_int64_t apr_interval_time_t;
57 /** short interval for I/O timeouts, in microseconds */
58 typedef apr_int32_t apr_short_interval_time_t;
59 
60 /** number of microseconds per second */
61 #define APR_USEC_PER_SEC APR_TIME_C(1000000)
62 
63 /** @return apr_time_t as a second */
64 #define apr_time_sec(time) ((time) / APR_USEC_PER_SEC)
65 
66 /** @return apr_time_t as a usec */
67 #define apr_time_usec(time) ((time) % APR_USEC_PER_SEC)
68 
69 /** @return apr_time_t as a msec */
70 #define apr_time_msec(time) (((time) / 1000) % 1000)
71 
72 /** @return apr_time_t as a msec */
73 #define apr_time_as_msec(time) ((time) / 1000)
74 
75 /** @return milliseconds as an apr_time_t */
76 #define apr_time_from_msec(msec) ((apr_time_t)(msec) * 1000)
77 
78 /** @return seconds as an apr_time_t */
79 #define apr_time_from_sec(sec) ((apr_time_t)(sec) * APR_USEC_PER_SEC)
80 
81 /** @return a second and usec combination as an apr_time_t */
82 #define apr_time_make(sec, usec) ((apr_time_t)(sec) * APR_USEC_PER_SEC \
83  + (apr_time_t)(usec))
84 
85 /**
86  * @return the current time
87  */
88 APR_DECLARE(apr_time_t) apr_time_now(void);
89 
90 /** @see apr_time_exp_t */
92 
93 /**
94  * a structure similar to ANSI struct tm with the following differences:
95  * - tm_usec isn't an ANSI field
96  * - tm_gmtoff isn't an ANSI field (it's a bsdism)
97  */
98 struct apr_time_exp_t {
99  /** microseconds past tm_sec */
100  apr_int32_t tm_usec;
101  /** (0-61) seconds past tm_min */
102  apr_int32_t tm_sec;
103  /** (0-59) minutes past tm_hour */
104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104"> 104ame="l00104">