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