DirectoryStream.st
branchjv
changeset 19662 1d6b7f21e0aa
parent 18786 237a87b4fe8f
parent 19651 59a06f7e5116
child 19863 513bd7237fe7
--- a/DirectoryStream.st	Tue Apr 26 21:57:25 2016 +0100
+++ b/DirectoryStream.st	Wed Apr 27 07:53:49 2016 +0100
@@ -141,6 +141,8 @@
 # define UINT STX_UINT
 
 # define __HANDLEVal(o)  (HANDLE)__externalAddressVal(o)
+// extern OBJ FileTimeToOsTime();
+extern OBJ FileTimeToOsTime1970();
 #endif /* WIN32 */
 
 #include "stxOSDefs.h"
@@ -524,20 +526,20 @@
     |nextResult resultInfo|
 
     (hitEOF or:[readAheadEntry isNil]) ifTrue:[
-        ^ self pastEndRead
+	^ self pastEndRead
     ].
 
     nextResult := OperatingSystem nextLinkInfoFrom:self dirPointer:dirPointer.
     nextResult isNil ifTrue:[
-        hitEOF := true.
+	hitEOF := true.
     ].
     readAheadEntry notNil ifTrue:[
-        resultInfo := readAheadEntry.
-        readAheadEntry := nextResult.
-        ^ resultInfo
+	resultInfo := readAheadEntry.
+	readAheadEntry := nextResult.
+	^ resultInfo
     ].
     nextResult isNil ifTrue:[
-        ^ self pastEndRead
+	^ self pastEndRead
     ].
     ^ nextResult
 ! !
