diff options
author | Jens Arnold <amiconn@rockbox.org> | 2007-04-20 17:35:05 +0000 |
---|---|---|
committer | Jens Arnold <amiconn@rockbox.org> | 2007-04-20 17:35:05 +0000 |
commit | 49be3faf0785d8c07b265a0488052f9d5902c612 (patch) | |
tree | 91242bbeaa3ac10da7a0b08cd97bbd94fcb48911 | |
parent | b7d93d06734940140256d190f187b9c7f4ec39d9 (diff) | |
download | rockbox-49be3faf0785d8c07b265a0488052f9d5902c612.tar.gz 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
-rw-r--r-- | uisimulator/common/io.c | 25 |
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, | |||
64 | unsigned short *ucs); | 64 | unsigned short *ucs); |
65 | extern unsigned char* utf8encode(unsigned long ucs, unsigned char *utf8); | 65 | extern unsigned char* utf8encode(unsigned long ucs, unsigned char *utf8); |
66 | 66 | ||
67 | /* UTF-8 <-> UCS2 conversion. Note that these functions aren't thread safe | 67 | /* Static buffers for the conversion results. This isn't thread safe, |
68 | * due to the use of static buffers. */ | 68 | * but it's sufficient for rockbox. */ |
69 | static wchar_t* utf8_to_ucs2(const unsigned char *utf8, int index) | 69 | static unsigned char convbuf1[3*MAX_PATH]; |
70 | static unsigned char convbuf2[3*MAX_PATH]; | ||
71 | |||
72 | static wchar_t* utf8_to_ucs2(const unsigned char *utf8, void *buffer) | ||
70 | { | 73 | { |
71 | static wchar_t wbuffer[2][MAX_PATH]; | 74 | wchar_t *ucs = buffer; |
72 | wchar_t *ucs = wbuffer[index]; | ||
73 | 75 | ||
74 | while (*utf8) | 76 | while (*utf8) |
75 | utf8 = utf8decode(utf8, ucs++); | 77 | utf8 = utf8decode(utf8, ucs++); |
76 | 78 | ||
77 | *ucs = 0; | 79 | *ucs = 0; |
78 | return wbuffer[index]; | 80 | return buffer; |
79 | } | 81 | } |
80 | static unsigned char *ucs2_to_utf8(const wchar_t *ucs) | 82 | static unsigned char *ucs2_to_utf8(const wchar_t *ucs, unsigned char *buffer) |
81 | { | 83 | { |
82 | static unsigned char buffer[3*MAX_PATH]; | ||
83 | unsigned char *utf8 = buffer; | 84 | unsigned char *utf8 = buffer; |
84 | 85 | ||
85 | while (*ucs) | 86 | while (*ucs) |
86 | utf8 = utf8encode(*ucs++, utf8); | 87 | utf8 = utf8encode(*ucs++, utf8); |
87 | 88 | ||
@@ -89,8 +90,8 @@ static unsigned char *ucs2_to_utf8(const wchar_t *ucs) | |||
89 | return buffer; | 90 | return buffer; |
90 | } | 91 | } |
91 | 92 | ||
92 | #define UTF8_TO_OS(a) utf8_to_ucs2(a,0) | 93 | #define UTF8_TO_OS(a) utf8_to_ucs2(a,convbuf1) |
93 | #define OS_TO_UTF8(a) ucs2_to_utf8(a) | 94 | #define OS_TO_UTF8(a) ucs2_to_utf8(a,convbuf1) |
94 | #define DIR_T _WDIR | 95 | #define DIR_T _WDIR |
95 | #define DIRENT_T struct _wdirent | 96 | #define DIRENT_T struct _wdirent |
96 | #define STAT_T struct _stat | 97 | #define STAT_T struct _stat |
@@ -104,7 +105,7 @@ extern int _wrmdir(const wchar_t*); | |||
104 | #define STAT(a,b) (_wstat)(UTF8_TO_OS(a),b) | 105 | #define STAT(a,b) (_wstat)(UTF8_TO_OS(a),b) |
105 | #define OPEN(a,b,c) (_wopen)(UTF8_TO_OS(a),b,c) | 106 | #define OPEN(a,b,c) (_wopen)(UTF8_TO_OS(a),b,c) |
106 | #define REMOVE(a) (_wremove)(UTF8_TO_OS(a)) | 107 | #define REMOVE(a) (_wremove)(UTF8_TO_OS(a)) |
107 | #define RENAME(a,b) (_wrename)(UTF8_TO_OS(a),utf8_to_ucs2(b,1)) | 108 | #define RENAME(a,b) (_wrename)(UTF8_TO_OS(a),utf8_to_ucs2(b,convbuf2)) |
108 | 109 | ||
109 | #else /* !__MINGW32__ */ | 110 | #else /* !__MINGW32__ */ |
110 | 111 | ||