Skip to content

Commit 404b8e3

Browse files
[SYCL][MacOS] Implement OSUtils::getCurrentDSODir for Darwin OS (#6933)
This patch fixes `misc.OsUtils` unit-test. Signed-off-by: Alexey Sachkov <[email protected]>
1 parent 775d068 commit 404b8e3

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

sycl/source/detail/os_util.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,20 @@ OSModuleHandle OSUtil::getOSModuleHandle(const void *VirtAddr) {
233233
return reinterpret_cast<OSModuleHandle>(Res.dli_fbase);
234234
}
235235

236-
std::string OSUtil::getCurrentDSODir() { return ""; }
236+
std::string OSUtil::getCurrentDSODir() {
237+
auto CurrentFunc = reinterpret_cast<const void *>(&getCurrentDSODir);
238+
Dl_info Info;
239+
int RetCode = dladdr(CurrentFunc, &Info);
240+
if (0 == RetCode) {
241+
// This actually indicates an error
242+
return "";
243+
}
244+
245+
auto Path = std::string(Info.dli_fname);
246+
auto LastSlashPos = Path.find_last_of('/');
247+
248+
return Path.substr(0, LastSlashPos);
249+
}
237250

238251
#endif // __SYCL_RT_OS
239252

sycl/unittests/misc/OsUtils.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ bool isSameDir(const char* LHS, const char* RHS) {
3939
struct stat StatBuf;
4040
if (stat(LHS, &StatBuf)) {
4141
perror("stat failed");
42-
exit(EXIT_FAILURE);
42+
return false;
4343
}
4444
ino_t InodeLHS = StatBuf.st_ino;
4545
if (stat(RHS, &StatBuf)) {
4646
perror("stat failed");
47-
exit(EXIT_FAILURE);
47+
return false;
4848
}
4949
ino_t InodeRHS = StatBuf.st_ino;
5050
return InodeRHS == InodeLHS;

0 commit comments

Comments
 (0)