168{
170
171
172
174 __crt_unique_heap_ptr<Character> owned_option(
option);
175
176 Character*
const equal_sign = traits::tcschr(
option,
'=');
178
179
180
181
184
185
186
187 bool const is_removal = *(equal_sign + 1) == '\0';
188
189
190
191
192
193
194 ensure_current_environment_is_not_initial_environment_nolock<Character>();
195
196
197
198
199
201 {
203 {
205
206
207
208
209
210 ensure_current_environment_is_not_initial_environment_nolock<Character>();
211 }
212 else
213 {
214
215
216 if (is_removal)
217 {
218 return 0;
219 }
220
221
222
224 {
226 }
227
229 {
230 return -1;
231 }
232
234 {
236 }
237
239 {
240 return -1;
241 }
242 }
243 }
244
245
246
247
248
249
250
252 if (!environment)
253 {
254 _ASSERTE((
"CRT logic error in setenv", 0));
255 return -1;
256 }
257
258
260
261
262
263 if (option_index >= 0 && environment[0])
264 {
266
267
268 if (is_removal)
269 {
270
271 size_t i =
static_cast<size_t>(option_index);
272 for (; environment[
i]; ++
i)
273 {
274 environment[
i] = environment[
i + 1];
275 }
276
277
278
279
280
281 Character** new_environment = _recalloc_crt_t(Character*, environment,
i).detach();
282 if (new_environment)
283 {
285 }
286 }
287
288 else
289 {
290 environment[option_index] = owned_option.detach();
291 }
292 }
293
294 else
295 {
296
297 if (is_removal)
298 {
299 return 0;
300 }
301
302
303 else
304 {
305 size_t const environment_count = static_cast<size_t>(-option_index);
306 if (environment_count + 2 < environment_count)
307 {
308 return -1;
309 }
310
311 if (environment_count + 2 >=
SIZE_MAX /
sizeof(Character*))
312 {
313 return -1;
314 }
315
316 Character** const new_environment = _recalloc_crt_t(Character*, environment, environment_count + 2).detach();
317 if (!new_environment)
318 {
319 return -1;
320 }
321
322 new_environment[environment_count] = owned_option.detach();
323 new_environment[environment_count + 1] = nullptr;
324
326 }
327 }
328
329
330
331
332
333
334 if (is_top_level_call)
335 {
337 __crt_unique_heap_ptr<Character>
const buffer(_calloc_crt_t(Character,
count));
339 {
340 return 0;
341 }
342
345
348
349 if (traits::set_environment_variable(
name, is_removal ?
nullptr :
value) == 0)
350 {
352 return -1;
353 }
354 }
355
356 return 0;
357}
__kernel_ptrdiff_t ptrdiff_t
__crt_state_management::dual_state_global< wchar_t ** > _wenviron_table
__crt_state_management::dual_state_global< char ** > _environ_table
GLuint GLuint GLsizei count
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
#define _VALIDATE_RETURN_NOEXC(expr, errorcode, retexpr)
static wchar_t **&__cdecl get_other_environment(char)
static ptrdiff_t __cdecl find_in_environment_nolock(Character const *const name, size_t const length)
static char **&__cdecl get_environment(char)