diff options
author | Simon Howard | 2009-06-07 00:56:23 +0000 |
---|---|---|
committer | Simon Howard | 2009-06-07 00:56:23 +0000 |
commit | 6d0bf9181121b4c117c80d05a7f097363c531774 (patch) | |
tree | 1f6ad34f552ab93ceebf4b6046f8ba90b7353c64 /wince/env.c | |
parent | dc8c45c667bc327e5e84e1d98d3f8b468d7a1553 (diff) | |
download | chocolate-doom-6d0bf9181121b4c117c80d05a7f097363c531774.tar.gz chocolate-doom-6d0bf9181121b4c117c80d05a7f097363c531774.tar.bz2 chocolate-doom-6d0bf9181121b4c117c80d05a7f097363c531774.zip |
Add Windows CE implementations of some ANSI C functions that are
missing.
Subversion-branch: /trunk/chocolate-doom
Subversion-revision: 1553
Diffstat (limited to 'wince/env.c')
-rw-r--r-- | wince/env.c | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/wince/env.c b/wince/env.c new file mode 100644 index 00000000..ceba6402 --- /dev/null +++ b/wince/env.c @@ -0,0 +1,77 @@ +// +// "Extension" implementation of getenv for Windows CE. +// +// I (Simon Howard) release this file to the public domain. +// + +#include <stdlib.h> +#include <string.h> + +#include <windows.h> +#include <lmcons.h> +#include <shlobj.h> + +#include "env.h" + +static int buffers_loaded = 0; +static char username_buf[UNLEN + 1]; +static char temp_buf[MAX_PATH + 1]; +static char home_buf[MAX_PATH + 1]; + +static void WCharToChar(wchar_t *src, char *dest, int buf_len) +{ + unsigned int len; + + len = wcslen(src); + + WideCharToMultiByte(CP_OEMCP, 0, src, len, dest, buf_len, NULL, NULL); +} + +static void LoadBuffers(void) +{ + wchar_t temp[MAX_PATH]; + DWORD buf_len; + + // Username: + + buf_len = UNLEN; + GetUserNameW(temp, &buf_len); + WCharToChar(temp, temp_buf, MAX_PATH); + + // Temp dir: + + GetTempPathW(MAX_PATH, temp); + WCharToChar(temp, temp_buf, MAX_PATH); + + // Use My Documents dir as home: + + SHGetSpecialFolderPath(NULL, temp, CSIDL_PERSONAL, 0); + WCharToChar(temp, home_buf, MAX_PATH); +} + +char *getenv(const char *name) +{ + if (!buffers_loaded) + { + LoadBuffers(); + buffers_loaded = 1; + } + + if (!strcmp(name, "USER") || !strcmp(name, "USERNAME")) + { + return username_buf; + } + else if (!strcmp(name, "TEMP")) + { + return temp_buf; + } + else if (!strcmp(name, "HOME")) + { + return home_buf; + } + else + { + return NULL; + } +} + |