diff options
| author | B. Watson <urchlay@slackware.uk> | 2025-11-29 01:02:02 -0500 |
|---|---|---|
| committer | B. Watson <urchlay@slackware.uk> | 2025-11-29 01:02:02 -0500 |
| commit | 3340301b02ae647cdb286112c32772bda0faf503 (patch) | |
| tree | 6847f4f17dee95c5801e3e80607f2c1f6c1f983c /src/extract.c | |
| parent | 0861fc6fc6614084bad79db36eeae4eefd75ff9e (diff) | |
| download | alftools-3340301b02ae647cdb286112c32772bda0faf503.tar.gz | |
unalf: actually use timestamps from the alf header (and add -T option to not use them).
Diffstat (limited to 'src/extract.c')
| -rw-r--r-- | src/extract.c | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/src/extract.c b/src/extract.c index 305cd4a..6d940a2 100644 --- a/src/extract.c +++ b/src/extract.c @@ -1,5 +1,7 @@ #include "unalf.h" #include "addrs.h" +#include <time.h> +#include <utime.h> int bad_checksum, bad_checksum_count = 0; int new_file = 0; @@ -101,6 +103,32 @@ void fix_filename(void) { } } +void set_datetime() { + u16 t, d; + struct tm tm; + time_t time; + struct utimbuf utb; + + t = dpeek(alf_hdr_time0); + d = dpeek(alf_hdr_date0); + + tm.tm_sec = (t & 0x1f) << 1; + tm.tm_hour = t >> 11; + if(tm.tm_hour == 24) tm.tm_hour = 0; + tm.tm_min = (t >> 5) & 0x3f; + + tm.tm_year = (d >> 9) + 1980 - 1900; + tm.tm_mon = ((d >> 5) & 0x0f) - 1; + tm.tm_mday = (d & 0x1f); + + time = mktime(&tm); + + if(time != (time_t) -1) { + utb.actime = utb.modtime = time; + utime(out_filename, &utb); /* ignore errors */ + } +} + void make_backup(void) { /* up to 12-char FILENAME.EXT, plus a ~, plus null terminator = 14 */ char backup[14]; @@ -162,7 +190,11 @@ void extract_alf(void) { fprintf(stderr, "%s: %s should be %u bytes, but extracted to %u.\n", self, out_filename, getquad(alf_hdr_origsize0), bytes_written); - if(!opts.extract_to_stdout) fclose(out_file); + if(!opts.extract_to_stdout) { + fclose(out_file); + if(!opts.ignore_datetime) + set_datetime(); + } out_filename = 0; } |
