mirror of
https://github.com/X11Libre/xserver.git
synced 2026-03-24 03:44:06 +00:00
putenv() is deprecated due several drawbacks: the passed buffer becomes part of the environment (not copied), thus the caller needs to allocate a permanent buffer first - and has no way to know whether it might become used later. And it has to fill in the new entry in the correct form (<name>+"="+<value>) setenv() instead is damn simple: pass env variable name and value separately, and no need to care what's going on under the hood. Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
28 lines
644 B
C
28 lines
644 B
C
#ifndef __XWIN_OS_COMPAT_H
|
|
#define __XWIN_OS_COMPAT_H
|
|
|
|
#include <stdlib.h>
|
|
#include <errno.h>
|
|
|
|
/* special workaround for mingw lacking setenv() */
|
|
#ifndef HAVE_SETENV
|
|
static inline int setenv(const char *name, const char *value, int overwrite)
|
|
{
|
|
size_t name_len = strlen(name);
|
|
size_t value_len = strlen(value);
|
|
size_t bufsz = name_len + value_len + 1;
|
|
char *buf = malloc(bufsz);
|
|
if (!buf) {
|
|
errno = ENOMEM;
|
|
return -1;
|
|
}
|
|
memcpy(buf, name, name_len);
|
|
memcpy(buf+name_len, value, value_len);
|
|
buf[name_len+value_len] = 0;
|
|
putenv(buf);
|
|
return 0;
|
|
}
|
|
#endif
|
|
|
|
#endif /* __XWIN_OS_COMPAT_H */
|