MacStd
OS X API using Standard C++
Loading...
Searching...
No Matches
dyld.hpp
1/*
2 SPDX-License-Identifier: MIT
3 Copyright © 2023 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 std::unique_ptr<char[]> heap_buffer(new char[capacity]);
28 result = _NSGetExecutablePath(heap_buffer.get(), &capacity);
29 if (result == 0) {
30 path = heap_buffer.get();
31 return 0;
32 }
33 }
34 return result;
35}