]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - contrib/ldns/ldns/duration.h
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / contrib / ldns / ldns / duration.h
1 /*
2  * $Id: duration.h 4341 2011-01-31 15:21:09Z matthijs $
3  *
4  * Copyright (c) 2009 NLNet Labs. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
19  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
21  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
23  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
25  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  *
27  */
28
29 /**
30  *
31  * This file is copied from the OpenDNSSEC source repository
32  * and only slightly adapted to make it fit.
33  */
34
35 /**
36  *
37  * Durations.
38  */
39
40 #ifndef LDNS_DURATION_H
41 #define LDNS_DURATION_H
42
43 #include <stdint.h>
44 #include <time.h>
45
46 /**
47  * Duration.
48  *
49  */
50 typedef struct ldns_duration_struct ldns_duration_type;
51 struct ldns_duration_struct
52 {
53     time_t years;
54     time_t months;
55     time_t weeks;
56     time_t days;
57     time_t hours;
58     time_t minutes;
59     time_t seconds;
60 };
61
62 /**
63  * Create a new 'instant' duration.
64  * \return ldns_duration_type* created duration
65  *
66  */
67 ldns_duration_type* ldns_duration_create(void);
68
69 /**
70  * Compare durations.
71  * \param[in] d1 one duration
72  * \param[in] d2 another duration
73  * \return int 0 if equal, -1 if d1 < d2, 1 if d2 < d1
74  *
75  */
76 int ldns_duration_compare(ldns_duration_type* d1, ldns_duration_type* d2);
77
78 /**
79  * Create a duration from string.
80  * \param[in] str string-format duration
81  * \return ldns_duration_type* created duration
82  *
83  */
84 ldns_duration_type* ldns_duration_create_from_string(const char* str);
85
86 /**
87  * Convert a duration to a string.
88  * \param[in] duration duration to be converted
89  * \return char* string-format duration
90  *
91  */
92 char* ldns_duration2string(ldns_duration_type* duration);
93
94 /**
95  * Convert a duration to a time.
96  * \param[in] duration duration to be converted
97  * \return time_t time-format duration
98  *
99  */
100 time_t ldns_duration2time(ldns_duration_type* duration);
101
102 /**
103  * Clean up duration.
104  * \param[in] duration duration to be cleaned up
105  *
106  */
107 void ldns_duration_cleanup(ldns_duration_type* duration);
108
109 #endif /* LDNS_DURATION_H */