version 1.176, 2022/06/03 04:30:47 |
version 1.177, 2022/08/11 01:56:51 |
|
|
struct tm tm; |
struct tm tm; |
time_t tt; |
time_t tt; |
char buf[32], *fmt; |
char buf[32], *fmt; |
|
const char *cp; |
|
size_t l; |
|
int is_utc = 0; |
|
|
*tp = 0; |
*tp = 0; |
|
|
|
l = strlen(s); |
|
if (l > 1 && strcasecmp(s + l - 1, "Z") == 0) { |
|
is_utc = 1; |
|
l--; |
|
} else if (l > 3 && strcasecmp(s + l - 3, "UTC") == 0) { |
|
is_utc = 1; |
|
l -= 3; |
|
} |
/* |
/* |
* POSIX strptime says "The application shall ensure that there |
* POSIX strptime says "The application shall ensure that there |
* is white-space or other non-alphanumeric characters between |
* is white-space or other non-alphanumeric characters between |
* any two conversion specifications" so arrange things this way. |
* any two conversion specifications" so arrange things this way. |
*/ |
*/ |
switch (strlen(s)) { |
switch (l) { |
case 8: /* YYYYMMDD */ |
case 8: /* YYYYMMDD */ |
fmt = "%Y-%m-%d"; |
fmt = "%Y-%m-%d"; |
snprintf(buf, sizeof(buf), "%.4s-%.2s-%.2s", s, s + 4, s + 6); |
snprintf(buf, sizeof(buf), "%.4s-%.2s-%.2s", s, s + 4, s + 6); |
|
|
} |
} |
|
|
memset(&tm, 0, sizeof(tm)); |
memset(&tm, 0, sizeof(tm)); |
if (strptime(buf, fmt, &tm) == NULL) |
if ((cp = strptime(buf, fmt, &tm)) == NULL || *cp != '\0') |
return SSH_ERR_INVALID_FORMAT; |
return SSH_ERR_INVALID_FORMAT; |
if ((tt = mktime(&tm)) < 0) |
if (is_utc) { |
return SSH_ERR_INVALID_FORMAT; |
if ((tt = timegm(&tm)) < 0) |
|
return SSH_ERR_INVALID_FORMAT; |
|
} else { |
|
if ((tt = mktime(&tm)) < 0) |
|
return SSH_ERR_INVALID_FORMAT; |
|
} |
/* success */ |
/* success */ |
*tp = (uint64_t)tt; |
*tp = (uint64_t)tt; |
return 0; |
return 0; |