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