Skip to content

Commit

Permalink
Factor out all uses of ctime()
Browse files Browse the repository at this point in the history
  • Loading branch information
jivanpal committed Aug 29, 2021
1 parent 7d2c295 commit 746c90e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 10 deletions.
1 change: 0 additions & 1 deletion include/drat/string/fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

#include <drat/asize.h>
#include <drat/time.h>
Expand Down
10 changes: 3 additions & 7 deletions include/drat/string/j.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

#if defined(__APPLE__) || defined(__BSD__)
#include <sys/stat.h>
Expand Down Expand Up @@ -173,12 +172,9 @@ void print_j_inode_val(j_inode_val_t* val, uint16_t val_len) {
printf("Uncompressed size: %s\n", tmp_string);
free(tmp_string);

time_t timestamp = val->create_time / 1000000000;
printf("Creation time: %s", ctime(&timestamp));
timestamp = val->mod_time / 1000000000;
printf("Last modification time: %s", ctime(&timestamp));
timestamp = val->change_time / 1000000000;
printf("Last access time: %s", ctime(&timestamp));
printf("Creation time: %s", apfs_timestamp_to_string(val->create_time));
printf("Last modification time: %s", apfs_timestamp_to_string(val->mod_time));
printf("Last access time: %s", apfs_timestamp_to_string(val->change_time));
printf("\n");

printf("Number of children / hard links: %u\n", val->nchildren);
Expand Down
5 changes: 3 additions & 2 deletions include/drat/time.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

/**
* Get a human-readable timestamp from an APFS timestamp (Unix timestamp in
* nanoseconds). The return value is a newline-terminated C-string store in the
* static buffer provided by the `ctime` API, so it must not be freed.
* nanoseconds). The return value is a newline-terminated C-string stored in
* the static buffer provided by the `ctime` API, so it must not be freed, and
* this function is not thread-safe.
*/
char* apfs_timestamp_to_string(uint64_t apfs_timestamp) {
// Dividing timestamps by 10^9 to convert APFS timestamps (Unix timestamps
Expand Down

0 comments on commit 746c90e

Please sign in to comment.