summaryrefslogtreecommitdiffstats
path: root/uisimulator/common
diff options
context:
space:
mode:
authorJens Arnold <amiconn@rockbox.org>2007-04-20 17:35:05 +0000
committerJens Arnold <amiconn@rockbox.org>2007-04-20 17:35:05 +0000
commit49be3faf0785d8c07b265a0488052f9d5902c612 (patch)
tree91242bbeaa3ac10da7a0b08cd97bbd94fcb48911 /uisimulator/common
parentb7d93d06734940140256d190f187b9c7f4ec39d9 (diff)
downloadrockbox-49be3faf0785d8c07b265a0488052f9d5902c612.tar.gz
rockbox-49be3faf0785d8c07b265a0488052f9d5902c612.tar.bz2
rockbox-49be3faf0785d8c07b265a0488052f9d5902c612.zip
A bit more readable code. Also saves one buffer.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@13222 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'uisimulator/common')
-rw-r--r--uisimulator/common/io.c25
1 files changed, 13 insertions, 12 deletions
diff --git a/uisimulator/common/io.c b/uisimulator/common/io.c
index b6f294cee1..3f7087876a 100644
--- a/uisimulator/common/io.c
+++ b/uisimulator/common/io.c
@@ -64,24 +64,25 @@ extern const unsigned char* utf8decode(const unsigned char *utf8,
unsigned short *ucs);
extern unsigned char* utf8encode(unsigned long ucs, unsigned char *utf8);
-/* UTF-8 <-> UCS2 conversion. Note that these functions aren't thread safe
- * due to the use of static buffers. */
-static wchar_t* utf8_to_ucs2(const unsigned char *utf8, int index)
+/* Static buffers for the conversion results. This isn't thread safe,
+ * but it's sufficient for rockbox. */
+static unsigned char convbuf1[3*MAX_PATH];
+static unsigned char convbuf2[3*MAX_PATH];
+
+static wchar_t* utf8_to_ucs2(const unsigned char *utf8, void *buffer)
{
- static wchar_t wbuffer[2][MAX_PATH];
- wchar_t *ucs = wbuffer[index];
+ wchar_t *ucs = buffer;
while (*utf8)
utf8 = utf8decode(utf8, ucs++);
*ucs = 0;
- return wbuffer[index];
+ return buffer;
}
-static unsigned char *ucs2_to_utf8(const wchar_t *ucs)
+static unsigned char *ucs2_to_utf8(const wchar_t *ucs, unsigned char *buffer)
{
- static unsigned char buffer[3*MAX_PATH];
unsigned char *utf8 = buffer;
-
+
while (*ucs)
utf8 = utf8encode(*ucs++, utf8);
@@ -89,8 +90,8 @@ static unsigned char *ucs2_to_utf8(const wchar_t *ucs)
return buffer;
}
-#define UTF8_TO_OS(a) utf8_to_ucs2(a,0)
-#define OS_TO_UTF8(a) ucs2_to_utf8(a)
+#define UTF8_TO_OS(a) utf8_to_ucs2(a,convbuf1)
+#define OS_TO_UTF8(a) ucs2_to_utf8(a,convbuf1)
#define DIR_T _WDIR
#define DIRENT_T struct _wdirent
#define STAT_T struct _stat
@@ -104,7 +105,7 @@ extern int _wrmdir(const wchar_t*);
#define STAT(a,b) (_wstat)(UTF8_TO_OS(a),b)
#define OPEN(a,b,c) (_wopen)(UTF8_TO_OS(a),b,c)
#define REMOVE(a) (_wremove)(UTF8_TO_OS(a))
-#define RENAME(a,b) (_wrename)(UTF8_TO_OS(a),utf8_to_ucs2(b,1))
+#define RENAME(a,b) (_wrename)(UTF8_TO_OS(a),utf8_to_ucs2(b,convbuf2))
#else /* !__MINGW32__ */