2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 1995 Matthias Ettrich
8 * Copyright 1995-2000 The LyX Team.
10 * ====================================================== */
21 #include <sys/types.h>
24 #include <boost/utility.hpp>
27 #if defined(__CYGWIN__) //Cygwin has it's own concept of X_OK ???
32 /** Use objects of this class to get information about files.
34 class FileInfo : boost::noncopyable {
39 /** Get information about file.
40 If link is true, the information is about the link itself, not
41 the file that is obtained by tracing the links. */
43 FileInfo(string const & path, bool link = false);
50 FileInfo & newFile(string const & path, bool link = false);
52 /// Query a new file descriptor
53 FileInfo & newFile(int fildes);
55 /// Returns a character describing file type (ls -F)
56 char const * typeIndicator() const;
58 /// File protection mode
59 mode_t getMode() const;
61 /// Constructs standard mode string (ls style)
62 void modeString(char * szString) const;
64 /// returns a letter describing a file type (ls style)
65 char typeLetter() const;
67 /// builds 'rwx' string describing file access rights
68 void flagRWX(mode_t i, char * szString) const;
70 /// updates mode string to match suid/sgid/sticky bits
71 void setSticky(char * szString) const;
74 time_t getModificationTime() const;
77 time_t getAccessTime() const;
80 time_t getStatusChangeTime() const;
82 /// Total file size in bytes
83 off_t getSize() const;
85 /// Number of hard links
86 nlink_t getNumberOfLinks() const;
94 /// Is the file information correct? Did the query succeed?
99 /// test for read permission
101 /// test for write permission
103 /// test for execute (search) permission
105 /// test for existence of file
108 /// Test whether the current user has a given set of permissions
109 bool access(int p) const;
110 /// Is the file writable for the current user?
111 bool writable() const { return access(FileInfo::wperm); }
112 /// Is the file readable for the current user?
113 bool readable() const { return access(FileInfo::rperm); }
114 /// Is the file executable for the current user?
115 bool executable() const { return access(FileInfo::xperm); }
116 /// Does the file exist?
117 bool exist() const { return access(FileInfo::eperm); }
121 bool isRegular() const;
127 bool isBlock() const;
131 bool isSocket() const;
133 int getError() const;