2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 1995 Matthias Ettrich
8 * Copyright 1995-2001 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 * Users must make sure to check fi.isOK() before any operations
35 * requiring the file to exist such as fi.isDir()
37 class FileInfo : boost::noncopyable {
42 /** Get information about file.
43 If link is true, the information is about the link itself, not
44 the file that is obtained by tracing the links. */
46 FileInfo(string const & path, bool link = false);
53 FileInfo & newFile(string const & path, bool link = false);
55 /// Query a new file descriptor
56 FileInfo & newFile(int fildes);
58 /// Returns a character describing file type (ls -F)
59 char const * typeIndicator() const;
61 /// File protection mode
62 mode_t getMode() const;
64 /// Constructs standard mode string (ls style)
65 void modeString(char * szString) const;
67 /// returns a letter describing a file type (ls style)
68 char typeLetter() const;
70 /// builds 'rwx' string describing file access rights
71 void flagRWX(mode_t i, char * szString) const;
73 /// updates mode string to match suid/sgid/sticky bits
74 void setSticky(char * szString) const;
77 time_t getModificationTime() const;
80 time_t getAccessTime() const;
83 time_t getStatusChangeTime() const;
85 /// Total file size in bytes
86 off_t getSize() const;
88 /// Number of hard links
89 nlink_t getNumberOfLinks() const;
97 /// Is the file information correct? Did the query succeed?
102 /// test for read permission
104 /// test for write permission
106 /// test for execute (search) permission
108 /// test for existence of file
111 /// Test whether the current user has a given set of permissions
112 bool access(int p) const;
113 /// Is the file writable for the current user?
114 bool writable() const { return access(FileInfo::wperm); }
115 /// Is the file readable for the current user?
116 bool readable() const { return access(FileInfo::rperm); }
117 /// Is the file executable for the current user?
118 bool executable() const { return access(FileInfo::xperm); }
119 /// Does the file exist?
120 bool exist() const { return access(FileInfo::eperm); }
124 bool isRegular() const;
130 bool isBlock() const;
134 bool isSocket() const;
136 int getError() const;