exposed mode value.
[libasyncio] / utils / asyncio_system_tools.hpp
1 /*
2 The software in this package is distributed under the GNU General
3 Public License version 2 (with a special exception described below).
4
5 A copy of GNU General Public License (GPL) is included in this distribution,
6 in the file COPYING.GPL.
7
8 As a special exception, if other files instantiate templates or use macros
9 or inline functions from this file, or you compile this file and link it
10 with other works to produce a work based on this file, this file
11 does not by itself cause the resulting work to be covered
12 by the GNU General Public License.
13
14 However the source code for this file must still be made available
15 in accordance with section (3) of the GNU General Public License.
16
17 This exception does not invalidate any other reasons why a work based
18 on this file might be covered by the GNU General Public License.
19 */
20 /**
21  * @file
22  * @brief some functions to wrap some system functions
23  *
24  * @author Reinhard Pfau \<Reinhard.Pfau@gmx.de\>
25  * @copyright &copy; Copyright 2009 by Intra2net AG
26  */
27
28
29 #ifndef _ASYNCIO_SYSTEM_TOOLS_HPP_
30 #define _ASYNCIO_SYSTEM_TOOLS_HPP_
31
32 #include <string>
33 #include <sys/types.h>
34
35
36 namespace AsyncIo
37 {
38 namespace Utils
39 {
40
41 /**
42  * @brief removed a file entry from file system (if existing).
43  * @param path path to be removed.
44  * @return @a true if the file was successfully deleted.
45  */
46 bool unlink( const std::string& path );
47
48
49 /**
50  * @brief represents a file(/path) status.
51  *
52  * This is basically a wrapper around the "stat" call.
53  */
54 class FileStat
55 {
56     public:
57         FileStat( const std::string& path, bool follow_symlinks= true );
58         ~FileStat();
59
60         /**
61          * @brief stat the path again and updates the values.
62          */
63         void refresh();
64
65         /**
66          * @brief returns if the stat values are valid.
67          * @return @a true if the stat values are valid.
68          */
69         bool is_valid() const { return m_is_valid; }
70
71         operator bool() const { return m_is_valid; }
72
73         mode_t mode() const { return m_mode; }
74
75         bool is_regular_file() const { return m_is_regular_file; }
76         bool is_directory() const { return m_is_directory; }
77         bool is_character_device() const { return m_is_character_device; }
78         bool is_block_device() const { return m_is_block_device; }
79         bool is_fifo() const { return m_is_fifo; }
80         bool is_symbolic_link() const { return m_is_symbolic_link; }
81         bool is_link() const { return m_is_symbolic_link; }
82         bool is_socket() const { return m_is_socket; }
83
84     private:
85         std::string m_path;
86         bool m_follow_symlinks;
87
88         bool m_is_valid;
89
90         mode_t m_mode;
91
92         bool m_is_regular_file      :1;
93         bool m_is_directory         :1;
94         bool m_is_character_device  :1;
95         bool m_is_block_device      :1;
96         bool m_is_fifo              :1;
97         bool m_is_symbolic_link     :1;
98         bool m_is_socket            :1;
99
100 }; // end of FileStat
101
102
103 } // end of namespace Utils
104 } // end of namespace AsyncIo
105
106
107 #endif