]> git.lyx.org Git - lyx.git/blob - src/support/FileInfo.h
the runlatex merge
[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         ///
38         ~FileInfo();
39
40         /// Query a new file
41         FileInfo& newFile(string const & path, bool link = false);
42
43         /// Query a new file descriptor
44         FileInfo& newFile(int fildes);
45         
46         /// Returns a character describing file type (ls -F)
47         char const * typeIndicator() const;
48
49         /// File protection mode
50         mode_t getMode() const;
51
52         /// Get "preferred" block size for efficient file system I/O
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         /// Total file size in bytes
77         off_t getSize() const;
78
79         /// Number of hard links
80         nlink_t getNumberOfLinks() const;
81
82         /// User ID of owner
83         uid_t getUid() const;
84
85         /// Group ID of owner
86         gid_t getGid() const;
87
88         /// Is the file information correct? Did the query succeed?
89         bool isOK() const;
90
91         /// Permission flags
92         enum perm_test {
93                 rperm = R_OK, // test for read permission
94                 wperm = W_OK, // test for write permission
95                 xperm = X_OK, // test for execute (search) permission
96                 eperm = F_OK  // test for existence of file
97         };
98         /// Test whether the current user has a given set of permissions
99         bool access(int p);
100         /// Is the file writable for the current user?
101         bool writable() { return access(FileInfo::wperm); }
102         /// Is the file readable for the current user?
103         bool readable() { return access(FileInfo::rperm); }
104         /// Is the file executable for the current user?
105         bool executable() { return access(FileInfo::xperm); }
106         /// Does the file exist?
107         bool exist() { return access(FileInfo::eperm); }
108         ///
109         bool isLink() const;
110         ///
111         bool isRegular() const;
112         ///
113         bool isDir() const;
114         ///
115         bool isChar() const;
116         ///
117         bool isBlock() const;
118         ///
119         bool isFifo() const;
120         ///
121         bool isSocket() const;
122         ///
123         int getError() const;
124         ///
125         enum {
126                 ///
127                 NoErr = -1
128         };
129 private:
130         ///
131         void init();
132         ///
133         void dostat(bool);
134         ///
135         struct stat * buf;
136         ///
137         int status;
138         ///
139         int err;
140         ///
141         string fname;
142 };
143
144 #endif