]> git.lyx.org Git - lyx.git/blob - src/support/FileInfo.h
remove noload/don't typeset
[lyx.git] / src / support / FileInfo.h
1 // -*- C++ -*-
2 /* This file is part of
3  * ======================================================
4  *
5  *           LyX, The Document Processor
6  *
7  *           Copyright 1995 Matthias Ettrich
8  *           Copyright 1995-2001 The LyX Team.
9  *
10  * ====================================================== */
11
12 #ifndef FILE_INFO_H
13 #define FILE_INFO_H
14
15 #ifdef __GNUG__
16 #pragma interface
17 #endif
18
19 #include <ctime>
20
21 #include <sys/types.h>
22 #include <sys/stat.h>
23 #include <unistd.h>
24 #include <boost/utility.hpp>
25 #include "LString.h"
26
27 /** Use objects of this class to get information about files.
28  *
29  * Users must make sure to check fi.isOK() before any operations
30  * requiring the file to exist such as fi.isDir()
31  */
32 class FileInfo : boost::noncopyable {
33 public:
34         ///
35         FileInfo();
36
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. */
40         explicit FileInfo(string const & path, bool link = false);
41
42         /// File descriptor
43         explicit FileInfo(int fildes);
44
45         /// Query a new file
46         FileInfo & newFile(string const & path, bool link = false);
47
48         /// Query a new file descriptor
49         FileInfo & newFile(int fildes);
50
51         /// Returns a character describing file type (ls -F)
52         char typeIndicator() const;
53
54         /// File protection mode
55         mode_t getMode() const;
56
57         /// Constructs standard mode string (ls style)
58         string modeString() const;
59
60         ///
61         time_t getModificationTime() const;
62
63         ///
64         time_t getAccessTime() const;
65
66         ///
67         time_t getStatusChangeTime() const;
68
69         /// Total file size in bytes
70         off_t getSize() const;
71
72         /// Number of hard links
73         nlink_t getNumberOfLinks() const;
74
75         /// User ID of owner
76         uid_t getUid() const;
77
78         /// Group ID of owner
79         gid_t getGid() const;
80
81         /// Is the file information correct? Did the query succeed?
82         bool isOK() const;
83
84         /// Permission flags
85         enum perm_test {
86                 /// test for read permission
87                 rperm = R_OK,
88                 /// test for write permission
89                 wperm = W_OK,
90                 /// test for execute (search) permission
91                 xperm = X_OK,
92                 /// test for existence of file
93                 eperm = F_OK
94         };
95         /// Test whether the current user has a given set of permissions
96         bool access(int p) const;
97         /// Is the file writable for the current user?
98         bool writable() const { return access(FileInfo::wperm); }
99         /// Is the file readable for the current user?
100         bool readable() const { return access(FileInfo::rperm); }
101         /// Is the file executable for the current user?
102         bool executable() const { return access(FileInfo::xperm); }
103         /// Does the file exist?
104         bool exist() const { return access(FileInfo::eperm); }
105         ///
106         bool isLink() const;
107         ///
108         bool isRegular() const;
109         ///
110         bool isDir() const;
111         ///
112         bool isChar() const;
113         ///
114         bool isBlock() const;
115         ///
116         bool isFifo() const;
117         ///
118         bool isSocket() const;
119         ///
120         int getError() const;
121         ///
122         enum Err {
123                 ///
124                 NoErr = -1
125         };
126 private:
127         ///
128         void init();
129         ///
130         void dostat(bool);
131
132         ///
133         struct stat buf_;
134         ///
135         int status_;
136         ///
137         int err_;
138         ///
139         string fname_;
140 };
141
142 #endif