Skip to content

Commit

Permalink
Use _wputenv() for Windows environment
Browse files Browse the repository at this point in the history
This fixes the handling of non-ASCII (and out-of-codepage) tundev names.
It looks like cscript/vpnc-script-win.js/netsh all Just Work™ at least
here on Windows 7 with my 'TAP♥' device.

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
  • Loading branch information
David Woodhouse authored and David Woodhouse committed Jul 29, 2014
1 parent 62ecb0e commit 800ea0e
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions compat.c
Expand Up @@ -186,17 +186,26 @@ char *openconnect__strndup(const char *s, size_t n)
#ifndef HAVE_SETENV
int openconnect__setenv(const char *name, const char *value, int overwrite)
{
char *buf;
struct oc_text_buf *buf;

if (!value) {
openconnect__unsetenv(name);
return 0;
}

buf = buf_alloc();
buf_append_utf16le(buf, name);
buf_append_utf16le(buf, "=");
buf_append_utf16le(buf, value);
if (buf_error(buf)) {
errno = -buf_free(buf);
return -1;
}

/* Windows putenv() takes a copy of the string */
buf = alloca(strlen(name) + strlen(value) + 2);
_wputenv((wchar_t *)buf->data);
buf_free(buf);

sprintf(buf, "%s=%s", name, value);
putenv(buf);
return 0;
}
#endif
Expand Down

0 comments on commit 800ea0e

Please sign in to comment.