Skip to content

Commit

Permalink
1.3.2: Internalise unix to squeak time conversion for MacOS
Browse files Browse the repository at this point in the history
  • Loading branch information
akgrant committed Jun 17, 2018
1 parent 2397f46 commit 309a810
Showing 1 changed file with 50 additions and 20 deletions.
70 changes: 50 additions & 20 deletions src/plugins/FileAttributesPlugin/FileAttributesPlugin.c
@@ -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__ ;



Expand All @@ -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;
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -402,6 +400,38 @@ 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;

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;
return squeakTime;
}


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

/* FileAttributesPlugin>>#fileCreationTimeFor:length:to: */
Expand Down Expand Up @@ -598,11 +628,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) */
Expand Down Expand Up @@ -809,11 +839,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) */
Expand Down Expand Up @@ -972,7 +1002,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) */
}
Expand All @@ -987,7 +1017,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) */
}
Expand All @@ -998,7 +1028,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) */
}
Expand Down Expand Up @@ -1376,7 +1406,7 @@ primitiveRewinddir(void)
EXPORT(sqInt)
primitiveVersionString(void)
{
popthenPush(1, stringFromCString("1.3.1"));
popthenPush(1, stringFromCString("1.3.2"));
return 0;
}

Expand Down Expand Up @@ -1550,11 +1580,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) */
Expand Down

0 comments on commit 309a810

Please sign in to comment.