Sending the stat: message to the CfsStat class returns a CfsStat instance containing the statistics for the file specified as its argument. These statistics can be accessed by sending messages, that match POSIX.1 stat structure names, to the instance. An example follows:To obtain the exact size of a file, send size to an open file descriptor rather than using stat:, because CfsFileDescriptor>>#size reflects the true size of the file based on the end-of-file position as of last write, while CfsStat>>#size obtains the amount of storage space allocated to the file by reading the file's directory entry. For this reason, the size obtained by sending size to a CfsState or CfsDirectoryEntry might not match the logical size of the file, and might not be up-to-date if the file is currently open, even if a flush was just performed on the file descriptor.The following messages can be sent to a CfsStat instance. The messages always answer a meaningful value, because all platforms support the information associated with them.Answers true if the receiver is reporting statistics for a block special file. Otherwise answers false.Answers true if the receiver is reporting statistics for a character special file. Otherwise answers false.Answers true if the receiver is reporting statistics for a pipe or for a FIFO special file. Otherwise answers false.Answers true if the receiver is reporting statistics for a special file. Otherwise answers false. A special file is any file that is neither a regular file nor a directory.The following messages in provide access to additional information that is not supported uniformly by all platforms. These messages can answer nil if a particular platform does not support the associated type of information.If repeated stat operations are to be performed, garbage creation can be minimized by creating an empty CfsStat instance and then reusing it by sending the stat: message to the instance. An example follows:By combining the stat: message with error checking, it is possible to test for file existence and other special properties. Some examples follow.Do not use stat: to try to prevent errors by testing whether a file exists before opening it. It is better to catch the fail case from the open operation, because the file can be deleted in the time between the existence test and opening the file.
![]() |