4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Lars Gullik Bjønnes
9 * Full author contact details are available in file CREDITS.
17 #include <sys/types.h>
20 #include <boost/utility.hpp>
26 /** Use objects of this class to get information about files.
28 * Users must make sure to check fi.isOK() before any operations
29 * requiring the file to exist such as fi.isDir()
31 class FileInfo : boost::noncopyable {
36 /** Get information about file.
37 If link is true, the information is about the link itself, not
38 the file that is obtained by tracing the links. */
39 explicit FileInfo(string const & path, bool link = false);
42 explicit FileInfo(int fildes);
45 FileInfo & newFile(string const & path, bool link = false);
47 /// Query a new file descriptor
48 FileInfo & newFile(int fildes);
50 /// Returns a character describing file type (ls -F)
51 char typeIndicator() const;
53 /// File protection mode
54 mode_t getMode() const;
56 /// Constructs standard mode string (ls style)
57 string modeString() const;
60 time_t getModificationTime() const;
63 time_t getAccessTime() const;
66 time_t getStatusChangeTime() const;
68 /// Total file size in bytes
69 off_t getSize() const;
71 /// Number of hard links
72 nlink_t getNumberOfLinks() const;
80 /// Is the file information correct? Did the query succeed?
85 /// test for read permission
87 /// test for write permission
89 /// test for execute (search) permission
91 /// test for existence of file
94 /// Test whether the current user has a given set of permissions
95 bool access(int p) const;
96 /// Is the file writable for the current user?
97 bool writable() const { return access(FileInfo::wperm); }
98 /// Is the file readable for the current user?
99 bool readable() const { return access(FileInfo::rperm); }
100 /// Is the file executable for the current user?
101 bool executable() const { return access(FileInfo::xperm); }
102 /// Does the file exist?
103 bool exist() const { return access(FileInfo::eperm); }
107 bool isRegular() const;
113 bool isBlock() const;
117 bool isSocket() const;
119 int getError() const;
141 } // namespace support