@@ -19,14 +19,10 @@ #define OF_APPLICATION_M #include #include -#ifdef __MACH__ -# include -#endif - #import "OFApplication.h" #import "OFString.h" #import "OFArray.h" #import "OFDictionary.h" #import "OFAutoreleasePool.h" @@ -33,11 +29,13 @@ #import "OFNotImplementedException.h" #import "macros.h" -#ifndef __MACH__ +#if defined(__MACH__) && !defined(OF_IOS) +# include +#elif !defined(OF_IOS) extern char **environ; #endif static OFApplication *app = nil; @@ -104,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; @@ -135,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