diff options
author | Avuton Olrich <avuton@gmail.com> | 2006-04-22 22:18:15 +0000 |
---|---|---|
committer | Avuton Olrich <avuton@gmail.com> | 2006-04-22 22:18:15 +0000 |
commit | 8220d3deac0f28e75e580e2f8d29fa2691d8e251 (patch) | |
tree | fb0104a0a8ba49e53035acde88ef6e5354cdcf7e | |
parent | 3accf44add6471c5e5890e53bed8b95b6eb0b573 (diff) | |
download | mpd-8220d3deac0f28e75e580e2f8d29fa2691d8e251.tar.gz mpd-8220d3deac0f28e75e580e2f8d29fa2691d8e251.tar.xz mpd-8220d3deac0f28e75e580e2f8d29fa2691d8e251.zip |
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
Diffstat (limited to '')
-rw-r--r-- | src/main.c | 42 |
1 files changed, 34 insertions, 8 deletions
diff --git a/src/main.c b/src/main.c index d0e64a27e..2732df05b 100644 --- a/src/main.c +++ b/src/main.c @@ -67,17 +67,43 @@ typedef struct _Options { int updateDB; } Options; -/* Solaris has been reported to have no setenv - * putenv() will automatically overwrite, so - * the overwrite macro will go unused +/* + * from git-1.3.0, needed for solaris */ #ifndef setenv -#define setenv(name,value,overwrite) { \ - char * tmp = NULL; \ - sprintf(tmp,"%s=%s",name,value); \ - putenv(tmp); \ +int setenv(const char *name, const char *value, int replace) +{ + int out; + 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[]) { ERROR("usage:\n"); |