|
7 | 7 | * |
8 | 8 | * |
9 | 9 | * IDENTIFICATION |
10 | | - * $PostgreSQL: pgsql/src/backend/tsearch/ts_locale.c,v 1.4 2007/11/15 21:14:38 momjian Exp $ |
| 10 | + * $PostgreSQL: pgsql/src/backend/tsearch/ts_locale.c,v 1.5 2007/11/24 21:20:07 tgl Exp $ |
11 | 11 | * |
12 | 12 | *------------------------------------------------------------------------- |
13 | 13 | */ |
|
23 | 23 | * wchar2char --- convert wide characters to multibyte format |
24 | 24 | * |
25 | 25 | * This has the same API as the standard wcstombs() function; in particular, |
26 | | - * tolen is the maximum number of bytes to store at *to, and *fromshould be |
| 26 | + * tolen is the maximum number of bytes to store at *to, and *frommust be |
27 | 27 | * zero-terminated. The output will be zero-terminated iff there is room. |
28 | 28 | */ |
29 | 29 | size_t |
@@ -73,21 +73,28 @@ char2wchar(wchar_t *to, size_t tolen, const char *from, size_t fromlen) |
73 | 73 | { |
74 | 74 | intr; |
75 | 75 |
|
76 | | -r=MultiByteToWideChar(CP_UTF8,0,from,fromlen,to,tolen); |
77 | | - |
78 | | -if (r <=0) |
| 76 | +/* stupid Microsloth API does not work for zero-length input */ |
| 77 | +if (fromlen==0) |
| 78 | +r=0; |
| 79 | +else |
79 | 80 | { |
80 | | -pg_verifymbstr(from,fromlen, false); |
81 | | -ereport(ERROR, |
82 | | -(errcode(ERRCODE_CHARACTER_NOT_IN_REPERTOIRE), |
83 | | -errmsg("invalid multibyte character for locale"), |
84 | | -errhint("The server's LC_CTYPE locale is probably incompatible with the database encoding."))); |
| 81 | +r=MultiByteToWideChar(CP_UTF8,0,from,fromlen,to,tolen-1); |
| 82 | + |
| 83 | +if (r <=0) |
| 84 | +{ |
| 85 | +/* see notes in oracle_compat.c about error reporting */ |
| 86 | +pg_verifymbstr(from,fromlen, false); |
| 87 | +ereport(ERROR, |
| 88 | +(errcode(ERRCODE_CHARACTER_NOT_IN_REPERTOIRE), |
| 89 | +errmsg("invalid multibyte character for locale"), |
| 90 | +errhint("The server's LC_CTYPE locale is probably incompatible with the database encoding."))); |
| 91 | +} |
85 | 92 | } |
86 | 93 |
|
87 | | -Assert(r <=tolen); |
| 94 | +Assert(r<tolen); |
| 95 | +to[r]=0; |
88 | 96 |
|
89 | | -/* Microsoft counts the zero terminator in the result */ |
90 | | -returnr-1; |
| 97 | +returnr; |
91 | 98 | } |
92 | 99 | #endif/* WIN32 */ |
93 | 100 |
|
|