 | | Determining the accessibilty of a file can be a tricky proposition. Certainly, the stat function can tell you the permission bits on a file, but that is not the same thing as telling you whether a file can actually be read (or written, or executed) by a user. For example, consider a world-readable file (mode 0444, or r- -r- -r- -) that is in a directory that is searchable only by its owner (mode 0700, or rwx------). The owner can read the file, but another user cannot. Even though the file has read permission for her, the directory that contains the file does not have access permission for her, so she cannot reach the file to open it. Thus, to properly test whether or not a file is accessible, you must check the complete path to the file from the root of the filesystem, one directory at a time. This requires some non-trivial programming to handle all the special cases. | |
|