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. */
41 FileInfo(string const & path, bool link = false);
48 FileInfo & newFile(string const & path, bool link = false);
50 /// Query a new file descriptor
51 FileInfo & newFile(int fildes);
53 /// Returns a character describing file type (ls -F)
54 char const * typeIndicator() const;
56 /// File protection mode
57 mode_t getMode() const;
59 /// Constructs standard mode string (ls style)
60 void modeString(char * szString) const;
62 /// returns a letter describing a file type (ls style)
63 char typeLetter() const;
65 /// builds 'rwx' string describing file access rights
66 void flagRWX(mode_t i, char * szString) const;
68 /// updates mode string to match suid/sgid/sticky bits
69 void setSticky(char * szString) const;
72 time_t getModificationTime() const;
75 time_t getAccessTime() const;
78 time_t getStatusChangeTime() const;
80 /// Total file size in bytes
81 off_t getSize() const;
83 /// Number of hard links
84 nlink_t getNumberOfLinks() const;
92 /// Is the file information correct? Did the query succeed?
97 /// test for read permission
99 /// test for write permission
101 /// test for execute (search) permission
103 /// test for existence of file
106 /// Test whether the current user has a given set of permissions
107 bool access(int p) const;
108 /// Is the file writable for the current user?
109 bool writable() const { return access(FileInfo::wperm); }
110 /// Is the file readable for the current user?
111 bool readable() const { return access(FileInfo::rperm); }
112 /// Is the file executable for the current user?
113 bool executable() const { return access(FileInfo::xperm); }
114 /// Does the file exist?
115 bool exist() const { return access(FileInfo::eperm); }
119 bool isRegular() const;
125 bool isBlock() const;
129 bool isSocket() const;
131 int getError() const;