Logo Search packages:      
Sourcecode: pwlib version File versions  Download package

BOOL PFile::GetInfo ( const PFilePath name,
PFileInfo info 
) [static, inherited]

Get information (eg protection, timestamps) on the specified file.

Returns:
TRUE if the file info was retrieved.

Definition at line 1011 of file ptlib.cxx.

References PFileInfo::accessed, PFileInfo::created, PString::Delete(), PString::GetLength(), PFileInfo::GroupExecute, PFileInfo::GroupRead, PFileInfo::GroupWrite, PFileInfo::hidden, PString::IsEmpty(), PDirectory::IsSeparator(), PFileInfo::modified, PFileInfo::permissions, PFileInfo::RegularFile, PFileInfo::size, PFileInfo::SubDirectory, PFileInfo::type, PFileInfo::UnknownFileType, PFileInfo::UserExecute, PFileInfo::UserRead, PFileInfo::UserWrite, PFileInfo::WorldExecute, PFileInfo::WorldRead, and PFileInfo::WorldWrite.

Referenced by PDirectory::GetInfo(), and PFile::GetInfo().

{
  if (name.IsEmpty())
    return FALSE;

  PString fn = name;
  PINDEX pos = fn.GetLength()-1;
  while (PDirectory::IsSeparator(fn[pos]))
    pos--;
  fn.Delete(pos+1, P_MAX_INDEX);

  struct stat s;
  if (stat(fn, &s) != 0)
    return FALSE;

  info.created =  (s.st_ctime < 0) ? 0 : s.st_ctime;
  info.modified = (s.st_mtime < 0) ? 0 : s.st_mtime;
  info.accessed = (s.st_atime < 0) ? 0 : s.st_atime;
  info.size = s.st_size;

#if defined(_WIN32)
  info.permissions = FileSecurityPermissions(name, -1);
  if (info.permissions < 0)
#endif
  {
    info.permissions = 0;
    if ((s.st_mode&S_IREAD) != 0)
      info.permissions |= PFileInfo::UserRead|PFileInfo::GroupRead|PFileInfo::WorldRead;
    if ((s.st_mode&S_IWRITE) != 0)
      info.permissions |= PFileInfo::UserWrite|PFileInfo::GroupWrite|PFileInfo::WorldWrite;
    if ((s.st_mode&S_IEXEC) != 0)
      info.permissions |= PFileInfo::UserExecute|PFileInfo::GroupExecute|PFileInfo::WorldExecute;
  }

  switch (s.st_mode & S_IFMT) {
    case S_IFREG :
      info.type = PFileInfo::RegularFile;
      break;

    case S_IFDIR :
      info.type = PFileInfo::SubDirectory;
      break;

    default:
      info.type = PFileInfo::UnknownFileType;
      break;
  }

#if defined(_WIN32)
  info.hidden = (GetFileAttributes(name) & FILE_ATTRIBUTE_HIDDEN) != 0;
#else
  unsigned int attr;
  _dos_getfileattr(name, &attr);
  info.hidden = (attr & _A_HIDDEN) != 0;
#endif

  return TRUE;
}


Generated by  Doxygen 1.6.0   Back to index