@@ -36,7 +36,6 @@ namespace fs = std::experimental::filesystem;
36
36
#include < libgen.h> // for dirname
37
37
#include < link.h>
38
38
#include < linux/limits.h> // for PATH_MAX
39
- #include < sys/stat.h>
40
39
#include < sys/sysinfo.h>
41
40
42
41
#elif defined(__SYCL_RT_OS_WINDOWS)
@@ -59,6 +58,15 @@ namespace sycl {
59
58
inline namespace _V1 {
60
59
namespace detail {
61
60
61
+ #if defined(__INTEL_PREVIEW_BREAKING_CHANGES)
62
+ static std::string getDirName (const char *Path)
63
+ #else
64
+ std::string OSUtil::getDirName (const char *Path)
65
+ #endif
66
+ {
67
+ return fs::path (Path).parent_path ().string ();
68
+ }
69
+
62
70
#if defined(__SYCL_RT_OS_LINUX)
63
71
bool procMapsAddressInRange (std::istream &Stream, uintptr_t Addr) {
64
72
uintptr_t Start = 0 , End = 0 ;
@@ -75,20 +83,6 @@ bool procMapsAddressInRange(std::istream &Stream, uintptr_t Addr) {
75
83
return Addr >= Start && Addr < End;
76
84
}
77
85
78
- #if defined(__INTEL_PREVIEW_BREAKING_CHANGES)
79
- static std::string getDirName (const char *Path)
80
- #else
81
- std::string OSUtil::getDirName (const char *Path)
82
- #endif
83
- {
84
- std::string Tmp (Path);
85
- // dirname(3) needs a writable C string: a null-terminator is written where a
86
- // path should split.
87
- size_t TruncatedSize = strlen (dirname (const_cast <char *>(Tmp.c_str ())));
88
- Tmp.resize (TruncatedSize);
89
- return Tmp;
90
- }
91
-
92
86
// / Returns an absolute path to a directory where the object was found.
93
87
std::string OSUtil::getCurrentDSODir () {
94
88
// Examine /proc/self/maps and find where this function (getCurrendDSODir)
@@ -157,7 +151,6 @@ std::string OSUtil::getCurrentDSODir() {
157
151
}
158
152
159
153
#elif defined(__SYCL_RT_OS_WINDOWS)
160
-
161
154
// / Returns an absolute path where the object was found.
162
155
// ur_win_proxy_loader.dll and sycl-jit.dll use this same logic. If it is
163
156
// changed significantly, it might be wise to change it there too.
@@ -180,21 +173,6 @@ std::string OSUtil::getCurrentDSODir() {
180
173
return Path;
181
174
}
182
175
183
- #if !defined(__INTEL_PREVIEW_BREAKING_CHANGES)
184
- std::string OSUtil::getDirName (const char *Path) {
185
- std::string Tmp (Path);
186
- // Remove trailing directory separators
187
- Tmp.erase (Tmp.find_last_not_of (" /\\ " ) + 1 , std::string::npos);
188
-
189
- size_t pos = Tmp.find_last_of (" /\\ " );
190
- if (pos != std::string::npos)
191
- return Tmp.substr (0 , pos);
192
-
193
- // If no directory separator is present return initial path like dirname does
194
- return Tmp;
195
- }
196
- #endif
197
-
198
176
#elif defined(__SYCL_RT_OS_DARWIN)
199
177
std::string OSUtil::getCurrentDSODir () {
200
178
auto CurrentFunc = reinterpret_cast <const void *>(&getCurrentDSODir);
@@ -210,7 +188,6 @@ std::string OSUtil::getCurrentDSODir() {
210
188
211
189
return Path.substr (0 , LastSlashPos);
212
190
}
213
-
214
191
#endif // __SYCL_RT_OS
215
192
216
193
size_t OSUtil::getOSMemSize () {
@@ -254,32 +231,12 @@ void OSUtil::alignedFree(void *Ptr) {
254
231
// Make all directories on the path, throws on error.
255
232
int OSUtil::makeDir (const char *Dir) {
256
233
assert ((Dir != nullptr ) && " Passed null-pointer as directory name." );
257
- if (isPathPresent (Dir))
258
- return 0 ;
259
-
260
- // older GCC doesn't have full C++ 17 support.
261
- #if __GNUC__ && __GNUC__ < 8
262
- std::string Path{Dir}, CurPath;
263
- size_t pos = 0 ;
264
-
265
- do {
266
- pos = Path.find_first_of (" /\\ " , ++pos);
267
- CurPath = Path.substr (0 , pos);
268
- #if defined(__SYCL_RT_OS_POSIX_SUPPORT)
269
- auto Res = mkdir (CurPath.c_str (), 0777 );
270
- #else
271
- auto Res = _mkdir (CurPath.c_str ());
272
- #endif
273
- if (Res && errno != EEXIST)
274
- throw std::runtime_error (" Failed to mkdir: " + CurPath + " (" +
275
- std::strerror (errno) + " )" );
276
234
277
- } while (pos != std::string::npos);
278
- #else
279
- // using filesystem is simpler, more reliable, works better on Win
280
- std::filesystem::path path (Dir);
281
- std::filesystem::create_directories (path.make_preferred ());
282
- #endif
235
+ if (!isPathPresent (Dir)) {
236
+ fs::path path (Dir);
237
+ fs::create_directories (path.make_preferred ());
238
+ }
239
+
283
240
return 0 ;
284
241
}
285
242
0 commit comments