From 6d0bf9181121b4c117c80d05a7f097363c531774 Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Sun, 7 Jun 2009 00:56:23 +0000 Subject: Add Windows CE implementations of some ANSI C functions that are missing. Subversion-branch: /trunk/chocolate-doom Subversion-revision: 1553 --- wince/Makefile.am | 8 ++++++ wince/env.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ wince/env.h | 13 ++++++++++ wince/errno.c | 20 +++++++++++++++ wince/errno.h | 15 +++++++++++ wince/fileops.c | 49 +++++++++++++++++++++++++++++++++++ wince/fileops.h | 14 ++++++++++ 7 files changed, 196 insertions(+) create mode 100644 wince/Makefile.am create mode 100644 wince/env.c create mode 100644 wince/env.h create mode 100644 wince/errno.c create mode 100644 wince/errno.h create mode 100644 wince/fileops.c create mode 100644 wince/fileops.h (limited to 'wince') diff --git a/wince/Makefile.am b/wince/Makefile.am new file mode 100644 index 00000000..f6c87759 --- /dev/null +++ b/wince/Makefile.am @@ -0,0 +1,8 @@ + +noinst_LIBRARIES=libc_wince.a + +libc_wince_a_SOURCES = \ + env.c env.h \ + errno.c errno.h \ + fileops.c fileops.h + 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 +#include + +#include +#include +#include + +#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; + } +} + diff --git a/wince/env.h b/wince/env.h new file mode 100644 index 00000000..c2cb4243 --- /dev/null +++ b/wince/env.h @@ -0,0 +1,13 @@ +// +// "Extension" implementation of getenv for Windows CE. +// +// I (Simon Howard) release this file to the public domain. +// + +#ifndef WINCE_ENV_H +#define WINCE_ENV_H + +extern char *getenv(const char *name); + +#endif /* #ifndef WINCE_ENV_H */ + diff --git a/wince/errno.c b/wince/errno.c new file mode 100644 index 00000000..28cd0899 --- /dev/null +++ b/wince/errno.c @@ -0,0 +1,20 @@ +// +// "Extension" implementation of errno.h for Windows CE. +// +// I (Simon Howard) release this file to the public domain. +// + +#include + +#include "errno.h" + +// This should really be a thread-local variable. Oh well. + +static int my_errno; + +int *_GetErrno() +{ + my_errno = GetLastError(); + return &my_errno; +} + diff --git a/wince/errno.h b/wince/errno.h new file mode 100644 index 00000000..e9b4721a --- /dev/null +++ b/wince/errno.h @@ -0,0 +1,15 @@ +// +// "Extension" implementation of errno.h for Windows CE. +// +// I (Simon Howard) release this file to the public domain. +// + +#ifndef WINCE_ERRNO_H +#define WINCE_ERRNO_H + +extern int *_GetErrno(); + +#define errno (*_GetErrno()) + +#endif /* #ifndef WINCE_ERROR_H */ + diff --git a/wince/fileops.c b/wince/fileops.c new file mode 100644 index 00000000..b0617bd3 --- /dev/null +++ b/wince/fileops.c @@ -0,0 +1,49 @@ +// +// "Extension" implementation of ANSI C file functions for Windows CE. +// +// I (Simon Howard) release this file to the public domain. +// + +#include +#include +#include + +#include + +#include "fileops.h" + +int remove(const char *pathname) +{ + wchar_t temp[MAX_PATH + 1]; + + MultiByteToWideChar(CP_OEMCP, + 0, + pathname, + strlen(pathname) + 1, + temp, + MAX_PATH); + + return DeleteFileW(temp) != 0; +} + +int rename(const char *oldpath, const char *newpath) +{ + wchar_t oldpath1[MAX_PATH + 1]; + wchar_t newpath1[MAX_PATH + 1]; + + MultiByteToWideChar(CP_OEMCP, + 0, + oldpath, + strlen(oldpath) + 1, + oldpath1, + MAX_PATH); + MultiByteToWideChar(CP_OEMCP, + 0, + newpath, + strlen(newpath) + 1, + newpath1, + MAX_PATH); + + return MoveFileW(oldpath1, newpath1); +} + diff --git a/wince/fileops.h b/wince/fileops.h new file mode 100644 index 00000000..757a34fd --- /dev/null +++ b/wince/fileops.h @@ -0,0 +1,14 @@ +// +// "Extension" implementation of ANSI C file functions for Windows CE. +// +// I (Simon Howard) release this file to the public domain. +// + +#ifndef WINCE_FILEOPS_H +#define WINCE_FILEOPS_H + +int remove(const char *pathname); +int rename(const char *oldpath, const char *newpath); + +#endif /* #ifndef WINCE_FILEOPS_H */ + -- cgit v1.2.3 From 52c831999bddb7b68b855d0fec644240863cbee2 Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Sun, 7 Jun 2009 01:27:30 +0000 Subject: Use GetUserNameExW, not GetUserName (doesn't exist on WinCE) Subversion-branch: /trunk/chocolate-doom Subversion-revision: 1556 --- wince/env.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'wince') diff --git a/wince/env.c b/wince/env.c index ceba6402..a678de2d 100644 --- a/wince/env.c +++ b/wince/env.c @@ -9,6 +9,7 @@ #include #include +#include #include #include "env.h" @@ -35,7 +36,7 @@ static void LoadBuffers(void) // Username: buf_len = UNLEN; - GetUserNameW(temp, &buf_len); + GetUserNameExW(NameDisplay, temp, &buf_len); WCharToChar(temp, temp_buf, MAX_PATH); // Temp dir: -- cgit v1.2.3 From 203e7e79a1a20b83fea8a91b46c8241c056a23b1 Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Sun, 7 Jun 2009 01:27:58 +0000 Subject: Add libc_wince.h header, and EISDIR error value. Subversion-branch: /trunk/chocolate-doom Subversion-revision: 1557 --- wince/errno.h | 2 ++ wince/libc_wince.h | 4 ++++ 2 files changed, 6 insertions(+) create mode 100644 wince/libc_wince.h (limited to 'wince') diff --git a/wince/errno.h b/wince/errno.h index e9b4721a..a2149b45 100644 --- a/wince/errno.h +++ b/wince/errno.h @@ -7,6 +7,8 @@ #ifndef WINCE_ERRNO_H #define WINCE_ERRNO_H +#define EISDIR 21 /* Is a directory */ + extern int *_GetErrno(); #define errno (*_GetErrno()) diff --git a/wince/libc_wince.h b/wince/libc_wince.h new file mode 100644 index 00000000..0d6fac05 --- /dev/null +++ b/wince/libc_wince.h @@ -0,0 +1,4 @@ + +#include "env.h" +#include "fileops.h" + -- cgit v1.2.3 From 61d40373640c0cabdaef4d4381ac5ae636fab642 Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Sun, 7 Jun 2009 01:56:21 +0000 Subject: Detect Windows CE target and build/include libc_wince files as necessary. Subversion-branch: /trunk/chocolate-doom Subversion-revision: 1561 --- wince/Makefile.am | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'wince') diff --git a/wince/Makefile.am b/wince/Makefile.am index f6c87759..7d694377 100644 --- a/wince/Makefile.am +++ b/wince/Makefile.am @@ -1,8 +1,16 @@ noinst_LIBRARIES=libc_wince.a +if WINDOWS_CE + libc_wince_a_SOURCES = \ env.c env.h \ errno.c errno.h \ fileops.c fileops.h +else + +libc_wince_a_SOURCES = + +endif + -- cgit v1.2.3 From cd07b206fa4e7ffa30aa1ef2e8e138603171fc9e Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Sun, 7 Jun 2009 01:59:49 +0000 Subject: Add README file for Windows CE library. Subversion-branch: /trunk/chocolate-doom Subversion-revision: 1562 --- wince/README | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 wince/README (limited to 'wince') diff --git a/wince/README b/wince/README new file mode 100644 index 00000000..76f282f4 --- /dev/null +++ b/wince/README @@ -0,0 +1,8 @@ +Windows CE is a horribly crippled operating system. The poor thing doesn't +even include a complete implementation of the ANSI standard C library. This +is a mini-library called libc_wince that implements some of the missing +library functions. I've only implemented those necessary to get Chocolate +Doom to compile. + +On non-Windows CE platforms it is just built as an empty library. + -- cgit v1.2.3 From a91a1c60f544d26195c2df9dd9cd1ef042deacf9 Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Mon, 8 Jun 2009 18:15:57 +0000 Subject: Use SDL's getenv/putenv implementation, and populate at startup. Subversion-branch: /trunk/chocolate-doom Subversion-revision: 1577 --- wince/env.c | 60 ++++++++++++++++++++++++++++-------------------------------- wince/env.h | 6 +++++- 2 files changed, 33 insertions(+), 33 deletions(-) (limited to 'wince') diff --git a/wince/env.c b/wince/env.c index a678de2d..bedeb434 100644 --- a/wince/env.c +++ b/wince/env.c @@ -14,21 +14,33 @@ #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); + len = wcslen(src) + 1; WideCharToMultiByte(CP_OEMCP, 0, src, len, dest, buf_len, NULL, NULL); } -static void LoadBuffers(void) +static void SetEnvironment(char *env_string, wchar_t *wvalue) +{ + char value[MAX_PATH + 10]; + int env_len; + + // Construct the string for putenv: NAME=value + + env_len = strlen(env_string); + strcpy(value, env_string); + + WCharToChar(wvalue, value + env_len, sizeof(value) - env_len); + + // Set the environment variable: + + putenv(value); +} + +void PopulateEnvironment(void) { wchar_t temp[MAX_PATH]; DWORD buf_len; @@ -37,42 +49,26 @@ static void LoadBuffers(void) buf_len = UNLEN; GetUserNameExW(NameDisplay, temp, &buf_len); - WCharToChar(temp, temp_buf, MAX_PATH); + SetEnvironment("USER=", temp); + SetEnvironment("USERNAME=", temp); // Temp dir: GetTempPathW(MAX_PATH, temp); - WCharToChar(temp, temp_buf, MAX_PATH); + SetEnvironment("TEMP=", temp); // Use My Documents dir as home: SHGetSpecialFolderPath(NULL, temp, CSIDL_PERSONAL, 0); - WCharToChar(temp, home_buf, MAX_PATH); -} + SetEnvironment("HOME=", temp); -char *getenv(const char *name) -{ - if (!buffers_loaded) { - LoadBuffers(); - buffers_loaded = 1; - } + char *home = getenv("HOME"); - 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; + MultiByteToWideChar(CP_ACP, 0, + home, strlen(home) + 1, + temp, sizeof(temp)); + MessageBoxW(NULL, temp, L"Home", MB_OK); } } diff --git a/wince/env.h b/wince/env.h index c2cb4243..d91f3fab 100644 --- a/wince/env.h +++ b/wince/env.h @@ -7,7 +7,11 @@ #ifndef WINCE_ENV_H #define WINCE_ENV_H -extern char *getenv(const char *name); +// SDL provides an implementation of getenv/putenv: + +#include "SDL_getenv.h" + +extern void PopulateEnvironment(void); #endif /* #ifndef WINCE_ENV_H */ -- cgit v1.2.3 From b6491fa4aefc073a760d4bad51f55c2d6c0f5f35 Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Mon, 8 Jun 2009 19:26:29 +0000 Subject: Remove debugging code. Subversion-branch: /trunk/chocolate-doom Subversion-revision: 1578 --- wince/env.c | 9 --------- 1 file changed, 9 deletions(-) (limited to 'wince') diff --git a/wince/env.c b/wince/env.c index bedeb434..72af2212 100644 --- a/wince/env.c +++ b/wince/env.c @@ -61,14 +61,5 @@ void PopulateEnvironment(void) SHGetSpecialFolderPath(NULL, temp, CSIDL_PERSONAL, 0); SetEnvironment("HOME=", temp); - - { - char *home = getenv("HOME"); - - MultiByteToWideChar(CP_ACP, 0, - home, strlen(home) + 1, - temp, sizeof(temp)); - MessageBoxW(NULL, temp, L"Home", MB_OK); - } } -- cgit v1.2.3