You need to sign in or sign up before continuing.
Commit 8220d3de authored by Avuton Olrich's avatar Avuton Olrich

Fix for the macro, use gitsetenv, thanks to normalperson, eleusis, jat

git-svn-id: https://svn.musicpd.org/mpd/trunk@4098 09075e82-0dd4-0310-85a5-a0d7c8717e4f
parent 3accf44a
...@@ -67,17 +67,43 @@ typedef struct _Options { ...@@ -67,17 +67,43 @@ typedef struct _Options {
int updateDB; int updateDB;
} Options; } Options;
/* Solaris has been reported to have no setenv /*
* putenv() will automatically overwrite, so * from git-1.3.0, needed for solaris
* the overwrite macro will go unused
*/ */
#ifndef setenv #ifndef setenv
#define setenv(name,value,overwrite) { \ int setenv(const char *name, const char *value, int replace)
char * tmp = NULL; \ {
sprintf(tmp,"%s=%s",name,value); \ int out;
putenv(tmp); \ size_t namelen, valuelen;
char *envstr;
if (!name || !value) return -1;
if (!replace) {
char *oldval = NULL;
oldval = getenv(name);
if (oldval) return 0;
}
namelen = strlen(name);
valuelen = strlen(value);
envstr = malloc((namelen + valuelen + 2));
if (!envstr) return -1;
memcpy(envstr, name, namelen);
envstr[namelen] = '=';
memcpy(envstr + namelen + 1, value, valuelen);
envstr[namelen + valuelen + 1] = 0;
out = putenv(envstr);
/* putenv(3) makes the argument string part of the environment,
* and changing that string modifies the environment --- which
* means we do not own that storage anymore. Do not free
* envstr.
*/
return out;
} }
#endif /* setenv */ #endif
void usage(char * argv[]) { void usage(char * argv[]) {
ERROR("usage:\n"); ERROR("usage:\n");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment