|
|
@@ -50,6 +50,16 @@ enum { STD_ASCTIME_BUF_SIZE = 26 };
|
|
|
*/
|
|
|
static char buf_asctime[2*3 + 5*INT_STRLEN_MAXIMUM(int) + 7 + 2 + 1 + 1];
|
|
|
|
|
|
+/* A similar buffer for ctime.
|
|
|
+ C89 requires that they be the same buffer.
|
|
|
+ This requirement was removed in C99, so support it only if requested,
|
|
|
+ as support is more likely to lead to bugs in badly-written programs. */
|
|
|
+#if SUPPORT_C89
|
|
|
+# define buf_ctime buf_asctime
|
|
|
+#else
|
|
|
+static char buf_ctime[sizeof buf_asctime];
|
|
|
+#endif
|
|
|
+
|
|
|
char *
|
|
|
asctime_r(register const struct tm *timeptr, char *buf)
|
|
|
{
|
|
|
@@ -91,7 +101,8 @@ asctime_r(register const struct tm *timeptr, char *buf)
|
|
|
timeptr->tm_mday, timeptr->tm_hour,
|
|
|
timeptr->tm_min, timeptr->tm_sec,
|
|
|
year);
|
|
|
- if (strlen(result) < STD_ASCTIME_BUF_SIZE || buf == buf_asctime)
|
|
|
+ if (strlen(result) < STD_ASCTIME_BUF_SIZE
|
|
|
+ || buf == buf_ctime || buf == buf_asctime)
|
|
|
return strcpy(buf, result);
|
|
|
else {
|
|
|
errno = EOVERFLOW;
|
|
|
@@ -116,6 +127,5 @@ ctime_r(const time_t *timep, char *buf)
|
|
|
char *
|
|
|
ctime(const time_t *timep)
|
|
|
{
|
|
|
- struct tm *tmp = localtime(timep);
|
|
|
- return tmp ? asctime(tmp) : NULL;
|
|
|
+ return ctime_r(timep, buf_ctime);
|
|
|
}
|