]> git.lyx.org Git - lyx.git/blob - src/support/FileInfo.h
Various fixes look at ChangeLog
[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         /// File descriptor
35         FileInfo(int fildes);
36
37         /// Query a new file
38         FileInfo & newFile(string const & path, bool link = false);
39         
40         /// Query a new file descriptor
41         FileInfo & newFile(int fildes);
42         
43         /// Returns a character describing file type (ls -F)
44         char const * typeIndicator() const;
45         
46         /// File protection mode
47         mode_t getMode() const;
48
49         /// Get "preferred" block size for efficient file system I/O
50         long getBlockSize() const;
51         
52         /// Constructs standard mode string (ls style)
53         void modeString(char * szString) const;
54         
55         /// returns a letter describing a file type (ls style)
56         char typeLetter() const;
57         
58         /// builds 'rwx' string describing file access rights
59         void flagRWX(unsigned short i, char * szString) const;
60         
61         /// updates mode string to match suid/sgid/sticky bits
62         void setSticky(char * szString) const;
63         
64         ///
65         time_t getModificationTime() const;
66         
67         ///
68         time_t getAccessTime() const;
69         
70         ///
71         time_t getStatusChangeTime() const;
72         
73         /// Total file size in bytes
74         off_t getSize() const;
75         
76         /// Number of hard links
77         nlink_t getNumberOfLinks() const;
78         
79         /// User ID of owner
80         uid_t getUid() const;
81         
82         /// Group ID of owner
83         gid_t getGid() const;
84         
85         /// Is the file information correct? Did the query succeed?
86         bool isOK() const;
87         
88         /// Permission flags
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         /// Test whether the current user has a given set of permissions
96         bool access(int p);
97         /// Is the file writable for the current user?
98         bool writable() { return access(FileInfo::wperm); }
99         /// Is the file readable for the current user?
100         bool readable() { return access(FileInfo::rperm); }
101         /// Is the file executable for the current user?
102         bool executable() { return access(FileInfo::xperm); }
103         /// Does the file exist?
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