A couple tweaks to support compiling against Haiku without changes.

This commit is contained in:
casey langen 2022-12-24 19:03:46 -08:00
parent 4128b7d6c4
commit 5c765a9520
3 changed files with 25 additions and 5 deletions

View File

@ -1,5 +1,10 @@
if (EXISTS "/etc/arch-release" OR EXISTS "/etc/manjaro-release" OR NO_NCURSESW) if(
add_definitions (-DNO_NCURSESW) NO_NCURSESW OR
elseif(CMAKE_SYSTEM_NAME MATCHES "FreeBSD" OR CMAKE_SYSTEM_NAME MATCHES "OpenBSD" ) EXISTS "/etc/arch-release" OR
EXISTS "/etc/manjaro-release" OR
CMAKE_SYSTEM_NAME MATCHES "FreeBSD" OR
CMAKE_SYSTEM_NAME MATCHES "OpenBSD" OR
CMAKE_SYSTEM_NAME MATCHES "Haiku"
)
add_definitions (-DNO_NCURSESW) add_definitions (-DNO_NCURSESW)
endif() endif()

View File

@ -54,6 +54,8 @@
#include <shellapi.h> #include <shellapi.h>
#elif __APPLE__ #elif __APPLE__
#include <mach-o/dyld.h> #include <mach-o/dyld.h>
#elif __HAIKU__
#include <kernel/image.h>
#else #else
#include <sys/types.h> #include <sys/types.h>
#include <unistd.h> #include <unistd.h>
@ -133,12 +135,25 @@ namespace musik { namespace core {
fs::path command = fs::absolute(fs::path(fs::u8path(argv[0]))); fs::path command = fs::absolute(fs::path(fs::u8path(argv[0])));
realpath(command.u8string().c_str(), pathbuf); realpath(command.u8string().c_str(), pathbuf);
delete[] argv; delete[] argv;
#elif defined __HAIKU__
image_info ii;
int32_t c = 0;
while (get_next_image_info(0, &c, &ii) == B_OK) {
if (ii.type == B_APP_IMAGE) {
if (strlen(ii.name)) {
std::string fn(ii.name);
result = u8path(fn).parent_path().u8string();
}
}
}
#else #else
std::string pathToProc = u8fmt("/proc/%d/exe", (int) getpid()); std::string pathToProc = u8fmt("/proc/%d/exe", (int) getpid());
readlink(pathToProc.c_str(), pathbuf, PATH_MAX); readlink(pathToProc.c_str(), pathbuf, PATH_MAX);
#endif #endif
if (!result.size() && strlen(pathbuf)) {
result.assign(pathbuf); result.assign(pathbuf);
}
size_t last = result.find_last_of("/"); size_t last = result.find_last_of("/");
result = result.substr(0, last); /* remove filename component */ result = result.substr(0, last); /* remove filename component */
#endif #endif