]> git.lyx.org Git - lyx.git/blob - src/support/FileInfo.h
remove commented HAVE_SSTREAM code
[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-2000 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 <unistd.h>
22 #include <sys/types.h>
23 #include <sys/stat.h>
24
25 #include "LString.h"
26
27 /** Use objects of this class to get information about files.
28  */
29 class FileInfo {
30 public:
31         ///
32         FileInfo();
33         
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. */
37         explicit
38         FileInfo(string const & path, bool link = false);
39
40         /// File descriptor
41         explicit
42         FileInfo(int fildes);
43
44         /// Query a new file
45         FileInfo & newFile(string const & path, bool link = false);
46         
47         /// Query a new file descriptor
48         FileInfo & newFile(int fildes);
49         
50         /// Returns a character describing file type (ls -F)
51         char const * typeIndicator() const;
52         
53         /// File protection mode
54         mode_t getMode() const;
55
56         /// Constructs standard mode string (ls style)
57         void modeString(char * szString) const;
58         
59         /// returns a letter describing a file type (ls style)
60         char typeLetter() const;
61         
62         /// builds 'rwx' string describing file access rights
63         void flagRWX(unsigned short i, char * szString) const;
64         
65         /// updates mode string to match suid/sgid/sticky bits
66         void setSticky(char * szString) const;
67         
68         ///
69         time_t getModificationTime() const;
70         
71         ///
72         time_t getAccessTime() const;
73         
74         ///
75         time_t getStatusChangeTime() const;
76         
77         /// Total file size in bytes
78         off_t getSize() const;
79         
80         /// Number of hard links
81         nlink_t getNumberOfLinks() const;
82         
83         /// User ID of owner
84         uid_t getUid() const;
85         
86         /// Group ID of owner
87         gid_t getGid() const;
88         
89         /// Is the file information correct? Did the query succeed?
90         bool isOK() const;
91         
92         /// Permission flags
93         enum perm_test {
94                 /// test for read permission
95                 rperm = R_OK,
96                 /// test for write permission
97                 wperm = W_OK,
98                 /// test for execute (search) permission
99                 xperm = X_OK,
100                 /// test for existence of file
101                 eperm = F_OK
102         };
103         /// Test whether the current user has a given set of permissions
104         bool access(int p);
105         /// Is the file writable for the current user?
106         bool writable() { return access(FileInfo::wperm); }
107         /// Is the file readable for the current user?
108         bool readable() { return access(FileInfo::rperm); }
109         /// Is the file executable for the current user?
110         bool executable() { return access(FileInfo::xperm); }
111         /// Does the file exist?
112         bool exist() { return access(FileInfo::eperm); }
113         ///
114         bool isLink() const;
115         ///
116         bool isRegular() const;
117         ///
118         bool isDir() const;
119         ///
120         bool isChar() const;
121         ///
122         bool isBlock() const;
123         ///
124         bool isFifo() const;
125         ///
126         bool isSocket() const;
127         ///
128         int getError() const;
129         ///
130         enum Err {
131                 ///
132                 NoErr = -1
133         };
134 private:
135         ///
136         void init();
137         ///
138         void dostat(bool);
139         ///
140         struct stat buf;
141         ///
142         int status;
143         ///
144         int err;
145         ///
146         string fname;
147 };
148
149 #endif