Mercurial > sdl-ios-xcode
comparison src/stdlib/SDL_getenv.c @ 1341:d02b552e5304
Configure dynamically generates SDL_config.h
I'm still wrestling with autoheader, but this should work for now...
Fixed lots of build problems with C library support disabled
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Tue, 07 Feb 2006 12:11:33 +0000 |
parents | 3692456e7b0f |
children | 22f39393668a |
comparison
equal
deleted
inserted
replaced
1340:58b114ef50e7 | 1341:d02b552e5304 |
---|---|
111 } else { | 111 } else { |
112 return(-1); | 112 return(-1); |
113 } | 113 } |
114 | 114 |
115 /* Allocate memory for the variable */ | 115 /* Allocate memory for the variable */ |
116 new_variable = (char *)malloc(strlen(variable)+1); | 116 new_variable = (char *)SDL_malloc(SDL_strlen(variable)+1); |
117 if ( ! new_variable ) { | 117 if ( ! new_variable ) { |
118 return(-1); | 118 return(-1); |
119 } | 119 } |
120 strcpy(new_variable, variable); | 120 SDL_strcpy(new_variable, variable); |
121 | 121 |
122 /* Actually put it into the environment */ | 122 /* Actually put it into the environment */ |
123 added = 0; | 123 added = 0; |
124 i = 0; | 124 i = 0; |
125 if ( SDL_env ) { | 125 if ( SDL_env ) { |
126 /* Check to see if it's already there... */ | 126 /* Check to see if it's already there... */ |
127 len = (value - name); | 127 len = (value - name); |
128 for ( ; SDL_env[i]; ++i ) { | 128 for ( ; SDL_env[i]; ++i ) { |
129 if ( strncmp(SDL_env[i], name, len) == 0 ) { | 129 if ( SDL_strncmp(SDL_env[i], name, len) == 0 ) { |
130 break; | 130 break; |
131 } | 131 } |
132 } | 132 } |
133 /* If we found it, just replace the entry */ | 133 /* If we found it, just replace the entry */ |
134 if ( SDL_env[i] ) { | 134 if ( SDL_env[i] ) { |
135 free(SDL_env[i]); | 135 SDL_free(SDL_env[i]); |
136 SDL_env[i] = new_variable; | 136 SDL_env[i] = new_variable; |
137 added = 1; | 137 added = 1; |
138 } | 138 } |
139 } | 139 } |
140 | 140 |
145 SDL_env = new_env; | 145 SDL_env = new_env; |
146 SDL_env[i++] = new_variable; | 146 SDL_env[i++] = new_variable; |
147 SDL_env[i++] = (char *)0; | 147 SDL_env[i++] = (char *)0; |
148 added = 1; | 148 added = 1; |
149 } else { | 149 } else { |
150 free(new_variable); | 150 SDL_free(new_variable); |
151 } | 151 } |
152 } | 152 } |
153 return (added ? 0 : -1); | 153 return (added ? 0 : -1); |
154 } | 154 } |
155 | 155 |
159 int len, i; | 159 int len, i; |
160 char *value; | 160 char *value; |
161 | 161 |
162 value = (char *)0; | 162 value = (char *)0; |
163 if ( SDL_env ) { | 163 if ( SDL_env ) { |
164 len = strlen(name); | 164 len = SDL_strlen(name); |
165 for ( i=0; SDL_env[i] && !value; ++i ) { | 165 for ( i=0; SDL_env[i] && !value; ++i ) { |
166 if ( (strncmp(SDL_env[i], name, len) == 0) && | 166 if ( (SDL_strncmp(SDL_env[i], name, len) == 0) && |
167 (SDL_env[i][len] == '=') ) { | 167 (SDL_env[i][len] == '=') ) { |
168 value = &SDL_env[i][len+1]; | 168 value = &SDL_env[i][len+1]; |
169 } | 169 } |
170 } | 170 } |
171 } | 171 } |
183 { | 183 { |
184 char *value; | 184 char *value; |
185 | 185 |
186 printf("Checking for non-existent variable... "); | 186 printf("Checking for non-existent variable... "); |
187 fflush(stdout); | 187 fflush(stdout); |
188 if ( ! getenv("EXISTS") ) { | 188 if ( ! SDL_getenv("EXISTS") ) { |
189 printf("okay\n"); | 189 printf("okay\n"); |
190 } else { | 190 } else { |
191 printf("failed\n"); | 191 printf("failed\n"); |
192 } | 192 } |
193 printf("Setting FIRST=VALUE1 in the environment... "); | 193 printf("Setting FIRST=VALUE1 in the environment... "); |
194 fflush(stdout); | 194 fflush(stdout); |
195 if ( putenv("FIRST=VALUE1") == 0 ) { | 195 if ( SDL_putenv("FIRST=VALUE1") == 0 ) { |
196 printf("okay\n"); | 196 printf("okay\n"); |
197 } else { | 197 } else { |
198 printf("failed\n"); | 198 printf("failed\n"); |
199 } | 199 } |
200 printf("Getting FIRST from the environment... "); | 200 printf("Getting FIRST from the environment... "); |
201 fflush(stdout); | 201 fflush(stdout); |
202 value = getenv("FIRST"); | 202 value = SDL_getenv("FIRST"); |
203 if ( value && (strcmp(value, "VALUE1") == 0) ) { | 203 if ( value && (SDL_strcmp(value, "VALUE1") == 0) ) { |
204 printf("okay\n"); | 204 printf("okay\n"); |
205 } else { | 205 } else { |
206 printf("failed\n"); | 206 printf("failed\n"); |
207 } | 207 } |
208 printf("Setting SECOND=VALUE2 in the environment... "); | 208 printf("Setting SECOND=VALUE2 in the environment... "); |
209 fflush(stdout); | 209 fflush(stdout); |
210 if ( putenv("SECOND=VALUE2") == 0 ) { | 210 if ( SDL_putenv("SECOND=VALUE2") == 0 ) { |
211 printf("okay\n"); | 211 printf("okay\n"); |
212 } else { | 212 } else { |
213 printf("failed\n"); | 213 printf("failed\n"); |
214 } | 214 } |
215 printf("Getting SECOND from the environment... "); | 215 printf("Getting SECOND from the environment... "); |
216 fflush(stdout); | 216 fflush(stdout); |
217 value = getenv("SECOND"); | 217 value = SDL_getenv("SECOND"); |
218 if ( value && (strcmp(value, "VALUE2") == 0) ) { | 218 if ( value && (SDL_strcmp(value, "VALUE2") == 0) ) { |
219 printf("okay\n"); | 219 printf("okay\n"); |
220 } else { | 220 } else { |
221 printf("failed\n"); | 221 printf("failed\n"); |
222 } | 222 } |
223 printf("Setting FIRST=NOVALUE in the environment... "); | 223 printf("Setting FIRST=NOVALUE in the environment... "); |
224 fflush(stdout); | 224 fflush(stdout); |
225 if ( putenv("FIRST=NOVALUE") == 0 ) { | 225 if ( SDL_putenv("FIRST=NOVALUE") == 0 ) { |
226 printf("okay\n"); | 226 printf("okay\n"); |
227 } else { | 227 } else { |
228 printf("failed\n"); | 228 printf("failed\n"); |
229 } | 229 } |
230 printf("Getting FIRST from the environment... "); | 230 printf("Getting FIRST from the environment... "); |
231 fflush(stdout); | 231 fflush(stdout); |
232 value = getenv("FIRST"); | 232 value = SDL_getenv("FIRST"); |
233 if ( value && (strcmp(value, "NOVALUE") == 0) ) { | 233 if ( value && (SDL_strcmp(value, "NOVALUE") == 0) ) { |
234 printf("okay\n"); | 234 printf("okay\n"); |
235 } else { | 235 } else { |
236 printf("failed\n"); | 236 printf("failed\n"); |
237 } | 237 } |
238 printf("Checking for non-existent variable... "); | 238 printf("Checking for non-existent variable... "); |
239 fflush(stdout); | 239 fflush(stdout); |
240 if ( ! getenv("EXISTS") ) { | 240 if ( ! SDL_getenv("EXISTS") ) { |
241 printf("okay\n"); | 241 printf("okay\n"); |
242 } else { | 242 } else { |
243 printf("failed\n"); | 243 printf("failed\n"); |
244 } | 244 } |
245 return(0); | 245 return(0); |