[hatari-devel] Help in verifying fix for yet-another Windows localtime() issue? |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/hatari-devel Archives
]
Hi,
There seems to be yet-another Windows localtime() issue reported
at atari-forum:
http://www.atari-forum.com/viewtopic.php?f=51&t=24999
Attached is a potential fix for it.
Could somebody with Windows try whether the problem can be reproduced
and whether the attached patch fixes it or not (so that I know should I
commit the patch or not)?
- Eero
diff -r 51b0f42111bd src/gemdos.c
--- a/src/gemdos.c Wed May 08 18:58:37 2013 +0200
+++ b/src/gemdos.c Thu May 09 13:40:35 2013 +0300
@@ -158,7 +158,7 @@
* Routine to convert time and date to GEMDOS format.
* Originally from the STonX emulator. (cheers!)
*/
-static bool GemDOS_DateTime2Tos(time_t t, DATETIME *DateTime)
+static void GemDOS_DateTime2Tos(time_t t, DATETIME *DateTime, const char *fname)
{
struct tm *x;
@@ -166,15 +166,18 @@
x = localtime(&t);
if (x == NULL)
- return false;
-
+ {
+ Log_Printf(LOG_WARN, "WARNING: '%s' timestamp is invalid for (Windows?) localtime(), defaulting to TOS epoch!", fname);
+ DateTime->timeword = 0;
+ DateTime->dateword = 0;
+ return;
+ }
/* Bits: 0-4 = secs/2, 5-10 = mins, 11-15 = hours (24-hour format) */
DateTime->timeword = (x->tm_sec>>1)|(x->tm_min<<5)|(x->tm_hour<<11);
/* Bits: 0-4 = day (1-31), 5-8 = month (1-12), 9-15 = years (since 1980) */
DateTime->dateword = x->tm_mday | ((x->tm_mon+1)<<5)
| (((x->tm_year-80 > 0) ? x->tm_year-80 : 0) << 9);
- return true;
}
/*-----------------------------------------------------------------------*/
@@ -184,12 +187,15 @@
*/
static bool GemDOS_GetFileInformation(int Handle, DATETIME *DateTime)
{
- struct stat filestat;
-
- if (stat(FileHandles[Handle].szActualName, &filestat) != 0)
- return false;
-
- return GemDOS_DateTime2Tos(filestat.st_mtime, DateTime);
+ const char *fname = FileHandles[Handle].szActualName;
+ struct stat fstat;
+
+ if (stat(fname, &fstat) == 0)
+ {
+ GemDOS_DateTime2Tos(fstat.st_mtime, DateTime, fname);
+ return true;
+ }
+ return false;
}
/*-----------------------------------------------------------------------*/
@@ -291,8 +297,7 @@
if (nFileAttr != 0 && !(nAttrMask & nFileAttr))
return 1;
- if (!GemDOS_DateTime2Tos(filestat.st_mtime, &DateTime))
- return -3;
+ GemDOS_DateTime2Tos(filestat.st_mtime, &DateTime, tempstr);
/* convert to atari-style uppercase */
Str_Filename2TOSname(file->d_name, pDTA->dta_name);