]> granicus.if.org Git - file/commitdiff
Add cdf_ctime.
authorChristos Zoulas <christos@zoulas.com>
Thu, 10 Feb 2011 17:03:15 +0000 (17:03 +0000)
committerChristos Zoulas <christos@zoulas.com>
Thu, 10 Feb 2011 17:03:15 +0000 (17:03 +0000)
ChangeLog
src/cdf.c
src/cdf.h
src/cdf_time.c
src/readcdf.c

index a35a2608afcf3866edd09a4e06922fa48eef0c81..fb17e0f537b256453c363a97ae479522dbfc2e68 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2011-02-10  12:03  Christos Zoulas <christos@zoulas.com>
+
+       * add cdf_ctime() that prints a meaningful error when time cannot
+         be converted.
+
 2011-02-02  20:40  Christos Zoulas <christos@zoulas.com>
 
        * help and version output to stdout.
index 638f2680ebb67cd80491384372ac95244c7cf995..57e2ff55737c71083d18620d88fe1fb37567a6fd 100644 (file)
--- a/src/cdf.c
+++ b/src/cdf.c
@@ -35,7 +35,7 @@
 #include "file.h"
 
 #ifndef lint
-FILE_RCSID("@(#)$File: cdf.c,v 1.39 2010/07/22 21:59:42 christos Exp $")
+FILE_RCSID("@(#)$File: cdf.c,v 1.40 2011/02/03 01:43:07 christos Exp $")
 #endif
 
 #include <assert.h>
@@ -1108,9 +1108,9 @@ cdf_dump_dir(const cdf_info_t *info, const cdf_header_t *h,
                (void)fprintf(stderr, "Right child: %d\n", d->d_right_child);
                (void)fprintf(stderr, "Flags: 0x%x\n", d->d_flags);
                cdf_timestamp_to_timespec(&ts, d->d_created);
-               (void)fprintf(stderr, "Created %s", ctime(&ts.tv_sec));
+               (void)fprintf(stderr, "Created %s", cdf_ctime(&ts.tv_sec));
                cdf_timestamp_to_timespec(&ts, d->d_modified);
-               (void)fprintf(stderr, "Modified %s", ctime(&ts.tv_sec));
+               (void)fprintf(stderr, "Modified %s", cdf_ctime(&ts.tv_sec));
                (void)fprintf(stderr, "Stream %d\n", d->d_stream_first_sector);
                (void)fprintf(stderr, "Size %d\n", d->d_size);
                switch (d->d_type) {
@@ -1182,7 +1182,7 @@ cdf_dump_property_info(const cdf_property_info_t *info, size_t count)
                        } else {
                                cdf_timestamp_to_timespec(&ts, tp);
                                (void)fprintf(stderr, "timestamp %s",
-                                   ctime(&ts.tv_sec));
+                                   cdf_ctime(&ts.tv_sec));
                        }
                        break;
                case CDF_CLIPBOARD:
index a1b998be38de04a91108e092b7a23ed3252a6c61..f31d9aa385630a072239728f1d1dc9d461d4bd5b 100644 (file)
--- a/src/cdf.h
+++ b/src/cdf.h
@@ -304,6 +304,7 @@ int cdf_print_elapsed_time(char *, size_t, cdf_timestamp_t);
 uint16_t cdf_tole2(uint16_t);
 uint32_t cdf_tole4(uint32_t);
 uint64_t cdf_tole8(uint64_t);
+char *cdf_ctime(const time_t *);
 
 #ifdef CDF_DEBUG
 void cdf_dump_header(const cdf_header_t *);
index 7d83ce84c1a1b8fd4f05d09777d5d1ca2964e66f..5a74c768333c53acad04387f1a2e13e0e8bf3cc5 100644 (file)
@@ -27,7 +27,7 @@
 #include "file.h"
 
 #ifndef lint
-FILE_RCSID("@(#)$File: cdf_time.c,v 1.8 2009/06/20 20:47:30 christos Exp $")
+FILE_RCSID("@(#)$File: cdf_time.c,v 1.9 2010/10/02 15:36:15 christos Exp $")
 #endif
 
 #include <time.h>
@@ -165,6 +165,18 @@ cdf_timespec_to_timestamp(cdf_timestamp_t *t, const struct timespec *ts)
        return 0;
 }
 
+char *
+cdf_ctime(const time_t *sec)
+{
+       static char ctbuf[26];
+       char *ptr = ctime(sec);
+       if (ptr != NULL)
+               return ptr;
+       (void)snprintf(ctbuf, sizeof(ctbuf), "*Bad* 0x%16.16llx\n",
+           (long long)*sec);
+       return ctbuf;
+}
+
 
 #ifdef TEST
 int
@@ -176,7 +188,7 @@ main(int argc, char *argv[])
        char *p, *q;
 
        cdf_timestamp_to_timespec(&ts, tst);
-       p = ctime(&ts.tv_sec);
+       p = cdf_ctime(&ts.tv_sec);
        if ((q = strchr(p, '\n')) != NULL)
                *q = '\0';
        if (strcmp(ref, p) != 0)
index 67b47d0e010ce792fe2f0add6be686a2d250ddff..95d5298d69339acc8343ef58fdf06694e159da68 100644 (file)
@@ -26,7 +26,7 @@
 #include "file.h"
 
 #ifndef lint
-FILE_RCSID("@(#)$File: readcdf.c,v 1.22 2010/01/20 01:36:55 christos Exp $")
+FILE_RCSID("@(#)$File: readcdf.c,v 1.23 2010/02/20 15:19:53 rrt Exp $")
 #endif
 
 #include <stdlib.h>
@@ -125,7 +125,7 @@ cdf_file_property_info(struct magic_set *ms, const cdf_property_info_t *info,
                                 } else {
                                         char *c, *ec;
                                         cdf_timestamp_to_timespec(&ts, tp);
-                                        c = ctime(&ts.tv_sec);
+                                        c = cdf_ctime(&ts.tv_sec);
                                         if ((ec = strchr(c, '\n')) != NULL)
                                                 *ec = '\0';