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