diff options
author | Simon Howard | 2009-06-09 18:28:51 +0000 |
---|---|---|
committer | Simon Howard | 2009-06-09 18:28:51 +0000 |
commit | 122dcc372f579c54ba2e6f793493cfa4d0a7d609 (patch) | |
tree | 5df714640d4ae007e95540c89b8f6f0d80f79767 /wince | |
parent | 46ad00deca23f3c57fcaed47af67f9003d6a4048 (diff) | |
parent | b6491fa4aefc073a760d4bad51f55c2d6c0f5f35 (diff) | |
download | chocolate-doom-122dcc372f579c54ba2e6f793493cfa4d0a7d609.tar.gz chocolate-doom-122dcc372f579c54ba2e6f793493cfa4d0a7d609.tar.bz2 chocolate-doom-122dcc372f579c54ba2e6f793493cfa4d0a7d609.zip |
Merge from trunk.
Subversion-branch: /branches/raven-branch
Subversion-revision: 1579
Diffstat (limited to 'wince')
-rw-r--r-- | wince/Makefile.am | 16 | ||||
-rw-r--r-- | wince/README | 8 | ||||
-rw-r--r-- | wince/env.c | 65 | ||||
-rw-r--r-- | wince/env.h | 17 | ||||
-rw-r--r-- | wince/errno.c | 20 | ||||
-rw-r--r-- | wince/errno.h | 17 | ||||
-rw-r--r-- | wince/fileops.c | 49 | ||||
-rw-r--r-- | wince/fileops.h | 14 | ||||
-rw-r--r-- | wince/libc_wince.h | 4 |
9 files changed, 210 insertions, 0 deletions
diff --git a/wince/Makefile.am b/wince/Makefile.am new file mode 100644 index 00000000..7d694377 --- /dev/null +++ b/wince/Makefile.am @@ -0,0 +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 + 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. + diff --git a/wince/env.c b/wince/env.c new file mode 100644 index 00000000..72af2212 --- /dev/null +++ b/wince/env.c @@ -0,0 +1,65 @@ +// +// "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 <secext.h> +#include <shlobj.h> + +#include "env.h" + +static void WCharToChar(wchar_t *src, char *dest, int buf_len) +{ + unsigned int len; + + len = wcslen(src) + 1; + + WideCharToMultiByte(CP_OEMCP, 0, src, len, dest, buf_len, NULL, NULL); +} + +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; + + // Username: + + buf_len = UNLEN; + GetUserNameExW(NameDisplay, temp, &buf_len); + SetEnvironment("USER=", temp); + SetEnvironment("USERNAME=", temp); + + // Temp dir: + + GetTempPathW(MAX_PATH, temp); + SetEnvironment("TEMP=", temp); + + // Use My Documents dir as home: + + SHGetSpecialFolderPath(NULL, temp, CSIDL_PERSONAL, 0); + SetEnvironment("HOME=", temp); +} + diff --git a/wince/env.h b/wince/env.h new file mode 100644 index 00000000..d91f3fab --- /dev/null +++ b/wince/env.h @@ -0,0 +1,17 @@ +// +// "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 + +// SDL provides an implementation of getenv/putenv: + +#include "SDL_getenv.h" + +extern void PopulateEnvironment(void); + +#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 <windows.h> + +#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..a2149b45 --- /dev/null +++ b/wince/errno.h @@ -0,0 +1,17 @@ +// +// "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 + +#define EISDIR 21 /* Is a directory */ + +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 <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include <windows.h> + +#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 */ + 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" + |