ADBlock is blocking some content on the site

ADBlock errore

Access all environment variables from native iOS C code

StackOverflow https://stackoverflow.com/questions/14280740


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 ?


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).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow