forwarding a patch that uses the fetch macros to pull in acpica and build it (NicJA).
[AROS.git] / compiler / posixc / strptime.c
bloba35d049bcc8dff0d1cd751931e73b2ef276a991c
1 /*
2 Copyright © 2008, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <time.h>
7 #include <errno.h>
8 #include <stdio.h>
9 #include <ctype.h>
11 #define MATCHUINT(dest, value) \
12 if(sscanf(s, "%u%n", &val, &matched) != EOF) \
13 dest = value; \
14 else \
15 return NULL; \
17 char *strptime(const char *s, const char *format, struct tm *tm)
19 int matched;
20 int val;
22 if (format == NULL || s == NULL || tm == NULL)
24 errno = EINVAL;
25 return NULL;
28 while (*format)
30 if (*format == '%')
32 matched = 0;
34 switch(*++format)
36 case '%':
37 matched = (*s == '%' ? 1 : EOF);
38 break;
39 case 'd':
40 case 'e':
41 MATCHUINT(tm->tm_mday, val);
42 break;
43 case 'H':
44 MATCHUINT(tm->tm_hour, val);
45 break;
46 case 'm':
47 MATCHUINT(tm->tm_mon, val - 1);
48 break;
49 case 'M':
50 MATCHUINT(tm->tm_min, val);
51 break;
52 case 'S':
53 MATCHUINT(tm->tm_sec, val);
54 break;
55 case 'w':
56 MATCHUINT(tm->tm_wday, val);
57 break;
58 case 'y':
59 MATCHUINT(tm->tm_year, val);
60 break;
61 case 'Y':
62 MATCHUINT(tm->tm_year, val - 1900);
63 break;
64 case '\0':
65 format--;
66 break;
67 default:
68 /* FIXME: Implement remaining conversions */
69 return 0;
72 s += matched;
74 else
76 /* whitespace matches zero or more whitespace characters */
77 if(isspace(*format))
79 while(isspace(*s))
80 s++;
82 else
84 /* compare characters directly */
85 if(*s != *format)
86 return NULL;
87 s++;
91 format++;
94 return (char *)s;