fix: fix environ not found when building env.
- re-organize included headers for env. - resolve environ not found when building env on macos. use our explicit extern declare to replace system header decl.
This commit is contained in:
@@ -1,40 +1,37 @@
|
|||||||
#include "env.hpp"
|
#include "env.hpp"
|
||||||
#include "macro/os_detector.hpp"
|
#include "macro/os_detector.hpp"
|
||||||
#include "string/reinterpret.hpp"
|
|
||||||
#include "num/safe_op.hpp"
|
#include "num/safe_op.hpp"
|
||||||
#include "num/safe_cast.hpp"
|
#include "num/safe_cast.hpp"
|
||||||
#include <string>
|
|
||||||
#include <string_view>
|
|
||||||
#include <memory>
|
|
||||||
#include <type_traits>
|
|
||||||
#include <stdexcept>
|
|
||||||
#include <filesystem>
|
|
||||||
|
|
||||||
#if defined(YYCC_OS_WINDOWS)
|
#if defined(YYCC_OS_WINDOWS)
|
||||||
|
// Windows headers
|
||||||
#include "encoding/windows.hpp"
|
#include "encoding/windows.hpp"
|
||||||
#include "windows/winfct.hpp"
|
#include "windows/winfct.hpp"
|
||||||
|
#include <memory> // For safely free gotten environment variable and commandline argument.
|
||||||
|
#include <type_traits> // Used by std::unique_ptr to get underlying pointer type.
|
||||||
#include "windows/import_guard_head.hpp"
|
#include "windows/import_guard_head.hpp"
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
#include <winbase.h>
|
#include <winbase.h>
|
||||||
#include <processenv.h> // For getting environment variables and commandline argument.
|
#include <processenv.h> // For getting environment variables and commandline argument.
|
||||||
#include <shellapi.h> // For getting commandline argument.
|
#include <shellapi.h> // For getting commandline argument.
|
||||||
#include "windows/import_guard_tail.hpp"
|
#include "windows/import_guard_tail.hpp"
|
||||||
#elif defined(YYCC_OS_LINUX)
|
#else
|
||||||
#include <cstdlib>
|
// POSIX headers
|
||||||
#include <cerrno>
|
#include "string/reinterpret.hpp"
|
||||||
#include <fstream> // For reading commandline argument.
|
#include <cstdlib> // For POSIX environment variable operations.
|
||||||
#include <unistd.h>
|
#include <cerrno> // For POSIX errno.
|
||||||
#include <sys/stat.h> // For reading symlink target.
|
#include <stdexcept> // For re-throw unexpected POSIX errno as STL exception.
|
||||||
|
#if defined(YYCC_OS_LINUX)
|
||||||
|
// Linux-only headers
|
||||||
|
#include <fstream> // For reading commandline argument.
|
||||||
#elif defined(YYCC_OS_MACOS)
|
#elif defined(YYCC_OS_MACOS)
|
||||||
#include <cstdlib>
|
// macOS-only headers
|
||||||
#include <cerrno>
|
#include <mach-o/dyld.h> // For getting current exe path.
|
||||||
#include <unistd.h>
|
#include <crt_externs.h> // For getting commandline argument.
|
||||||
#include <cstring>
|
|
||||||
#include <mach-o/dyld.h> // For getting current exe path.
|
|
||||||
#include <crt_externs.h> // For getting commandline argument.
|
|
||||||
#else
|
#else
|
||||||
#error "Not supported OS"
|
#error "Not supported OS"
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#define SAFECAST ::yycc::num::safe_cast
|
#define SAFECAST ::yycc::num::safe_cast
|
||||||
#define SAFEOP ::yycc::num::safe_op
|
#define SAFEOP ::yycc::num::safe_op
|
||||||
@@ -160,6 +157,7 @@ namespace yycc::env {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if defined(YYCC_OS_WINDOWS)
|
#if defined(YYCC_OS_WINDOWS)
|
||||||
|
|
||||||
class EnvironmentStringsDeleter {
|
class EnvironmentStringsDeleter {
|
||||||
public:
|
public:
|
||||||
EnvironmentStringsDeleter() {}
|
EnvironmentStringsDeleter() {}
|
||||||
@@ -170,6 +168,11 @@ namespace yycc::env {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
using SmartEnvironmentStrings = std::unique_ptr<std::remove_pointer_t<LPWCH>, EnvironmentStringsDeleter>;
|
using SmartEnvironmentStrings = std::unique_ptr<std::remove_pointer_t<LPWCH>, EnvironmentStringsDeleter>;
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
extern char** environ;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
VarResult<std::vector<VarPair>> get_vars() {
|
VarResult<std::vector<VarPair>> get_vars() {
|
||||||
|
|||||||
Reference in New Issue
Block a user