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
|
2000-03-16 04:29:22 +00:00
|
|
|
* Copyright 1995-2000 The LyX Team.
|
1999-10-02 16:21:10 +00:00
|
|
|
*
|
1999-11-15 10:54:16 +00:00
|
|
|
* ====================================================== */
|
1999-10-02 16:21:10 +00:00
|
|
|
|
|
|
|
#ifndef FILE_INFO_H
|
|
|
|
#define FILE_INFO_H
|
|
|
|
|
2000-07-24 13:53:19 +00:00
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma interface
|
|
|
|
#endif
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
#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"
|
|
|
|
|
2000-08-07 20:58:24 +00:00
|
|
|
/** Use objects of this class to get information about files.
|
|
|
|
*/
|
1999-09-27 18:44:28 +00:00
|
|
|
class FileInfo {
|
|
|
|
public:
|
|
|
|
///
|
|
|
|
FileInfo();
|
1999-11-09 22:20:24 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
/** Get information about file.
|
1999-11-09 22:20:24 +00:00
|
|
|
If link is true, the information is about the link itself, not
|
|
|
|
the file that is obtained by tracing the links. */
|
2000-04-08 17:02:02 +00:00
|
|
|
explicit
|
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
|
2000-04-08 17:02:02 +00:00
|
|
|
explicit
|
1999-09-27 18:44:28 +00:00
|
|
|
FileInfo(int fildes);
|
|
|
|
|
1999-10-12 21:37:10 +00:00
|
|
|
/// Query a new file
|
1999-11-09 22:20:24 +00:00
|
|
|
FileInfo & newFile(string const & path, bool link = false);
|
|
|
|
|
1999-10-12 21:37:10 +00:00
|
|
|
/// Query a new file descriptor
|
1999-11-09 22:20:24 +00:00
|
|
|
FileInfo & newFile(int fildes);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
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-11-09 22:20:24 +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
|
|
|
/// 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
|
2000-10-18 14:07:29 +00:00
|
|
|
void flagRWX(mode_t 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-11-09 22:20:24 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
|
|
|
time_t getModificationTime() const;
|
1999-11-09 22:20:24 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
|
|
|
time_t getAccessTime() const;
|
1999-11-09 22:20:24 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
|
|
|
time_t getStatusChangeTime() const;
|
1999-11-09 22:20:24 +00:00
|
|
|
|
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-11-09 22:20:24 +00:00
|
|
|
|
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-11-09 22:20:24 +00:00
|
|
|
|
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-11-09 22:20:24 +00:00
|
|
|
|
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-11-09 22:20:24 +00:00
|
|
|
|
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-11-09 22:20:24 +00:00
|
|
|
|
1999-10-12 21:37:10 +00:00
|
|
|
/// Permission flags
|
1999-09-27 18:44:28 +00:00
|
|
|
enum perm_test {
|
2000-08-07 20:58:24 +00:00
|
|
|
/// test for read permission
|
|
|
|
rperm = R_OK,
|
|
|
|
/// test for write permission
|
|
|
|
wperm = W_OK,
|
|
|
|
/// test for execute (search) permission
|
|
|
|
xperm = X_OK,
|
|
|
|
/// test for existence of file
|
|
|
|
eperm = F_OK
|
1999-09-27 18:44:28 +00:00
|
|
|
};
|
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;
|
|
|
|
///
|
2000-08-07 20:58:24 +00:00
|
|
|
enum Err {
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
|
|
|
NoErr = -1
|
|
|
|
};
|
|
|
|
private:
|
|
|
|
///
|
|
|
|
void init();
|
|
|
|
///
|
|
|
|
void dostat(bool);
|
|
|
|
///
|
1999-11-09 22:20:24 +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
|