UnixOperatingSystem.st
changeset 8475 24e7d19b3475
parent 8469 928145276114
child 8490 605b944693e0
--- a/UnixOperatingSystem.st	Fri Aug 13 21:26:17 2004 +0200
+++ b/UnixOperatingSystem.st	Fri Aug 13 21:29:04 2004 +0200
@@ -4669,17 +4669,6 @@
     ^ self primitiveFailed
 !
 
-isSymbolicLink:aPathName
-    "return true, if the given file is a symbolic link"
-
-    ^ (self linkInfoOf:aPathName) notNil
-
-    "
-     OperatingSystem isSymbolicLink:'Make.proto'
-     OperatingSystem isSymbolicLink:'Makefile'
-    "
-!
-
 isValidPath:aPathName
     "return true, if 'aPathName' is a valid path name
      (i.e. the file or directory exists)"
@@ -4736,26 +4725,25 @@
 !
 
 linkInfoOf:aPathName
-    "return some object filled with info for the file 'aPathName'
-     IF aPathName is a symbolic link.
+    "return some object filled with info for the file 'aPathName'.
 
      The info (for which corresponding access methods are understood by
      the returned object) is:
-	 type            - a symbol giving the files type
-	 mode            - numeric access mode
-	 uid             - owners user id
-	 gid             - owners group id
-	 size            - files size
-	 id              - files number (i.e. inode number)
-	 accessed        - last access time (as Timestamp)
-	 modified        - last modification time (as Timestamp)
-	 statusChanged   - last status change time (as Timestamp)
-	 alternativeName     - (windows only:) the MSDOS name of the file
-	 recordFormatNumeric - (VMS only:) numeric value of the recordFormat
-	 recordFormat        - (VMS only:) symbolic value of the recordFormat
-	 recordAttributes    - (VMS only:) recordAttributes
-	 fixedHeaderSize     - (VMS only:) fixed header size in a variable record format
-	 recordSize          - (VMS only:) record size.
+         type            - a symbol giving the files type
+         mode            - numeric access mode
+         uid             - owners user id
+         gid             - owners group id
+         size            - files size
+         id              - files number (i.e. inode number)
+         accessed        - last access time (as Timestamp)
+         modified        - last modification time (as Timestamp)
+         statusChanged   - last status change time (as Timestamp)
+         alternativeName     - (windows only:) the MSDOS name of the file
+         recordFormatNumeric - (VMS only:) numeric value of the recordFormat
+         recordFormat        - (VMS only:) symbolic value of the recordFormat
+         recordAttributes    - (VMS only:) recordAttributes
+         fixedHeaderSize     - (VMS only:) fixed header size in a variable record format
+         recordSize          - (VMS only:) record size.
 
      Some of the fields may be returned as nil on systems which do not provide
      all of the information.
