summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdtime/strptime.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libc/stdtime/strptime.c')
-rw-r--r--lib/libc/stdtime/strptime.c105
1 files changed, 52 insertions, 53 deletions
diff --git a/lib/libc/stdtime/strptime.c b/lib/libc/stdtime/strptime.c
index 7228780..4c0ab26 100644
--- a/lib/libc/stdtime/strptime.c
+++ b/lib/libc/stdtime/strptime.c
@@ -56,7 +56,7 @@ __FBSDID("$FreeBSD$");
static char * _strptime(const char *, const char *, struct tm *, int *, locale_t);
-#define asizeof(a) (sizeof (a) / sizeof ((a)[0]))
+#define asizeof(a) (sizeof (a) / sizeof ((a)[0]))
static char *
_strptime(const char *buf, const char *fmt, struct tm *tm, int *GMTp,
@@ -64,8 +64,7 @@ _strptime(const char *buf, const char *fmt, struct tm *tm, int *GMTp,
{
char c;
const char *ptr;
- int i,
- len;
+ int i, len;
int Ealternative, Oalternative;
struct lc_time_T *tptr = __get_current_time_locale(locale);
@@ -82,7 +81,7 @@ _strptime(const char *buf, const char *fmt, struct tm *tm, int *GMTp,
isspace_l((unsigned char)*buf, locale))
buf++;
else if (c != *buf++)
- return 0;
+ return (NULL);
continue;
}
@@ -94,18 +93,18 @@ label:
case 0:
case '%':
if (*buf++ != '%')
- return 0;
+ return (NULL);
break;
case '+':
buf = _strptime(buf, tptr->date_fmt, tm, GMTp, locale);
- if (buf == 0)
- return 0;
+ if (buf == NULL)
+ return (NULL);
break;
case 'C':
if (!isdigit_l((unsigned char)*buf, locale))
- return 0;
+ return (NULL);
/* XXX This will break for 3-digit centuries. */
len = 2;
@@ -116,21 +115,21 @@ label:
len--;
}
if (i < 19)
- return 0;
+ return (NULL);
tm->tm_year = i * 100 - 1900;
break;
case 'c':
buf = _strptime(buf, tptr->c_fmt, tm, GMTp, locale);
- if (buf == 0)
- return 0;
+ if (buf == NULL)
+ return (NULL);
break;
case 'D':
buf = _strptime(buf, "%m/%d/%y", tm, GMTp, locale);
- if (buf == 0)
- return 0;
+ if (buf == NULL)
+ return (NULL);
break;
case 'E':
@@ -147,43 +146,43 @@ label:
case 'F':
buf = _strptime(buf, "%Y-%m-%d", tm, GMTp, locale);
- if (buf == 0)
- return 0;
+ if (buf == NULL)
+ return (NULL);
break;
case 'R':
buf = _strptime(buf, "%H:%M", tm, GMTp, locale);
- if (buf == 0)
- return 0;
+ if (buf == NULL)
+ return (NULL);
break;
case 'r':
buf = _strptime(buf, tptr->ampm_fmt, tm, GMTp, locale);
- if (buf == 0)
- return 0;
+ if (buf == NULL)
+ return (NULL);
break;
case 'T':
buf = _strptime(buf, "%H:%M:%S", tm, GMTp, locale);
- if (buf == 0)
- return 0;
+ if (buf == NULL)
+ return (NULL);
break;
case 'X':
buf = _strptime(buf, tptr->X_fmt, tm, GMTp, locale);
- if (buf == 0)
- return 0;
+ if (buf == NULL)
+ return (NULL);
break;
case 'x':
buf = _strptime(buf, tptr->x_fmt, tm, GMTp, locale);
- if (buf == 0)
- return 0;
+ if (buf == NULL)
+ return (NULL);
break;
case 'j':
if (!isdigit_l((unsigned char)*buf, locale))
- return 0;
+ return (NULL);
len = 3;
for (i = 0; len && *buf != 0 &&
@@ -193,7 +192,7 @@ label:
len--;
}
if (i < 1 || i > 366)
- return 0;
+ return (NULL);
tm->tm_yday = i - 1;
break;
@@ -205,7 +204,7 @@ label:
break;
if (!isdigit_l((unsigned char)*buf, locale))
- return 0;
+ return (NULL);
len = 2;
for (i = 0; len && *buf != 0 &&
@@ -217,11 +216,11 @@ label:
if (c == 'M') {
if (i > 59)
- return 0;
+ return (NULL);
tm->tm_min = i;
} else {
if (i > 60)
- return 0;
+ return (NULL);
tm->tm_sec = i;
}
@@ -245,7 +244,7 @@ label:
* digits if used incorrectly.
*/
if (!isdigit_l((unsigned char)*buf, locale))
- return 0;
+ return (NULL);
len = 2;
for (i = 0; len && *buf != 0 &&
@@ -256,9 +255,9 @@ label:
}
if (c == 'H' || c == 'k') {
if (i > 23)
- return 0;
+ return (NULL);
} else if (i > 12)
- return 0;
+ return (NULL);
tm->tm_hour = i;
@@ -277,7 +276,7 @@ label:
len = strlen(tptr->am);
if (strncasecmp_l(buf, tptr->am, len, locale) == 0) {
if (tm->tm_hour > 12)
- return 0;
+ return (NULL);
if (tm->tm_hour == 12)
tm->tm_hour = 0;
buf += len;
@@ -287,14 +286,14 @@ label:
len = strlen(tptr->pm);
if (strncasecmp_l(buf, tptr->pm, len, locale) == 0) {
if (tm->tm_hour > 12)
- return 0;
+ return (NULL);
if (tm->tm_hour != 12)
tm->tm_hour += 12;
buf += len;
break;
}
- return 0;
+ return (NULL);
case 'A':
case 'a':
@@ -309,7 +308,7 @@ label:
break;
}
if (i == asizeof(tptr->weekday))
- return 0;
+ return (NULL);
tm->tm_wday = i;
buf += len;
@@ -324,7 +323,7 @@ label:
* range for now.
*/
if (!isdigit_l((unsigned char)*buf, locale))
- return 0;
+ return (NULL);
len = 2;
for (i = 0; len && *buf != 0 &&
@@ -334,7 +333,7 @@ label:
len--;
}
if (i > 53)
- return 0;
+ return (NULL);
if (*buf != 0 &&
isspace_l((unsigned char)*buf, locale))
@@ -345,11 +344,11 @@ label:
case 'w':
if (!isdigit_l((unsigned char)*buf, locale))
- return 0;
+ return (NULL);
i = *buf - '0';
if (i > 6)
- return 0;
+ return (NULL);
tm->tm_wday = i;
@@ -371,7 +370,7 @@ label:
* digits if used incorrectly.
*/
if (!isdigit_l((unsigned char)*buf, locale))
- return 0;
+ return (NULL);
len = 2;
for (i = 0; len && *buf != 0 &&
@@ -381,7 +380,7 @@ label:
len--;
}
if (i > 31)
- return 0;
+ return (NULL);
tm->tm_mday = i;
@@ -424,7 +423,7 @@ label:
}
}
if (i == asizeof(tptr->month))
- return 0;
+ return (NULL);
tm->tm_mon = i;
buf += len;
@@ -432,7 +431,7 @@ label:
case 'm':
if (!isdigit_l((unsigned char)*buf, locale))
- return 0;
+ return (NULL);
len = 2;
for (i = 0; len && *buf != 0 &&
@@ -442,7 +441,7 @@ label:
len--;
}
if (i < 1 || i > 12)
- return 0;
+ return (NULL);
tm->tm_mon = i - 1;
@@ -465,7 +464,7 @@ label:
n = strtol_l(buf, &cp, 10, locale);
if (errno == ERANGE || (long)(t = n) != n) {
errno = sverrno;
- return 0;
+ return (NULL);
}
errno = sverrno;
buf = cp;
@@ -481,7 +480,7 @@ label:
break;
if (!isdigit_l((unsigned char)*buf, locale))
- return 0;
+ return (NULL);
len = (c == 'Y') ? 4 : 2;
for (i = 0; len && *buf != 0 &&
@@ -495,7 +494,7 @@ label:
if (c == 'y' && i < 69)
i += 100;
if (i < 0)
- return 0;
+ return (NULL);
tm->tm_year = i;
@@ -526,7 +525,7 @@ label:
} else if (0 == strcmp(zonestr, tzname[1])) {
tm->tm_isdst = 1;
} else {
- return 0;
+ return (NULL);
}
buf += cp - buf;
}
@@ -541,7 +540,7 @@ label:
if (*buf == '-')
sign = -1;
else
- return 0;
+ return (NULL);
}
buf++;
@@ -552,7 +551,7 @@ label:
i += *buf - '0';
buf++;
} else
- return 0;
+ return (NULL);
}
tm->tm_hour -= sign * (i / 100);
@@ -562,7 +561,7 @@ label:
break;
}
}
- return (char *)buf;
+ return ((char *)buf);
}
OpenPOWER on IntegriCloud