Some fixes, enhancements for environment handling.
git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@1424 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "port.h"
|
||||
|
||||
#ifndef HAVE_STRUPR
|
||||
@@ -40,3 +41,41 @@ strupr (char *str)
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_SETENV
|
||||
int
|
||||
setenv (const char *name, const char *value, int overwrite)
|
||||
{
|
||||
char *string, *ptr;
|
||||
size_t nameLen, valueLen;
|
||||
|
||||
if (!overwrite)
|
||||
{
|
||||
char *old;
|
||||
|
||||
old = getenv (name);
|
||||
if (old != NULL)
|
||||
return 0;
|
||||
}
|
||||
|
||||
nameLen = strlen (name);
|
||||
valueLen = strlen (value);
|
||||
|
||||
string = malloc (nameLen + valueLen + 2);
|
||||
// "NAME=VALUE\0"
|
||||
// putenv() does NOT make a copy, but uses the string passed.
|
||||
|
||||
ptr = string;
|
||||
|
||||
strcpy (string, name);
|
||||
ptr += nameLen;
|
||||
|
||||
*ptr = '=';
|
||||
ptr++;
|
||||
|
||||
strcpy (ptr, value);
|
||||
|
||||
return putenv (string);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user