Index: src/OFApplication.m ================================================================== --- src/OFApplication.m +++ src/OFApplication.m @@ -17,25 +17,26 @@ #include "config.h" #define OF_APPLICATION_M #include +#include #import "OFApplication.h" #import "OFString.h" #import "OFArray.h" #import "OFDictionary.h" #import "OFAutoreleasePool.h" #import "OFNotImplementedException.h" -#include +#import "macros.h" -#ifdef __MACH__ +#if defined(__MACH__) && !defined(OF_IOS) # include -#else - extern char **environ; +#elif !defined(OF_IOS) +extern char **environ; #endif static OFApplication *app = nil; static void @@ -101,22 +102,24 @@ { self = [super init]; @try { OFAutoreleasePool *pool; - char **env; +#if defined(__MACH__) && !defined(OF_IOS) + char **env = *_NSGetEnviron(); +#elif !defined(OF_IOS) + char **env = environ; +#else + char *env; +#endif environment = [[OFMutableDictionary alloc] init]; atexit(atexit_handler); -#ifdef __MACH__ - env = *_NSGetEnviron(); -#else - env = environ; -#endif pool = [[OFAutoreleasePool alloc] init]; +#ifndef OF_IOS for (; *env != NULL; env++) { OFString *key; OFString *value; char *sep; @@ -132,10 +135,38 @@ [environment setObject: value forKey: key]; [pool releaseObjects]; } +#else + /* + * iOS does not provide environ and Apple does not allow using + * _NSGetEnviron on iOS. Therefore, we just get a few common + * variables from the environment which applications might + * expect. + */ + if ((env = getenv("HOME")) != NULL) + [environment + setObject: [OFString stringWithCString: env] + forKey: @"HOME"]; + if ((env = getenv("PATH")) != NULL) + [environment + setObject: [OFString stringWithCString: env] + forKey: @"PATH"]; + if ((env = getenv("SHELL")) != NULL) + [environment + setObject: [OFString stringWithCString: env] + forKey: @"SHELL"]; + if ((env = getenv("TMPDIR")) != NULL) + [environment + setObject: [OFString stringWithCString: env] + forKey: @"TMPDIR"]; + if ((env = getenv("USER")) != NULL) + [environment + setObject: [OFString stringWithCString: env] + forKey: @"USER"]; +#endif [pool release]; /* * Class swizzle the environment to be immutable, as we don't * need to change it anymore and expose it only as Index: src/macros.h ================================================================== --- src/macros.h +++ src/macros.h @@ -226,10 +226,18 @@ # define of_bswap32_if_le(i) of_bswap32(i) # define of_bswap64_if_le(i) of_bswap64(i) # define of_bswap32_vec_if_be(buf, len) #endif +/* + * We define it here and not in objfw-defs.h, as it would be theoretically + * possible to build a universal binary for Mac OS X and iOS. + */ +#if defined(__MACH__) && defined(__arm__) +# define OF_IOS +#endif + #define OF_ROL(val, bits) \ (((val) << ((bits) % (sizeof(val) * 8))) | \ (val) >> (sizeof(val) * 8 - ((bits) % (sizeof(val) * 8)))) #define OF_HASH_INIT(hash) hash = 0