ereOn
ereOn

Reputation: 55736

Access all environment variables from native iOS C code

I have to port an existing code written in C and C++ to iOS.

This code, at some point, uses the environ variable to access all the environment variables.

When compiling this code with the iOS compiler toolchain, it complains that environ is not a defined symbol. I couldn't find any header that would provide it or any suitable alternative.

Unfortunately, environ is used to get all the environment variables and pass them to a sub-routine. That is, getenv() is not an option, since we don't know what environment variables to check for.

Is there a way in C or C++ code, with the iOS compiler toolchain, to access to the environ variable ? Or do you know any alternative solution ?

Upvotes: 2

Views: 692

Answers (1)

user405725
user405725

Reputation:

The environ variable must be declared in the user program, in your C code. So just declare it like this before accessing:

extern char **environ;

You may also find this article about iOS environment helpful (it has an example project as well).

Upvotes: 3

Related Questions