@@ -4776,75 +4764,112 @@
     char pathBuffer[1024];
 
     if (__isStringLike(aPathName)) {
-	__BEGIN_INTERRUPTABLE__
-	do {
-	    ret = lstat((char *) __stringVal(aPathName), &buf);
-	} while ((ret < 0) && (errno == EINTR));
-	__END_INTERRUPTABLE__
-
-	if (ret < 0) {
-	    @global(LastErrorNumber) = __MKSMALLINT(errno);
-	    RETURN ( nil );
-	}
-	switch (buf.st_mode & S_IFMT) {
-	    default:
-		RETURN ( nil ); /* not a symbolic link */
-
-	    case S_IFLNK:
-		type = @symbol(symbolicLink);
-		break;
-	}
-
-	if (sizeof(buf.st_ino) == 8) {
-	    id = __MKUINT64(&buf.st_ino);
-	} else {
-	    id = __MKUINT(buf.st_ino);
-	}
-	mode = __MKSMALLINT(buf.st_mode & 0777);
-	uid = __MKSMALLINT(buf.st_uid);
-	gid = __MKSMALLINT(buf.st_gid);
-	nLink = __MKSMALLINT(buf.st_nlink);
-	if (sizeof(buf.st_size) == 8) {
-	    size = __MKINT64(&buf.st_size);
-	} else {
-	    size = __MKINT(buf.st_size);
-	}
-	aOStime = __MKUINT(buf.st_atime);
-	mOStime = __MKUINT(buf.st_mtime);
-	cOStime = __MKUINT(buf.st_ctime);
-	if ((ret = readlink((char *) __stringVal(aPathName), pathBuffer, sizeof(pathBuffer))) < 0) {
-	    @global(LastErrorNumber) = __MKSMALLINT(errno);
-	    RETURN ( nil );
-	}
-	pathBuffer[ret] = '\0';  /* readlink does not 0-terminate */
-	path = __MKSTRING(pathBuffer);
+        __BEGIN_INTERRUPTABLE__
+        do {
+            ret = lstat((char *) __stringVal(aPathName), &buf);
+        } while ((ret < 0) && (errno == EINTR));
+        __END_INTERRUPTABLE__
+
+        if (ret < 0) {
+            @global(LastErrorNumber) = __MKSMALLINT(errno);
+            RETURN ( nil );
+        }
+        switch (buf.st_mode & S_IFMT) {
+    # ifdef S_IFLNK
+            case S_IFLNK:
+                type = @symbol(symbolicLink);
+                if ((ret = readlink((char *) __stringVal(aPathName), pathBuffer, sizeof(pathBuffer))) < 0) {
+                    @global(LastErrorNumber) = __MKSMALLINT(errno);
+                    RETURN ( nil );
+                }
+                pathBuffer[ret] = '\0';  /* readlink does not 0-terminate */
+                path = __MKSTRING(pathBuffer);
+                break;
+    # endif
+            case S_IFDIR:
+                type = @symbol(directory);
+                break;
+
+            case S_IFREG:
+                type = @symbol(regular);
+                break;
+    # ifdef S_IFCHR
+            case S_IFCHR:
+                type = @symbol(characterSpecial);
+                break;
+    # endif
+    # ifdef S_IFBLK
+            case S_IFBLK:
+                type = @symbol(blockSpecial);
+                break;
+    # endif
+    # ifdef S_IFMPC
+            case S_IFMPC:
+                type = @symbol(multiplexedCharacterSpecial);
+                break;
+    # endif
+    # ifdef S_IFMPB
+            case S_IFMPB:
+                type = @symbol(multiplexedBlockSpecial);
+                break;
+    # endif
+    # ifdef S_IFSOCK
+            case S_IFSOCK:
+                type = @symbol(socket);
+                break;
+    # endif
+    # ifdef S_IFIFO
+            case S_IFIFO:
+                type = @symbol(fifo);
+                break;
+    # endif
+            default:
+                type = @symbol(unknown);
+                break;
+        }
+
+        if (sizeof(buf.st_ino) == 8) {
+            id = __MKUINT64(&buf.st_ino);
+        } else {
+            id = __MKUINT(buf.st_ino);
+        }
+        mode = __MKSMALLINT(buf.st_mode & 0777);
+        uid = __MKSMALLINT(buf.st_uid);
+        gid = __MKSMALLINT(buf.st_gid);
+        nLink = __MKSMALLINT(buf.st_nlink);
+        if (sizeof(buf.st_size) == 8) {
+            size = __MKINT64(&buf.st_size);
+        } else {
+            size = __MKINT(buf.st_size);
+        }
+        aOStime = __MKUINT(buf.st_atime);
+        mOStime = __MKUINT(buf.st_mtime);
+        cOStime = __MKUINT(buf.st_ctime);
     }
 #else
     RETURN ( nil );
 #endif
 %}.
     mode notNil ifTrue:[
-	^ FileStatusInfo
-	    type:type
-	    mode:mode
-	    uid:uid
-	    gid:gid
-	    size:size
-	    id:id
-	    accessed:aOStime
-	    modified:mOStime
-	    statusChanged:cOStime
-	    path:path
-	    numLinks:nLink.
+        ^ FileStatusInfo
+            type:type
+            mode:mode
+            uid:uid
+            gid:gid
+            size:size
+            id:id
+            accessed:aOStime
+            modified:mOStime
+            statusChanged:cOStime
+            path:path
+            numLinks:nLink.
    ].
    ^ self primitiveFailed
 
    "
     OperatingSystem infoOf:'Make.proto'
     OperatingSystem linkInfoOf:'Make.proto'
-
-    OperatingSystem infoOf:'resources/motif.style'
-    OperatingSystem linkInfoOf:'resources/motif.style'
+    OperatingSystem linkInfoOf:'/usr/tmp'
    "
 !
 
@@ -10458,14 +10483,6 @@
     ^ id
 !
 
-isDirectory
-    ^ type == #directory
-!
-
-isSymbolicLink
-    ^ type == #symbolicLink
-!
-
 mode
     "return mode"
 
@@ -10592,6 +10609,40 @@
     numLinks := nL.
 ! !
 
+!UnixOperatingSystem::FileStatusInfo methodsFor:'queries'!
+
+isBlockSpecial
+    ^ type == #blockSpecial
+!
+
+isCharacterSpecial
+    ^ type == #characterSpecial
+!
+
+isDirectory
+    ^ type == #directory
+!
+
+isFifo
+    ^ type == #fifo
+!
+
+isRegular
+    ^ type == #regular
+!
+
+isSocket
+    ^ type == #socket
+!
+
+isSymbolicLink
+    ^ type == #symbolicLink
+!
+
+isUnknown
+    ^ type == #unknown
+! !
+
 !UnixOperatingSystem::MountInfo methodsFor:'accessing'!
 
 mountPointPath
@@ -12285,7 +12336,7 @@
 !UnixOperatingSystem class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/UnixOperatingSystem.st,v 1.211 2004-08-10 15:17:12 stefan Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/UnixOperatingSystem.st,v 1.212 2004-08-13 19:29:04 stefan Exp $'
 ! !
 
 UnixOperatingSystem initialize!