Deleted Added
full compact
strptime.c (54301) strptime.c (54316)
1/*
2 * Powerdog Industries kindly requests feedback from anyone modifying
3 * this function:
4 *
5 * Date: Thu, 05 Jun 1997 23:17:17 -0400
6 * From: Kevin Ruddy <kevin.ruddy@powerdog.com>
7 * To: James FitzGibbon <james@nexis.net>
8 * Subject: Re: Use of your strptime(3) code (fwd)

--- 39 unchanged lines hidden (view full) ---

48 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
49 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
50 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
51 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
52 */
53
54#ifdef LIBC_RCS
55static const char rcsid[] =
1/*
2 * Powerdog Industries kindly requests feedback from anyone modifying
3 * this function:
4 *
5 * Date: Thu, 05 Jun 1997 23:17:17 -0400
6 * From: Kevin Ruddy <kevin.ruddy@powerdog.com>
7 * To: James FitzGibbon <james@nexis.net>
8 * Subject: Re: Use of your strptime(3) code (fwd)

--- 39 unchanged lines hidden (view full) ---

48 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
49 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
50 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
51 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
52 */
53
54#ifdef LIBC_RCS
55static const char rcsid[] =
56 "$FreeBSD: head/lib/libc/stdtime/strptime.c 54301 1999-12-08 11:11:40Z sheldonh $";
56 "$FreeBSD: head/lib/libc/stdtime/strptime.c 54316 1999-12-08 15:49:10Z sheldonh $";
57#endif
58
59#ifndef lint
60#ifndef NOID
61static char copyright[] =
62"@(#) Copyright (c) 1994 Powerdog Industries. All rights reserved.";
63static char sccsid[] = "@(#)strptime.c 0.1 (Powerdog) 94/03/27";
64#endif /* !defined NOID */

--- 59 unchanged lines hidden (view full) ---

124 if (buf == 0)
125 return 0;
126 break;
127
128 case 'C':
129 if (!isdigit((unsigned char)*buf))
130 return 0;
131
57#endif
58
59#ifndef lint
60#ifndef NOID
61static char copyright[] =
62"@(#) Copyright (c) 1994 Powerdog Industries. All rights reserved.";
63static char sccsid[] = "@(#)strptime.c 0.1 (Powerdog) 94/03/27";
64#endif /* !defined NOID */

--- 59 unchanged lines hidden (view full) ---

124 if (buf == 0)
125 return 0;
126 break;
127
128 case 'C':
129 if (!isdigit((unsigned char)*buf))
130 return 0;
131
132 for (i = 0; *buf != 0 && isdigit((unsigned char)*buf); buf++) {
132 /* XXX This will break for 3-digit centuries. */
133 len = 2;
134 for (i = 0; len && *buf != 0 && isdigit((unsigned char)*buf); buf++) {
133 i *= 10;
134 i += *buf - '0';
135 i *= 10;
136 i += *buf - '0';
137 len--;
135 }
136 if (i < 19)
137 return 0;
138
139 tm->tm_year = i * 100 - 1900;
140 break;
141
142 case 'c':

--- 58 unchanged lines hidden (view full) ---

201 if (buf == 0)
202 return 0;
203 break;
204
205 case 'j':
206 if (!isdigit((unsigned char)*buf))
207 return 0;
208
138 }
139 if (i < 19)
140 return 0;
141
142 tm->tm_year = i * 100 - 1900;
143 break;
144
145 case 'c':

--- 58 unchanged lines hidden (view full) ---

