15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
*/
#include "config.h"
#define OF_APPLICATION_M
#include <stdlib.h>
#import "OFApplication.h"
#import "OFString.h"
#import "OFArray.h"
#import "OFDictionary.h"
#import "OFAutoreleasePool.h"
#import "OFNotImplementedException.h"
#include <string.h>
#ifdef __MACH__
# include <crt_externs.h>
#else
extern char **environ;
#endif
static OFApplication *app = nil;
static void
atexit_handler()
{
|
>
|
|
|
|
|
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
*/
#include "config.h"
#define OF_APPLICATION_M
#include <stdlib.h>
#include <string.h>
#import "OFApplication.h"
#import "OFString.h"
#import "OFArray.h"
#import "OFDictionary.h"
#import "OFAutoreleasePool.h"
#import "OFNotImplementedException.h"
#import "macros.h"
#if defined(__MACH__) && !defined(OF_IOS)
# include <crt_externs.h>
#elif !defined(OF_IOS)
extern char **environ;
#endif
static OFApplication *app = nil;
static void
atexit_handler()
{
|
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
|
- init
{
self = [super init];
@try {
OFAutoreleasePool *pool;
char **env;
environment = [[OFMutableDictionary alloc] init];
atexit(atexit_handler);
#ifdef __MACH__
env = *_NSGetEnviron();
#else
env = environ;
#endif
pool = [[OFAutoreleasePool alloc] init];
for (; *env != NULL; env++) {
OFString *key;
OFString *value;
char *sep;
if ((sep = strchr(*env, '=')) == NULL) {
fprintf(stderr, "Warning: Invalid environment "
"variable: %s\n", *env);
continue;
}
key = [OFString stringWithCString: *env
length: sep - *env];
value = [OFString stringWithCString: sep + 1];
[environment setObject: value
forKey: key];
[pool releaseObjects];
}
[pool release];
/*
* Class swizzle the environment to be immutable, as we don't
* need to change it anymore and expose it only as
* OFDictionary*. But not swizzling it would create a real copy
* each time -[copy] is called.
|
>
>
>
|
>
>
>
<
<
<
<
<
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
- init
{
self = [super init];
@try {
OFAutoreleasePool *pool;
#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);
pool = [[OFAutoreleasePool alloc] init];
#ifndef OF_IOS
for (; *env != NULL; env++) {
OFString *key;
OFString *value;
char *sep;
if ((sep = strchr(*env, '=')) == NULL) {
fprintf(stderr, "Warning: Invalid environment "
"variable: %s\n", *env);
continue;
}
key = [OFString stringWithCString: *env
length: sep - *env];
value = [OFString stringWithCString: sep + 1];
[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
* OFDictionary*. But not swizzling it would create a real copy
* each time -[copy] is called.
|