Commit ee9aad5f5798b938fa6f3ebbb7ada6d47678a95e
1 parent
f4f81190
Exists in
master
and in
3 other branches
Correcao na conversao de codepage em windows
Showing
1 changed file
with
26 additions
and
13 deletions
Show diff stats
util.c
| ... | ... | @@ -160,16 +160,9 @@ LIB3270_EXPORT const char * lib3270_win32_strerror(int e) |
| 160 | 160 | return buffer; |
| 161 | 161 | } |
| 162 | 162 | |
| 163 | - trace("%s",buffer); | |
| 164 | - | |
| 165 | 163 | #ifdef HAVE_ICONV |
| 166 | 164 | { |
| 167 | 165 | // Convert from windows codepage to UTF-8 pw3270´s default charset |
| 168 | - char tmpbuffer[4096]; | |
| 169 | - size_t in = strlen(buffer); | |
| 170 | - size_t out = 4095; | |
| 171 | - char * ptr = tmpbuffer; | |
| 172 | - | |
| 173 | 166 | iconv_t hConv = iconv_open("UTF-8",lib3270_win32_local_charset()); |
| 174 | 167 | |
| 175 | 168 | trace("[%s]",buffer); |
| ... | ... | @@ -178,23 +171,43 @@ LIB3270_EXPORT const char * lib3270_win32_strerror(int e) |
| 178 | 171 | { |
| 179 | 172 | lib3270_write_log(NULL,"iconv","%s: Error creating charset conversion",__FUNCTION__); |
| 180 | 173 | } |
| 181 | - else if(iconv(hConv,(const char **) &buffer,&in,&ptr,&out) != ((size_t) -1)) | |
| 174 | + else | |
| 182 | 175 | { |
| 183 | - // strncpy(buffer,tmpbuffer,4096); | |
| 184 | - } | |
| 176 | + size_t in = strlen(buffer); | |
| 177 | + size_t out = (in << 1); | |
| 178 | + char * ptr; | |
| 179 | + char * outBuffer = (char *) malloc(out); | |
| 180 | + ICONV_CONST char * inBuffer = (ICONV_CONST char *) buffer; | |
| 185 | 181 | |
| 186 | - trace("[%s]",buffer); | |
| 182 | + memset(ptr=outBuffer,0,out); | |
| 183 | + | |
| 184 | + iconv(hConv,NULL,NULL,NULL,NULL); // Reset state | |
| 185 | + | |
| 186 | + if(iconv(hConv,&inBuffer,&in,&ptr,&out) != ((size_t) -1)) | |
| 187 | + { | |
| 188 | + strncpy(buffer,outBuffer,4095); | |
| 189 | + } | |
| 190 | + | |
| 191 | + free(outBuffer); | |
| 192 | + | |
| 193 | + iconv_close(hConv); | |
| 194 | + } | |
| 187 | 195 | |
| 188 | - iconv_close(hConv); | |
| 189 | 196 | } |
| 190 | 197 | #endif // HAVE_ICONV |
| 191 | 198 | |
| 192 | - trace("[%s]",buffer); | |
| 193 | 199 | return buffer; |
| 194 | 200 | } |
| 195 | 201 | |
| 196 | 202 | LIB3270_EXPORT const char * lib3270_win32_local_charset(void) |
| 197 | 203 | { |
| 204 | + // Reference: | |
| 205 | + // http://msdn.microsoft.com/en-us/library/windows/desktop/dd318070(v=vs.85).aspx | |
| 206 | + | |
| 207 | + #warning TODO: Use GetACP() to identify the correct code page | |
| 208 | + | |
| 209 | + trace("Windows CHARSET is %u",GetACP()); | |
| 210 | + | |
| 198 | 211 | return "CP1252"; |
| 199 | 212 | } |
| 200 | 213 | ... | ... |