summaryrefslogtreecommitdiffabout
path: root/libical/src/libical/icalperiod.c
Unidiff
Diffstat (limited to 'libical/src/libical/icalperiod.c') (more/less context) (ignore whitespace changes)
-rw-r--r--libical/src/libical/icalperiod.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/libical/src/libical/icalperiod.c b/libical/src/libical/icalperiod.c
index c74c157..0dfbe81 100644
--- a/libical/src/libical/icalperiod.c
+++ b/libical/src/libical/icalperiod.c
@@ -23,40 +23,34 @@
23 Code is Eric Busboom 23 Code is Eric Busboom
24 24
25 25
26 ======================================================================*/ 26 ======================================================================*/
27 27
28#ifdef HAVE_CONFIG_H 28#ifdef HAVE_CONFIG_H
29#include <config.h> 29#include <config.h>
30#endif 30#endif
31 31
32#include "icalperiod.h" 32#include "icalperiod.h"
33 33
34#include <assert.h> 34#include <assert.h>
35#include <string.h> 35#include <string.h>
36#include <stdlib.h> 36#include <stdlib.h>
37#include <stdio.h> 37#include <stdio.h>
38 38
39#ifdef ICAL_NO_LIBICAL
40#define icalerror_set_errno(x)
41#define icalerror_check_arg_rv(x,y)
42#define icalerror_check_arg_re(x,y,z)
43#else
44#include "icalerror.h" 39#include "icalerror.h"
45#include "icalmemory.h" 40#include "icalmemory.h"
46#endif
47 41
48 42
49 43
50 44
51struct icalperiodtype icalperiodtype_from_string (const char* str) 45struct icalperiodtype icalperiodtype_from_string (const char* str)
52{ 46{
53 47
54 struct icalperiodtype p, null_p; 48 struct icalperiodtype p, null_p;
55 char *s = icalmemory_strdup(str); 49 char *s = icalmemory_strdup(str);
56 char *start, *end = s; 50 char *start, *end = s;
57 icalerrorstate es; 51 icalerrorstate es;
58 52
59 /* Errors are normally generated in the following code, so save 53 /* Errors are normally generated in the following code, so save
60 the error state for resoration later */ 54 the error state for resoration later */
61 55
62 icalerrorenum e = icalerrno; 56 icalerrorenum e = icalerrno;
@@ -84,75 +78,81 @@ struct icalperiodtype icalperiodtype_from_string (const char* str)
84 icalerror_set_error_state(ICAL_MALFORMEDDATA_ERROR,ICAL_ERROR_NONFATAL); 78 icalerror_set_error_state(ICAL_MALFORMEDDATA_ERROR,ICAL_ERROR_NONFATAL);
85 79
86 p.end = icaltime_from_string(end); 80 p.end = icaltime_from_string(end);
87 81
88 icalerror_set_error_state(ICAL_MALFORMEDDATA_ERROR,es); 82 icalerror_set_error_state(ICAL_MALFORMEDDATA_ERROR,es);
89 83
90 84
91 if (icaltime_is_null_time(p.end)){ 85 if (icaltime_is_null_time(p.end)){
92 86
93 p.duration = icaldurationtype_from_string(end); 87 p.duration = icaldurationtype_from_string(end);
94 88
95 if(icaldurationtype_as_int(p.duration) == 0) goto error; 89 if(icaldurationtype_as_int(p.duration) == 0) goto error;
96 } 90 }
97 91
98 icalerrno = e; 92 icalerrno = e;
99 93
94 icalmemory_free_buffer(s);
95
100 return p; 96 return p;
101 97
102 error: 98 error:
103 icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR); 99 icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR);
100
101 if (s)
102 icalmemory_free_buffer (s);
104 return null_p; 103 return null_p;
105} 104}
106 105
107 106
108const char* icalperiodtype_as_ical_string(struct icalperiodtype p) 107const char* icalperiodtype_as_ical_string(struct icalperiodtype p)
109{ 108{
110 109
111 const char* start; 110 const char* start;
112 const char* end; 111 const char* end;
113 112
114 char *buf; 113 char *buf;
115 size_t buf_size = 40; 114 size_t buf_size = 40;
116 char* buf_ptr = 0; 115 char* buf_ptr = 0;
117 116
118 buf = (char*)icalmemory_new_buffer(buf_size); 117 buf = (char*)icalmemory_new_buffer(buf_size);
119 buf_ptr = buf; 118 buf_ptr = buf;
120 119
121 120
122 start = icaltime_as_ical_string(p.start); 121 start = icaltime_as_ical_string(p.start);
123 122
124 icalmemory_append_string(&buf, &buf_ptr, &buf_size, start); 123 icalmemory_append_string(&buf, &buf_ptr, &buf_size, start);
125 124
126 if(!icaltime_is_null_time(p.end)){ 125 if(!icaltime_is_null_time(p.end)){
127 end = icaltime_as_ical_string(p.end); 126 end = icaltime_as_ical_string(p.end);
128 } else { 127 } else {
129 end = icaldurationtype_as_ical_string(p.duration); 128 end = icaldurationtype_as_ical_string(p.duration);
130 } 129 }
131 130
132 icalmemory_append_char(&buf, &buf_ptr, &buf_size, '/'); 131 icalmemory_append_char(&buf, &buf_ptr, &buf_size, '/');
133 132
134 icalmemory_append_string(&buf, &buf_ptr, &buf_size, end); 133 icalmemory_append_string(&buf, &buf_ptr, &buf_size, end);
135 134
135 icalmemory_add_tmp_buffer(buf);
136 136
137 return buf; 137 return buf;
138} 138}
139 139
140 140
141 141
142struct icalperiodtype icalperiodtype_null_period() { 142struct icalperiodtype icalperiodtype_null_period(void) {
143 struct icalperiodtype p; 143 struct icalperiodtype p;
144 p.start = icaltime_null_time(); 144 p.start = icaltime_null_time();
145 p.end = icaltime_null_time(); 145 p.end = icaltime_null_time();
146 p.duration = icaldurationtype_null_duration(); 146 p.duration = icaldurationtype_null_duration();
147 147
148 return p; 148 return p;
149} 149}
150int icalperiodtype_is_null_period(struct icalperiodtype p){ 150int icalperiodtype_is_null_period(struct icalperiodtype p){
151 151
152 if(icaltime_is_null_time(p.start) && 152 if(icaltime_is_null_time(p.start) &&
153 icaltime_is_null_time(p.end) && 153 icaltime_is_null_time(p.end) &&
154 icaldurationtype_is_null_duration(p.duration)){ 154 icaldurationtype_is_null_duration(p.duration)){
155 return 1; 155 return 1;
156 } else { 156 } else {
157 return 0; 157 return 0;
158 } 158 }