bool djvFileInfo::stat(const QString & path) { //DJV_DEBUG("djvFileInfo::stat"); //DJV_DEBUG_PRINT("path = " << path); _exists = false; _type = static_cast<TYPE>(0); _size = 0; _user = 0; _permissions = 0; _time = time_t(); _STAT info; djvMemory::fill<quint8>(0, &info, sizeof(_STAT)); const QString fileName = djvFileInfoUtil::fixPath(path.length() ? path : _path) + this->fileName(-1, false); //DJV_DEBUG_PRINT("fileName = " << fileName); //! \todo Try to stat multiple variations of the path name to find the //! correct one. Is this still necessary? const QString fileName2 = fileName + '/'; const QString fileName3 = fileName.mid(0, fileName.length() - 1); //DJV_DEBUG_PRINT("fileName2 = " << fileName2); //DJV_DEBUG_PRINT("fileName3 = " << fileName3); if (0 == _STAT_FNC(fileName.toLatin1().data(), &info)) { //DJV_DEBUG_PRINT("fileName"); } else if ( 0 == _STAT_FNC(fileName2.toLatin1().data(), &info)) { //DJV_DEBUG_PRINT("fileName2"); } else if ( 0 == _STAT_FNC(fileName3.toLatin1().data(), &info)) { //DJV_DEBUG_PRINT("fileName3"); } else { QString err; #if defined(DJV_WINDOWS) char tmp[djvStringUtil::cStringLength] = ""; ::strerror_s(tmp, djvStringUtil::cStringLength, errno); err = tmp; #endif // DJV_WINDOWS //DJV_DEBUG_PRINT("errno = " << err); return false; } _exists = true; _size = info.st_size; _user = info.st_uid; _permissions = 0; _time = info.st_mtime; _type = FILE; _permissions = 0; //DJV_DEBUG_PRINT("size = " << _size); #if defined(DJV_WINDOWS) if (info.st_mode & _S_IFDIR) { _type = DIRECTORY; } _permissions |= (info.st_mode & _S_IREAD ) ? djvFileInfo::READ : 0; _permissions |= (info.st_mode & _S_IWRITE) ? djvFileInfo::WRITE : 0; _permissions |= (info.st_mode & _S_IEXEC ) ? djvFileInfo::EXEC : 0; #else // DJV_WINDOWS if (S_ISDIR(info.st_mode)) { _type = DIRECTORY; } _permissions |= (info.st_mode & S_IRUSR) ? READ : 0; _permissions |= (info.st_mode & S_IWUSR) ? WRITE : 0; _permissions |= (info.st_mode & S_IXUSR) ? EXEC : 0; #endif // DJV_WINDOWS //DJV_DEBUG_PRINT("type = " << _type); return true; }
bool File::stat(const String & path) { //DJV_DEBUG("File::stat"); //DJV_DEBUG_PRINT("path = " << path); _STAT info; Memory::set<uint8_t>(0, &info, sizeof(_STAT)); const String file = File_Util::path_fix(path.size() ? path : _path) + get(-1, false); //DJV_DEBUG_PRINT("file = " << file); //! \todo Windows stat. if (0 == _STAT_FNC(file.c_str(), &info)) ; else if ( 0 == _STAT_FNC(String(file + File_Util::path_separator).c_str(), &info)) ; else if ( 0 == _STAT_FNC( String(file, static_cast<int>(file.size()) - 1).c_str(), &info)) ; else { String err; #if defined(DJV_WINDOWS) //! \todo MinGW does not define strerror_s()? //char tmp[cstring_size] = ""; //::strerror_s(tmp, cstring_size, errno); //err = tmp; err = ::strerror(errno); #else // DJV_WINDOWS err = ::strerror(errno); #endif // DJV_WINDOWS //DJV_DEBUG_PRINT("errno = " << err); return false; } _size = info.st_size; _user = info.st_uid; _perm = 0; _time = info.st_mtime; #if defined(DJV_WINDOWS) if (info.st_mode & _S_IFDIR) { _type = DIRECTORY; } _perm |= (info.st_mode & _S_IREAD) ? file::READ : 0; _perm |= (info.st_mode & _S_IWRITE) ? file::WRITE : 0; _perm |= (info.st_mode & _S_IEXEC) ? file::EXEC : 0; #else // DJV_WINDOWS if (S_ISDIR(info.st_mode)) { _type = DIRECTORY; } _perm |= (info.st_mode & S_IRUSR) ? READ : 0; _perm |= (info.st_mode & S_IWUSR) ? WRITE : 0; _perm |= (info.st_mode & S_IXUSR) ? EXEC : 0; #endif // DJV_WINDOWS return true; }