diff options
Diffstat (limited to 'src/tools/imgtool/modules')
-rw-r--r-- | src/tools/imgtool/modules/amiga.cpp | 31 | ||||
-rw-r--r-- | src/tools/imgtool/modules/cybiko.cpp | 16 | ||||
-rw-r--r-- | src/tools/imgtool/modules/cybikoxt.cpp | 17 | ||||
-rw-r--r-- | src/tools/imgtool/modules/fat.cpp | 36 | ||||
-rw-r--r-- | src/tools/imgtool/modules/mac.cpp | 4 | ||||
-rw-r--r-- | src/tools/imgtool/modules/macbin.cpp | 4 | ||||
-rw-r--r-- | src/tools/imgtool/modules/macutil.cpp | 40 | ||||
-rw-r--r-- | src/tools/imgtool/modules/macutil.h | 3 | ||||
-rw-r--r-- | src/tools/imgtool/modules/prodos.cpp | 35 | ||||
-rw-r--r-- | src/tools/imgtool/modules/thomson.cpp | 24 |
10 files changed, 104 insertions, 106 deletions
diff --git a/src/tools/imgtool/modules/amiga.cpp b/src/tools/imgtool/modules/amiga.cpp index 7a7a3572320..c1c5563012e 100644 --- a/src/tools/imgtool/modules/amiga.cpp +++ b/src/tools/imgtool/modules/amiga.cpp @@ -2,7 +2,7 @@ // copyright-holders:Dirk Best /**************************************************************************** - amiga.c + amiga.cpp Amiga floppies @@ -290,15 +290,11 @@ static int is_leap(int year) /* Convert amiga time to standard time */ -static time_t amiga_crack_time(amiga_date *date) +static imgtool::datetime amiga_crack_time(amiga_date *date) { int month_days[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; int year = 1978, month = 1, year_days = 365; /* base date */ int day = date->days; - struct tm t; - - /* initialize struct */ - memset(&t, 0, sizeof(t)); /* first calculate the year */ while (day >= year_days) @@ -316,15 +312,16 @@ static time_t amiga_crack_time(amiga_date *date) month++; } - /* fill the struct with our calculated values */ - t.tm_year = year - 1900; - t.tm_mon = month - 1; - t.tm_mday = day + 1; - t.tm_hour = date->mins / 60; - t.tm_min = date->mins % 60; - t.tm_sec = date->ticks / 50; + // fill the struct with our calculated values + util::arbitrary_datetime dt; + dt.year = year; + dt.month = month; + dt.day_of_month = day; + dt.hour = date->mins / 60; + dt.minute = date->mins % 60; + dt.second = date->ticks / 50; - return mktime(&t); + return imgtool::datetime(imgtool::datetime::datetime_type::LOCAL, dt); } @@ -1785,9 +1782,9 @@ static void amiga_image_info(imgtool::image &img, std::ostream &stream) ret = read_root_block(img, &root); if (ret) return; - t_c = amiga_crack_time(&root.c); - t_v = amiga_crack_time(&root.v); - t_r = amiga_crack_time(&root.r); + t_c = amiga_crack_time(&root.c).to_time_t(); + t_v = amiga_crack_time(&root.v).to_time_t(); + t_r = amiga_crack_time(&root.r).to_time_t(); strftime(c, sizeof(c), "%d-%b-%y %H:%M:%S", localtime(&t_c)); strftime(v, sizeof(v), "%d-%b-%y %H:%M:%S", localtime(&t_v)); diff --git a/src/tools/imgtool/modules/cybiko.cpp b/src/tools/imgtool/modules/cybiko.cpp index 81184533291..4ba278ddd2b 100644 --- a/src/tools/imgtool/modules/cybiko.cpp +++ b/src/tools/imgtool/modules/cybiko.cpp @@ -64,15 +64,19 @@ static cybiko_file_system *get_cfs(imgtool::image &image) } // 2208988800 is the number of seconds between 1900/01/01 and 1970/01/01 +typedef util::arbitrary_clock<std::uint32_t, 1900, 1, 1, 0, 0, 0, std::ratio<1, 1> > cybiko_clock; -static time_t time_crack( uint32_t cfs_time) +imgtool::datetime cybiko_time_crack(uint32_t cfs_time) { - return (time_t)(cfs_time - 2208988800UL); + cybiko_clock::duration d(cfs_time); + std::chrono::time_point<cybiko_clock> tp(d); + return imgtool::datetime(imgtool::datetime::datetime_type::LOCAL, tp); } -static uint32_t time_setup( time_t ansi_time) +uint32_t cybiko_time_setup(const imgtool::datetime &t) { - return (uint32_t)(ansi_time + 2208988800UL); + auto cybiko_time_point = cybiko_clock::from_arbitrary_time_point(t.time_point()); + return cybiko_time_point.time_since_epoch().count(); } static uint32_t buffer_read_32_be( uint8_t *buffer) @@ -412,7 +416,7 @@ static imgtoolerr_t cybiko_image_next_enum(imgtool::directory &enumeration, imgt { strcpy(ent.filename, file.name); ent.filesize = file.size; - ent.lastmodified_time = time_crack(file.date); + ent.lastmodified_time = cybiko_time_crack(file.date); ent.filesize = file.size; } else @@ -501,7 +505,7 @@ static imgtoolerr_t cybiko_image_write_file(imgtool::partition &partition, const { buffer[6] = 0; strcpy(BLOCK_FILENAME(buffer), filename); - buffer_write_32_be( buffer + 6 + FILE_HEADER_SIZE - 4, time_setup( time( NULL))); + buffer_write_32_be(buffer + 6 + FILE_HEADER_SIZE - 4, cybiko_time_setup(imgtool::datetime::now(imgtool::datetime::datetime_type::LOCAL))); sourcef.read(buffer + 6 + FILE_HEADER_SIZE, buffer[1]); } else diff --git a/src/tools/imgtool/modules/cybikoxt.cpp b/src/tools/imgtool/modules/cybikoxt.cpp index a649dbe8909..8c2980de449 100644 --- a/src/tools/imgtool/modules/cybikoxt.cpp +++ b/src/tools/imgtool/modules/cybikoxt.cpp @@ -55,17 +55,8 @@ static cybiko_file_system *get_cfs(imgtool::image &image) return (cybiko_file_system*)image.extra_bytes(); } -// 2208988800 is the number of seconds between 1900/01/01 and 1970/01/01 - -static time_t time_crack( uint32_t cfs_time) -{ - return (time_t)(cfs_time - 2208988800UL); -} - -static uint32_t time_setup( time_t ansi_time) -{ - return (uint32_t)(ansi_time + 2208988800UL); -} +extern imgtool::datetime cybiko_time_crack(uint32_t cfs_time); +extern uint32_t cybiko_time_setup(const imgtool::datetime &t); static uint32_t buffer_read_32_be( uint8_t *buffer) { @@ -382,7 +373,7 @@ static imgtoolerr_t cybiko_image_next_enum(imgtool::directory &enumeration, imgt { strcpy(ent.filename, file.name); ent.filesize = file.size; - ent.lastmodified_time = time_crack(file.date); + ent.lastmodified_time = cybiko_time_crack(file.date); ent.filesize = file.size; } else @@ -475,7 +466,7 @@ static imgtoolerr_t cybiko_image_write_file(imgtool::partition &partition, const { buffer[6] = 0x20; strcpy(BLOCK_FILENAME(buffer), filename); - buffer_write_32_be( buffer + 6 + FILE_HEADER_SIZE - 4, time_setup( time( NULL))); + buffer_write_32_be( buffer + 6 + FILE_HEADER_SIZE - 4, cybiko_time_setup(imgtool::datetime::now(imgtool::datetime::datetime_type::LOCAL))); sourcef.read(buffer + 6 + FILE_HEADER_SIZE, buffer[1]); } else diff --git a/src/tools/imgtool/modules/fat.cpp b/src/tools/imgtool/modules/fat.cpp index aa15a4783f6..e1b3a914c2b 100644 --- a/src/tools/imgtool/modules/fat.cpp +++ b/src/tools/imgtool/modules/fat.cpp @@ -2,7 +2,7 @@ // copyright-holders:Raphael Nabet /**************************************************************************** - fat.c + fat.cpp PC FAT disk images @@ -184,8 +184,8 @@ struct fat_dirent uint32_t first_cluster; uint32_t dirent_sector_index; uint32_t dirent_sector_offset; - time_t creation_time; - time_t lastmodified_time; + imgtool::datetime creation_time; + imgtool::datetime lastmodified_time; }; struct fat_freeentry_info @@ -1241,33 +1241,25 @@ static void fat_cannonicalize_sfn(char *sfn, const uint8_t *sfn_bytes) -static time_t fat_crack_time(uint32_t fat_time) +static imgtool::datetime fat_crack_time(uint32_t fat_time) { - struct tm t; - time_t now; - - time(&now); - t = *localtime(&now); - - t.tm_sec = ((fat_time >> 0) & 0x001F) * 2; - t.tm_min = ((fat_time >> 5) & 0x003F); - t.tm_hour = ((fat_time >> 11) & 0x001F); - t.tm_mday = ((fat_time >> 16) & 0x001F); - t.tm_mon = ((fat_time >> 21) & 0x000F); - t.tm_year = ((fat_time >> 25) & 0x007F) + 1980 - 1900; - - return mktime(&t); + util::arbitrary_datetime dt; + dt.second = ((fat_time >> 0) & 0x001F) * 2; + dt.minute = ((fat_time >> 5) & 0x003F); + dt.hour = ((fat_time >> 11) & 0x001F); + dt.day_of_month = ((fat_time >> 16) & 0x001F); + dt.month = ((fat_time >> 21) & 0x000F); + dt.year = ((fat_time >> 25) & 0x007F) + 1980; + return imgtool::datetime(imgtool::datetime::LOCAL, dt); } static uint32_t fat_setup_time(time_t ansi_time) { - struct tm t; - uint32_t result = 0; - - t = *localtime(&ansi_time); + std::tm t = *localtime(&ansi_time); + uint32_t result = 0; result |= (((uint32_t) (t.tm_sec / 2)) & 0x001F) << 0; result |= (((uint32_t) t.tm_min) & 0x003F) << 5; result |= (((uint32_t) t.tm_hour) & 0x001F) << 11; diff --git a/src/tools/imgtool/modules/mac.cpp b/src/tools/imgtool/modules/mac.cpp index 546a153a7e8..f606451c6e1 100644 --- a/src/tools/imgtool/modules/mac.cpp +++ b/src/tools/imgtool/modules/mac.cpp @@ -5827,10 +5827,10 @@ static imgtoolerr_t mac_image_getattrs(imgtool::partition &partition, const char break; case IMGTOOLATTR_TIME_CREATED: - values[i].t = mac_crack_time(cat_info.createDate); + values[i].t = mac_crack_time(cat_info.createDate).to_time_t(); break; case IMGTOOLATTR_TIME_LASTMODIFIED: - values[i].t = mac_crack_time(cat_info.modifyDate); + values[i].t = mac_crack_time(cat_info.modifyDate).to_time_t(); break; } } diff --git a/src/tools/imgtool/modules/macbin.cpp b/src/tools/imgtool/modules/macbin.cpp index c937ff22163..30400dffdbb 100644 --- a/src/tools/imgtool/modules/macbin.cpp +++ b/src/tools/imgtool/modules/macbin.cpp @@ -323,8 +323,8 @@ static imgtoolerr_t macbinary_writefile(imgtool::partition &partition, const cha return err; /* set up attributes */ - attr_values[0].t = mac_crack_time(creation_time); - attr_values[1].t = mac_crack_time(lastmodified_time); + attr_values[0].t = mac_crack_time(creation_time).to_time_t(); + attr_values[1].t = mac_crack_time(lastmodified_time).to_time_t(); attr_values[2].i = type_code; attr_values[3].i = creator_code; attr_values[4].i = finder_flags; diff --git a/src/tools/imgtool/modules/macutil.cpp b/src/tools/imgtool/modules/macutil.cpp index 1bab14487cd..08c8b84989f 100644 --- a/src/tools/imgtool/modules/macutil.cpp +++ b/src/tools/imgtool/modules/macutil.cpp @@ -15,32 +15,54 @@ typedef util::arbitrary_clock<std::uint32_t, 1904, 1, 1, 0, 0, 0, std::ratio<1, 1> > classic_mac_clock; -time_t mac_crack_time(uint32_t t) +//------------------------------------------------- +// mac_crack_time +//------------------------------------------------- + +imgtool::datetime mac_crack_time(uint32_t t) { classic_mac_clock::duration d(t); - std::chrono::time_point<std::chrono::system_clock> tp = classic_mac_clock::to_system_clock(std::chrono::time_point<classic_mac_clock>(d)); - return std::chrono::system_clock::to_time_t(tp); + std::chrono::time_point<classic_mac_clock> tp(d); + return imgtool::datetime(imgtool::datetime::datetime_type::LOCAL, tp); } +//------------------------------------------------- +// mac_setup_time +//------------------------------------------------- -uint32_t mac_setup_time(time_t t) +uint32_t mac_setup_time(const imgtool::datetime &t) { - auto system_time_point = std::chrono::system_clock::from_time_t(t); - auto mac_time_point = classic_mac_clock::from_system_clock(system_time_point); + auto mac_time_point = classic_mac_clock::from_arbitrary_time_point(t.time_point()); return mac_time_point.time_since_epoch().count(); } +//------------------------------------------------- +// mac_setup_time +//------------------------------------------------- + +uint32_t mac_setup_time(time_t t) +{ + imgtool::datetime dt(imgtool::datetime::datetime_type::LOCAL, t); + return mac_setup_time(dt); +} + + +//------------------------------------------------- +// mac_time_now +//------------------------------------------------- uint32_t mac_time_now(void) { - time_t now; - time(&now); - return mac_setup_time(now); + imgtool::datetime dt = imgtool::datetime::now(imgtool::datetime::datetime_type::LOCAL); + return mac_setup_time(dt); } +//------------------------------------------------- +// mac_identify_fork +//------------------------------------------------- imgtoolerr_t mac_identify_fork(const char *fork_string, mac_fork_t *fork_num) { diff --git a/src/tools/imgtool/modules/macutil.h b/src/tools/imgtool/modules/macutil.h index fcec0728c95..0ab3315874b 100644 --- a/src/tools/imgtool/modules/macutil.h +++ b/src/tools/imgtool/modules/macutil.h @@ -29,7 +29,8 @@ enum mac_filecategory_t /* converting Classic Mac OS time <==> Imgtool time */ -time_t mac_crack_time(uint32_t t); +imgtool::datetime mac_crack_time(uint32_t t); +uint32_t mac_setup_time(const imgtool::datetime &t); uint32_t mac_setup_time(time_t t); uint32_t mac_time_now(void); diff --git a/src/tools/imgtool/modules/prodos.cpp b/src/tools/imgtool/modules/prodos.cpp index 4c01612283f..6db41ae529b 100644 --- a/src/tools/imgtool/modules/prodos.cpp +++ b/src/tools/imgtool/modules/prodos.cpp @@ -186,24 +186,19 @@ enum creation_policy_t -static time_t prodos_crack_time(uint32_t prodos_time) -{ - struct tm t; - time_t now; - - time(&now); - t = *localtime(&now); - - t.tm_sec = 0; - t.tm_min = (prodos_time >> 16) & 0x3F; - t.tm_hour = (prodos_time >> 24) & 0x1F; - t.tm_mday = (prodos_time >> 0) & 0x1F; - t.tm_mon = (prodos_time >> 5) & 0x0F; - t.tm_year = (prodos_time >> 9) & 0x7F; - - if (t.tm_year <= 49) - t.tm_year += 100; - return mktime(&t); +static imgtool::datetime prodos_crack_time(uint32_t prodos_time) +{ + util::arbitrary_datetime dt; + dt.second = 0; + dt.minute = ((prodos_time >> 16) & 0x3F); + dt.hour = ((prodos_time >> 24) & 0x1F); + dt.day_of_month = ((prodos_time >> 0) & 0x1F); + dt.month = ((prodos_time >> 5) & 0x0F) + 1; + dt.year = ((prodos_time >> 9) & 0x7F) + 1900; + if (dt.year <= 1949) + dt.year += 100; + + return imgtool::datetime(imgtool::datetime::datetime_type::LOCAL, dt); } @@ -2039,10 +2034,10 @@ static imgtoolerr_t prodos_diskimage_getattrs(imgtool::partition &partition, con break; case IMGTOOLATTR_TIME_CREATED: - values[i].t = prodos_crack_time(ent.creation_time); + values[i].t = prodos_crack_time(ent.creation_time).to_time_t(); break; case IMGTOOLATTR_TIME_LASTMODIFIED: - values[i].t = prodos_crack_time(ent.lastmodified_time); + values[i].t = prodos_crack_time(ent.lastmodified_time).to_time_t(); break; } } diff --git a/src/tools/imgtool/modules/thomson.cpp b/src/tools/imgtool/modules/thomson.cpp index d7adce9dbb9..d2848a00cde 100644 --- a/src/tools/imgtool/modules/thomson.cpp +++ b/src/tools/imgtool/modules/thomson.cpp @@ -485,24 +485,20 @@ static void thom_conv_filename(const char* s, char name[9], char ext[4]) } } -static time_t thom_crack_time(thom_dirent* d) +static imgtool::datetime thom_crack_time(thom_dirent* d) { - struct tm t; - time_t now; - /* check */ - if ( d->day < 1 || d->day > 31 || d->month < 1 || d->month > 12 ) return 0; + if ( d->day < 1 || d->day > 31 || d->month < 1 || d->month > 12 ) return imgtool::datetime(); /* converts */ - time( &now ); - t = *localtime( &now ); - t.tm_sec = 0; - t.tm_min = 0; - t.tm_hour = 0; - t.tm_mday = d->day; - t.tm_mon = d->month - 1; - t.tm_year = (d->year < 65 ) ? d->year + 100 : d->year; - return mktime(&t); + util::arbitrary_datetime dt; + dt.second = 0; + dt.minute = 0; + dt.hour = 0; + dt.day_of_month = d->day; + dt.month = d->month; + dt.year = d->year + (d->year < 65 ? 2000 : 1900); + return imgtool::datetime(imgtool::datetime::datetime_type::LOCAL, dt); } static void thom_make_time(thom_dirent* d, time_t time) |