2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 1995 Matthias Ettrich
8 * Copyright 1995-1999 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. */
32 FileInfo(string const & path, bool link = false);
38 FileInfo & newFile(string const & path, bool link = false);
40 /// Query a new file descriptor
41 FileInfo & newFile(int fildes);
43 /// Returns a character describing file type (ls -F)
44 char const * typeIndicator() const;
46 /// File protection mode
47 mode_t getMode() const;
49 /// Get "preferred" block size for efficient file system I/O
50 long getBlockSize() const;
52 /// Constructs standard mode string (ls style)
53 void modeString(char * szString) const;
55 /// returns a letter describing a file type (ls style)
56 char typeLetter() const;
58 /// builds 'rwx' string describing file access rights
59 void flagRWX(unsigned short i, char * szString) const;
61 /// updates mode string to match suid/sgid/sticky bits
62 void setSticky(char * szString) const;
65 time_t getModificationTime() const;
68 time_t getAccessTime() const;
71 time_t getStatusChangeTime() const;
73 /// Total file size in bytes
74 off_t getSize() const;
76 /// Number of hard links
77 nlink_t getNumberOfLinks() const;
85 /// Is the file information correct? Did the query succeed?
90 rperm = R_OK, // test for read permission
91 wperm = W_OK, // test for write permission
92 xperm = X_OK, // test for execute (search) permission
93 eperm = F_OK // test for existence of file
95 /// Test whether the current user has a given set of permissions
97 /// Is the file writable for the current user?
98 bool writable() { return access(FileInfo::wperm); }
99 /// Is the file readable for the current user?
100 bool readable() { return access(FileInfo::rperm); }
101 /// Is the file executable for the current user?
102 bool executable() { return access(FileInfo::xperm); }
103 /// Does the file exist?
104 bool exist() { return access(FileInfo::eperm); }
108 bool isRegular() const;
114 bool isBlock() const;
118 bool isSocket() const;
120 int getError() const;