Commit | Line | Data |
---|---|---|
8c15b8c7 TJ |
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 | */ | |
ef51ea7e RP |
20 | /** |
21 | * @file | |
22 | * @brief some functions to wrap some system functions | |
23 | * | |
24 | * @author Reinhard Pfau \<Reinhard.Pfau@gmx.de\> | |
17f28a25 | 25 | * |
ef51ea7e | 26 | * @copyright © Copyright 2009 by Intra2net AG |
17f28a25 | 27 | * @contact Intra2net Opensource Team \<opensource@intra2net.com\> |
ef51ea7e RP |
28 | */ |
29 | ||
30 | ||
31 | #ifndef _ASYNCIO_SYSTEM_TOOLS_HPP_ | |
32 | #define _ASYNCIO_SYSTEM_TOOLS_HPP_ | |
33 | ||
34 | #include <string> | |
b96b430a | 35 | #include <sys/types.h> |
74622ea8 | 36 | #include <stdint.h> |
ef51ea7e RP |
37 | |
38 | ||
39 | namespace AsyncIo | |
40 | { | |
41 | namespace Utils | |
42 | { | |
43 | ||
9b21df9d RP |
44 | /** |
45 | * @brief removed a file entry from file system (if existing). | |
46 | * @param path path to be removed. | |
47 | * @return @a true if the file was successfully deleted. | |
48 | */ | |
85108f09 RP |
49 | bool unlink( const std::string& path ); |
50 | ||
51 | ||
9b21df9d RP |
52 | /** |
53 | * @brief represents a file(/path) status. | |
54 | * | |
55 | * This is basically a wrapper around the "stat" call. | |
56 | */ | |
85108f09 RP |
57 | class FileStat |
58 | { | |
59 | public: | |
9b21df9d | 60 | FileStat( const std::string& path, bool follow_symlinks= true ); |
85108f09 RP |
61 | ~FileStat(); |
62 | ||
9b21df9d RP |
63 | /** |
64 | * @brief stat the path again and updates the values. | |
65 | */ | |
85108f09 RP |
66 | void refresh(); |
67 | ||
9b21df9d RP |
68 | /** |
69 | * @brief returns if the stat values are valid. | |
70 | * @return @a true if the stat values are valid. | |
71 | */ | |
85108f09 RP |
72 | bool is_valid() const { return m_is_valid; } |
73 | ||
74 | operator bool() const { return m_is_valid; } | |
75 | ||
b96b430a RP |
76 | mode_t mode() const { return m_mode; } |
77 | ||
85108f09 RP |
78 | bool is_regular_file() const { return m_is_regular_file; } |
79 | bool is_directory() const { return m_is_directory; } | |
9b21df9d RP |
80 | bool is_character_device() const { return m_is_character_device; } |
81 | bool is_block_device() const { return m_is_block_device; } | |
82 | bool is_fifo() const { return m_is_fifo; } | |
83 | bool is_symbolic_link() const { return m_is_symbolic_link; } | |
84 | bool is_link() const { return m_is_symbolic_link; } | |
85 | bool is_socket() const { return m_is_socket; } | |
c3b830a2 | 86 | bool is_exec_file() const { return m_is_exec_file; } |
85108f09 RP |
87 | |
88 | private: | |
89 | std::string m_path; | |
9b21df9d | 90 | bool m_follow_symlinks; |
85108f09 RP |
91 | |
92 | bool m_is_valid; | |
93 | ||
b96b430a RP |
94 | mode_t m_mode; |
95 | ||
96 | bool m_is_regular_file :1; | |
97 | bool m_is_directory :1; | |
98 | bool m_is_character_device :1; | |
99 | bool m_is_block_device :1; | |
100 | bool m_is_fifo :1; | |
101 | bool m_is_symbolic_link :1; | |
102 | bool m_is_socket :1; | |
c3b830a2 | 103 | bool m_is_exec_file :1; |
85108f09 RP |
104 | |
105 | }; // end of FileStat | |
106 | ||
ef51ea7e | 107 | |
17f28a25 RP |
108 | /* |
109 | * IPv4 support | |
110 | */ | |
111 | ||
112 | class IPv4Address | |
113 | { | |
114 | public: | |
115 | IPv4Address(); | |
116 | IPv4Address( uint32_t _address ); | |
117 | ||
118 | bool is_valid() const {return m_valid;} | |
119 | ||
120 | uint32_t get_address() const { return m_address; } | |
121 | ||
122 | uint32_t get_address_nbo() const; | |
123 | ||
124 | private: | |
125 | ||
126 | uint32_t m_address; | |
127 | bool m_valid; | |
128 | }; // end of IPv4Address | |
129 | ||
130 | ||
ef51ea7e | 131 | } // end of namespace Utils |
9b21df9d | 132 | } // end of namespace AsyncIo |
ef51ea7e RP |
133 | |
134 | ||
135 | #endif |