Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add inlined ArchEnviron function for OS X. #138

Merged
merged 1 commit into from
May 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions pxr/base/lib/arch/debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "pxr/pxr.h"
#include "pxr/base/arch/debugger.h"
#include "pxr/base/arch/daemon.h"
#include "pxr/base/arch/env.h"
#include "pxr/base/arch/error.h"
#include "pxr/base/arch/export.h"
#include "pxr/base/arch/stackTrace.h"
Expand Down Expand Up @@ -325,18 +326,12 @@ Arch_DebuggerRunUnrelatedProcessPosix(bool (*cb)(void*), void* data)
_exit(0);
}

PXR_NAMESPACE_CLOSE_SCOPE

extern char** environ;

PXR_NAMESPACE_OPEN_SCOPE

static
bool
Arch_DebuggerAttachExecPosix(void* data)
{
char** args = (char**)data;
execve(args[0], args, environ);
execve(args[0], args, ArchEnviron());
return false;
}

Expand Down
14 changes: 14 additions & 0 deletions pxr/base/lib/arch/env.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@

#include <stdlib.h>

#if defined(ARCH_OS_DARWIN)
#include <crt_externs.h>
#else
extern "C" char** environ;
#endif

PXR_NAMESPACE_OPEN_SCOPE

bool
Expand Down Expand Up @@ -124,4 +130,12 @@ ArchExpandEnvironmentVariables(const std::string& value)
return result;
}

char** ArchEnviron() {
#if defined(ARCH_OS_DARWIN)
return *_NSGetEnviron();
#else
return environ;
#endif
}

PXR_NAMESPACE_CLOSE_SCOPE
8 changes: 8 additions & 0 deletions pxr/base/lib/arch/env.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ ARCH_API
std::string
ArchExpandEnvironmentVariables(const std::string& str);

///
/// Return an array of the environment variables.
/// \ingroup group_arch_SystemFunctions
///
ARCH_API
char**
ArchEnviron();

PXR_NAMESPACE_CLOSE_SCOPE

#endif // ARCH_ENV_H
10 changes: 2 additions & 8 deletions pxr/base/lib/arch/stackTrace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "pxr/base/arch/debugger.h"
#include "pxr/base/arch/defines.h"
#include "pxr/base/arch/demangle.h"
#include "pxr/base/arch/env.h"
#include "pxr/base/arch/error.h"
#include "pxr/base/arch/errno.h"
#include "pxr/base/arch/export.h"
Expand Down Expand Up @@ -223,13 +224,6 @@ static const char* const* stackTraceArgv = nullptr;

static long _GetAppElapsedTime();

PXR_NAMESPACE_CLOSE_SCOPE

// asgetenv() want's this but we can't declare it inside the namespace.
extern char **environ;

PXR_NAMESPACE_OPEN_SCOPE

namespace {

// Return the length of s.
Expand Down Expand Up @@ -292,7 +286,7 @@ const char* asgetenv(const char* name)
{
if (name) {
const size_t len = asstrlen(name);
for (char** i = environ; *i; ++i) {
for (char** i = ArchEnviron(); *i; ++i) {
const char* var = *i;
if (asstrneq(var, name, len)) {
if (var[len] == '=') {
Expand Down