diff --git a/MacStd.xcodeproj/project.pbxproj b/MacStd.xcodeproj/project.pbxproj index 1350c3e..2a95a12 100644 --- a/MacStd.xcodeproj/project.pbxproj +++ b/MacStd.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + F439D28E2ABA7DCC00B92CAE /* unistd.hpp in Headers */ = {isa = PBXBuildFile; fileRef = F439D28D2ABA7DCC00B92CAE /* unistd.hpp */; }; F4AE3B802AB440A000464926 /* dyld.hpp in Headers */ = {isa = PBXBuildFile; fileRef = F4AE3B7E2AB440A000464926 /* dyld.hpp */; }; F4AE3B812AB440A000464926 /* common.hpp in Headers */ = {isa = PBXBuildFile; fileRef = F4AE3B7F2AB440A000464926 /* common.hpp */; }; F4AE3BA22AB44AC500464926 /* Tests.mm in Sources */ = {isa = PBXBuildFile; fileRef = F4AE3BA12AB44AC400464926 /* Tests.mm */; }; @@ -26,6 +27,7 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + F439D28D2ABA7DCC00B92CAE /* unistd.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = unistd.hpp; path = include/MacStd/unistd.hpp; sourceTree = ""; }; F4AE3B732AB43EB600464926 /* libMacStd.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libMacStd.a; sourceTree = BUILT_PRODUCTS_DIR; }; F4AE3B7E2AB440A000464926 /* dyld.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = dyld.hpp; path = include/MacStd/dyld.hpp; sourceTree = ""; }; F4AE3B7F2AB440A000464926 /* common.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = common.hpp; path = include/MacStd/common.hpp; sourceTree = ""; }; @@ -63,6 +65,7 @@ F4AE3BCF2AB4561A00464926 /* pch.hpp */, F4AE3B742AB43EB600464926 /* Products */, F4AE3BA02AB44AC400464926 /* Tests */, + F439D28D2ABA7DCC00B92CAE /* unistd.hpp */, ); sourceTree = ""; }; @@ -93,6 +96,7 @@ F4AE3BD12AB4561A00464926 /* pch.hpp in Headers */, F4AE3B802AB440A000464926 /* dyld.hpp in Headers */, F4AE3B812AB440A000464926 /* common.hpp in Headers */, + F439D28E2ABA7DCC00B92CAE /* unistd.hpp in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -347,7 +351,7 @@ CURRENT_PROJECT_VERSION = 1; GENERATE_INFOPLIST_FILE = YES; IPHONEOS_DEPLOYMENT_TARGET = 16.4; - MACOSX_DEPLOYMENT_TARGET = 13.3; + MACOSX_DEPLOYMENT_TARGET = 10.15; MARKETING_VERSION = 1.0; PRODUCT_BUNDLE_IDENTIFIER = si.amebis.MacStd.Tests; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -365,7 +369,7 @@ CURRENT_PROJECT_VERSION = 1; GENERATE_INFOPLIST_FILE = YES; IPHONEOS_DEPLOYMENT_TARGET = 16.4; - MACOSX_DEPLOYMENT_TARGET = 13.3; + MACOSX_DEPLOYMENT_TARGET = 10.15; MARKETING_VERSION = 1.0; PRODUCT_BUNDLE_IDENTIFIER = si.amebis.MacStd.Tests; PRODUCT_NAME = "$(TARGET_NAME)"; diff --git a/Tests/Tests.mm b/Tests/Tests.mm index 83dc030..fb778e0 100644 --- a/Tests/Tests.mm +++ b/Tests/Tests.mm @@ -5,6 +5,7 @@ #import #include "../include/MacStd/dyld.hpp" +#include "../include/MacStd/unistd.hpp" @interface Tests : XCTestCase @end @@ -24,6 +25,11 @@ XCTAssert(_NSGetExecutablePath(path) == 0); } +- (void)test_getcwd { + std::string path; + XCTAssert(getcwd(path)); +} + - (void)testPerformanceExample { // This is an example of a performance test case. [self measureBlock:^{ diff --git a/include/MacStd/unistd.hpp b/include/MacStd/unistd.hpp new file mode 100644 index 0000000..97e5cc2 --- /dev/null +++ b/include/MacStd/unistd.hpp @@ -0,0 +1,34 @@ +/* + SPDX-License-Identifier: MIT + Copyright © 2023 Amebis +*/ + +#pragma once + +#include "common.hpp" +#include +#include + +/// +/// Copies the absolute pathname of the current working directory +/// +/// \sa [getcwd function](https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/getcwd.3.html) +/// +inline const char* getcwd(std::string& path) +{ + char stack_buffer[MACSTD_STACK_BUFFER_BYTES]; + auto result = getcwd(stack_buffer, MACSTD_STACK_BUFFER_BYTES); + if (result) { + path = result; + return path.data(); + } + if (errno == ERANGE) { + result = getcwd(NULL, 0); + if (result) { + path = result; + free(result); + return path.data(); + } + } + return NULL; +} diff --git a/src/pch.hpp b/src/pch.hpp index cea7e9d..6e3eee6 100644 --- a/src/pch.hpp +++ b/src/pch.hpp @@ -6,3 +6,4 @@ #pragma once #include "../include/MacStd/dyld.hpp" +#include "../include/MacStd/unistd.hpp"