MacStd
OS X API using Standard C++
Loading...
Searching...
No Matches
dyld.hpp
1/*
2 SPDX-License-Identifier: MIT
3 Copyright © 2023-2024 Amebis
4*/
5
6#pragma once
7
8#include "common.hpp"
9#include <mach-o/dyld.h>
10#include <string>
11
17inline int _NSGetExecutablePath(std::string& path)
18{
19 char stack_buffer[MACSTD_STACK_BUFFER_BYTES];
20 uint32_t capacity = MACSTD_STACK_BUFFER_BYTES;
21 int result = _NSGetExecutablePath(stack_buffer, &capacity);
22 if (result == 0) {
23 path = stack_buffer;
24 return 0;
25 }
26 if (result == -1) {
27 path.resize(capacity - 1);
28 result = _NSGetExecutablePath(&path[0], &capacity);
29 if (result == 0) {
30 path.resize(strnlen(path.data(), path.size()));
31 return 0;
32 }
33 }
34 return result;
35}