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 * ====================================================== */
21 #include <sys/types.h>
24 #include <boost/utility.hpp>
27 /** Use objects of this class to get information about files.
29 class FileInfo : boost::noncopyable {
34 /** Get information about file.
35 If link is true, the information is about the link itself, not
36 the file that is obtained by tracing the links. */
38 FileInfo(string const & path, bool link = false);
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 const * typeIndicator() const;
53 /// File protection mode
54 mode_t getMode() const;
56 /// Constructs standard mode string (ls style)
57 void modeString(char * szString) const;
59 /// returns a letter describing a file type (ls style)
60 char typeLetter() const;
62 /// builds 'rwx' string describing file access rights
63 void flagRWX(mode_t i, char * szString) const;
65 /// updates mode string to match suid/sgid/sticky bits
66 void setSticky(char * szString) const;
69 time_t getModificationTime() const;
72 time_t getAccessTime() const;
75 time_t getStatusChangeTime() const;
77 /// Total file size in bytes
78 off_t getSize() const;
80 /// Number of hard links
81 nlink_t getNumberOfLinks() const;
89 /// Is the file information correct? Did the query succeed?
94 /// test for read permission
96 /// test for write permission
98 /// test for execute (search) permission
100 /// test for existence of file
103 /// Test whether the current user has a given set of permissions
104 bool access(int p) const;
105 /// Is the file writable for the current user?
106 bool writable() const { return access(FileInfo::wperm); }
107 /// Is the file readable for the current user?
108 bool readable() const { return access(FileInfo::rperm); }
109 /// Is the file executable for the current user?
110 bool executable() const { return access(FileInfo::xperm); }
111 /// Does the file exist?
112 bool exist() const { return access(FileInfo::eperm); }
116 bool isRegular() const;
122 bool isBlock() const;
126 bool isSocket() const;
128 int getError() const;