aboutsummaryrefslogtreecommitdiff
path: root/time/strftime.c
diff options
context:
space:
mode:
Diffstat (limited to 'time/strftime.c')
-rw-r--r--time/strftime.c28
1 files changed, 11 insertions, 17 deletions
diff --git a/time/strftime.c b/time/strftime.c
index 61f688e1b2..04d0e565df 100644
--- a/time/strftime.c
+++ b/time/strftime.c
@@ -416,15 +416,14 @@ my_strftime (s, maxsize, format, tp)
{
int hour12 = tp->tm_hour;
#ifdef _NL_CURRENT
- /* We cannot make the following values variables since we must dealy
+ /* We cannot make the following values variables since we must delay
the evaluation of these values until really needed since some
expressions might not be valid in every situation. The `struct tm'
- might be generated by a strptime() call and therefore initialized
+ might be generated by a strptime() call that initialized
only a few elements. Dereference the pointers only if the format
requires this. Then it is ok to fail if the pointers are invalid. */
# define a_wkday _NL_CURRENT (LC_TIME, ABDAY_1 + tp->tm_wday)
# define f_wkday _NL_CURRENT (LC_TIME, DAY_1 + tp->tm_wday)
-# define f_wkday _NL_CURRENT (LC_TIME, DAY_1 + tp->tm_wday)
# define a_month _NL_CURRENT (LC_TIME, ABMON_1 + tp->tm_mon)
# define f_month _NL_CURRENT (LC_TIME, MON_1 + tp->tm_mon)
# define ampm _NL_CURRENT (LC_TIME, tp->tm_hour > 11 ? PM_STR : AM_STR)
@@ -432,22 +431,17 @@ my_strftime (s, maxsize, format, tp)
# define aw_len strlen (a_wkday)
# define am_len strlen (a_month)
# define ap_len strlen (ampm)
-
-# define wkday_len strlen (f_wkday)
-# define month_len strlen (f_month)
#else
# if !HAVE_STRFTIME
- const char *const f_wkday = weekday_name[tp->tm_wday];
- const char *const f_month = month_name[tp->tm_mon];
- const char *const a_wkday = f_wkday;
- const char *const a_month = f_month;
- const char *const ampm = "AMPM" + 2 * (hour12 > 11);
+# define f_wkday (weekday_name[tp->tm_wday])
+# define f_month (month_name[tp->tm_mon])
+# define a_wkday f_wkday
+# define a_month f_month
+# define ampm ("AMPM" + 2 * (tp->tm_hour > 11))
+
size_t aw_len = 3;
size_t am_len = 3;
size_t ap_len = 2;
-
- size_t wkday_len = strlen (f_wkday);
- size_t month_len = strlen (f_month);
# endif
#endif
const char *zone;
@@ -669,7 +663,7 @@ my_strftime (s, maxsize, format, tp)
to_lowcase = 0;
}
#if defined _NL_CURRENT || !HAVE_STRFTIME
- cpy (wkday_len, f_wkday);
+ cpy (strlen (f_wkday), f_wkday);
break;
#else
goto underlying_strftime;
@@ -695,7 +689,7 @@ my_strftime (s, maxsize, format, tp)
to_lowcase = 0;
}
#if defined _NL_CURRENT || !HAVE_STRFTIME
- cpy (month_len, f_month);
+ cpy (strlen (f_month), f_month);
break;
#else
goto underlying_strftime;
@@ -1227,7 +1221,7 @@ my_strftime (s, maxsize, format, tp)
}
}
- if (p)
+ if (p && i < maxsize)
*p = '\0';
return i;
}