1999-09-27 18:44:28 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
/* This file is part of
|
1999-10-02 16:21:10 +00:00
|
|
|
* ======================================================
|
|
|
|
*
|
|
|
|
* LyX, The Document Processor
|
|
|
|
*
|
|
|
|
* Copyright 1995 Matthias Ettrich
|
|
|
|
* Copyright 1995-1999 The LyX Team.
|
|
|
|
*
|
|
|
|
* ======================================================*/
|
|
|
|
|
|
|
|
#ifndef FILE_INFO_H
|
|
|
|
#define FILE_INFO_H
|
|
|
|
|
|
|
|
#include <ctime>
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
1999-10-02 16:21:10 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
#include "LString.h"
|
|
|
|
|
|
|
|
/** Use objects of this class to get information about files. */
|
|
|
|
class FileInfo {
|
|
|
|
public:
|
|
|
|
///
|
|
|
|
FileInfo();
|
|
|
|
|
|
|
|
/** Get information about file.
|
|
|
|
If link is true, the information is about the link itself, not
|
|
|
|
the file that is obtained by tracing the links. */
|
1999-10-02 16:21:10 +00:00
|
|
|
FileInfo(string const & path, bool link = false);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-10-12 21:37:10 +00:00
|
|
|
/// File descriptor
|
1999-09-27 18:44:28 +00:00
|
|
|
FileInfo(int fildes);
|
|
|
|
|
|
|
|
///
|
|
|
|
~FileInfo();
|
|
|
|
|
1999-10-12 21:37:10 +00:00
|
|
|
/// Query a new file
|
1999-10-02 16:21:10 +00:00
|
|
|
FileInfo& newFile(string const & path, bool link = false);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-10-12 21:37:10 +00:00
|
|
|
/// Query a new file descriptor
|
1999-09-27 18:44:28 +00:00
|
|
|
FileInfo& newFile(int fildes);
|
|
|
|
|
1999-10-12 21:37:10 +00:00
|
|
|
/// Returns a character describing file type (ls -F)
|
1999-10-02 16:21:10 +00:00
|
|
|
char const * typeIndicator() const;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-10-12 21:37:10 +00:00
|
|
|
/// File protection mode
|
1999-09-27 18:44:28 +00:00
|
|
|
mode_t getMode() const;
|
|
|
|
|
1999-10-12 21:37:10 +00:00
|
|
|
/// Get "preferred" block size for efficient file system I/O
|
1999-09-27 18:44:28 +00:00
|
|
|
long getBlockSize() const;
|
|
|
|
|
1999-10-12 21:37:10 +00:00
|
|
|
/// Constructs standard mode string (ls style)
|
1999-10-02 16:21:10 +00:00
|
|
|
void modeString(char * szString) const;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
/// returns a letter describing a file type (ls style)
|
|
|
|
char typeLetter() const;
|
|
|
|
|
|
|
|
/// builds 'rwx' string describing file access rights
|
1999-10-02 16:21:10 +00:00
|
|
|
void flagRWX(unsigned short i, char * szString) const;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
/// updates mode string to match suid/sgid/sticky bits
|
1999-10-02 16:21:10 +00:00
|
|
|
void setSticky(char * szString) const;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
///
|
|
|
|
time_t getModificationTime() const;
|
|
|
|
|
|
|
|
///
|
|
|
|
time_t getAccessTime() const;
|
|
|
|
|
|
|
|
///
|
|
|
|
time_t getStatusChangeTime() const;
|
|
|
|
|
1999-10-12 21:37:10 +00:00
|
|
|
/// Total file size in bytes
|
1999-09-27 18:44:28 +00:00
|
|
|
off_t getSize() const;
|
|
|
|
|
1999-10-12 21:37:10 +00:00
|
|
|
/// Number of hard links
|
1999-09-27 18:44:28 +00:00
|
|
|
nlink_t getNumberOfLinks() const;
|
|
|
|
|
1999-10-12 21:37:10 +00:00
|
|
|
/// User ID of owner
|
1999-09-27 18:44:28 +00:00
|
|
|
uid_t getUid() const;
|
1999-10-12 21:37:10 +00:00
|
|
|
|
|
|
|
/// Group ID of owner
|
1999-09-27 18:44:28 +00:00
|
|
|
gid_t getGid() const;
|
1999-10-12 21:37:10 +00:00
|
|
|
|
|
|
|
/// Is the file information correct? Did the query succeed?
|
1999-09-27 18:44:28 +00:00
|
|
|
bool isOK() const;
|
1999-10-12 21:37:10 +00:00
|
|
|
|
|
|
|
/// Permission flags
|
1999-09-27 18:44:28 +00:00
|
|
|
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
|
|
|
|
};
|
1999-10-12 21:37:10 +00:00
|
|
|
/// Test whether the current user has a given set of permissions
|
1999-09-27 18:44:28 +00:00
|
|
|
bool access(int p);
|
1999-10-12 21:37:10 +00:00
|
|
|
/// Is the file writable for the current user?
|
1999-09-27 18:44:28 +00:00
|
|
|
bool writable() { return access(FileInfo::wperm); }
|
1999-10-12 21:37:10 +00:00
|
|
|
/// Is the file readable for the current user?
|
1999-09-27 18:44:28 +00:00
|
|
|
bool readable() { return access(FileInfo::rperm); }
|
1999-10-12 21:37:10 +00:00
|
|
|
/// Is the file executable for the current user?
|
1999-09-27 18:44:28 +00:00
|
|
|
bool executable() { return access(FileInfo::xperm); }
|
1999-10-12 21:37:10 +00:00
|
|
|
/// Does the file exist?
|
1999-09-27 18:44:28 +00:00
|
|
|
bool exist() { return access(FileInfo::eperm); }
|
|
|
|
///
|
|
|
|
bool isLink() const;
|
|
|
|
///
|
|
|
|
bool isRegular() const;
|
|
|
|
///
|
|
|
|
bool isDir() const;
|
|
|
|
///
|
|
|
|
bool isChar() const;
|
|
|
|
///
|
|
|
|
bool isBlock() const;
|
|
|
|
///
|
|
|
|
bool isFifo() const;
|
|
|
|
///
|
|
|
|
bool isSocket() const;
|
|
|
|
///
|
|
|
|
int getError() const;
|
|
|
|
///
|
|
|
|
enum {
|
|
|
|
///
|
|
|
|
NoErr = -1
|
|
|
|
};
|
|
|
|
private:
|
|
|
|
///
|
|
|
|
void init();
|
|
|
|
///
|
|
|
|
void dostat(bool);
|
|
|
|
///
|
1999-10-02 16:21:10 +00:00
|
|
|
struct stat * buf;
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
|
|
|
int status;
|
|
|
|
///
|
|
|
|
int err;
|
|
|
|
///
|
1999-10-02 16:21:10 +00:00
|
|
|
string fname;
|
1999-09-27 18:44:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|