int UserFile::access(const String& path, int mode) { struct stat buf; auto ret = urlStat(path, &buf, k_STREAM_URL_STAT_QUIET); if (ret < 0 || mode == F_OK) { return ret; } return buf.st_mode & mode ? 0 : -1; }
int UserFile::access(const String& path, int mode) { struct stat buf; auto ret = urlStat(path, &buf, k_STREAM_URL_STAT_QUIET); if (ret < 0 || mode == F_OK) { return ret; } // The mode flags in stat are different from the flags used by access. #ifdef _MSC_VER auto uid = -1; auto gid = -1; #else auto uid = geteuid(); auto gid = getegid(); #endif switch (mode) { case R_OK: // Test for read permission. return simulateAccessResult( (buf.st_uid == uid && (buf.st_mode & S_IRUSR)) || (buf.st_gid == gid && (buf.st_mode & S_IRGRP)) || (buf.st_mode & S_IROTH)); case W_OK: // Test for write permission. return simulateAccessResult( (buf.st_uid == uid && (buf.st_mode & S_IWUSR)) || (buf.st_gid == gid && (buf.st_mode & S_IWGRP)) || (buf.st_mode & S_IWOTH)); case X_OK: // Test for execute permission. return simulateAccessResult( !(buf.st_mode & S_IFDIR) && // Directories are not executable ((buf.st_uid == uid && (buf.st_mode & S_IXUSR)) || (buf.st_gid == gid && (buf.st_mode & S_IXGRP)) || (buf.st_mode & S_IXOTH))); default: // Unknown mode. return -1; } }
int UserFile::stat(const String& path, struct stat* buf) { return urlStat(path, buf); }
int UserFile::lstat(const String& path, struct stat* buf) { return urlStat(path, buf, k_STREAM_URL_STAT_LINK); }