]> git.lyx.org Git - lyx.git/blob - src/support/FileInfo.h
remove a cygwin #ifdef
[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
41         FileInfo(string const & path, bool link = false);
42
43         /// File descriptor
44         explicit
45         FileInfo(int fildes);
46
47         /// Query a new file
48         FileInfo & newFile(string const & path, bool link = false);
49         
50         /// Query a new file descriptor
51         FileInfo & newFile(int fildes);
52         
53         /// Returns a character describing file type (ls -F)
54         char const * typeIndicator() const;
55         
56         /// File protection mode
57         mode_t getMode() const;
58
59         /// Constructs standard mode string (ls style)
60         void modeString(char * szString) const;
61         
62         /// returns a letter describing a file type (ls style)
63         char typeLetter() const;
64         
65         /// builds 'rwx' string describing file access rights
66         void flagRWX(mode_t i, char * szString) const;
67         
68         /// updates mode string to match suid/sgid/sticky bits
69         void setSticky(char * szString) const;
70         
71         ///
72         time_t getModificationTime() const;
73         
74         ///
75         time_t getAccessTime() const;
76         
77         ///
78         time_t getStatusChangeTime() const;
79         
80         /// Total file size in bytes
81         off_t getSize() const;
82         
83         /// Number of hard links
84         nlink_t getNumberOfLinks() const;
85         
86         /// User ID of owner
87         uid_t getUid() const;
88         
89         /// Group ID of owner
90         gid_t getGid() const;
91         
92         /// Is the file information correct? Did the query succeed?
93         bool isOK() const;
94         
95         /// Permission flags
96         enum perm_test {
97                 /// test for read permission
98                 rperm = R_OK,
99                 /// test for write permission
100                 wperm = W_OK,
101                 /// test for execute (search) permission
102                 xperm = X_OK,
103                 /// test for existence of file
104                 eperm = F_OK
105         };
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); }
116         ///
117         bool isLink() const;
118         ///
119         bool isRegular() const;
120         ///
121         bool isDir() const;
122         ///
123         bool isChar() const;
124         ///
125         bool isBlock() const;
126         ///
127         bool isFifo() const;
128         ///
129         bool isSocket() const;
130         ///
131         int getError() const;
132         ///
133         enum Err {
134                 ///
135                 NoErr = -1
136         };
137 private:
138         ///
139         void init();
140         ///
141         void dostat(bool);
142         ///
143         struct stat buf;
144         ///
145         int status;
146         ///
147         int err;
148         ///
149         string fname;
150 };
151
152 #endif