comparison cutils.c @ 515:ad72189eec07 libavformat

* replacing calls to not-always-available gmtime_r with our own code. The new helper function actually differs in semantics from gmtime_r, so if that seems to be a problem I can actually move it to dv.c completely, since only DV muxer uses the code anyway.
author romansh
date Wed, 18 Aug 2004 08:15:07 +0000
parents 9f4f4ca9f7b5
children da1d5db0ce5c
comparison
equal deleted inserted replaced
514:828bdf418a7b 515:ad72189eec07
145 t += 3600 * tm->tm_hour + 60 * tm->tm_min + tm->tm_sec; 145 t += 3600 * tm->tm_hour + 60 * tm->tm_min + tm->tm_sec;
146 146
147 return t; 147 return t;
148 } 148 }
149 149
150 #define ISLEAP(y) (((y) % 4 == 0) && (((y) % 100) != 0 || ((y) % 400) == 0))
151 #define LEAPS_COUNT(y) ((y)/4 - (y)/100 + (y)/400)
152
153 /* this is our own gmtime_r. it differs from its POSIX counterpart in a
154 couple of places, though. */
155 struct tm *brktimegm(time_t secs, struct tm *tm)
156 {
157 int days, y, ny, m;
158 int md[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
159
160 days = secs / 86400;
161 secs %= 86400;
162 tm->tm_hour = secs / 3600;
163 tm->tm_min = (secs % 3600) / 60;
164 tm->tm_sec = secs % 60;
165
166 /* oh well, may be someone some day will invent a formula for this stuff */
167 y = 1970; /* start "guessing" */
168 while (days >= (ISLEAP(y)?366:365)) {
169 ny = (y + days/366);
170 days -= (ny - y) * 365 + LEAPS_COUNT(ny - 1) - LEAPS_COUNT(y - 1);
171 y = ny;
172 }
173 md[1] = ISLEAP(y)?29:28;
174 for (m=0; days >= md[m]; m++)
175 days -= md[m];
176
177 tm->tm_year = y; /* unlike gmtime_r we store complete year here */
178 tm->tm_mon = m+1; /* unlike gmtime_r tm_mon is from 1 to 12 */
179 tm->tm_mday = days+1;
180
181 return tm;
182 }
183
150 /* get a positive number between n_min and n_max, for a maximum length 184 /* get a positive number between n_min and n_max, for a maximum length
151 of len_max. Return -1 if error. */ 185 of len_max. Return -1 if error. */
152 static int date_get_num(const char **pp, 186 static int date_get_num(const char **pp,
153 int n_min, int n_max, int len_max) 187 int n_min, int n_max, int len_max)
154 { 188 {