Skip to content
Permalink
Browse files

Merge FileAttributesPlugin 1.3.2: Change from Unix (UTC) timestamps t…

…o Squeak timestamps for file attributes.

Getting UTC timestamps on Windows is problematic...
  • Loading branch information...
akgrant43 committed Jun 17, 2018
2 parents 2cc9f1a + 84433d3 commit 140ff02e7a49f9fbcd6e772cac5828ca3aa2fda5
@@ -150,6 +150,19 @@ unsigned volatile long long
ioUTCMicrosecondsNow() { return currentUTCMicroseconds(); }
#endif /* STACKVM */


/*
* Convert the supplied Unix (UTC) time to Squeak time.
*
* WARNING: On 32 bit platforms time_t is only 32 bits long.
* Since Squeak has an Epoch of 1901 while Unix uses 1970 the
* result is that overflow always occurs for times beyond about 1967.
* The expected result ends up in the image because the value is treated
* as an unsigned integer when converting to an oop.
* convertToSqueakTime should be deprecated in favour of
* convertToLongSqueakTime.
*
*/
time_t convertToSqueakTime(time_t unixTime)
{
#ifdef HAVE_TM_GMTOFF
@@ -165,3 +178,33 @@ time_t convertToSqueakTime(time_t unixTime)
and 52 non-leap years later than Squeak. */
return unixTime + ((52*365UL + 17*366UL) * 24*60*60UL);
}


/*
* Convert the supplied Unix (UTC) time to Squeak time.
*
* Squeak time has an epoch of 1901 and uses local time
* i.e. timezone + daylight savings
*
* Answer an sqLong which is guaranteed to be 64 bits on all platforms.
*/
sqLong convertToLongSqueakTime(time_t unixTime)
{
sqLong result;

result = unixTime;
#ifdef HAVE_TM_GMTOFF
result += localtime(&unixTime)->tm_gmtoff;
#else
# ifdef HAVE_TIMEZONE
result += ((daylight) * 60*60) - timezone;
# else
# error: cannot determine timezone correction
# endif
#endif
/* Squeak epoch is Jan 1, 1901. Unix epoch is Jan 1, 1970: 17 leap years
and 52 non-leap years later than Squeak. */
result += ((52*365UL + 17*366UL) * 24*60*60UL);
return result;
}

@@ -16,4 +16,4 @@

void SetUpTimers(void);
time_t convertToSqueakTime(time_t unixTime);
time_t convertToSqueakTime(time_t unixTime);
sqLong convertToLongSqueakTime(time_t unixTime);
@@ -225,6 +225,7 @@ long ioMicroMSecs(void)
}

time_t convertToSqueakTime(time_t unixTime);
sqLong convertToLongSqueakTime(time_t unixTime);

/* returns the local wall clock time */
sqInt ioSeconds(void)
@@ -261,6 +262,20 @@ usqLong
ioUTCMicrosecondsNow() { return currentUTCMicroseconds(); }
#endif /* STACKVM */



/*
* Convert the supplied Unix (UTC) time to Squeak time.
*
* WARNING: On 32 bit platforms time_t is only 32 bits long.
* Since Squeak has an Epoch of 1901 while Unix uses 1970 the
* result is that overflow always occurs for times beyond about 1967.
* The expected result ends up in the image because the value is treated
* as an unsigned integer when converting to an oop.
* convertToSqueakTime should be deprecated in favour of
* convertToLongSqueakTime.
*
*/
time_t convertToSqueakTime(time_t unixTime)
{
#ifdef HAVE_TM_GMTOFF
@@ -278,6 +293,35 @@ time_t convertToSqueakTime(time_t unixTime)
}


/*
* Convert the supplied Unix (UTC) time to Squeak time.
*
* Squeak time has an epoch of 1901 and uses local time
* i.e. timezone + daylight savings
*
* Answer an sqLong which is guaranteed to be 64 bits on all platforms.
*/
sqLong convertToLongSqueakTime(time_t unixTime)
{
sqLong result;

result = unixTime;
#ifdef HAVE_TM_GMTOFF
result += localtime(&unixTime)->tm_gmtoff;
#else
# ifdef HAVE_TIMEZONE
result += ((daylight) * 60*60) - timezone;
# else
# error: cannot determine timezone correction
# endif
#endif
/* Squeak epoch is Jan 1, 1901. Unix epoch is Jan 1, 1970: 17 leap years
and 52 non-leap years later than Squeak. */
result += ((52*365UL + 17*366UL) * 24*60*60UL);
return result;
}


/*** VM & Image File Naming ***/


