| 171 | #endif |
| 172 | |
| 173 | static char* |
| 174 | _strptime(const char* buf, const char* fmt, struct tm* tm, int* GMTp) |
| 175 | { |
| 176 | char c; |
| 177 | const char* ptr; |
| 178 | int i; |
| 179 | size_t len = 0; |
| 180 | int Ealternative, Oalternative; |
| 181 | struct lc_time_T* tptr = __get_current_time_locale(); |
| 182 | |
| 183 | ptr = fmt; |
| 184 | while (*ptr != 0) { |
| 185 | if (*buf == 0) |
| 186 | break; |
| 187 | |
| 188 | c = *ptr++; |
| 189 | |
| 190 | if (c != '%') { |
| 191 | if (isspace((unsigned char)c)) |
| 192 | while (*buf != 0 && isspace((unsigned char)*buf)) |
| 193 | ++buf; |
| 194 | else if (c != *buf++) |
| 195 | return 0; |
| 196 | continue; |
| 197 | } |
| 198 | |
| 199 | Ealternative = 0; |
| 200 | Oalternative = 0; |
| 201 | label: |
| 202 | c = *ptr++; |
| 203 | switch (c) { |
| 204 | case 0: |
| 205 | case '%': |
| 206 | if (*buf++ != '%') |
| 207 | return 0; |
| 208 | break; |
| 209 | |
| 210 | case '+': |
| 211 | buf = _strptime(buf, tptr->date_fmt, tm, GMTp); |
| 212 | if (buf == 0) |
| 213 | return 0; |
| 214 | break; |
| 215 | |
| 216 | case 'C': |
| 217 | if (!isdigit((unsigned char)*buf)) |
| 218 | return 0; |
| 219 | |
| 220 | /* XXX This will break for 3-digit centuries. */ |
| 221 | len = 2; |
| 222 | for (i = 0; len && *buf != 0 && isdigit((unsigned char)*buf); buf++) { |
| 223 | i *= 10; |
| 224 | i += *buf - '0'; |
| 225 | --len; |
| 226 | } |
| 227 | if (i < 19) |
| 228 | return 0; |
| 229 | |
| 230 | tm->tm_year = i * 100 - 1900; |
no test coverage detected