Source Code (Use browser search to find items of interest.)
Class Index
klyx'FileInfo (./klyx/src/FileInfo.h:22)
class FileInfo {
public:
///
FileInfo();
///
FileInfo(LString const &path, bool link = false);
///
FileInfo(int fildes);
///
~FileInfo();
///
FileInfo& newFile(LString const &path, bool link = false);
///
FileInfo& newFile(int fildes);
/// returns a character describing file type (ls -F)
char const *typeIndicator();
///
mode_t getMode();
///
long getBlockSize();
/// constructs standard mode string (ls style)
void modeString(char *szString);
/// returns a letter describing a file type (ls style)
char typeLetter();
/// builds 'rwx' string describing file access rights
void flagRWX(unsigned short i, char *szString);
/// updates mode string to match suid/sgid/sticky bits
void setSticky(char *szString);
///
time_t& getModificationTime();
///
time_t& getAccessTime();
///
time_t& getStatusChangeTime();
///
off_t getSize();
///
nlink_t getNumberOfLinks();
///
uid_t getUid();
///
gid_t getGid();
///
bool isOK();
///
enum perm_test {
rperm = R_OK, // test for read permission
wperm = W_OK, // test for write permission
xperm = X_OK, // test for execute (search) permission
eperm = F_OK // test for existence of file
};
///
bool access(int p);
///
bool writable() { return access(FileInfo::wperm); }
///
bool readable() { return access(FileInfo::rperm); }
///
bool executable() { return access(FileInfo::xperm); }
///
bool exist() { return access(FileInfo::eperm); }
///
bool isLink();
///
bool isRegular();
///
bool isDir();
///
bool isChar();
///
bool isBlock();
///
bool isFifo();
///
bool isSocket();
///
int getError();
///
enum {
///
NoErr = -1
};
private:
///
void init();
///
void dostat(bool);
///
struct stat *buf;
///
int status;
///
int err;
///
LString fname;
};
klyx'FileInfo::FileInfo() (./klyx/src/FileInfo.C:113)
FileInfo::FileInfo()
{
init();
}
klyx'FileInfo::FileInfo() (./klyx/src/FileInfo.C:119)
FileInfo::FileInfo(LString const &path, bool link)
: fname(path)
{
init();
dostat(link);
}
klyx'FileInfo::FileInfo() (./klyx/src/FileInfo.C:127)
FileInfo::FileInfo(int fildes)
{
init();
status = fstat(fildes, buf);
if (status) err = errno;
}
klyx'FileInfo::~FileInfo() (./klyx/src/FileInfo.C:135)
FileInfo::~FileInfo()
{
delete[] buf;
}
klyx'FileInfo::init() (./klyx/src/FileInfo.C:141)
void FileInfo::init()
{
status = 0;
err = NoErr;
buf = (struct stat*) new char[sizeof(struct stat)];
}
klyx'FileInfo::dostat() (./klyx/src/FileInfo.C:149)
void FileInfo::dostat(bool link)
{
if (link) {
status = lstat(fname.c_str(), buf);
} else {
status = stat(fname.c_str(), buf);
}
if (status) err = errno;
}
klyx'FileInfo::newFile() (./klyx/src/FileInfo.C:160)
FileInfo& FileInfo::newFile(LString const &path, bool link)
{
fname = path;
status = 0;
err = NoErr;
dostat(link);
return *this;
}
klyx'FileInfo::newFile() (./klyx/src/FileInfo.C:173)
FileInfo& FileInfo::newFile(int fildes)
{
status = 0;
err = NoErr;
status = fstat(fildes, buf);
if (status) err = errno;
return *this;
}
klyx'FileInfo::typeIndicator() (./klyx/src/FileInfo.C:183)
char const *FileInfo::typeIndicator()
{
if (S_ISDIR(buf->st_mode)) return ("/");
#ifdef S_ISLNK
if (S_ISLNK(buf->st_mode)) return ("@");
#endif
#ifdef S_ISFIFO
if (S_ISFIFO(buf->st_mode)) return ("|");
#endif
#ifdef S_ISSOCK
if (S_ISSOCK(buf->st_mode)) return ("=");
#endif
if (S_ISREG(buf->st_mode) && (buf->st_mode & (S_IEXEC | S_IXGRP | S_IXOTH)))
return ("*");
return "";
}
klyx'FileInfo::getMode() (./klyx/src/FileInfo.C:201)
mode_t FileInfo::getMode()
{
return buf->st_mode;
}
klyx'FileInfo::getBlockSize() (./klyx/src/FileInfo.C:206)
long FileInfo::getBlockSize()
{
return buf->st_blksize; /* Preferred I/O block size */
}
klyx'FileInfo::modeString() (./klyx/src/FileInfo.C:211)
void FileInfo::modeString(char *szString)
{
szString[0] = typeLetter();
flagRWX((buf->st_mode & 0700) << 0, &szString[1]);
flagRWX((buf->st_mode & 0070) << 3, &szString[4]);
flagRWX((buf->st_mode & 0007) << 6, &szString[7]);
setSticky(szString);
szString[10] = 0;
}
klyx'FileInfo::typeLetter() (./klyx/src/FileInfo.C:222)
char FileInfo::typeLetter()
{
#ifdef S_ISBLK
if (S_ISBLK(buf->st_mode)) return 'b';
#endif
if (S_ISCHR(buf->st_mode)) return 'c';
if (S_ISDIR(buf->st_mode)) return 'd';
if (S_ISREG(buf->st_mode)) return '-';
#ifdef S_ISFIFO
if (S_ISFIFO(buf->st_mode)) return 'p';
#endif
#ifdef S_ISLNK
if (S_ISLNK(buf->st_mode)) return 'l';
#endif
#ifdef S_ISSOCK
if (S_ISSOCK(buf->st_mode)) return 's';
#endif
#ifdef S_ISMPC
if (S_ISMPC(buf->st_mode)) return 'm';
#endif
#ifdef S_ISNWK
if (S_ISNWK(buf->st_mode)) return 'n';
#endif
return '?';
}
klyx'FileInfo::flagRWX() (./klyx/src/FileInfo.C:249)
void FileInfo::flagRWX(unsigned short i, char *szString)
{
szString[0] = (i & S_IRUSR) ? 'r' : '-';
szString[1] = (i & S_IWUSR) ? 'w' : '-';
szString[2] = (i & S_IXUSR) ? 'x' : '-';
}
klyx'FileInfo::setSticky() (./klyx/src/FileInfo.C:257)
void FileInfo::setSticky(char *szString)
{
#ifdef S_ISUID
if (buf->st_mode & S_ISUID) {
if (szString[3] != 'x') szString[3] = 'S';
else szString[3] = 's';
}
#endif
#ifdef S_ISGID
if (buf->st_mode & S_ISGID) {
if (szString[6] != 'x') szString[6] = 'S';
else szString[6] = 's';
}
#endif
#ifdef S_ISVTX
if (buf->st_mode & S_ISVTX) {
if (szString[9] != 'x') szString[9] = 'T';
else szString[9] = 't';
}
#endif
}
klyx'FileInfo::getModificationTime() (./klyx/src/FileInfo.C:280)
time_t& FileInfo::getModificationTime()
{
return buf->st_mtime;
}
klyx'FileInfo::getAccessTime() (./klyx/src/FileInfo.C:286)
time_t& FileInfo::getAccessTime()
{
return buf->st_atime;
}
klyx'FileInfo::getStatusChangeTime() (./klyx/src/FileInfo.C:292)
time_t& FileInfo::getStatusChangeTime()
{
return buf->st_ctime;
}
klyx'FileInfo::getNumberOfLinks() (./klyx/src/FileInfo.C:298)
nlink_t FileInfo::getNumberOfLinks()
{
return buf->st_nlink;
}
klyx'FileInfo::getUid() (./klyx/src/FileInfo.C:304)
uid_t FileInfo::getUid()
{
return buf->st_uid;
}
klyx'FileInfo::getGid() (./klyx/src/FileInfo.C:310)
gid_t FileInfo::getGid()
{
return buf->st_gid;
}
klyx'FileInfo::getSize() (./klyx/src/FileInfo.C:316)
off_t FileInfo::getSize()
{
return buf->st_size;
}
klyx'FileInfo::getError() (./klyx/src/FileInfo.C:322)
int FileInfo::getError()
{
return err;
}
klyx'FileInfo::isOK() (./klyx/src/FileInfo.C:328)
bool FileInfo::isOK()
{
return (status) ? false : true;
}
klyx'FileInfo::isLink() (./klyx/src/FileInfo.C:334)
bool FileInfo::isLink()
{
return S_ISLNK(buf->st_mode);
}
klyx'FileInfo::isRegular() (./klyx/src/FileInfo.C:340)
bool FileInfo::isRegular()
{
return S_ISREG(buf->st_mode);
}
klyx'FileInfo::isDir() (./klyx/src/FileInfo.C:346)
bool FileInfo::isDir()
{
return S_ISDIR(buf->st_mode);
}
klyx'FileInfo::isChar() (./klyx/src/FileInfo.C:352)
bool FileInfo::isChar()
{
return S_ISCHR(buf->st_mode);
}
klyx'FileInfo::isBlock() (./klyx/src/FileInfo.C:358)
bool FileInfo::isBlock()
{
return S_ISBLK(buf->st_mode);
}
klyx'FileInfo::isFifo() (./klyx/src/FileInfo.C:364)
bool FileInfo::isFifo()
{
return S_ISFIFO(buf->st_mode);
}
klyx'FileInfo::isSocket() (./klyx/src/FileInfo.C:370)
bool FileInfo::isSocket()
{
return S_ISSOCK(buf->st_mode);
}
klyx'FileInfo::access() (./klyx/src/FileInfo.C:376)
bool FileInfo::access(int p)
{
// if we don`t have a filename we fail
if (fname.empty()) return false;
if (::access(fname.c_str(), p) == 0)
return true;
else {
// If we were really kind, we would also tell why
// the file access failed.
return false;
}
}