Added:
trunk/t/ctime64.t.c
Modified:
trunk/Makefile
trunk/time64.c
trunk/time64.h
Log:
Implement ctime64() and ctime64_r()
Modified: trunk/Makefile
==============================================================================
--- trunk/Makefile (original)
+++ trunk/Makefile Wed Jan 7 17:00:35 2009
@@ -48,6 +48,9 @@
t/asctime64.t : t/tap.c t/asctime64.t.c time64.o
$(LINK) time64.o t/asctime64.t.c -o $@
+t/ctime64.t : t/tap.c t/ctime64.t.c time64.o
+ $(LINK) time64.o t/ctime64.t.c -o $@
+
t/seconds_between_years.t : t/tap.c t/seconds_between_years.t.c time64.c
$(LINK) t/seconds_between_years.t.c -o $@
Added: trunk/t/ctime64.t.c
==============================================================================
--- (empty file)
+++ trunk/t/ctime64.t.c Wed Jan 7 17:00:35 2009
@@ -0,0 +1,45 @@
+#include "time64.h"
+#include "t/tap.c"
+
+int main(void) {
+ Time64_T time = 12345678987654321LL;
+ char* ctime_ret1;
+ char* ctime_ret2;
+ char ctime_buf1[35];
+
+ /* The ctime() function shall convert the time pointed to by clock,
representing time
+ in seconds since the Epoch, to local time in the form of a string.
It shall be equivalent
+ to: asctime(localtime(clock)) (ISO)
+ */
+ is_str( ctime64(&time), asctime64(localtime64(&time)), "ctime64()" );
+
+ /* The asctime(), ctime(), gmtime(), and localtime() functions shall
return values in
+ one of two static objects: a broken-down time structure and an
array of char. Execution
+ of any of the functions may overwrite the information returned in
either of these
+ objects by any of the other functions. (POSIX)
+ */
+ ctime_ret1 = ctime64(&time);
+ time++;
+ ctime_ret2 = ctime64(&time);
+ is_str( ctime_ret1, ctime_ret2, " return is static" );
+
+ /* The ctime_r() function shall convert the calendar time pointed to
by clock to local
+ time in exactly the same form as ctime() and put the string into
the array pointed
+ to by buf (which shall be at least 26 bytes in size) and return buf.
+ (We need 35 bytes) (POSIX)
+ */
+ ctime_ret1 = ctime64_r(&time, ctime_buf1);
+ is_str( ctime_ret1, ctime_buf1, "ctime64_r()" );
+ is_str( ctime_ret1, asctime64(localtime64(&time)), " right time" );
+
+ /* Unlike ctime(), the thread-safe version ctime_r() is not required
to set tzname. (ISO)
+ (I don't understand)
+ */
+
+ /* Upon successful completion, ctime_r() shall return a pointer to the
string pointed to
+ by buf. When an error is encountered, a null pointer shall be
returned. (POSIX)
+ (Can't think of any way to make it error)
+ */
+
+ return 0;
+}
Modified: trunk/time64.c
==============================================================================
--- trunk/time64.c (original)
+++ trunk/time64.c Wed Jan 7 17:00:35 2009
@@ -740,6 +740,14 @@
}
+char *ctime64_r( const Time64_T* time, char* result ) {
+ struct TM date;
+
+ localtime64_r( time, &date );
+ return asctime64_r( &date, result );
+}
+
+
/* Non-thread safe versions of the above */
struct TM *localtime64(const Time64_T *time) {
return localtime64_r(time, &Static_Return_Date);
@@ -751,4 +759,8 @@
char *asctime64( const struct TM* date ) {
return asctime64_r( date, Static_Return_String );
+}
+
+char *ctime64( const Time64_T* time ) {
+ return asctime64(localtime64(time));
}
Modified: trunk/time64.h
==============================================================================
--- trunk/time64.h (original)
+++ trunk/time64.h Wed Jan 7 17:00:35 2009
@@ -50,6 +50,9 @@
char *asctime64 (const struct TM *);
char *asctime64_r (const struct TM *, char *);
+char *ctime64 (const Time64_T*);
+char *ctime64_r (const Time64_T*, char*);
+
Time64_T timegm64 (const struct TM *);
Time64_T mktime64 (const struct TM *);
Time64_T timelocal64 (const struct TM *);