projects/aports·blob master · refs

276 lines · 10.1 KiB

1Author: Patrycja Rosa <[email protected]>
2Date: Thu, 03 Feb 2022 05:06:47 +0100
3
4 replace throw with noexcept
5
6 throw has been deprecated in C++11 and removed in C++17
7
8diff --git a/conf.cc b/conf.cc
9index e9b596d..e537e00 100644
10--- a/conf.cc
11+++ b/conf.cc
12@@ -28,7 +28,7 @@
13
14 using namespace std;
15
16-static void expand_tree(const string& path, filepath_container& ds) throw (error)
17+static void expand_tree(const string& path, filepath_container& ds) noexcept (false)
18 {
19 DIR* dir = opendir(path.c_str());
20 if (!dir)
21diff --git a/file.cc b/file.cc
22index 1e90348..36f3495 100644
23--- a/file.cc
24+++ b/file.cc
25@@ -98,7 +98,7 @@ void infopath::readonly_set(bool Areadonly)
26 /**
27 * Check if a file exists.
28 */
29-bool file_exists(const string& path) throw (error)
30+bool file_exists(const string& path) noexcept (false)
31 {
32 struct stat s;
33 if (stat(path.c_str(), &s) != 0) {
34@@ -114,7 +114,7 @@ bool file_exists(const string& path) throw (error)
35 /**
36 * Write a whole file.
37 */
38-void file_write(const string& path, const char* data, unsigned size) throw (error)
39+void file_write(const string& path, const char* data, unsigned size) noexcept (false)
40 {
41 FILE* f = fopen(path.c_str(), "wb");
42 if (!f)
43@@ -134,7 +134,7 @@ void file_write(const string& path, const char* data, unsigned size) throw (erro
44 /**
45 * Read a whole file.
46 */
47-void file_read(const string& path, char* data, unsigned size) throw (error)
48+void file_read(const string& path, char* data, unsigned size) noexcept (false)
49 {
50 file_read(path, data, 0, size);
51 }
52@@ -142,7 +142,7 @@ void file_read(const string& path, char* data, unsigned size) throw (error)
53 /**
54 * Read a whole file.
55 */
56-void file_read(const string& path, char* data, unsigned offset, unsigned size) throw (error)
57+void file_read(const string& path, char* data, unsigned offset, unsigned size) noexcept (false)
58 {
59 FILE* f = fopen(path.c_str(), "rb");
60 if (!f)
61@@ -166,7 +166,7 @@ void file_read(const string& path, char* data, unsigned offset, unsigned size) t
62 /**
63 * Get the time of a file.
64 */
65-time_t file_time(const string& path) throw (error)
66+time_t file_time(const string& path) noexcept (false)
67 {
68 struct stat s;
69 if (stat(path.c_str(), &s)!=0)
70@@ -178,7 +178,7 @@ time_t file_time(const string& path) throw (error)
71 /**
72 * Set the time of a file.
73 */
74-void file_utime(const string& path, time_t tod) throw (error)
75+void file_utime(const string& path, time_t tod) noexcept (false)
76 {
77 struct utimbuf u;
78
79@@ -192,7 +192,7 @@ void file_utime(const string& path, time_t tod) throw (error)
80 /**
81 * Get the size of a file.
82 */
83-unsigned file_size(const string& path) throw (error)
84+unsigned file_size(const string& path) noexcept (false)
85 {
86 struct stat s;
87 if (stat(path.c_str(), &s)!=0)
88@@ -204,7 +204,7 @@ unsigned file_size(const string& path) throw (error)
89 /**
90 * Get the crc of a file.
91 */
92-crc_t file_crc(const string& path) throw (error)
93+crc_t file_crc(const string& path) noexcept (false)
94 {
95 unsigned size = file_size(path);
96
97@@ -227,7 +227,7 @@ crc_t file_crc(const string& path) throw (error)
98 /**
99 * Copy a file.
100 */
101-void file_copy(const string& path1, const string& path2) throw (error)
102+void file_copy(const string& path1, const string& path2) noexcept (false)
103 {
104 unsigned size;
105
106@@ -249,7 +249,7 @@ void file_copy(const string& path1, const string& path2) throw (error)
107 /**
108 * Move a file.
109 */
110-void file_move(const string& path1, const string& path2) throw (error)
111+void file_move(const string& path1, const string& path2) noexcept (false)
112 {
113 if (rename(path1.c_str(), path2.c_str())!=0
114 && errno==EXDEV) {
115@@ -271,7 +271,7 @@ void file_move(const string& path1, const string& path2) throw (error)
116 /**
117 * Remove a file.
118 */
119-void file_remove(const string& path1) throw (error)
120+void file_remove(const string& path1) noexcept (false)
121 {
122 if (remove(path1.c_str())!=0) {
123 throw error() << "Failed remove of " << path1;
124@@ -281,7 +281,7 @@ void file_remove(const string& path1) throw (error)
125 /**
126 * Rename a file.
127 */
128-void file_rename(const string& path1, const string& path2) throw (error)
129+void file_rename(const string& path1, const string& path2) noexcept (false)
130 {
131 if (rename(path1.c_str(), path2.c_str())!=0) {
132 throw error() << "Failed rename of " << path1 << " to " << path2;
133@@ -291,7 +291,7 @@ void file_rename(const string& path1, const string& path2) throw (error)
134 /**
135 * Randomize a name file.
136 */
137-string file_randomize(const string& path, int n) throw ()
138+string file_randomize(const string& path, int n) noexcept (true)
139 {
140 ostringstream os;
141
142@@ -307,7 +307,7 @@ string file_randomize(const string& path, int n) throw ()
143 return os.str();
144 }
145
146-string file_temp(const string& path) throw ()
147+string file_temp(const string& path) noexcept (true)
148 {
149 ostringstream os;
150
151@@ -319,7 +319,7 @@ string file_temp(const string& path) throw ()
152 /**
153 * Get the directory from a path.
154 */
155-string file_dir(const string& path) throw ()
156+string file_dir(const string& path) noexcept (true)
157 {
158 size_t pos = path.rfind('/');
159 if (pos == string::npos) {
160@@ -332,7 +332,7 @@ string file_dir(const string& path) throw ()
161 /**
162 * Get the file name from a path.
163 */
164-string file_name(const string& path) throw ()
165+string file_name(const string& path) noexcept (true)
166 {
167 size_t pos = path.rfind('/');
168 if (pos == string::npos) {
169@@ -345,7 +345,7 @@ string file_name(const string& path) throw ()
170 /**
171 * Get the basepath (path without extension) from a path.
172 */
173-string file_basepath(const string& path) throw ()
174+string file_basepath(const string& path) noexcept (true)
175 {
176 size_t dot = path.rfind('.');
177 if (dot == string::npos)
178@@ -357,7 +357,7 @@ string file_basepath(const string& path) throw ()
179 /**
180 * Get the basename (name without extension) from a path.
181 */
182-string file_basename(const string& path) throw ()
183+string file_basename(const string& path) noexcept (true)
184 {
185 string name = file_name(path);
186 size_t dot = name.rfind('.');
187@@ -370,7 +370,7 @@ string file_basename(const string& path) throw ()
188 /**
189 * Get the extension from a path.
190 */
191-string file_ext(const string& path) throw ()
192+string file_ext(const string& path) noexcept (true)
193 {
194 string name = file_name(path);
195 size_t dot = name.rfind('.');
196@@ -383,7 +383,7 @@ string file_ext(const string& path) throw ()
197 /**
198 * Compare two path.
199 */
200-int file_compare(const string& path1, const string& path2) throw ()
201+int file_compare(const string& path1, const string& path2) noexcept (true)
202 {
203 return strcasecmp(path1.c_str(), path2.c_str());
204 }
205@@ -391,7 +391,7 @@ int file_compare(const string& path1, const string& path2) throw ()
206 /**
207 * Convert a path to the C format.
208 */
209-string file_adjust(const string& path) throw ()
210+string file_adjust(const string& path) noexcept (true)
211 {
212 string r;
213 for(unsigned i=0;i<path.length();++i) {
214@@ -409,7 +409,7 @@ string file_adjust(const string& path) throw ()
215 /**
216 * Make a drectory tree.
217 */
218-void file_mktree(const std::string& path) throw (error)
219+void file_mktree(const std::string& path) noexcept (false)
220 {
221 string dir = file_dir(path);
222 string name = file_name(path);
223diff --git a/file.h b/file.h
224index 1b0cf85..b3843c0 100644
225--- a/file.h
226+++ b/file.h
227@@ -67,28 +67,28 @@ typedef unsigned crc_t;
228 crc_t crc_compute(const char* data, unsigned len);
229 crc_t crc_compute(crc_t pred, const char* data, unsigned len);
230
231-bool file_exists(const std::string& file) throw (error);
232-void file_write(const std::string& path, const char* data, unsigned size) throw (error);
233-void file_read(const std::string& path, char* data, unsigned size) throw (error);
234-void file_read(const std::string& path, char* data, unsigned offset, unsigned size) throw (error);
235-time_t file_time(const std::string& path) throw (error);
236-void file_utime(const std::string& path, time_t tod) throw (error);
237-unsigned file_size(const std::string& path) throw (error);
238-crc_t file_crc(const std::string& path) throw (error);
239-void file_copy(const std::string& path1, const std::string& path2) throw (error);
240-void file_move(const std::string& path1, const std::string& path2) throw (error);
241-void file_remove(const std::string& path1) throw (error);
242-void file_mktree(const std::string& path1) throw (error);
243+bool file_exists(const std::string& file) noexcept (false);
244+void file_write(const std::string& path, const char* data, unsigned size) noexcept (false);
245+void file_read(const std::string& path, char* data, unsigned size) noexcept (false);
246+void file_read(const std::string& path, char* data, unsigned offset, unsigned size) noexcept (false);
247+time_t file_time(const std::string& path) noexcept (false);
248+void file_utime(const std::string& path, time_t tod) noexcept (false);
249+unsigned file_size(const std::string& path) noexcept (false);
250+crc_t file_crc(const std::string& path) noexcept (false);
251+void file_copy(const std::string& path1, const std::string& path2) noexcept (false);
252+void file_move(const std::string& path1, const std::string& path2) noexcept (false);
253+void file_remove(const std::string& path1) noexcept (false);
254+void file_mktree(const std::string& path1) noexcept (false);
255
256-std::string file_temp(const std::string& path) throw ();
257-std::string file_randomize(const std::string& path, int n) throw ();
258-std::string file_name(const std::string& file) throw ();
259-std::string file_dir(const std::string& file) throw ();
260-std::string file_basename(const std::string& file) throw ();
261-std::string file_basepath(const std::string& file) throw ();
262-std::string file_ext(const std::string& file) throw ();
263-int file_compare(const std::string& path1, const std::string& path2) throw ();
264-std::string file_adjust(const std::string& path) throw ();
265+std::string file_temp(const std::string& path) noexcept (true);
266+std::string file_randomize(const std::string& path, int n) noexcept (true);
267+std::string file_name(const std::string& file) noexcept (true);
268+std::string file_dir(const std::string& file) noexcept (true);
269+std::string file_basename(const std::string& file) noexcept (true);
270+std::string file_basepath(const std::string& file) noexcept (true);
271+std::string file_ext(const std::string& file) noexcept (true);
272+int file_compare(const std::string& path1, const std::string& path2) noexcept (true);
273+std::string file_adjust(const std::string& path) noexcept (true);
274
275 #endif
276