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 * str) const;
62 /// returns a letter describing a file type (ls style)
63 char typeLetter() const;
66 time_t getModificationTime() const;
69 time_t getAccessTime() const;
72 time_t getStatusChangeTime() const;
74 /// Total file size in bytes
75 off_t getSize() const;
77 /// Number of hard links
78 nlink_t getNumberOfLinks() const;
86 /// Is the file information correct? Did the query succeed?
91 /// test for read permission
93 /// test for write permission
95 /// test for execute (search) permission
97 /// test for existence of file
100 /// Test whether the current user has a given set of permissions
101 bool access(int p) const;
102 /// Is the file writable for the current user?
103 bool writable() const { return access(FileInfo::wperm); }
104 /// Is the file readable for the current user?
105 bool readable() const { return access(FileInfo::rperm); }
106 /// Is the file executable for the current user?
107 bool executable() const { return access(FileInfo::xperm); }
108 /// Does the file exist?
109 bool exist() const { return access(FileInfo::eperm); }
113 bool isRegular() const;
119 bool isBlock() const;
123 bool isSocket() const;
125 int getError() const;