xref: /minix3/external/bsd/atf/dist/tools/fs.hpp (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc //
2*0a6a1f1dSLionel Sambuc // Automated Testing Framework (atf)
3*0a6a1f1dSLionel Sambuc //
4*0a6a1f1dSLionel Sambuc // Copyright (c) 2007 The NetBSD Foundation, Inc.
5*0a6a1f1dSLionel Sambuc // All rights reserved.
6*0a6a1f1dSLionel Sambuc //
7*0a6a1f1dSLionel Sambuc // Redistribution and use in source and binary forms, with or without
8*0a6a1f1dSLionel Sambuc // modification, are permitted provided that the following conditions
9*0a6a1f1dSLionel Sambuc // are met:
10*0a6a1f1dSLionel Sambuc // 1. Redistributions of source code must retain the above copyright
11*0a6a1f1dSLionel Sambuc //    notice, this list of conditions and the following disclaimer.
12*0a6a1f1dSLionel Sambuc // 2. Redistributions in binary form must reproduce the above copyright
13*0a6a1f1dSLionel Sambuc //    notice, this list of conditions and the following disclaimer in the
14*0a6a1f1dSLionel Sambuc //    documentation and/or other materials provided with the distribution.
15*0a6a1f1dSLionel Sambuc //
16*0a6a1f1dSLionel Sambuc // THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
17*0a6a1f1dSLionel Sambuc // CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
18*0a6a1f1dSLionel Sambuc // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19*0a6a1f1dSLionel Sambuc // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20*0a6a1f1dSLionel Sambuc // IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
21*0a6a1f1dSLionel Sambuc // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22*0a6a1f1dSLionel Sambuc // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23*0a6a1f1dSLionel Sambuc // GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24*0a6a1f1dSLionel Sambuc // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25*0a6a1f1dSLionel Sambuc // IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26*0a6a1f1dSLionel Sambuc // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27*0a6a1f1dSLionel Sambuc // IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28*0a6a1f1dSLionel Sambuc //
29*0a6a1f1dSLionel Sambuc 
30*0a6a1f1dSLionel Sambuc #if !defined(TOOLS_FS_HPP)
31*0a6a1f1dSLionel Sambuc #define TOOLS_FS_HPP
32*0a6a1f1dSLionel Sambuc 
33*0a6a1f1dSLionel Sambuc extern "C" {
34*0a6a1f1dSLionel Sambuc #include <sys/types.h>
35*0a6a1f1dSLionel Sambuc #include <sys/stat.h>
36*0a6a1f1dSLionel Sambuc }
37*0a6a1f1dSLionel Sambuc 
38*0a6a1f1dSLionel Sambuc #include <map>
39*0a6a1f1dSLionel Sambuc #include <memory>
40*0a6a1f1dSLionel Sambuc #include <ostream>
41*0a6a1f1dSLionel Sambuc #include <set>
42*0a6a1f1dSLionel Sambuc #include <stdexcept>
43*0a6a1f1dSLionel Sambuc #include <string>
44*0a6a1f1dSLionel Sambuc 
45*0a6a1f1dSLionel Sambuc namespace tools {
46*0a6a1f1dSLionel Sambuc namespace fs {
47*0a6a1f1dSLionel Sambuc 
48*0a6a1f1dSLionel Sambuc // ------------------------------------------------------------------------
49*0a6a1f1dSLionel Sambuc // The "path" class.
50*0a6a1f1dSLionel Sambuc // ------------------------------------------------------------------------
51*0a6a1f1dSLionel Sambuc 
52*0a6a1f1dSLionel Sambuc //!
53*0a6a1f1dSLionel Sambuc //! \brief A class to represent a path to a file.
54*0a6a1f1dSLionel Sambuc //!
55*0a6a1f1dSLionel Sambuc //! The path class represents the route to a file or directory in the
56*0a6a1f1dSLionel Sambuc //! file system.  All file manipulation operations use this class to
57*0a6a1f1dSLionel Sambuc //! represent their arguments as it takes care of normalizing user-provided
58*0a6a1f1dSLionel Sambuc //! strings and ensures they are valid.
59*0a6a1f1dSLionel Sambuc //!
60*0a6a1f1dSLionel Sambuc //! It is important to note that the file pointed to by a path need not
61*0a6a1f1dSLionel Sambuc //! exist.
62*0a6a1f1dSLionel Sambuc //!
63*0a6a1f1dSLionel Sambuc class path {
64*0a6a1f1dSLionel Sambuc     //!
65*0a6a1f1dSLionel Sambuc     //! \brief Internal representation of a path.
66*0a6a1f1dSLionel Sambuc     //!
67*0a6a1f1dSLionel Sambuc     std::string m_data;
68*0a6a1f1dSLionel Sambuc 
69*0a6a1f1dSLionel Sambuc public:
70*0a6a1f1dSLionel Sambuc     //! \brief Constructs a new path from a user-provided string.
71*0a6a1f1dSLionel Sambuc     //!
72*0a6a1f1dSLionel Sambuc     //! This constructor takes a string, either provided by the program's
73*0a6a1f1dSLionel Sambuc     //! code or by the user and constructs a new path object.  The string
74*0a6a1f1dSLionel Sambuc     //! is normalized to not contain multiple delimiters together and to
75*0a6a1f1dSLionel Sambuc     //! remove any trailing one.
76*0a6a1f1dSLionel Sambuc     //!
77*0a6a1f1dSLionel Sambuc     //! The input string cannot be empty.
78*0a6a1f1dSLionel Sambuc     //!
79*0a6a1f1dSLionel Sambuc     explicit path(const std::string&);
80*0a6a1f1dSLionel Sambuc 
81*0a6a1f1dSLionel Sambuc     //!
82*0a6a1f1dSLionel Sambuc     //! \brief Destructor for the path class.
83*0a6a1f1dSLionel Sambuc     //!
84*0a6a1f1dSLionel Sambuc     ~path(void);
85*0a6a1f1dSLionel Sambuc 
86*0a6a1f1dSLionel Sambuc     //!
87*0a6a1f1dSLionel Sambuc     //! \brief Returns a pointer to a C-style string representing this path.
88*0a6a1f1dSLionel Sambuc     //!
89*0a6a1f1dSLionel Sambuc     const char* c_str(void) const;
90*0a6a1f1dSLionel Sambuc 
91*0a6a1f1dSLionel Sambuc     //!
92*0a6a1f1dSLionel Sambuc     //! \brief Returns a string representing this path.
93*0a6a1f1dSLionel Sambuc     //! XXX Really needed?
94*0a6a1f1dSLionel Sambuc     //!
95*0a6a1f1dSLionel Sambuc     std::string str(void) const;
96*0a6a1f1dSLionel Sambuc 
97*0a6a1f1dSLionel Sambuc     //!
98*0a6a1f1dSLionel Sambuc     //! \brief Returns the branch path of this path.
99*0a6a1f1dSLionel Sambuc     //!
100*0a6a1f1dSLionel Sambuc     //! Calculates and returns the branch path of this path.  In other
101*0a6a1f1dSLionel Sambuc     //! words, it returns what the standard ::dirname function would return.
102*0a6a1f1dSLionel Sambuc     //!
103*0a6a1f1dSLionel Sambuc     path branch_path(void) const;
104*0a6a1f1dSLionel Sambuc 
105*0a6a1f1dSLionel Sambuc     //!
106*0a6a1f1dSLionel Sambuc     //! \brief Returns the leaf name of this path.
107*0a6a1f1dSLionel Sambuc     //!
108*0a6a1f1dSLionel Sambuc     //! Calculates and returns the leaf name of this path.  In other words,
109*0a6a1f1dSLionel Sambuc     //! it returns what the standard ::basename function would return.
110*0a6a1f1dSLionel Sambuc     //!
111*0a6a1f1dSLionel Sambuc     std::string leaf_name(void) const;
112*0a6a1f1dSLionel Sambuc 
113*0a6a1f1dSLionel Sambuc     //!
114*0a6a1f1dSLionel Sambuc     //! \brief Checks whether this path is absolute or not.
115*0a6a1f1dSLionel Sambuc     //!
116*0a6a1f1dSLionel Sambuc     //! Returns a boolean indicating if this is an absolute path or not;
117*0a6a1f1dSLionel Sambuc     //! i.e. if it starts with a slash.
118*0a6a1f1dSLionel Sambuc     //!
119*0a6a1f1dSLionel Sambuc     bool is_absolute(void) const;
120*0a6a1f1dSLionel Sambuc 
121*0a6a1f1dSLionel Sambuc     //!
122*0a6a1f1dSLionel Sambuc     //! \brief Checks whether this path points to the root directory or not.
123*0a6a1f1dSLionel Sambuc     //!
124*0a6a1f1dSLionel Sambuc     //! Returns a boolean indicating if this is path points to the root
125*0a6a1f1dSLionel Sambuc     //! directory or not.  The checks made by this are extremely simple (so
126*0a6a1f1dSLionel Sambuc     //! the results cannot always be trusted) but they are enough for our
127*0a6a1f1dSLionel Sambuc     //! modest sanity-checking needs.  I.e. "/../" could return false.
128*0a6a1f1dSLionel Sambuc     //!
129*0a6a1f1dSLionel Sambuc     bool is_root(void) const;
130*0a6a1f1dSLionel Sambuc 
131*0a6a1f1dSLionel Sambuc     //!
132*0a6a1f1dSLionel Sambuc     //! \brief Converts the path to be absolute.
133*0a6a1f1dSLionel Sambuc     //!
134*0a6a1f1dSLionel Sambuc     //! \pre The path was not absolute.
135*0a6a1f1dSLionel Sambuc     //!
136*0a6a1f1dSLionel Sambuc     path to_absolute(void) const;
137*0a6a1f1dSLionel Sambuc 
138*0a6a1f1dSLionel Sambuc     //!
139*0a6a1f1dSLionel Sambuc     //! \brief Checks if two paths are equal.
140*0a6a1f1dSLionel Sambuc     //!
141*0a6a1f1dSLionel Sambuc     bool operator==(const path&) const;
142*0a6a1f1dSLionel Sambuc 
143*0a6a1f1dSLionel Sambuc     //!
144*0a6a1f1dSLionel Sambuc     //! \brief Checks if two paths are different.
145*0a6a1f1dSLionel Sambuc     //!
146*0a6a1f1dSLionel Sambuc     bool operator!=(const path&) const;
147*0a6a1f1dSLionel Sambuc 
148*0a6a1f1dSLionel Sambuc     //!
149*0a6a1f1dSLionel Sambuc     //! \brief Concatenates a path with a string.
150*0a6a1f1dSLionel Sambuc     //!
151*0a6a1f1dSLionel Sambuc     //! Constructs a new path object that is the concatenation of the
152*0a6a1f1dSLionel Sambuc     //! left-hand path with the right-hand string.  The string is normalized
153*0a6a1f1dSLionel Sambuc     //! before the concatenation, and a path delimiter is introduced between
154*0a6a1f1dSLionel Sambuc     //! the two components if needed.
155*0a6a1f1dSLionel Sambuc     //!
156*0a6a1f1dSLionel Sambuc     path operator/(const std::string&) const;
157*0a6a1f1dSLionel Sambuc 
158*0a6a1f1dSLionel Sambuc     //!
159*0a6a1f1dSLionel Sambuc     //! \brief Concatenates a path with another path.
160*0a6a1f1dSLionel Sambuc     //!
161*0a6a1f1dSLionel Sambuc     //! Constructs a new path object that is the concatenation of the
162*0a6a1f1dSLionel Sambuc     //! left-hand path with the right-hand one. A path delimiter is
163*0a6a1f1dSLionel Sambuc     //! introduced between the two components if needed.
164*0a6a1f1dSLionel Sambuc     //!
165*0a6a1f1dSLionel Sambuc     path operator/(const path&) const;
166*0a6a1f1dSLionel Sambuc 
167*0a6a1f1dSLionel Sambuc     //!
168*0a6a1f1dSLionel Sambuc     //! \brief Checks if a path has to be sorted before another one
169*0a6a1f1dSLionel Sambuc     //!        lexicographically.
170*0a6a1f1dSLionel Sambuc     //!
171*0a6a1f1dSLionel Sambuc     bool operator<(const path&) const;
172*0a6a1f1dSLionel Sambuc };
173*0a6a1f1dSLionel Sambuc 
174*0a6a1f1dSLionel Sambuc // ------------------------------------------------------------------------
175*0a6a1f1dSLionel Sambuc // The "file_info" class.
176*0a6a1f1dSLionel Sambuc // ------------------------------------------------------------------------
177*0a6a1f1dSLionel Sambuc 
178*0a6a1f1dSLionel Sambuc class directory;
179*0a6a1f1dSLionel Sambuc 
180*0a6a1f1dSLionel Sambuc //!
181*0a6a1f1dSLionel Sambuc //! \brief A class that contains information about a file.
182*0a6a1f1dSLionel Sambuc //!
183*0a6a1f1dSLionel Sambuc //! The file_info class holds information about an specific file that
184*0a6a1f1dSLionel Sambuc //! exists in the file system.
185*0a6a1f1dSLionel Sambuc //!
186*0a6a1f1dSLionel Sambuc class file_info {
187*0a6a1f1dSLionel Sambuc     int m_type;
188*0a6a1f1dSLionel Sambuc     struct stat m_sb;
189*0a6a1f1dSLionel Sambuc 
190*0a6a1f1dSLionel Sambuc public:
191*0a6a1f1dSLionel Sambuc     //!
192*0a6a1f1dSLionel Sambuc     //! \brief The file's type.
193*0a6a1f1dSLionel Sambuc     //!
194*0a6a1f1dSLionel Sambuc     static const int blk_type;
195*0a6a1f1dSLionel Sambuc     static const int chr_type;
196*0a6a1f1dSLionel Sambuc     static const int dir_type;
197*0a6a1f1dSLionel Sambuc     static const int fifo_type;
198*0a6a1f1dSLionel Sambuc     static const int lnk_type;
199*0a6a1f1dSLionel Sambuc     static const int reg_type;
200*0a6a1f1dSLionel Sambuc     static const int sock_type;
201*0a6a1f1dSLionel Sambuc     static const int wht_type;
202*0a6a1f1dSLionel Sambuc 
203*0a6a1f1dSLionel Sambuc     //!
204*0a6a1f1dSLionel Sambuc     //! \brief Constructs a new file_info based on a given file.
205*0a6a1f1dSLionel Sambuc     //!
206*0a6a1f1dSLionel Sambuc     //! This constructor creates a new file_info object and fills it with
207*0a6a1f1dSLionel Sambuc     //! the data returned by ::stat when run on the given file, which must
208*0a6a1f1dSLionel Sambuc     //! exist.
209*0a6a1f1dSLionel Sambuc     //!
210*0a6a1f1dSLionel Sambuc     explicit file_info(const path&);
211*0a6a1f1dSLionel Sambuc 
212*0a6a1f1dSLionel Sambuc     //!
213*0a6a1f1dSLionel Sambuc     //! \brief The destructor.
214*0a6a1f1dSLionel Sambuc     //!
215*0a6a1f1dSLionel Sambuc     ~file_info(void);
216*0a6a1f1dSLionel Sambuc 
217*0a6a1f1dSLionel Sambuc     //!
218*0a6a1f1dSLionel Sambuc     //! \brief Returns the device containing the file.
219*0a6a1f1dSLionel Sambuc     //!
220*0a6a1f1dSLionel Sambuc     dev_t get_device(void) const;
221*0a6a1f1dSLionel Sambuc 
222*0a6a1f1dSLionel Sambuc     //!
223*0a6a1f1dSLionel Sambuc     //! \brief Returns the file's inode.
224*0a6a1f1dSLionel Sambuc     //!
225*0a6a1f1dSLionel Sambuc     ino_t get_inode(void) const;
226*0a6a1f1dSLionel Sambuc 
227*0a6a1f1dSLionel Sambuc     //!
228*0a6a1f1dSLionel Sambuc     //! \brief Returns the file's permissions.
229*0a6a1f1dSLionel Sambuc     //!
230*0a6a1f1dSLionel Sambuc     mode_t get_mode(void) const;
231*0a6a1f1dSLionel Sambuc 
232*0a6a1f1dSLionel Sambuc     //!
233*0a6a1f1dSLionel Sambuc     //! \brief Returns the file's size.
234*0a6a1f1dSLionel Sambuc     //!
235*0a6a1f1dSLionel Sambuc     off_t get_size(void) const;
236*0a6a1f1dSLionel Sambuc 
237*0a6a1f1dSLionel Sambuc     //!
238*0a6a1f1dSLionel Sambuc     //! \brief Returns the file's type.
239*0a6a1f1dSLionel Sambuc     //!
240*0a6a1f1dSLionel Sambuc     int get_type(void) const;
241*0a6a1f1dSLionel Sambuc 
242*0a6a1f1dSLionel Sambuc     //!
243*0a6a1f1dSLionel Sambuc     //! \brief Returns whether the file is readable by its owner or not.
244*0a6a1f1dSLionel Sambuc     //!
245*0a6a1f1dSLionel Sambuc     bool is_owner_readable(void) const;
246*0a6a1f1dSLionel Sambuc 
247*0a6a1f1dSLionel Sambuc     //!
248*0a6a1f1dSLionel Sambuc     //! \brief Returns whether the file is writable by its owner or not.
249*0a6a1f1dSLionel Sambuc     //!
250*0a6a1f1dSLionel Sambuc     bool is_owner_writable(void) const;
251*0a6a1f1dSLionel Sambuc 
252*0a6a1f1dSLionel Sambuc     //!
253*0a6a1f1dSLionel Sambuc     //! \brief Returns whether the file is executable by its owner or not.
254*0a6a1f1dSLionel Sambuc     //!
255*0a6a1f1dSLionel Sambuc     bool is_owner_executable(void) const;
256*0a6a1f1dSLionel Sambuc 
257*0a6a1f1dSLionel Sambuc     //!
258*0a6a1f1dSLionel Sambuc     //! \brief Returns whether the file is readable by the users belonging
259*0a6a1f1dSLionel Sambuc     //! to its group or not.
260*0a6a1f1dSLionel Sambuc     //!
261*0a6a1f1dSLionel Sambuc     bool is_group_readable(void) const;
262*0a6a1f1dSLionel Sambuc 
263*0a6a1f1dSLionel Sambuc     //!
264*0a6a1f1dSLionel Sambuc     //! \brief Returns whether the file is writable the users belonging to
265*0a6a1f1dSLionel Sambuc     //! its group or not.
266*0a6a1f1dSLionel Sambuc     //!
267*0a6a1f1dSLionel Sambuc     bool is_group_writable(void) const;
268*0a6a1f1dSLionel Sambuc 
269*0a6a1f1dSLionel Sambuc     //!
270*0a6a1f1dSLionel Sambuc     //! \brief Returns whether the file is executable by the users
271*0a6a1f1dSLionel Sambuc     //! belonging to its group or not.
272*0a6a1f1dSLionel Sambuc     //!
273*0a6a1f1dSLionel Sambuc     bool is_group_executable(void) const;
274*0a6a1f1dSLionel Sambuc 
275*0a6a1f1dSLionel Sambuc     //!
276*0a6a1f1dSLionel Sambuc     //! \brief Returns whether the file is readable by people different
277*0a6a1f1dSLionel Sambuc     //! than the owner and those belonging to the group or not.
278*0a6a1f1dSLionel Sambuc     //!
279*0a6a1f1dSLionel Sambuc     bool is_other_readable(void) const;
280*0a6a1f1dSLionel Sambuc 
281*0a6a1f1dSLionel Sambuc     //!
282*0a6a1f1dSLionel Sambuc     //! \brief Returns whether the file is write by people different
283*0a6a1f1dSLionel Sambuc     //! than the owner and those belonging to the group or not.
284*0a6a1f1dSLionel Sambuc     //!
285*0a6a1f1dSLionel Sambuc     bool is_other_writable(void) const;
286*0a6a1f1dSLionel Sambuc 
287*0a6a1f1dSLionel Sambuc     //!
288*0a6a1f1dSLionel Sambuc     //! \brief Returns whether the file is executable by people different
289*0a6a1f1dSLionel Sambuc     //! than the owner and those belonging to the group or not.
290*0a6a1f1dSLionel Sambuc     //!
291*0a6a1f1dSLionel Sambuc     bool is_other_executable(void) const;
292*0a6a1f1dSLionel Sambuc };
293*0a6a1f1dSLionel Sambuc 
294*0a6a1f1dSLionel Sambuc // ------------------------------------------------------------------------
295*0a6a1f1dSLionel Sambuc // The "directory" class.
296*0a6a1f1dSLionel Sambuc // ------------------------------------------------------------------------
297*0a6a1f1dSLionel Sambuc 
298*0a6a1f1dSLionel Sambuc //!
299*0a6a1f1dSLionel Sambuc //! \brief A class representing a file system directory.
300*0a6a1f1dSLionel Sambuc //!
301*0a6a1f1dSLionel Sambuc //! The directory class represents a group of files in the file system and
302*0a6a1f1dSLionel Sambuc //! corresponds to exactly one directory.
303*0a6a1f1dSLionel Sambuc //!
304*0a6a1f1dSLionel Sambuc class directory : public std::map< std::string, file_info > {
305*0a6a1f1dSLionel Sambuc public:
306*0a6a1f1dSLionel Sambuc     //!
307*0a6a1f1dSLionel Sambuc     //! \brief Constructs a new directory.
308*0a6a1f1dSLionel Sambuc     //!
309*0a6a1f1dSLionel Sambuc     //! Constructs a new directory object representing the given path.
310*0a6a1f1dSLionel Sambuc     //! The directory must exist at creation time as the contents of the
311*0a6a1f1dSLionel Sambuc     //! class are gathered from it.
312*0a6a1f1dSLionel Sambuc     //!
313*0a6a1f1dSLionel Sambuc     directory(const path&);
314*0a6a1f1dSLionel Sambuc 
315*0a6a1f1dSLionel Sambuc     //!
316*0a6a1f1dSLionel Sambuc     //! \brief Returns the file names of the files in the directory.
317*0a6a1f1dSLionel Sambuc     //!
318*0a6a1f1dSLionel Sambuc     //! Returns the leaf names of all files contained in the directory.
319*0a6a1f1dSLionel Sambuc     //! I.e. the keys of the directory map.
320*0a6a1f1dSLionel Sambuc     //!
321*0a6a1f1dSLionel Sambuc     std::set< std::string > names(void) const;
322*0a6a1f1dSLionel Sambuc };
323*0a6a1f1dSLionel Sambuc 
324*0a6a1f1dSLionel Sambuc // ------------------------------------------------------------------------
325*0a6a1f1dSLionel Sambuc // The "temp_dir" class.
326*0a6a1f1dSLionel Sambuc // ------------------------------------------------------------------------
327*0a6a1f1dSLionel Sambuc 
328*0a6a1f1dSLionel Sambuc class temp_dir {
329*0a6a1f1dSLionel Sambuc     std::auto_ptr< tools::fs::path > m_path;
330*0a6a1f1dSLionel Sambuc 
331*0a6a1f1dSLionel Sambuc public:
332*0a6a1f1dSLionel Sambuc     temp_dir(const tools::fs::path&);
333*0a6a1f1dSLionel Sambuc     ~temp_dir(void);
334*0a6a1f1dSLionel Sambuc 
335*0a6a1f1dSLionel Sambuc     const tools::fs::path& get_path(void) const;
336*0a6a1f1dSLionel Sambuc };
337*0a6a1f1dSLionel Sambuc 
338*0a6a1f1dSLionel Sambuc // ------------------------------------------------------------------------
339*0a6a1f1dSLionel Sambuc // Free functions.
340*0a6a1f1dSLionel Sambuc // ------------------------------------------------------------------------
341*0a6a1f1dSLionel Sambuc 
342*0a6a1f1dSLionel Sambuc //!
343*0a6a1f1dSLionel Sambuc //! \brief Checks if the given path exists.
344*0a6a1f1dSLionel Sambuc //!
345*0a6a1f1dSLionel Sambuc bool exists(const path&);
346*0a6a1f1dSLionel Sambuc 
347*0a6a1f1dSLionel Sambuc //!
348*0a6a1f1dSLionel Sambuc //! \brief Looks for the given program in the PATH.
349*0a6a1f1dSLionel Sambuc //!
350*0a6a1f1dSLionel Sambuc //! Given a program name (without slashes) looks for it in the path and
351*0a6a1f1dSLionel Sambuc //! returns its full path name if found, otherwise an empty path.
352*0a6a1f1dSLionel Sambuc //!
353*0a6a1f1dSLionel Sambuc bool have_prog_in_path(const std::string&);
354*0a6a1f1dSLionel Sambuc 
355*0a6a1f1dSLionel Sambuc //!
356*0a6a1f1dSLionel Sambuc //! \brief Checks if the given path exists, is accessible and is executable.
357*0a6a1f1dSLionel Sambuc //!
358*0a6a1f1dSLionel Sambuc bool is_executable(const path&);
359*0a6a1f1dSLionel Sambuc 
360*0a6a1f1dSLionel Sambuc //!
361*0a6a1f1dSLionel Sambuc //! \brief Removes a given file.
362*0a6a1f1dSLionel Sambuc //!
363*0a6a1f1dSLionel Sambuc void remove(const path&);
364*0a6a1f1dSLionel Sambuc 
365*0a6a1f1dSLionel Sambuc //!
366*0a6a1f1dSLionel Sambuc //! \brief Removes an empty directory.
367*0a6a1f1dSLionel Sambuc //!
368*0a6a1f1dSLionel Sambuc void rmdir(const path&);
369*0a6a1f1dSLionel Sambuc 
370*0a6a1f1dSLionel Sambuc tools::fs::path change_directory(const tools::fs::path&);
371*0a6a1f1dSLionel Sambuc void cleanup(const tools::fs::path&);
372*0a6a1f1dSLionel Sambuc tools::fs::path get_current_dir(void);
373*0a6a1f1dSLionel Sambuc 
374*0a6a1f1dSLionel Sambuc } // namespace fs
375*0a6a1f1dSLionel Sambuc } // namespace tools
376*0a6a1f1dSLionel Sambuc 
377*0a6a1f1dSLionel Sambuc #endif // !defined(TOOLS_FS_HPP)
378