summaryrefslogtreecommitdiffstats
path: root/libc/tzcode/asctime.c
diff options
context:
space:
mode:
authorThe Android Open Source Project <initial-contribution@android.com>2009-03-18 22:20:24 -0700
committerThe Android Open Source Project <initial-contribution@android.com>2009-03-18 22:20:24 -0700
commitedbe7fc97bab7ff0684053d1be564330689bf3ad (patch)
tree271db0992a091d68f17f073ba9573c4698f97ce1 /libc/tzcode/asctime.c
parent78bf5fc677a2d25d50598b01781eafacdb5e6afe (diff)
downloadbionic-edbe7fc97bab7ff0684053d1be564330689bf3ad.zip
bionic-edbe7fc97bab7ff0684053d1be564330689bf3ad.tar.gz
bionic-edbe7fc97bab7ff0684053d1be564330689bf3ad.tar.bz2
auto import //branches/master/...@140412
Diffstat (limited to 'libc/tzcode/asctime.c')
-rw-r--r--libc/tzcode/asctime.c106
1 files changed, 53 insertions, 53 deletions
diff --git a/libc/tzcode/asctime.c b/libc/tzcode/asctime.c
index e0804f1..22bba34 100644
--- a/libc/tzcode/asctime.c
+++ b/libc/tzcode/asctime.c
@@ -11,7 +11,7 @@
#ifndef lint
#ifndef NOID
-static char elsieid[] = "@(#)asctime.c 8.2";
+static char elsieid[] = "@(#)asctime.c 8.2";
#endif /* !defined NOID */
#endif /* !defined lint */
@@ -39,9 +39,9 @@ static char elsieid[] = "@(#)asctime.c 8.2";
** but many implementations pad anyway; most likely the standards are buggy.
*/
#ifdef __GNUC__
-#define ASCTIME_FMT "%.3s %.3s%3d %2.2d:%2.2d:%2.2d %-4s\n"
+#define ASCTIME_FMT "%.3s %.3s%3d %2.2d:%2.2d:%2.2d %-4s\n"
#else /* !defined __GNUC__ */
-#define ASCTIME_FMT "%.3s %.3s%3d %02.2d:%02.2d:%02.2d %-4s\n"
+#define ASCTIME_FMT "%.3s %.3s%3d %02.2d:%02.2d:%02.2d %-4s\n"
#endif /* !defined __GNUC__ */
/*
** For years that are more than four digits we put extra spaces before the year
@@ -50,12 +50,12 @@ static char elsieid[] = "@(#)asctime.c 8.2";
** that no output is better than wrong output).
*/
#ifdef __GNUC__
-#define ASCTIME_FMT_B "%.3s %.3s%3d %2.2d:%2.2d:%2.2d %s\n"
+#define ASCTIME_FMT_B "%.3s %.3s%3d %2.2d:%2.2d:%2.2d %s\n"
#else /* !defined __GNUC__ */
-#define ASCTIME_FMT_B "%.3s %.3s%3d %02.2d:%02.2d:%02.2d %s\n"
+#define ASCTIME_FMT_B "%.3s %.3s%3d %02.2d:%02.2d:%02.2d %s\n"
#endif /* !defined __GNUC__ */
-#define STD_ASCTIME_BUF_SIZE 26
+#define STD_ASCTIME_BUF_SIZE 26
/*
** Big enough for something such as
** ??? ???-2147483648 -2147483648:-2147483648:-2147483648 -2147483648\n
@@ -66,9 +66,9 @@ static char elsieid[] = "@(#)asctime.c 8.2";
** as an example; the define below calculates the maximum for the system at
** hand.
*/
-#define MAX_ASCTIME_BUF_SIZE (2*3+5*INT_STRLEN_MAXIMUM(int)+7+2+1+1)
+#define MAX_ASCTIME_BUF_SIZE (2*3+5*INT_STRLEN_MAXIMUM(int)+7+2+1+1)
-static char buf_asctime[MAX_ASCTIME_BUF_SIZE];
+static char buf_asctime[MAX_ASCTIME_BUF_SIZE];
/*
** A la ISO/IEC 9945-1, ANSI/IEEE Std 1003.1, 2004 Edition.
@@ -76,54 +76,54 @@ static char buf_asctime[MAX_ASCTIME_BUF_SIZE];
char *
asctime_r(timeptr, buf)
-register const struct tm * timeptr;
-char * buf;
+register const struct tm * timeptr;
+char * buf;
{
- static const char wday_name[][3] = {
- "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
- };
- static const char mon_name[][3] = {
- "Jan", "Feb", "Mar", "Apr", "May", "Jun",
- "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
- };
- register const char * wn;
- register const char * mn;
- char year[INT_STRLEN_MAXIMUM(int) + 2];
- char result[MAX_ASCTIME_BUF_SIZE];
+ static const char wday_name[][3] = {
+ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
+ };
+ static const char mon_name[][3] = {
+ "Jan", "Feb", "Mar", "Apr", "May", "Jun",
+ "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
+ };
+ register const char * wn;
+ register const char * mn;
+ char year[INT_STRLEN_MAXIMUM(int) + 2];
+ char result[MAX_ASCTIME_BUF_SIZE];
- if (timeptr->tm_wday < 0 || timeptr->tm_wday >= DAYSPERWEEK)
- wn = "???";
- else wn = wday_name[timeptr->tm_wday];
- if (timeptr->tm_mon < 0 || timeptr->tm_mon >= MONSPERYEAR)
- mn = "???";
- else mn = mon_name[timeptr->tm_mon];
- /*
- ** Use strftime's %Y to generate the year, to avoid overflow problems
- ** when computing timeptr->tm_year + TM_YEAR_BASE.
- ** Assume that strftime is unaffected by other out-of-range members
- ** (e.g., timeptr->tm_mday) when processing "%Y".
- */
- (void) strftime(year, sizeof year, "%Y", timeptr);
- /*
- ** We avoid using snprintf since it's not available on all systems.
- */
- (void) sprintf(result,
- ((strlen(year) <= 4) ? ASCTIME_FMT : ASCTIME_FMT_B),
- wn, mn,
- timeptr->tm_mday, timeptr->tm_hour,
- timeptr->tm_min, timeptr->tm_sec,
- year);
- if (strlen(result) < STD_ASCTIME_BUF_SIZE || buf == buf_asctime) {
- (void) strcpy(buf, result);
- return buf;
- } else {
+ if (timeptr->tm_wday < 0 || timeptr->tm_wday >= DAYSPERWEEK)
+ wn = "???";
+ else wn = wday_name[timeptr->tm_wday];
+ if (timeptr->tm_mon < 0 || timeptr->tm_mon >= MONSPERYEAR)
+ mn = "???";
+ else mn = mon_name[timeptr->tm_mon];
+ /*
+ ** Use strftime's %Y to generate the year, to avoid overflow problems
+ ** when computing timeptr->tm_year + TM_YEAR_BASE.
+ ** Assume that strftime is unaffected by other out-of-range members
+ ** (e.g., timeptr->tm_mday) when processing "%Y".
+ */
+ (void) strftime(year, sizeof year, "%Y", timeptr);
+ /*
+ ** We avoid using snprintf since it's not available on all systems.
+ */
+ (void) sprintf(result,
+ ((strlen(year) <= 4) ? ASCTIME_FMT : ASCTIME_FMT_B),
+ wn, mn,
+ timeptr->tm_mday, timeptr->tm_hour,
+ timeptr->tm_min, timeptr->tm_sec,
+ year);
+ if (strlen(result) < STD_ASCTIME_BUF_SIZE || buf == buf_asctime) {
+ (void) strcpy(buf, result);
+ return buf;
+ } else {
#ifdef EOVERFLOW
- errno = EOVERFLOW;
+ errno = EOVERFLOW;
#else /* !defined EOVERFLOW */
- errno = EINVAL;
+ errno = EINVAL;
#endif /* !defined EOVERFLOW */
- return NULL;
- }
+ return NULL;
+ }
}
/*
@@ -132,7 +132,7 @@ char * buf;
char *
asctime(timeptr)
-register const struct tm * timeptr;
+register const struct tm * timeptr;
{
- return asctime_r(timeptr, buf_asctime);
+ return asctime_r(timeptr, buf_asctime);
}