@@ -1,9 +1,9 @@
/* Automatically generated by
VMPluginCodeGenerator VMMaker.oscog-topa.2418 uuid: 6a3317fd-ca50-498f-8879-332f920fe363
from
FileAttributesPlugin FileAttributesPlugin.oscog-AlistairGrant.30 uuid: 943fc170-d5c4-4cfd-846c-c3c937a110b5
FileAttributesPlugin * FileAttributesPlugin.oscog-AlistairGrant.30 uuid: 943fc170-d5c4-4cfd-846c-c3c937a110b5
*/
static char __buildInfo[] = "FileAttributesPlugin FileAttributesPlugin.oscog-AlistairGrant.30 uuid: 943fc170-d5c4-4cfd-846c-c3c937a110b5 " __DATE__ ;
static char __buildInfo[] = "FileAttributesPlugin * FileAttributesPlugin.oscog-AlistairGrant.30 uuid: 943fc170-d5c4-4cfd-846c-c3c937a110b5 " __DATE__ ;



@@ -21,9 +21,6 @@ static char __buildInfo[] = "FileAttributesPlugin FileAttributesPlugin.oscog-Ali
#include <winbase.h>
#define FAIL() { return -1; }
#include "sqWin32File.h"
#else
#include "sqMemoryAccess.h"
extern sqLong convertToLongSqueakTime(time_t unixTime);
#endif
typedef struct dirptrstruct {
DIR *dp;
@@ -72,6 +69,7 @@ EXPORT(sqInt) checkAccessmodeto(sqInt pathString, sqInt mode, sqInt *flag);
#if _WIN32
static sqLong convertWinToSqueakTime(SYSTEMTIME st);
#endif /* _WIN32 */
static sqLong faConvertUnixToLongSqueakTime(time_t unixTime);
#if _WIN32
static sqInt fileCreationTimeForlengthto(char *pathString, sqInt pathLength, sqLong *creationDate);
#endif /* _WIN32 */
@@ -187,9 +185,9 @@ extern
struct VirtualMachine* interpreterProxy;
static const char *moduleName =
#ifdef SQUEAK_BUILTIN_PLUGIN
"FileAttributesPlugin FileAttributesPlugin.oscog-AlistairGrant.30 (i)"
"FileAttributesPlugin * FileAttributesPlugin.oscog-AlistairGrant.30 (i)"
#else
"FileAttributesPlugin FileAttributesPlugin.oscog-AlistairGrant.30 (e)"
"FileAttributesPlugin * FileAttributesPlugin.oscog-AlistairGrant.30 (e)"
#endif
;
static void * sCLPfn;
@@ -402,6 +400,43 @@ convertWinToSqueakTime(SYSTEMTIME st)
#endif /* _WIN32 */


/* Convert the supplied Unix (UTC) time to Squeak time.
Squeak time has an epoch of 1901 and uses local time
i.e. timezone + daylight savings
Answer an sqLong which is guaranteed to be 64 bits on all platforms.
*/

/* FileAttributesPlugin>>#faConvertUnixToLongSqueakTime: */
static sqLong
faConvertUnixToLongSqueakTime(time_t unixTime)
{
sqLong squeakTime;


# if defined(_WIN32)
squeakTime = 0;
# else /* defined(_WIN32) */
squeakTime = unixTime;

# if defined(HAVE_TM_GMTOFF)
squeakTime += localtime(&unixTime)->tm_gmtoff;
# else /* defined(HAVE_TM_GMTOFF) */

# if defined(HAVE_TIMEZONE)
squeakTime += (daylight*60*60) - timezone;
# else /* defined(HAVE_TIMEZONE) */

#error: cannot determine timezone correction
# endif /* defined(HAVE_TIMEZONE) */
# endif /* defined(HAVE_TM_GMTOFF) */
squeakTime += (52*365UL + 17*366UL) * 24*60*60UL;
# endif /* defined(_WIN32) */
return squeakTime;
}


/* Get the creationDate for the supplied file. */

/* FileAttributesPlugin>>#fileCreationTimeFor:length:to: */
@@ -598,11 +633,11 @@ fileToAttributeArraymaskarray(char *cPathName, sqInt attributeMask, sqInt *attri

# if defined(_WIN32)
# else /* defined(_WIN32) */
attributeDate = convertToLongSqueakTime((statBufPointer1->st_atime));
attributeDate = faConvertUnixToLongSqueakTime((statBufPointer1->st_atime));
storePointerofObjectwithValue(8, statArray, signed64BitIntegerFor(attributeDate));
attributeDate = convertToLongSqueakTime((statBufPointer1->st_mtime));
attributeDate = faConvertUnixToLongSqueakTime((statBufPointer1->st_mtime));
storePointerofObjectwithValue(9, statArray, signed64BitIntegerFor(attributeDate));
attributeDate = convertToLongSqueakTime((statBufPointer1->st_ctime));
attributeDate = faConvertUnixToLongSqueakTime((statBufPointer1->st_ctime));
storePointerofObjectwithValue(10, statArray, signed64BitIntegerFor(attributeDate));
storePointerofObjectwithValue(11, statArray, nilObject());
# endif /* defined(_WIN32) */
@@ -809,11 +844,11 @@ posixFileTimesFromto(struct stat *statBufPointer, sqInt attributeArray)

# if defined(_WIN32)
# else /* defined(_WIN32) */
attributeDate = convertToLongSqueakTime((statBufPointer->st_atime));
attributeDate = faConvertUnixToLongSqueakTime((statBufPointer->st_atime));
storePointerofObjectwithValue(8, attributeArray, signed64BitIntegerFor(attributeDate));
attributeDate = convertToLongSqueakTime((statBufPointer->st_mtime));
attributeDate = faConvertUnixToLongSqueakTime((statBufPointer->st_mtime));
storePointerofObjectwithValue(9, attributeArray, signed64BitIntegerFor(attributeDate));
attributeDate = convertToLongSqueakTime((statBufPointer->st_ctime));
attributeDate = faConvertUnixToLongSqueakTime((statBufPointer->st_ctime));
storePointerofObjectwithValue(10, attributeArray, signed64BitIntegerFor(attributeDate));
storePointerofObjectwithValue(11, attributeArray, nilObject());
# endif /* defined(_WIN32) */
@@ -972,7 +1007,7 @@ primitiveFileAttribute(void)
}
resultOop = signed64BitIntegerFor(attributeDate);
# else /* defined(_WIN32) */
attributeDate = convertToLongSqueakTime((statBuf.st_atime));
attributeDate = faConvertUnixToLongSqueakTime((statBuf.st_atime));
resultOop = signed64BitIntegerFor(attributeDate);
# endif /* defined(_WIN32) */
}
@@ -987,7 +1022,7 @@ primitiveFileAttribute(void)
}
resultOop = signed64BitIntegerFor(attributeDate);
# else /* defined(_WIN32) */
attributeDate = convertToLongSqueakTime((statBuf.st_mtime));
attributeDate = faConvertUnixToLongSqueakTime((statBuf.st_mtime));
resultOop = signed64BitIntegerFor(attributeDate);
# endif /* defined(_WIN32) */
}
@@ -998,7 +1033,7 @@ primitiveFileAttribute(void)
# if defined(_WIN32)
resultOop = nilObject();
# else /* defined(_WIN32) */
attributeDate = convertToLongSqueakTime((statBuf.st_ctime));
attributeDate = faConvertUnixToLongSqueakTime((statBuf.st_ctime));
resultOop = signed64BitIntegerFor(attributeDate);
# endif /* defined(_WIN32) */
}
@@ -1376,7 +1411,7 @@ primitiveRewinddir(void)
EXPORT(sqInt)
primitiveVersionString(void)
{
popthenPush(1, stringFromCString("1.3.1"));
popthenPush(1, stringFromCString("1.3.2"));
return 0;
}

@@ -1550,11 +1585,11 @@ statArrayFortoArrayfromfileName(char *cPathName, sqInt attributeArray, struct st

# if defined(_WIN32)
# else /* defined(_WIN32) */
attributeDate = convertToLongSqueakTime((statBufPointer->st_atime));
attributeDate = faConvertUnixToLongSqueakTime((statBufPointer->st_atime));
storePointerofObjectwithValue(8, attributeArray, signed64BitIntegerFor(attributeDate));
attributeDate = convertToLongSqueakTime((statBufPointer->st_mtime));
attributeDate = faConvertUnixToLongSqueakTime((statBufPointer->st_mtime));
storePointerofObjectwithValue(9, attributeArray, signed64BitIntegerFor(attributeDate));
attributeDate = convertToLongSqueakTime((statBufPointer->st_ctime));
attributeDate = faConvertUnixToLongSqueakTime((statBufPointer->st_ctime));
storePointerofObjectwithValue(10, attributeArray, signed64BitIntegerFor(attributeDate));
storePointerofObjectwithValue(11, attributeArray, nilObject());
# endif /* defined(_WIN32) */

0 comments on commit 140ff02

Please sign in to comment.
You can’t perform that action at this time.