Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion libs/cnmatrix/include/cnmatrix/cn_matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@

#include <stdbool.h>

#include <malloc.h>
#include <stdlib.h>
#ifdef _WIN32
#include <malloc.h> // alloca on MSVC
#endif
#include "cnmatrix/cn_flt.h"
#include "math.h"
#include "string.h"
Expand Down
5 changes: 5 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ if(USE_HIDAPI)
add_definitions (-DHIDAPI)
IF(WIN32)
SET(SURVIVE_SRCS ${SURVIVE_SRCS} ../redist/hid-windows.c)
elseif(APPLE)
find_package(PkgConfig REQUIRED)
pkg_check_modules(HIDAPI REQUIRED hidapi)
list(APPEND ADDITIONAL_LIBRARIES ${HIDAPI_LIBRARIES})
include_directories(${HIDAPI_INCLUDE_DIRS})
else()
list(APPEND ADDITIONAL_LIBRARIES udev hidapi-libusb)
endif()
Expand Down
20 changes: 18 additions & 2 deletions src/survive_plugins.unix.h

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Squash this commit with fca5e6f and its good to go

Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,19 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#ifdef __APPLE__
#include <mach-o/dyld.h>
#endif

#include "assert.h"

#pragma GCC diagnostic ignored "-Wpedantic"

#ifdef __APPLE__
static const char* plugin_ext() { return ".dylib"; }
#else
static const char* plugin_ext() { return ".so"; }
#endif

#ifndef PATH_MAX
#define PATH_MAX 4096
Expand All @@ -37,8 +44,17 @@ static const char *get_so_filename() {
static const char *get_exe_filename() {
static char exe_path[PATH_MAX] = { 0 };
if (exe_path[0] == 0) {
size_t len = readlink("/proc/self/exe", exe_path, sizeof(exe_path));
exe_path[len] = 0;
#ifdef __APPLE__
uint32_t size = sizeof(exe_path);
if (_NSGetExecutablePath(exe_path, &size) != 0)
exe_path[0] = 0;
#else
ssize_t len = readlink("/proc/self/exe", exe_path, sizeof(exe_path) - 1);
if (len > 0)
exe_path[len] = 0;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if that's needed, PATH_MAX should be big enough and it is already zero'd

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both issues cleaned up. Good catches.

else
exe_path[0] = 0;
#endif
}
return exe_path;
}
Expand Down
Loading