summaryrefslogtreecommitdiff
path: root/wince
diff options
context:
space:
mode:
authorSimon Howard2009-06-07 00:56:23 +0000
committerSimon Howard2009-06-07 00:56:23 +0000
commit6d0bf9181121b4c117c80d05a7f097363c531774 (patch)
tree1f6ad34f552ab93ceebf4b6046f8ba90b7353c64 /wince
parentdc8c45c667bc327e5e84e1d98d3f8b468d7a1553 (diff)
downloadchocolate-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')
-rw-r--r--wince/Makefile.am8
-rw-r--r--wince/env.c77
-rw-r--r--wince/env.h13
-rw-r--r--wince/errno.c20
-rw-r--r--wince/errno.h15
-rw-r--r--wince/fileops.c49
-rw-r--r--wince/fileops.h14
7 files changed, 196 insertions, 0 deletions
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 <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;
+ }
+}
+
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 <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..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 <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 */
+