204 if (buf == 0)
205 return 0;
206 break;
207
208 case 'j':
209 if (!isdigit((unsigned char)*buf))
210 return 0;
211
209 for (i = 0; *buf != 0 && isdigit((unsigned char)*buf); buf++) {
212 len = 3;
213 for (i = 0; len && *buf != 0 && isdigit((unsigned char)*buf); buf++) {
210 i *= 10;
211 i += *buf - '0';
214 i *= 10;
215 i += *buf - '0';
216 len--;
212 }
213 if (i < 1 || i > 366)
214 return 0;
215
216 tm->tm_yday = i - 1;
217 break;
218
219 case 'M':
220 case 'S':
221 if (*buf == 0 || isspace((unsigned char)*buf))
222 break;
223
224 if (!isdigit((unsigned char)*buf))
225 return 0;
226
217 }
218 if (i < 1 || i > 366)
219 return 0;
220
221 tm->tm_yday = i - 1;
222 break;
223
224 case 'M':
225 case 'S':
226 if (*buf == 0 || isspace((unsigned char)*buf))
227 break;
228
229 if (!isdigit((unsigned char)*buf))
230 return 0;
231
227 for (i = 0; *buf != 0 && isdigit((unsigned char)*buf); buf++) {
232 len = 2;
233 for (i = 0; len && *buf != 0 && isdigit((unsigned char)*buf); buf++) {
228 i *= 10;
229 i += *buf - '0';
234 i *= 10;
235 i += *buf - '0';
236 len--;
230 }
231
232 if (c == 'M') {
233 if (i > 59)
234 return 0;
235 tm->tm_min = i;
236 } else {
237 if (i > 60)

--- 5 unchanged lines hidden (view full) ---

243 while (*ptr != 0 && !isspace((unsigned char)*ptr))
244 ptr++;
245 break;
246
247 case 'H':
248 case 'I':
249 case 'k':
250 case 'l':
237 }
238
239 if (c == 'M') {
240 if (i > 59)
241 return 0;
242 tm->tm_min = i;
243 } else {
244 if (i > 60)

--- 5 unchanged lines hidden (view full) ---

250 while (*ptr != 0 && !isspace((unsigned char)*ptr))
251 ptr++;
252 break;
253
254 case 'H':
255 case 'I':
256 case 'k':
257 case 'l':
258 /*
259 * Of these, %l is the only specifier explicitly
260 * documented as not being zero-padded. However,
261 * there is no harm in allowing zero-padding.
262 *
263 * XXX The %l specifier may gobble one too many
264 * digits if used incorrectly.
265 */
251 if (!isdigit((unsigned char)*buf))
252 return 0;
253
266 if (!isdigit((unsigned char)*buf))
267 return 0;
268
254 for (i = 0; *buf != 0 && isdigit((unsigned char)*buf); buf++) {
269 len = 2;
270 for (i = 0; len && *buf != 0 && isdigit((unsigned char)*buf); buf++) {
255 i *= 10;
256 i += *buf - '0';
271 i *= 10;
272 i += *buf - '0';
273 len--;
257 }
258 if (c == 'H' || c == 'k') {
259 if (i > 23)
260 return 0;
261 } else if (i > 12)
262 return 0;
263
264 tm->tm_hour = i;
265
266 if (*buf != 0 && isspace((unsigned char)*buf))
267 while (*ptr != 0 && !isspace((unsigned char)*ptr))
268 ptr++;
269 break;
270
271 case 'p':
274 }
275 if (c == 'H' || c == 'k') {
276 if (i > 23)
277 return 0;
278 } else if (i > 12)
279 return 0;
280
281 tm->tm_hour = i;
282
283 if (*buf != 0 && isspace((unsigned char)*buf))
284 while (*ptr != 0 && !isspace((unsigned char)*ptr))
285 ptr++;
286 break;
287
288 case 'p':
289 /*
290 * XXX This is bogus if parsed before hour-related
291 * specifiers.
292 */
272 len = strlen(Locale->am);
273 if (strncasecmp(buf, Locale->am, len) == 0) {
274 if (tm->tm_hour > 12)
275 return 0;
276 if (tm->tm_hour == 12)
277 tm->tm_hour = 0;
278 buf += len;
279 break;

--- 41 unchanged lines hidden (view full) ---

321 * XXX This is bogus, as we can not assume any valid
322 * information present in the tm structure at this
323 * point to calculate a real value, so just check the
324 * range for now.
325 */
326 if (!isdigit((unsigned char)*buf))
327 return 0;
328
293 len = strlen(Locale->am);
294 if (strncasecmp(buf, Locale->am, len) == 0) {
295 if (tm->tm_hour > 12)
296 return 0;
297 if (tm->tm_hour == 12)
298 tm->tm_hour = 0;
299 buf += len;
300 break;

--- 41 unchanged lines hidden (view full) ---

342 * XXX This is bogus, as we can not assume any valid
343 * information present in the tm structure at this
344 * point to calculate a real value, so just check the
345 * range for now.
346 */
347 if (!isdigit((unsigned char)*buf))
348 return 0;
349
329 for (i = 0; *buf != 0 && isdigit((unsigned char)*buf); buf++) {
350 len = 2;
351 for (i = 0; len && *buf != 0 && isdigit((unsigned char)*buf); buf++) {
330 i *= 10;
331 i += *buf - '0';
352 i *= 10;
353 i += *buf - '0';
354 len--;
332 }
333 if (i > 53)
334 return 0;
335
336 if (*buf != 0 && isspace((unsigned char)*buf))
337 while (*ptr != 0 && !isspace((unsigned char)*ptr))
338 ptr++;
339 break;
340
341 case 'w':
342 if (!isdigit((unsigned char)*buf))
343 return 0;
344
355 }
356 if (i > 53)
357 return 0;
358
359 if (*buf != 0 && isspace((unsigned char)*buf))
360 while (*ptr != 0 && !isspace((unsigned char)*ptr))
361 ptr++;
362 break;
363
364 case 'w':
365 if (!isdigit((unsigned char)*buf))
366 return 0;
367
345 for (i = 0; *buf != 0 && isdigit((unsigned char)*buf); buf++) {
346 i *= 10;
347 i += *buf - '0';
348 }
368 i = *buf - '0';
349 if (i > 6)
350 return 0;
351
352 tm->tm_wday = i;
353
354 if (*buf != 0 && isspace((unsigned char)*buf))
355 while (*ptr != 0 && !isspace((unsigned char)*ptr))
356 ptr++;
357 break;
358
359 case 'd':
360 case 'e':
369 if (i > 6)
370 return 0;
371
372 tm->tm_wday = i;
373
374 if (*buf != 0 && isspace((unsigned char)*buf))
375 while (*ptr != 0 && !isspace((unsigned char)*ptr))
376 ptr++;
377 break;
378
379 case 'd':
380 case 'e':
381 /*
382 * The %e specifier is explicitly documented as not
383 * being zero-padded but there is no harm in allowing
384 * such padding.
385 *
386 * XXX The %e specifier may gobble one too many
387 * digits if used incorrectly.
388 */
361 if (!isdigit((unsigned char)*buf))
362 return 0;
363
389 if (!isdigit((unsigned char)*buf))
390 return 0;
391
364 for (i = 0; *buf != 0 && isdigit((unsigned char)*buf); buf++) {
392 len = 2;
393 for (i = 0; len && *buf != 0 && isdigit((unsigned char)*buf); buf++) {
365 i *= 10;
366 i += *buf - '0';
394 i *= 10;
395 i += *buf - '0';
396 len--;
367 }
368 if (i > 31)
369 return 0;
370
371 tm->tm_mday = i;
372
373 if (*buf != 0 && isspace((unsigned char)*buf))
374 while (*ptr != 0 && !isspace((unsigned char)*ptr))

--- 34 unchanged lines hidden (view full) ---

409 tm->tm_mon = i;
410 buf += len;
411 break;
412
413 case 'm':
414 if (!isdigit((unsigned char)*buf))
415 return 0;
416
397 }
398 if (i > 31)
399 return 0;
400
401 tm->tm_mday = i;
402
403 if (*buf != 0 && isspace((unsigned char)*buf))
404 while (*ptr != 0 && !isspace((unsigned char)*ptr))

--- 34 unchanged lines hidden (view full) ---

439 tm->tm_mon = i;
440 buf += len;
441 break;
442
443 case 'm':
444 if (!isdigit((unsigned char)*buf))
445 return 0;
446
417 for (i = 0; *buf != 0 && isdigit((unsigned char)*buf); buf++) {
447 len = 2;
448 for (i = 0; len && *buf != 0 && isdigit((unsigned char)*buf); buf++) {
418 i *= 10;
419 i += *buf - '0';
449 i *= 10;
450 i += *buf - '0';
451 len--;
420 }
421 if (i < 1 || i > 12)
422 return 0;
423
424 tm->tm_mon = i - 1;
425
426 if (*buf != 0 && isspace((unsigned char)*buf))
427 while (*ptr != 0 && !isspace((unsigned char)*ptr))
428 ptr++;
429 break;
430
431 case 'Y':
432 case 'y':
433 if (*buf == 0 || isspace((unsigned char)*buf))
434 break;
435
436 if (!isdigit((unsigned char)*buf))
437 return 0;
438
452 }
453 if (i < 1 || i > 12)
454 return 0;
455
456 tm->tm_mon = i - 1;
457
458 if (*buf != 0 && isspace((unsigned char)*buf))
459 while (*ptr != 0 && !isspace((unsigned char)*ptr))
460 ptr++;
461 break;
462
463 case 'Y':
464 case 'y':
465 if (*buf == 0 || isspace((unsigned char)*buf))
466 break;
467
468 if (!isdigit((unsigned char)*buf))
469 return 0;
470
439 for (i = 0; *buf != 0 && isdigit((unsigned char)*buf); buf++) {
471 len = (c == 'Y') ? 4 : 2;
472 for (i = 0; len && *buf != 0 && isdigit((unsigned char)*buf); buf++) {
440 i *= 10;
441 i += *buf - '0';
473 i *= 10;
474 i += *buf - '0';
475 len--;
442 }
443 if (c == 'Y')
444 i -= 1900;
445 if (c == 'y' && i < 69)
446 i += 100;
447 if (i < 0)
448 return 0;
449

--- 60 unchanged lines hidden ---
476 }
477 if (c == 'Y')
478 i -= 1900;
479 if (c == 'y' && i < 69)
480 i += 100;
481 if (i < 0)
482 return 0;
483

--- 60 unchanged lines hidden ---