]> git.lyx.org Git - lyx.git/blob - src/support/FileInfo.h
removed bogus Assert
[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-1999 The LyX Team.
9  *
10  * ======================================================*/
11
12 #ifndef FILE_INFO_H
13 #define FILE_INFO_H
14
15 #include <ctime>
16
17 #include <unistd.h>
18 #include <sys/types.h>
19 #include <sys/stat.h>
20
21 #include "LString.h"
22
23 /** Use objects of this class to get information about files. */
24 class FileInfo {
25 public:
26         ///
27         FileInfo();
28
29         /** Get information about file.
30         If link is true, the information is about the link itself, not
31         the file that is obtained by tracing the links. */
32         FileInfo(string const & path, bool link = false);
33
34         ///
35         FileInfo(int fildes);
36
37         ///
38         ~FileInfo();
39
40         ///
41         FileInfo& newFile(string const & path, bool link = false);
42
43         ///
44         FileInfo& newFile(int fildes);
45         
46         /// returns a character describing file type (ls -F)
47         char const * typeIndicator() const;
48
49         ///
50         mode_t getMode() const;
51
52         ///
53         long getBlockSize() const;
54         
55         /// constructs standard mode string (ls style)
56         void modeString(char * szString) const;
57         
58         /// returns a letter describing a file type (ls style)
59         char typeLetter() const;
60         
61         /// builds 'rwx' string describing file access rights
62         void flagRWX(unsigned short i, char * szString) const;
63         
64         /// updates mode string to match suid/sgid/sticky bits
65         void setSticky(char * szString) const;
66
67         ///
68         time_t getModificationTime() const;
69
70         ///
71         time_t getAccessTime() const;
72
73         ///
74         time_t getStatusChangeTime() const;
75
76         ///
77         off_t getSize() const;
78
79         ///
80         nlink_t getNumberOfLinks() const;
81
82         ///
83         uid_t getUid() const;
84         ///
85         gid_t getGid() const;
86         ///
87         bool isOK() const;
88         ///
89         enum perm_test {
90                 rperm = R_OK, // test for read permission
91                 wperm = W_OK, // test for write permission
92                 xperm = X_OK, // test for execute (search) permission
93                 eperm = F_OK  // test for existence of file
94         };
95         ///
96         bool access(int p);
97         ///
98         bool writable() { return access(FileInfo::wperm); }
99         ///
100         bool readable() { return access(FileInfo::rperm); }
101         ///
102         bool executable() { return access(FileInfo::xperm); }
103         ///
104         bool exist() { 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 {
123                 ///
124                 NoErr = -1
125         };
126 private:
127         ///
128         void init();
129         ///
130         void dostat(bool);
131         ///
132         struct stat * buf;
133         ///
134         int status;
135         ///
136         int err;
137         ///
138         string fname;
139 };
140
141 #endif
142