ObjFW  Check-in [932c2eb049]

Overview
Comment:Don't use _NSGetEnviron or environ on iOS.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 932c2eb0498f2734da07054ce34fecfb97d425d1e74eefde0872f95dafe16963
User & Date: js on 2011-06-26 00:30:14
Other Links: manifest | tags
Context
2011-06-26
00:32
Use TEST_LAUNCHER on remote host in target run-on-ios. check-in: 1b62412349 user: js tags: trunk
00:30
Don't use _NSGetEnviron or environ on iOS. check-in: 932c2eb049 user: js tags: trunk
2011-06-25
20:47
Fix a possible warning in macros.h. check-in: b0b3a22b9a user: js tags: trunk
Changes

Modified src/OFApplication.m from [af28ed9259] to [2e89fcfb3b].

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
45
#include "config.h"

#define OF_APPLICATION_M

#include <stdlib.h>
#include <string.h>

#ifdef __MACH__
# include <crt_externs.h>
#endif

#import "OFApplication.h"
#import "OFString.h"
#import "OFArray.h"
#import "OFDictionary.h"
#import "OFAutoreleasePool.h"

#import "OFNotImplementedException.h"

#import "macros.h"

#ifndef __MACH__


extern char **environ;
#endif

static OFApplication *app = nil;

static void
atexit_handler(void)







<
<
<
<










|
>
>







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>
#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(void)
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

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

Modified src/macros.h from [fb95ceb8de] to [9584592c80].

270
271
272
273
274
275
276








277
278
279
280
281
282
283
#else
# define of_bswap_float_if_be(i) (i)
# define of_bswap_double_if_be(i) (i)
# define of_bswap_float_if_le(i) of_bswap_float(i)
# define of_bswap_double_if_le(i) of_bswap_double(i)
#endif









#define OF_ROL(value, bits)						\
	(((value) << ((bits) % (sizeof(value) * 8))) |			\
	(value) >> (sizeof(value) * 8 - ((bits) % (sizeof(value) * 8))))

#define OF_HASH_INIT(hash) hash = 0
#define OF_HASH_ADD(hash, byte)		\
	{				\







>
>
>
>
>
>
>
>







270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
#else
# define of_bswap_float_if_be(i) (i)
# define of_bswap_double_if_be(i) (i)
# define of_bswap_float_if_le(i) of_bswap_float(i)
# define of_bswap_double_if_le(i) of_bswap_double(i)
#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(value, bits)						\
	(((value) << ((bits) % (sizeof(value) * 8))) |			\
	(value) >> (sizeof(value) * 8 - ((bits) % (sizeof(value) * 8))))

#define OF_HASH_INIT(hash) hash = 0
#define OF_HASH_ADD(hash, byte)		\
	{				\