#include <9pm/windows.h>
#include <9pm/u.h>
#include <9pm/libc.h>

/* for some reason this has to be different */
#undef GetEnvironmentStrings
LPWSTR WINAPI
_GetEnvironmentStrings(VOID)
{
	int n;
	Rune *buf, *q;
	char *s, *p;

	if(win_useunicode)
		return GetEnvironmentStringsW();

	s = GetEnvironmentStrings();
	for(p=s,n=0; *p; p+=strlen(p)+1)
		n += utflen(p)+1;
	n++;
	buf = win_malloc(n*sizeof(Rune));
	for(p=s,q=buf; *p; p+=strlen(p)+1)
		 q += win_utf2wstrn(q, n, p)+1;
	*q++ = 0;
	FreeEnvironmentStringsA(s);
	return buf;
}


syntax highlighted by Code2HTML, v. 0.9.1