2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 1995 Matthias Ettrich
8 * Copyright 1995-2001 The LyX Team.
10 * ====================================================== */
21 #include <sys/types.h>
24 #include <boost/utility.hpp>
27 /** Use objects of this class to get information about files.
29 * Users must make sure to check fi.isOK() before any operations
30 * requiring the file to exist such as fi.isDir()
32 class FileInfo : boost::noncopyable {
37 /** Get information about file.
38 If link is true, the information is about the link itself, not
39 the file that is obtained by tracing the links. */
40 explicit FileInfo(string const & path, bool link = false);
43 explicit FileInfo(int fildes);
46 FileInfo & newFile(string const & path, bool link = false);
48 /// Query a new file descriptor
49 FileInfo & newFile(int fildes);
51 /// Returns a character describing file type (ls -F)
52 char typeIndicator() const;
54 /// File protection mode
55 mode_t getMode() const;
57 /// Constructs standard mode string (ls style)
58 string modeString() const;
61 time_t getModificationTime() const;
64 time_t getAccessTime() const;
67 time_t getStatusChangeTime() const;
69 /// Total file size in bytes
70 off_t getSize() const;
72 /// Number of hard links
73 nlink_t getNumberOfLinks() const;
81 /// Is the file information correct? Did the query succeed?
86 /// test for read permission
88 /// test for write permission
90 /// test for execute (search) permission
92 /// test for existence of file
95 /// Test whether the current user has a given set of permissions
96 bool access(int p) const;
97 /// Is the file writable for the current user?
98 bool writable() const { return access(FileInfo::wperm); }
99 /// Is the file readable for the current user?
100 bool readable() const { return access(FileInfo::rperm); }
101 /// Is the file executable for the current user?
102 bool executable() const { return access(FileInfo::xperm); }
103 /// Does the file exist?
104 bool exist() const { return access(FileInfo::eperm); }
108 bool isRegular() const;
114 bool isBlock() const;
118 bool isSocket() const;
120 int getError() const;