File tree Expand file tree Collapse file tree 4 files changed +35
-5
lines changed Expand file tree Collapse file tree 4 files changed +35
-5
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ Author: Michael Tautschnig, 2018
11
11
12
12
#include " hybrid_binary.h"
13
13
14
+ #include < util/file_util.h>
14
15
#include < util/run.h>
15
16
#include < util/suffix.h>
16
17
@@ -64,8 +65,8 @@ int hybrid_binary(
64
65
}
65
66
66
67
// delete the goto binary
67
- int remove_result = remove (goto_binary_file. c_str () );
68
- if (remove_result != 0 )
68
+ bool remove_result = file_remove (goto_binary_file);
69
+ if (!remove_result )
69
70
{
70
71
message.error () << " Remove failed: " << std::strerror (errno)
71
72
<< messaget::eom;
@@ -124,8 +125,8 @@ int hybrid_binary(
124
125
}
125
126
126
127
// delete the goto binary
127
- int remove_result = remove (goto_binary_file. c_str () );
128
- if (remove_result != 0 )
128
+ bool remove_result = file_remove (goto_binary_file);
129
+ if (!remove_result )
129
130
{
130
131
message.error () << " Remove failed: " << std::strerror (errno)
131
132
<< messaget::eom;
Original file line number Diff line number Diff line change @@ -203,3 +203,21 @@ bool create_directory(const std::string &path)
203
203
return mkdir (path.c_str (), 0777 ) == 0 ;
204
204
#endif
205
205
}
206
+
207
+ bool file_exists (const std::string &path)
208
+ {
209
+ #ifdef _WIN32
210
+ return _waccess (utf8_to_utf16_native_endian (path).c_str (), 0 ) == 0 ;
211
+ #else
212
+ return access (path.c_str (), F_OK) == 0 ;
213
+ #endif
214
+ }
215
+
216
+ bool file_remove (const std::string &path)
217
+ {
218
+ #ifdef _WIN32
219
+ return _wunlink (utf8_to_utf16_native_endian (path).c_str ()) == 0 ;
220
+ #else
221
+ return unlink (path.c_str ()) == 0 ;
222
+ #endif
223
+ }
Original file line number Diff line number Diff line change @@ -32,4 +32,14 @@ bool is_directory(const std::string &path);
32
32
// / \return true iff the directory was created
33
33
bool create_directory (const std::string &path);
34
34
35
+ // / Check whether file with given path exists.
36
+ // / C++17 will allow us to use std::filesystem::directory_entry(file).exists()
37
+ // / \return true iff the file exists
38
+ bool file_exists (const std::string &path);
39
+
40
+ // Delete a file with given path
41
+ // / C++17 will allow us to use std::filesystem::remove
42
+ // / \return true if the file was deleted, false if it did not exist
43
+ bool file_remove (const std::string &path);
44
+
35
45
#endif // CPROVER_UTIL_FILE_UTIL_H
Original file line number Diff line number Diff line change @@ -34,6 +34,7 @@ Author: Daniel Kroening
34
34
#include < cstring>
35
35
36
36
#include " exception_utils.h"
37
+ #include " file_util.h"
37
38
38
39
#if defined(__linux__) || \
39
40
defined (__FreeBSD_kernel__) || \
@@ -143,5 +144,5 @@ std::string get_temporary_file(
143
144
temporary_filet::~temporary_filet ()
144
145
{
145
146
if (!name.empty ())
146
- std::remove (name. c_str () );
147
+ file_remove (name);
147
148
}
You can’t perform that action at this time.
0 commit comments