Mercurial > libavformat.hg
annotate cutils.c @ 1485:9000f9cdac49 libavformat
fix checksum check (was my bug not libnut)
author | michael |
---|---|
date | Sun, 12 Nov 2006 12:16:59 +0000 |
parents | 0899bfe4105c |
children | 2b2cae486387 |
rev | line source |
---|---|
0 | 1 /* |
2 * Various simple utilities for ffmpeg system | |
3 * Copyright (c) 2000, 2001, 2002 Fabrice Bellard | |
4 * | |
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
896
diff
changeset
|
5 * This file is part of FFmpeg. |
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
896
diff
changeset
|
6 * |
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
896
diff
changeset
|
7 * FFmpeg is free software; you can redistribute it and/or |
0 | 8 * modify it under the terms of the GNU Lesser General Public |
9 * License as published by the Free Software Foundation; either | |
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
896
diff
changeset
|
10 * version 2.1 of the License, or (at your option) any later version. |
0 | 11 * |
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
896
diff
changeset
|
12 * FFmpeg is distributed in the hope that it will be useful, |
0 | 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 * Lesser General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU Lesser General Public | |
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
896
diff
changeset
|
18 * License along with FFmpeg; if not, write to the Free Software |
896
edbe5c3717f9
Update licensing information: The FSF changed postal address.
diego
parents:
887
diff
changeset
|
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
0 | 20 */ |
21 #include "avformat.h" | |
22 | |
23 #if !defined(CONFIG_NOCUTILS) | |
24 /** | |
25 * Return TRUE if val is a prefix of str. If it returns TRUE, ptr is | |
26 * set to the next character in 'str' after the prefix. | |
27 * | |
28 * @param str input string | |
29 * @param val prefix to test | |
30 * @param ptr updated after the prefix in str in there is a match | |
31 * @return TRUE if there is a match | |
32 */ | |
33 int strstart(const char *str, const char *val, const char **ptr) | |
34 { | |
35 const char *p, *q; | |
36 p = str; | |
37 q = val; | |
38 while (*q != '\0') { | |
39 if (*p != *q) | |
40 return 0; | |
41 p++; | |
42 q++; | |
43 } | |
44 if (ptr) | |
45 *ptr = p; | |
46 return 1; | |
47 } | |
48 | |
49 /** | |
50 * Return TRUE if val is a prefix of str (case independent). If it | |
51 * returns TRUE, ptr is set to the next character in 'str' after the | |
52 * prefix. | |
53 * | |
54 * @param str input string | |
55 * @param val prefix to test | |
56 * @param ptr updated after the prefix in str in there is a match | |
57 * @return TRUE if there is a match */ | |
58 int stristart(const char *str, const char *val, const char **ptr) | |
59 { | |
60 const char *p, *q; | |
61 p = str; | |
62 q = val; | |
63 while (*q != '\0') { | |
887 | 64 if (toupper(*(const unsigned char *)p) != toupper(*(const unsigned char *)q)) |
0 | 65 return 0; |
66 p++; | |
67 q++; | |
68 } | |
69 if (ptr) | |
70 *ptr = p; | |
71 return 1; | |
72 } | |
73 | |
74 /** | |
75 * Copy the string str to buf. If str length is bigger than buf_size - | |
76 * 1 then it is clamped to buf_size - 1. | |
77 * NOTE: this function does what strncpy should have done to be | |
78 * useful. NEVER use strncpy. | |
885 | 79 * |
0 | 80 * @param buf destination buffer |
81 * @param buf_size size of destination buffer | |
82 * @param str source string | |
83 */ | |
84 void pstrcpy(char *buf, int buf_size, const char *str) | |
85 { | |
86 int c; | |
87 char *q = buf; | |
88 | |
89 if (buf_size <= 0) | |
90 return; | |
91 | |
92 for(;;) { | |
93 c = *str++; | |
94 if (c == 0 || q >= buf + buf_size - 1) | |
95 break; | |
96 *q++ = c; | |
97 } | |
98 *q = '\0'; | |
99 } | |
100 | |
101 /* strcat and truncate. */ | |
102 char *pstrcat(char *buf, int buf_size, const char *s) | |
103 { | |
104 int len; | |
105 len = strlen(buf); | |
885 | 106 if (len < buf_size) |
0 | 107 pstrcpy(buf + len, buf_size - len, s); |
108 return buf; | |
109 } | |
110 | |
111 #endif | |
151 | 112 |
113 /* add one element to a dynamic array */ | |
114 void __dynarray_add(unsigned long **tab_ptr, int *nb_ptr, unsigned long elem) | |
115 { | |
116 int nb, nb_alloc; | |
117 unsigned long *tab; | |
118 | |
119 nb = *nb_ptr; | |
120 tab = *tab_ptr; | |
121 if ((nb & (nb - 1)) == 0) { | |
122 if (nb == 0) | |
123 nb_alloc = 1; | |
124 else | |
125 nb_alloc = nb * 2; | |
126 tab = av_realloc(tab, nb_alloc * sizeof(unsigned long)); | |
127 *tab_ptr = tab; | |
128 } | |
129 tab[nb++] = elem; | |
130 *nb_ptr = nb; | |
131 } | |
132 | |
230
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
133 time_t mktimegm(struct tm *tm) |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
134 { |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
135 time_t t; |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
136 |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
137 int y = tm->tm_year + 1900, m = tm->tm_mon + 1, d = tm->tm_mday; |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
138 |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
139 if (m < 3) { |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
140 m += 12; |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
141 y--; |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
142 } |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
143 |
885 | 144 t = 86400 * |
230
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
145 (d + (153 * m - 457) / 5 + 365 * y + y / 4 - y / 100 + y / 400 - 719469); |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
146 |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
147 t += 3600 * tm->tm_hour + 60 * tm->tm_min + tm->tm_sec; |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
148 |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
149 return t; |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
150 } |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
151 |
515
ad72189eec07
* replacing calls to not-always-available gmtime_r with our own code.
romansh
parents:
230
diff
changeset
|
152 #define ISLEAP(y) (((y) % 4 == 0) && (((y) % 100) != 0 || ((y) % 400) == 0)) |
ad72189eec07
* replacing calls to not-always-available gmtime_r with our own code.
romansh
parents:
230
diff
changeset
|
153 #define LEAPS_COUNT(y) ((y)/4 - (y)/100 + (y)/400) |
ad72189eec07
* replacing calls to not-always-available gmtime_r with our own code.
romansh
parents:
230
diff
changeset
|
154 |
885 | 155 /* this is our own gmtime_r. it differs from its POSIX counterpart in a |
515
ad72189eec07
* replacing calls to not-always-available gmtime_r with our own code.
romansh
parents:
230
diff
changeset
|
156 couple of places, though. */ |
ad72189eec07
* replacing calls to not-always-available gmtime_r with our own code.
romansh
parents:
230
diff
changeset
|
157 struct tm *brktimegm(time_t secs, struct tm *tm) |
885 | 158 { |
515
ad72189eec07
* replacing calls to not-always-available gmtime_r with our own code.
romansh
parents:
230
diff
changeset
|
159 int days, y, ny, m; |
ad72189eec07
* replacing calls to not-always-available gmtime_r with our own code.
romansh
parents:
230
diff
changeset
|
160 int md[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; |
ad72189eec07
* replacing calls to not-always-available gmtime_r with our own code.
romansh
parents:
230
diff
changeset
|
161 |
ad72189eec07
* replacing calls to not-always-available gmtime_r with our own code.
romansh
parents:
230
diff
changeset
|
162 days = secs / 86400; |
ad72189eec07
* replacing calls to not-always-available gmtime_r with our own code.
romansh
parents:
230
diff
changeset
|
163 secs %= 86400; |
ad72189eec07
* replacing calls to not-always-available gmtime_r with our own code.
romansh
parents:
230
diff
changeset
|
164 tm->tm_hour = secs / 3600; |
ad72189eec07
* replacing calls to not-always-available gmtime_r with our own code.
romansh
parents:
230
diff
changeset
|
165 tm->tm_min = (secs % 3600) / 60; |
ad72189eec07
* replacing calls to not-always-available gmtime_r with our own code.
romansh
parents:
230
diff
changeset
|
166 tm->tm_sec = secs % 60; |
ad72189eec07
* replacing calls to not-always-available gmtime_r with our own code.
romansh
parents:
230
diff
changeset
|
167 |
ad72189eec07
* replacing calls to not-always-available gmtime_r with our own code.
romansh
parents:
230
diff
changeset
|
168 /* oh well, may be someone some day will invent a formula for this stuff */ |
ad72189eec07
* replacing calls to not-always-available gmtime_r with our own code.
romansh
parents:
230
diff
changeset
|
169 y = 1970; /* start "guessing" */ |
ad72189eec07
* replacing calls to not-always-available gmtime_r with our own code.
romansh
parents:
230
diff
changeset
|
170 while (days >= (ISLEAP(y)?366:365)) { |
887 | 171 ny = (y + days/366); |
172 days -= (ny - y) * 365 + LEAPS_COUNT(ny - 1) - LEAPS_COUNT(y - 1); | |
173 y = ny; | |
515
ad72189eec07
* replacing calls to not-always-available gmtime_r with our own code.
romansh
parents:
230
diff
changeset
|
174 } |
ad72189eec07
* replacing calls to not-always-available gmtime_r with our own code.
romansh
parents:
230
diff
changeset
|
175 md[1] = ISLEAP(y)?29:28; |
ad72189eec07
* replacing calls to not-always-available gmtime_r with our own code.
romansh
parents:
230
diff
changeset
|
176 for (m=0; days >= md[m]; m++) |
887 | 177 days -= md[m]; |
515
ad72189eec07
* replacing calls to not-always-available gmtime_r with our own code.
romansh
parents:
230
diff
changeset
|
178 |
ad72189eec07
* replacing calls to not-always-available gmtime_r with our own code.
romansh
parents:
230
diff
changeset
|
179 tm->tm_year = y; /* unlike gmtime_r we store complete year here */ |
ad72189eec07
* replacing calls to not-always-available gmtime_r with our own code.
romansh
parents:
230
diff
changeset
|
180 tm->tm_mon = m+1; /* unlike gmtime_r tm_mon is from 1 to 12 */ |
ad72189eec07
* replacing calls to not-always-available gmtime_r with our own code.
romansh
parents:
230
diff
changeset
|
181 tm->tm_mday = days+1; |
ad72189eec07
* replacing calls to not-always-available gmtime_r with our own code.
romansh
parents:
230
diff
changeset
|
182 |
ad72189eec07
* replacing calls to not-always-available gmtime_r with our own code.
romansh
parents:
230
diff
changeset
|
183 return tm; |
ad72189eec07
* replacing calls to not-always-available gmtime_r with our own code.
romansh
parents:
230
diff
changeset
|
184 } |
ad72189eec07
* replacing calls to not-always-available gmtime_r with our own code.
romansh
parents:
230
diff
changeset
|
185 |
230
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
186 /* get a positive number between n_min and n_max, for a maximum length |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
187 of len_max. Return -1 if error. */ |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
188 static int date_get_num(const char **pp, |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
189 int n_min, int n_max, int len_max) |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
190 { |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
191 int i, val, c; |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
192 const char *p; |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
193 |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
194 p = *pp; |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
195 val = 0; |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
196 for(i = 0; i < len_max; i++) { |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
197 c = *p; |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
198 if (!isdigit(c)) |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
199 break; |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
200 val = (val * 10) + c - '0'; |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
201 p++; |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
202 } |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
203 /* no number read ? */ |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
204 if (p == *pp) |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
205 return -1; |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
206 if (val < n_min || val > n_max) |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
207 return -1; |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
208 *pp = p; |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
209 return val; |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
210 } |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
211 |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
212 /* small strptime for ffmpeg */ |
885 | 213 const char *small_strptime(const char *p, const char *fmt, |
230
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
214 struct tm *dt) |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
215 { |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
216 int c, val; |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
217 |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
218 for(;;) { |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
219 c = *fmt++; |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
220 if (c == '\0') { |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
221 return p; |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
222 } else if (c == '%') { |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
223 c = *fmt++; |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
224 switch(c) { |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
225 case 'H': |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
226 val = date_get_num(&p, 0, 23, 2); |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
227 if (val == -1) |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
228 return NULL; |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
229 dt->tm_hour = val; |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
230 break; |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
231 case 'M': |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
232 val = date_get_num(&p, 0, 59, 2); |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
233 if (val == -1) |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
234 return NULL; |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
235 dt->tm_min = val; |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
236 break; |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
237 case 'S': |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
238 val = date_get_num(&p, 0, 59, 2); |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
239 if (val == -1) |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
240 return NULL; |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
241 dt->tm_sec = val; |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
242 break; |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
243 case 'Y': |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
244 val = date_get_num(&p, 0, 9999, 4); |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
245 if (val == -1) |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
246 return NULL; |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
247 dt->tm_year = val - 1900; |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
248 break; |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
249 case 'm': |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
250 val = date_get_num(&p, 1, 12, 2); |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
251 if (val == -1) |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
252 return NULL; |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
253 dt->tm_mon = val - 1; |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
254 break; |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
255 case 'd': |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
256 val = date_get_num(&p, 1, 31, 2); |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
257 if (val == -1) |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
258 return NULL; |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
259 dt->tm_mday = val; |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
260 break; |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
261 case '%': |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
262 goto match; |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
263 default: |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
264 return NULL; |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
265 } |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
266 } else { |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
267 match: |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
268 if (c != *p) |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
269 return NULL; |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
270 p++; |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
271 } |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
272 } |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
273 return p; |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
274 } |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
275 |