Skip to content

Commit

Permalink
Move ctime() to separate file
Browse files Browse the repository at this point in the history
localtime() is referenced by do_fstat(), which is always (indirectly)
referenced by the startup code. Having ctime defined in the same file
will also always pull in asctime & strftime.
  • Loading branch information
th-otto committed Jan 15, 2024
1 parent 0cbc725 commit 72667bf
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 21 deletions.
1 change: 1 addition & 0 deletions tz/SRCFILES
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# the files that should go only into source distributions.

SRCFILES = asctime.c \
ctime.c \
difftime.c \
localtime.c \
strftime.c \
Expand Down
22 changes: 22 additions & 0 deletions tz/ctime.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include "private.h"

/*
** 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))
*/
char *ctime(const time_t *timep)
{
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;
}
21 changes: 0 additions & 21 deletions tz/localtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -1938,27 +1938,6 @@ static struct tm *timesub(const time_t *timep, int_fast32_t offset, struct state
return tmp;
}

/*
** 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))
*/
char *ctime(const time_t *timep)
{
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
Expand Down

0 comments on commit 72667bf

Please sign in to comment.