2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 1995 Matthias Ettrich
8 * Copyright 1995-2000 The LyX Team.
10 * ====================================================== */
18 #include <sys/types.h>
23 /** Use objects of this class to get information about files. */
29 /** Get information about file.
30 If link is true, the information is about the link itself, not
31 the file that is obtained by tracing the links. */
33 FileInfo(string const & path, bool link = false);
40 FileInfo & newFile(string const & path, bool link = false);
42 /// Query a new file descriptor
43 FileInfo & newFile(int fildes);
45 /// Returns a character describing file type (ls -F)
46 char const * typeIndicator() const;
48 /// File protection mode
49 mode_t getMode() const;
51 /// Constructs standard mode string (ls style)
52 void modeString(char * szString) const;
54 /// returns a letter describing a file type (ls style)
55 char typeLetter() const;
57 /// builds 'rwx' string describing file access rights
58 void flagRWX(unsigned short i, char * szString) const;
60 /// updates mode string to match suid/sgid/sticky bits
61 void setSticky(char * szString) const;
64 time_t getModificationTime() const;
67 time_t getAccessTime() const;
70 time_t getStatusChangeTime() const;
72 /// Total file size in bytes
73 off_t getSize() const;
75 /// Number of hard links
76 nlink_t getNumberOfLinks() const;
84 /// Is the file information correct? Did the query succeed?
89 rperm = R_OK, // test for read permission
90 wperm = W_OK, // test for write permission
91 xperm = X_OK, // test for execute (search) permission
92 eperm = F_OK // test for existence of file
94 /// Test whether the current user has a given set of permissions
96 /// Is the file writable for the current user?
97 bool writable() { return access(FileInfo::wperm); }
98 /// Is the file readable for the current user?
99 bool readable() { return access(FileInfo::rperm); }
100 /// Is the file executable for the current user?
101 bool executable() { return access(FileInfo::xperm); }
102 /// Does the file exist?
103 bool exist() { return access(FileInfo::eperm); }
107 bool isRegular() const;
113 bool isBlock() const;
117 bool isSocket() const;
119 int getError() const;