@@ -583,135 +585,135 @@
 
     ok = false;
     if (__INST(dirPointer) == nil) {
-        if (__isStringLike(encodedPathName)) {
-            __BEGIN_INTERRUPTABLE__
-            __threadErrno = 0;
-            do {
-                d = opendir((char *) __stringVal(encodedPathName));
-            } while ((d == NULL) && (__threadErrno == EINTR));
-            __END_INTERRUPTABLE__
+	if (__isStringLike(encodedPathName)) {
+	    __BEGIN_INTERRUPTABLE__
+	    __threadErrno = 0;
+	    do {
+		d = opendir((char *) __stringVal(encodedPathName));
+	    } while ((d == NULL) && (__threadErrno == EINTR));
+	    __END_INTERRUPTABLE__
 
-            if (d == NULL) {
-                error = __mkSmallInteger(__threadErrno);
-            } else {
-                dp = __MKEXTERNALADDRESS(d); __INST(dirPointer) = dp; __STORE(self, dp);
-                ok = true;
-            }
-        }
+	    if (d == NULL) {
+		error = __mkSmallInteger(__threadErrno);
+	    } else {
+		dp = __MKEXTERNALADDRESS(d); __INST(dirPointer) = dp; __STORE(self, dp);
+		ok = true;
+	    }
+	}
     }
 #else
 #ifdef WIN32
     HANDLE d;
     OBJ path, dp;
     union {
-        char pattern[MAXPATHLEN];
-        wchar_t wpattern[MAXPATHLEN];
+	char pattern[MAXPATHLEN];
+	wchar_t wpattern[MAXPATHLEN];
     } uP;
     union {
-        WIN32_FIND_DATAA data;
-        WIN32_FIND_DATAW wdata;
+	WIN32_FIND_DATAA data;
+	WIN32_FIND_DATAW wdata;
     } uD;
 
     ok = false;
     if (__INST(dirPointer) == nil) {
-        path = __INST(pathName);
-        if (__isStringLike(path)) {
-            int l = __stringSize(path);
+	path = __INST(pathName);
+	if (__isStringLike(path)) {
+	    int l = __stringSize(path);
 
-            if (l < (MAXPATHLEN-4)) {
-                strncpy(uP.pattern, __stringVal(path), l);
-                strcpy(uP.pattern+l, "\\*");
+	    if (l < (MAXPATHLEN-4)) {
+		strncpy(uP.pattern, __stringVal(path), l);
+		strcpy(uP.pattern+l, "\\*");
 
-                do {
-                    __threadErrno = 0;
-                    d = STX_API_NOINT_CALL2( "FindFirstFileA", FindFirstFileA, uP.pattern, &uD.data );
-                } while ((d < 0) && (__threadErrno == EINTR));
+		do {
+		    __threadErrno = 0;
+		    d = STX_API_NOINT_CALL2( "FindFirstFileA", FindFirstFileA, uP.pattern, &uD.data );
+		} while ((d < 0) && (__threadErrno == EINTR));
 
-                if (d == INVALID_HANDLE_VALUE) {
-                    error = __mkSmallInteger(GetLastError());
-                } else {
-                    dp = __MKEXTERNALADDRESS(d); __INST(dirPointer) = dp; __STORE(self, dp);
+		if (d == INVALID_HANDLE_VALUE) {
+		    error = __mkSmallInteger(GetLastError());
+		} else {
+		    dp = __MKEXTERNALADDRESS(d); __INST(dirPointer) = dp; __STORE(self, dp);
 
-                    fileSize   = __MKLARGEINT64(1, uD.data.nFileSizeLow, uD.data.nFileSizeHigh );
-                    osPathname = __MKSTRING( uD.data.cFileName );
-                    osFileAttributes = __mkSmallInteger( uD.data.dwFileAttributes );
+		    fileSize   = __MKLARGEINT64(1, uD.data.nFileSizeLow, uD.data.nFileSizeHigh );
+		    osPathname = __MKSTRING( uD.data.cFileName );
+		    osFileAttributes = __mkSmallInteger( uD.data.dwFileAttributes );
 
-                    osCrtTime = FileTimeToOsTime(&uD.data.ftCreationTime);
-                    osAccTime = FileTimeToOsTime(&uD.data.ftLastAccessTime);
-                    osModTime = FileTimeToOsTime(&uD.data.ftLastWriteTime);
-                    ok = true;
-                }
-            }
-        }
-        else if (__isUnicode16String(path)) {
-            int l = __unicode16StringSize(path);
-            int i;
+		    osCrtTime = FileTimeToOsTime1970(&uD.data.ftCreationTime);
+		    osAccTime = FileTimeToOsTime1970(&uD.data.ftLastAccessTime);
+		    osModTime = FileTimeToOsTime1970(&uD.data.ftLastWriteTime);
+		    ok = true;
+		}
+	    }
+	}
+	else if (__isUnicode16String(path)) {
+	    int l = __unicode16StringSize(path);
+	    int i;
 
-            if (l < (MAXPATHLEN-4)) {
-                for (i=0; i<l; i++) {
-                    uP.wpattern[i] = __unicode16StringVal(path)[i];
-                }
-                uP.wpattern[i++] = '\\';
-                uP.wpattern[i++] = '*';
-                uP.wpattern[i] = 0;
+	    if (l < (MAXPATHLEN-4)) {
+		for (i=0; i<l; i++) {
+		    uP.wpattern[i] = __unicode16StringVal(path)[i];
+		}
+		uP.wpattern[i++] = '\\';
+		uP.wpattern[i++] = '*';
+		uP.wpattern[i] = 0;
 
-                do {
-                    __threadErrno = 0;
-                    d = STX_API_NOINT_CALL2( "FindFirstFileW", FindFirstFileW, uP.wpattern, &uD.wdata );
-                } while ((d < 0) && (__threadErrno == EINTR));
+		do {
+		    __threadErrno = 0;
+		    d = STX_API_NOINT_CALL2( "FindFirstFileW", FindFirstFileW, uP.wpattern, &uD.wdata );
+		} while ((d < 0) && (__threadErrno == EINTR));
 
-                if (d == INVALID_HANDLE_VALUE) {
-                    error = __mkSmallInteger(GetLastError());
-                } else {
-                    dp = __MKEXTERNALADDRESS(d); __INST(dirPointer) = dp; __STORE(self, dp);
+		if (d == INVALID_HANDLE_VALUE) {
+		    error = __mkSmallInteger(GetLastError());
+		} else {
+		    dp = __MKEXTERNALADDRESS(d); __INST(dirPointer) = dp; __STORE(self, dp);
 
-                    fileSize   = __MKLARGEINT64(1, uD.wdata.nFileSizeLow, uD.wdata.nFileSizeHigh );
-                    osPathname = __MKU16STRING( uD.wdata.cFileName );
-                    osFileAttributes = __mkSmallInteger( uD.data.dwFileAttributes );
+		    fileSize   = __MKLARGEINT64(1, uD.wdata.nFileSizeLow, uD.wdata.nFileSizeHigh );
+		    osPathname = __MKU16STRING( uD.wdata.cFileName );
+		    osFileAttributes = __mkSmallInteger( uD.data.dwFileAttributes );
 
-                    osCrtTime = FileTimeToOsTime(&uD.wdata.ftCreationTime);
-                    osAccTime = FileTimeToOsTime(&uD.wdata.ftLastAccessTime);
-                    osModTime = FileTimeToOsTime(&uD.wdata.ftLastWriteTime);
-                    ok = true;
-                }
-            }
-        }
+		    osCrtTime = FileTimeToOsTime1970(&uD.wdata.ftCreationTime);
+		    osAccTime = FileTimeToOsTime1970(&uD.wdata.ftLastAccessTime);
+		    osModTime = FileTimeToOsTime1970(&uD.wdata.ftLastWriteTime);
+		    ok = true;
+		}
+	    }
+	}
     }
 #endif
 #endif
 %}.
 
     ok == true ifTrue:[
-        self registerForFinalization.
-        osPathname isNil ifTrue:[
-            "UNIX: does not automatically provide the first entry"
+	self registerForFinalization.
+	osPathname isNil ifTrue:[
+	    "UNIX: does not automatically provide the first entry"
 
-            StreamError handle:[:ex |
-                self close.
-                ex reject.
-            ] do:[
-                readAheadEntry := OperatingSystem nextLinkInfoFrom:self dirPointer:dirPointer.
-            ].
-        ] ifFalse:[
-            "Windows already provides the first entry's info"
+	    StreamError handle:[:ex |
+		self close.
+		ex reject.
+	    ] do:[
+		readAheadEntry := OperatingSystem nextLinkInfoFrom:self dirPointer:dirPointer.
+	    ].
+	] ifFalse:[
+	    "Windows already provides the first entry's info"
 
-            readAheadEntry := OperatingSystem
-                linkInfoFor:osPathname
-                fileSize:fileSize
-                fileAttributes:osFileAttributes
-                osCrtTime:osCrtTime
-                osAccTime:osAccTime
-                osModTime:osModTime
-        ].
+	    readAheadEntry := OperatingSystem
+		linkInfoFor:osPathname
+		fileSize:fileSize
+		fileAttributes:osFileAttributes
+		osCrtTime:osCrtTime
+		osAccTime:osAccTime
+		osModTime:osModTime
+	].
 
-        ^ self
+	^ self
     ].
 
     ok notNil ifTrue:[
-        dirPointer notNil ifTrue:[^ self errorAlreadyOpen].
+	dirPointer notNil ifTrue:[^ self errorAlreadyOpen].
     ].
     error notNil ifTrue:[
-        ^ self openError:(lastErrorNumber := error).
+	^ self openError:(lastErrorNumber := error).
     ].
     ^ nil
 !
@@ -768,4 +770,3 @@
 version_CVS
     ^ '$Header$'
 ! !
-