[tz] [PROPOSED 2/4] Refactor location of ctime, ctime_r

Paul Eggert eggert at cs.ucla.edu
Wed Nov 30 19:25:50 UTC 2022


* asctime.c (ctime, ctime_r): Move here ...
* localtime.c (ctime): ... from here, as it’s a bit better
location and should help simplify future changes.
---
 asctime.c   | 15 +++++++++++++++
 localtime.c | 21 ---------------------
 2 files changed, 15 insertions(+), 21 deletions(-)

diff --git a/asctime.c b/asctime.c
index f0159f8..c001621 100644
--- a/asctime.c
+++ b/asctime.c
@@ -104,3 +104,18 @@ asctime(register const struct tm *timeptr)
 {
 	return asctime_r(timeptr, buf_asctime);
 }
+
+char *
+ctime_r(const time_t *timep, char *buf)
+{
+  struct tm mytm;
+  struct tm *tmp = localtime_r(timep, &mytm);
+  return tmp ? asctime_r(tmp, buf) : NULL;
+}
+
+char *
+ctime(const time_t *timep)
+{
+  struct tm *tmp = localtime(timep);
+  return tmp ? asctime(tmp) : NULL;
+}
diff --git a/localtime.c b/localtime.c
index 462d054..cb34a9e 100644
--- a/localtime.c
+++ b/localtime.c
@@ -1842,27 +1842,6 @@ timesub(const time_t *timep, int_fast32_t offset,
 	return tmp;
 }
 
-char *
-ctime(const time_t *timep)
-{
-/*
-** Section 4.12.3.2 of X3.159-1989 requires that
-**	The ctime function converts the calendar time pointed to by timer
-**	to local time in the form of a string. It is equivalent to
-**		asctime(localtime(timer))
-*/
-  struct tm *tmp = localtime(timep);
-  return tmp ? asctime(tmp) : NULL;
-}
-
-char *
-ctime_r(const time_t *timep, char *buf)
-{
-  struct tm mytm;
-  struct tm *tmp = localtime_r(timep, &mytm);
-  return tmp ? asctime_r(tmp, buf) : NULL;
-}
-
 /*
 ** Adapted from code provided by Robert Elz, who writes:
 **	The "best" way to do mktime I think is based on an idea of Bob
-- 
2.38.1



More information about the tz mailing list