1 /* 2 * Copyright (c) 1999, 2021 Tanuki Software, Ltd. 3 * http://www.tanukisoftware.com 4 * All rights reserved. 5 * 6 * This software is the proprietary information of Tanuki Software. 7 * You shall use it only in accordance with the terms of the 8 * license agreement you entered into with Tanuki Software. 9 * http://wrapper.tanukisoftware.com/doc/english/licenseOverview.html 10 */ 11 12 #ifndef _LOCALIZE 13 #define _LOCALIZE 14 #include <stdio.h> 15 16 #ifndef WIN32 17 18 #define MBSTOWCS_QUERY_LENGTH 0 19 20 #ifdef UNICODE 21 #include <wchar.h> 22 #ifdef _sntprintf 23 #undef _sntprintf 24 #endif 25 26 #include <stdarg.h> 27 #include <stdlib.h> 28 #include <unistd.h> 29 #include <sys/types.h> 30 #include <sys/stat.h> 31 #include <locale.h> 32 #include <syslog.h> 33 #include <time.h> 34 #include <wctype.h> 35 36 #define __max(x,y) (((x) > (y)) ? (x) : (y)) 37 #define __min(x,y) (((x) < (y)) ? (x) : (y)) 38 39 #if defined(SOLARIS) || defined(HPUX) 40 #define WRAPPER_USE_PUTENV 41 #endif 42 43 #ifdef FREEBSD 44 #include <dlfcn.h> 45 #endif 46 47 48 #if defined(MACOSX) || defined(HPUX) || defined(FREEBSD) || defined(SOLARIS) 49 #ifndef wcscasecmp 50 extern int wcscasecmp(const wchar_t* s1, const wchar_t* s2); 51 #define ECSCASECMP 52 #endif 53 #endif 54 55 56 #define TEXT(x) L##x 57 typedef wchar_t TCHAR; 58 typedef wchar_t _TUCHAR; 59 60 extern int _tprintf(const wchar_t *fmt,...) ; 61 extern int multiByteToWideChar(const char *multiByteChars, const char *multiByteEncoding, char *interumEncoding, wchar_t **outputBuffer, int localizeErrorMessage); 62 extern int converterMBToWide(const char *multiByteChars, const char *multiByteEncoding, wchar_t **outputBufferW, int localizeErrorMessage); 63 64 #define _taccess _waccess 65 #define _tstoi64 _wtoi64 66 #define _ttoi64 _wtoi64 67 #define cgetts _cgetws 68 extern int _tchdir(const TCHAR *path); 69 extern int _texecvp(TCHAR* arg, TCHAR **cmd); 70 extern int _tmkfifo(TCHAR* arg, mode_t mode); 71 #define _tchmod _wchmod 72 extern int _tchown(const TCHAR *path, uid_t owner, gid_t group); 73 #define _tcprintf _cwprintf 74 #define _cputts _cputws 75 #define _tcreat _wcreat 76 #define _tcscanf _cwscanf 77 #define _tctime64 _wctime64 78 #define _texecl _wexecl 79 #define _texecle _wexecle 80 #define _texeclp _wexeclp 81 #define _texeclpe _wexeclpe 82 #define _texecv _wexecv 83 extern int _texecve(TCHAR* arg, TCHAR **cmd, TCHAR** env); 84 #define _texecvpe _wexecvpe 85 #define _tfdopen _wfdopen 86 #define _fgettchar _fgetwchar 87 #define _tfindfirst _wfindfirst 88 #define _tfindnext64 _wfindnext64 89 #define _tfindnext _wfindnext 90 #define _tfindnexti64 _wfindnexti64 91 #define _fputtchar _fputwchar 92 #define _tfsopen _wfsopen 93 #define _tfullpath _wfullpath 94 #define _gettch _getwch 95 #define _gettche _getwche 96 extern TCHAR* _tgetcwd(TCHAR *buf, size_t size); 97 #define _tgetdcwd _wgetdcwd 98 #define _ltot _ltow 99 #define _tmakepath _wmakepath 100 #define _tmkdir _wmkdir 101 #define _tmktemp _wmktemp 102 extern int _topen(const TCHAR *path, int oflag, mode_t mode); 103 #define _puttch _putwch 104 #if defined(WRAPPER_USE_PUTENV) 105 extern int _tputenv(const TCHAR *string); 106 #else 107 extern int _tsetenv(const TCHAR *name, const TCHAR *value, int overwrite); 108 extern void _tunsetenv(const TCHAR *name); 109 #endif 110 #define _trmdir _wrmdir 111 #define _sctprintf _scwprintf 112 #define _tsearchenv _wsearchenv 113 114 #define _sntscanf _snwscanf 115 #define _tsopen _wsopen 116 #define _tspawnl _wspawnl 117 #define _tspawnle _wspawnle 118 #define _tspawnlp _wspawnlp 119 #define _tspawnlpe _wspawnlpe 120 #define _tspawnv _wspawnv 121 #define _tspawnve _wspawnve 122 #define _tspawnvp _wspawnvp 123 #define _tspawnvpe _wspawnvpe 124 #define _tsplitpath _wsplitpath 125 #define _tstat64 _wstat64 126 extern int _tstat(const wchar_t* filename, struct stat *buf); 127 128 #define _tstati64 _wstati64 129 #define _tstrdate _wstrdate 130 #define _tcsdec _wcsdec 131 #define _tcsdup wcsdup /* replaced _wcsdup by wcsdup - but both not supported on Zos */ 132 #define _tcsicmp wcscasecmp 133 /* Intentionally do not allow use of _trealpath because it does not specify a buffer length. 134 * #define _trealpath 135 * Define our own _trealpathN below. */ 136 extern wchar_t* _trealpathN(const wchar_t* fileName, wchar_t *resolvedName, size_t resolvedNameSize); 137 #define _tcsicoll _wcsicoll 138 #define _tcsinc _wcsinc 139 #define _tcslwr _wcslwr 140 #define _tcsnbcnt _wcsncnt 141 #define _tcsnccnt _wcsncnt 142 #define _tcsnccnt _wcsncnt 143 #define _tcsnccoll _wcsncoll 144 #define _tcsnextc _wcsnextc 145 #define _tcsncicmp _wcsnicmp 146 #define _tcsnicmp _wcsnicmp 147 #define _tcsncicoll _wcsnicoll 148 #define _tcsnicoll _wcsnicoll 149 #define _tcsninc _wcsninc 150 #define _tcsncset _wcsnset 151 #define _tcsnset _wcsnset 152 #define _tcsrev _wcsrev 153 #define _tcsset _wcsset 154 #define _tcsspnp _wcsspnp 155 #define _tstrtime wcsftime 156 #define _tcstoi64 _wcstoi64 157 #define _tcstoui64 _wcstoui64 158 #define _tcsupr _wcsupr 159 #define _ttempnam _wtempnam 160 #define _ui64tot _ui64tow 161 #define _ultot _ultow 162 #define _ungettch _ungetwch 163 extern int _tunlink(const wchar_t* address); 164 #define _tutime64 _wutime64 165 #define _tutime _wutime 166 #define _vsctprintf _vscwprintf 167 #if defined(HPUX) 168 extern int _vsntprintf(wchar_t *ws, size_t n, const wchar_t *format, va_list arg); 169 #else 170 #define _vsntprintf vswprintf 171 #endif 172 #define _tasctime _wasctime 173 #define _tstof _wtof 174 #define _tstoi _wtoi 175 #define _ttoi(x) wcstol(x, NULL, 10) 176 #define _tstol _wtol 177 #define _ttol _wtol 178 #define _tctime _wctime 179 #define _fgettc fgetwc 180 #define _fgetts fgetws 181 extern FILE* _tfopen(const wchar_t* file, const wchar_t* mode); 182 extern FILE* _tpopen(const wchar_t* command, const wchar_t* mode); 183 #define _fputtc fputwc 184 #define _fputts fputws 185 #define _tfreopen _wfreopen 186 #define _ftscanf fwscanf 187 #define _gettc getwc 188 #define _gettchar getwchar 189 /** 190 * This Wrapper function internally does a malloc to generate the 191 * Wide-char version of the return string. This must be freed by the caller. 192 * Only needed inside the following: 193 * #if !defined(WIN32) && defined(UNICODE) 194 * #endif 195 */ 196 extern TCHAR * _tgetenv ( const TCHAR * name ); 197 #define _getts getws 198 #define _istalnum iswalnum 199 #define _istalpha iswalpha 200 #define _istascii iswascii 201 #define _istcntrl iswcntrl 202 #define _istdigit iswdigit 203 #define _istgraph iswgraph 204 #define _istleadbyte isleadbyte 205 #define _istlower iswlower 206 #define _istprint iswprint 207 #define _istpunct iswpunct 208 #define _istspace iswspace 209 #define _istupper iswupper 210 #define _istxdigit iswxdigit 211 #define _tmain wmain 212 #define _tperror _wperror 213 /*_tprintf wprintf*/ 214 #define _puttc putwc 215 #define _puttchar putwchar 216 #define _putts _putws 217 extern int _tremove(const TCHAR *path); 218 extern int _trename(const TCHAR *path, const TCHAR *to); 219 extern void _topenlog(const TCHAR *ident, int logopt, int facility); 220 extern void _tsyslog(int priority, const TCHAR *message); 221 #define _tscanf wscanf 222 extern TCHAR *_tsetlocale(int category, const TCHAR *locale) ; 223 extern int _sntprintf(TCHAR *str, size_t size, const TCHAR *format, ...); 224 #define _stprintf _sntprintf 225 extern int _ftprintf(FILE *stream, const wchar_t *format, ...); 226 #define _stscanf swscanf 227 #define _tcscat wcscat 228 #define _tcschr wcschr 229 #define _tcscmp wcscmp 230 #define _tcscoll wcscoll 231 #define _tcscpy wcscpy 232 #define _tcscspn wcscspn 233 #define _tcserror _wcserror 234 #define _tcsftime wcsftime 235 #define _tcsclen wcslen 236 #define _tcslen wcslen 237 #define _tcsncat wcsncat 238 #define _tcsnccat wcsncat 239 #define _tcsnccmp wcsncmp 240 #define _tcsncmp wcsncmp 241 #define _tcsnccpy wcsncpy 242 #define _tcsncpy wcsncpy 243 #define _tcspbrk wcspbrk 244 #define _tcsrchr wcsrchr 245 #define _tcsspn wcsspn 246 #define _tcsstr wcsstr 247 #define _tcstod wcstod 248 #define _tcstok wcstok 249 #define _tcstol wcstol 250 #define _tcstoul wcstoul 251 #define _tcsxfrm wcsxfrm 252 #define _tsystem _wsystem 253 #define _ttmpnam _wtmpnam 254 #define _totlower towlower 255 #define _totupper towupper 256 #define _ungettc ungetwc 257 #define _vftprintf vfwprintf 258 #define _vtprintf vwprintf 259 #define _vstprintf vswprintf 260 extern size_t _treadlink(TCHAR* exe, TCHAR* fullpath, size_t size); 261 262 extern long _tpathconf(const TCHAR *path, int name); 263 264 #else /* ASCII */ 265 266 #define TEXT(x) x 267 typedef char TCHAR; 268 typedef unsigned char _TUCHAR; 269 #define _tpathconf pathconf 270 #define _taccess _access 271 #define _treadlink readlink 272 #define _tstoi64 _atoi64 273 #define _ttoi64 _atoi64 274 #define cgetts _cgets 275 #define _tchdir chdir 276 #define _tchmod chmod 277 #define _tcprintf _cprintf 278 #define _cputts _cputs 279 #define _tcreat _creat 280 #define _tcscanf _cscanf 281 #define _tctime64 _ctime64 282 #define _tmkfifo mkfifo 283 #define _texecl execl 284 #define _texecle execle 285 #define _texeclp execlp 286 #define _texeclpe execlpe 287 #define _texecv execv 288 #define _texecve execve 289 #define _texecvp execvp 290 #define _texecvpe execvpe 291 #define _tfdopen _fdopen 292 #define _fgettchar _fgetchar 293 #define _tfindfirst _findfirst 294 #define _tfindnext64 _findnext64 295 #define _tfindnext _findnext 296 #define _tfindnexti64 _findnexti64 297 #define _fputtchar _fputchar 298 #define _tfsopen _fsopen 299 #define _tfullpath _fullpath 300 #define _gettch _getch 301 #define _gettche _getche 302 #define _tgetcwd getcwd 303 #define _tgetdcwd getdcwd 304 #define _ltot _ltoa 305 #define _tmakepath _makepath 306 #define _tmkdir _mkdir 307 #define _tmktemp _mktemp 308 #define _topen open 309 #define _puttch _putch 310 /*#define _tputenv putenv*/ 311 #define _tsetenv setenv 312 #define _tunsetenv unsetenv 313 #define _trmdir _rmdir 314 #define _sctprintf _scprintf 315 #define _tsearchenv _searchenv 316 #define _sntprintf _snprintf 317 #define _sntscanf _snscanf 318 #define _tsopen _sopen 319 #define _tspawnl _spawnl 320 #define _tspawnle _spawnle 321 #define _tspawnlp _spawnlp 322 #define _tspawnlpe _spawnlpe 323 #define _tspawnv _spawnv 324 #define _tspawnve _spawnve 325 #define _tspawnvp _spawnvp 326 #define _tspawnvpe _spawnvpe 327 #define _tsplitpath _splitpath 328 #define _tstat64 _stat64 329 #define _tstat stat 330 #define _tstati64 _stati64 331 #define _tstrdate _strdate 332 #define _tcsdec _strdec 333 #define _tcsdup strdup /* replaced _strdup by strdup */ 334 #define _tcsicmp strcasecmp 335 #define _tcsicoll _stricoll 336 #define _tcsinc _strinc 337 /* Intentionally do not allow use of _trealpath because it does not specify a buffer length. 338 * #define _trealpath realpath 339 * Define our own _trealpathN below. */ 340 #define _trealpathN(fileName, resolvedName, resolvedNameSize) realpath(fileName, resolvedName) 341 #define _tcslwr _strlwr 342 #define _tcsnbcnt _strncnt 343 #define _tcsnccnt _strncnt 344 #define _tcsnccnt _strncnt 345 #define _tcsnccoll _strncoll 346 #define _tcsnextc _strnextc 347 #define _tcsncicmp _strnicmp 348 #define _tcsnicmp _strnicmp 349 #define _tcsncicoll _strnicoll 350 #define _tcsnicoll _strnicoll 351 #define _tcsninc _strninc 352 #define _tcsncset _strnset 353 #define _tcsnset _strnset 354 #define _tcsrev _strrev 355 #define _tcsset _strset 356 #define _tcsspnp _strspnp 357 #define _tstrtime strftime 358 #define _tcstoi64 _strtoi64 359 #define _tcstoui64 _strtoui64 360 #define _tcsupr _strupr 361 #define _ttempnam _tempnam 362 #define _ui64tot _ui64toa 363 #define _ultot _ultoa 364 #define _ungettch _ungetch 365 #define _tunlink unlink 366 #define _tutime64 _utime64 367 #define _tutime _utime 368 #define _vsctprintf _vscprintf 369 #define _vsntprintf vsnprintf 370 #define _tasctime asctime 371 #define _tstof atof 372 #define _tstoi atoi 373 #define _ttoi atoi 374 #define _tstol atol 375 #define _ttol atol 376 #define _tctime ctime 377 #define _fgettc fgetc 378 #define _fgetts fgets 379 #define _tfopen fopen 380 #define _tpopen popen 381 #define _ftprintf fprintf 382 #define _fputtc fputc 383 #define _fputts fputs 384 #define _tfreopen freopen 385 #define _ftscanf fscanf 386 #define _gettc getc 387 #define _gettchar getchar 388 #define _tgetenv getenv 389 #define _getts gets 390 #define _istalnum isalnum 391 #define _istalpha isalpha 392 #define _istascii isascii 393 #define _istcntrl iscntrl 394 #define _istdigit isdigit 395 #define _istgraph isgraph 396 #define _istlead islead 397 #define _istleadbyte isleadbyte 398 #define _istlegal islegal 399 #define _istlower islower 400 #define _istprint isprint 401 #define _istpunct ispunct 402 #define _istspace isspace 403 #define _istupper isupper 404 #define _istxdigit isxdigit 405 #define _tmain main 406 #define _tperror perror 407 #define _tprintf printf 408 #define _puttc putc 409 #define _puttchar putchar 410 #define _putts puts 411 #define _tremove remove 412 #define _trename rename 413 #define _tscanf scanf 414 #define _tsetlocale setlocale 415 #define _sntprintf snprintf 416 #define _stscanf sscanf 417 #define _tcscat strcat 418 #define _tcschr strchr 419 #define _tcscmp strcmp 420 #define _tcscoll strcoll 421 #define _tcscpy strcpy 422 #define _tcscspn strcspn 423 #define _tcserror strerror 424 #define _tcsftime strftime 425 #define _tcsclen strlen 426 #define _tcslen strlen 427 #define _tcsncat strncat 428 #define _tcsnccat strncat 429 #define _tcsnccmp strncmp 430 #define _tcsncmp strncmp 431 #define _tcsnccpy strncpy 432 #define _tcsncpy strncpy 433 #define _tcspbrk strpbrk 434 #define _tcsrchr strrchr 435 #define _tcsspn strspn 436 #define _tcsstr strstr 437 #define _tcstod strtod 438 #define _tcstok strtok 439 #define _tcstol strtol 440 #define _tcstoul strtoul 441 #define _tcsxfrm strxfrm 442 #define _tsystem system 443 #define _ttmpnam tmpnam 444 #define _totlower tolower 445 #define _totupper toupper 446 #define _ungettc ungetc 447 #define _vftprintf vfprintf 448 #define _vtprintf vprintf 449 #define _vstprintf vsprintf 450 #define _topenlog openlog 451 #define _tsyslog syslog 452 #endif 453 #else /* WIN32 */ 454 #include <tchar.h> 455 #include <sys/types.h> 456 #include <sys/stat.h> 457 extern int multiByteToWideChar(const char *multiByteChars, int encoding, TCHAR **outputBufferW, int localizeErrorMessage); 458 #endif 459 /* Define boolean constants. */ 460 #ifndef TRUE 461 #define TRUE -1 462 #endif 463 464 #ifndef FALSE 465 #define FALSE 0 466 #endif 467 468 #define STATUS_UNCHANGED 0 469 #define STATUS_ENABLED 1 470 #define STATUS_DISABLED 2 471 #define STATUS_UNKNOWN 3 472 473 #ifndef WIN32 474 #ifdef HPUX 475 #define MB_UTF8 "utf8" 476 #else 477 #define MB_UTF8 "UTF-8" 478 #endif 479 #define __UTF8 MB_UTF8 480 #else 481 #define __UTF8 CP_UTF8 482 #endif 483 484 #define TCHAR_TAB TEXT('\t') 485 486 #ifdef WIN32 487 #define FILE_SEPARATOR TEXT("\\") 488 #define FILE_SEPARATOR_C TEXT('\\') 489 #else 490 #define FILE_SEPARATOR TEXT("/") 491 #define FILE_SEPARATOR_C TEXT('/') 492 #endif 493 494 #define ENCODING_BUFFER_SIZE 32 /* ex: x-windows-iso2022jp */ 495 496 void wrapperSecureZero(void* str, size_t size); 497 498 void wrapperSecureFree(void* str, size_t size); 499 500 void wrapperSecureFreeStrW(TCHAR* str); 501 502 void wrapperSecureFreeStrMB(char* str); 503 504 extern TCHAR* toLower(const TCHAR* value); 505 506 extern TCHAR* toUpper(const TCHAR* value); 507 508 extern void clearNonAlphanumeric(TCHAR* bufferIn, TCHAR* bufferOut); 509 510 extern int compareEncodings(TCHAR* encoding1, TCHAR* encoding2, int ignoreCase, int ignorePunctuation); 511 512 extern int compareEncodingsSysMode(TCHAR* encoding1, TCHAR* encoding2); 513 514 #ifndef WIN32 515 /** 516 * Get the encoding of the current locale. 517 * 518 * @param buffer output buffer 519 * 520 * @return the buffer or NULL if the encoding could not be retrieved. 521 */ 522 TCHAR* getCurrentLocaleEncoding(TCHAR* buffer); 523 #endif 524 525 #ifndef WIN32 526 #define ICONV_ENCODING_SUPPORTED 0 527 #define ICONV_ENCODING_KNOWN_ISSUE 1 528 #define ICONV_ENCODING_NOT_SUPPORTED 2 529 530 /** 531 * Check if the given encoding is supported by the iconv library. 532 * 533 * @return ICONV_ENCODING_SUPPORTED if the encoding is supported, 534 * ICONV_ENCODING_KNOWN_ISSUE if the encoding exist on iconv but fails to convert some characters. 535 * ICONV_ENCODING_NOT_SUPPORTED if the encoding is not supported. 536 */ 537 int getIconvEncodingMBSupport(const char* encodingMB); 538 /** 539 * Check if the given encoding is supported by the iconv library. 540 * 541 * @return ICONV_ENCODING_SUPPORTED if the encoding is supported, 542 * ICONV_ENCODING_KNOWN_ISSUE if the encoding exist on iconv but fails to convert some characters. 543 * ICONV_ENCODING_NOT_SUPPORTED if the encoding is not supported. 544 */ 545 int getIconvEncodingSupport(const TCHAR* encoding); 546 #endif 547 548 #ifdef _LIBICONV_VERSION 549 #ifdef AIX /* the AIX version of iconv.h doesn't have _LIBICONV_VERSION (need to check the other platforms) */ 550 #define USE_LIBICONV_GNU 551 #endif 552 #endif 553 554 #ifdef FREEBSD 555 /** 556 * Get the name of the iconv library that was loaded. 557 * 558 * @return the name of the iconv library (wide chars). 559 */ 560 extern TCHAR* getIconvLibName(); 561 562 /** 563 * Tries to load libiconv and then fallback in FreeBSD. 564 * Unfortunately we can not do any pretty logging here as iconv is 565 * required for all of that to work. 566 * 567 * @return TRUE if there were any problems, FALSE otherwise. 568 */ 569 extern int loadIconvLibrary(); 570 #endif 571 572 /** 573 * Define a cross platform way to compare strings while ignoring case. 574 */ 575 #ifdef WIN32 576 #define strIgnoreCaseCmp _stricmp 577 #else 578 #define strIgnoreCaseCmp strcasecmp 579 #endif 580 #define strcmpIgnoreCase(str1, str2) _tcsicmp(str1, str2) 581 582 /** 583 * Function to get the system encoding name/number for the encoding 584 * of the conf file 585 * 586 * @para String holding the encoding from the conf file 587 * 588 * @return TRUE if not found, FALSE otherwise 589 * 590 */ 591 #ifdef WIN32 592 extern int getEncodingByName(char* encodingMB, int *encoding); 593 #else 594 extern int getEncodingByName(char* encodingMB, char** encoding); 595 #endif 596 597 #ifdef WIN32 598 /** 599 * Converts a Wide string into a specific multibyte encoded string. 600 * 601 * @prarm wideChars The Wide string to be converted. 602 * @param outputBufferMB Returns a newly malloced buffer containing the target MB chars. 603 * Will contain an error message if the function returns TRUE. 604 * If this is NULL then there was an out of memory problem. 605 * Caller must free this up. 606 * @param outputEncoding Output encoding to use. 607 * 608 * @return TRUE if there were any problems. False otherwise. 609 */ 610 extern int converterWideToMB(const TCHAR *wideChars, char **outputBufferMB, int outputEncoding); 611 612 /** 613 * Converts a native multibyte string into a specific multibyte encoded string. 614 * 615 * @param multiByteChars The original multi-byte chars. 616 * @param inputEncoding The multi-byte encoding. 617 * @param outputBufferMB Returns a newly malloced buffer containing the target MB chars. 618 * Will contain an error message if the function returns TRUE. 619 * If this is NULL then there was an out of memory problem. 620 * Caller must free this up. 621 * @param outputEncoding Output encoding to use. 622 * 623 * @return -1 if there were any problems. buffer size (>=0) if everything was Ok. 624 */ 625 extern int converterMBToMB(const char *multiByteChars, int inputEncoding, char **outputBufferMB, int outputEncoding); 626 #else 627 628 #ifdef HPUX 629 /** 630 * Turns on or off a fix used in converterMBToMB() 631 */ 632 void toggleIconvHpuxFix(int value); 633 #endif 634 635 /** 636 * Converts a native multibyte string into a specific multibyte encoded string. 637 * 638 * @param multiByteChars The original multi-byte chars. 639 * @param multiByteEncoding The multi-byte encoding. 640 * @param outputBufferMB Returns a newly malloced buffer containing the target MB chars. 641 * Will contain an error message if the function returns TRUE. 642 * If this is NULL then there was an out of memory problem. 643 * Caller must free this up. 644 * @param outputEncoding Output encoding to use. 645 * 646 * @return -1 if there were any problems. buffer size (>=0) if everything was Ok. 647 */ 648 extern int converterMBToMB(const char *multiByteChars, const char *multiByteEncoding, char **outputBufferMB, const char *outputEncoding); 649 650 /** 651 * Converts a Wide string into a specific multibyte encoded string. 652 * 653 * @prarm wideChars The Wide string to be converted. 654 * @param outputBufferMB Returns a newly malloced buffer containing the target MB chars. 655 * Will contain an error message if the function returns TRUE. 656 * If this is NULL then there was an out of memory problem. 657 * Caller must free this up. 658 * @param outputEncoding Output encoding to use. 659 * 660 * @return TRUE if there were any problems. False otherwise. 661 */ 662 extern int converterWideToMB(const TCHAR *wideChars, char **outputBufferMB, const char *outputEncoding); 663 #endif 664 665 /** 666 * Gets the error code for the last operation that failed. 667 */ 668 extern int wrapperGetLastError(); 669 670 /* 671 * Corrects a path in place by replacing all '/' characters with '\' 672 * on Windows platforms. Does nothing on NIX platforms. 673 * 674 * filename - Filename to be modified. Could be null. 675 */ 676 extern int wrapperCorrectWindowsPath(TCHAR *filename); 677 678 /* 679 * Corrects a path in place by replacing all '\' characters with '/' 680 * on NIX platforms. Does nothing on Windows platforms. 681 * 682 * filename - Filename to be modified. Could be null. 683 */ 684 extern int wrapperCorrectNixPath(TCHAR *filename); 685 #endif 686 687 688 /* Helper defines used to help trace where certain calls are being made. */ 689 /*#define DEBUG_MBSTOWCS*/ 690 #ifdef DEBUG_MBSTOWCS 691 #ifdef WIN32 692 #define mbstowcs(x,y,z) mbstowcs(x,y,z); wprintf(L"%S:%d:%S mbstowcs(%S, %S, %S) -> mbstowcs(%p, \"%S\", %d)\n", __FILE__, __LINE__, __FUNCTION__, #x, #y, #z, (void *)x, y, (int)z) 693 #else 694 #define mbstowcs(x,y,z) mbstowcs(x,y,z); wprintf(L"%s:%d:%s mbstowcs(%s, %s, %s) -> mbstowcs(%p, \"%s\", %d)\n", __FILE__, __LINE__, __FUNCTION__, #x, #y, #z, (void *)x, y, (int)z) 695 #endif 696 #endif 697 698 /*#define DEBUG_MALLOC*/ 699 #ifdef DEBUG_MALLOC 700 extern void *malloc2(size_t size, const char *file, int line, const char *func, const char *sizeVar); 701 #define malloc(x) malloc2(x, __FILE__, __LINE__, __FUNCTION__, #x) 702 #ifdef WIN32 703 #define free(x) wprintf(L"%S:%d:%S free(%S) -> free(%p)\n", __FILE__, __LINE__, __FUNCTION__, #x, (void *)x); free(x) 704 #else 705 #define free(x) wprintf(L"%s:%d:%s free(%s) -> free(%p)\n", __FILE__, __LINE__, __FUNCTION__, #x, (void *)x); free(x) 706 #endif 707 #endif 708 709