| 1 |
/* |
| 2 |
* tchar.h |
| 3 |
* |
| 4 |
* This file is a part of NSIS. |
| 5 |
* |
| 6 |
* Copyright (C) 1999-2026 Nullsoft and Contributors |
| 7 |
* |
| 8 |
* This software is provided 'as-is', without any express or implied |
| 9 |
* warranty. |
| 10 |
* |
| 11 |
* For Unicode support by Jim Park -- 08/30/2007 |
| 12 |
*/ |
| 13 |
|
| 14 |
// Jim Park: Only those we use are listed here. |
| 15 |
|
| 16 |
#pragma once |
| 17 |
#ifdef _UNICODE |
| 18 |
|
| 19 |
#include <wchar.h> |
| 20 |
|
| 21 |
#ifndef _T |
| 22 |
#define __T(x) L ## x |
| 23 |
#define _T(x) __T(x) |
| 24 |
#define _TEXT(x) __T(x) |
| 25 |
#endif |
| 26 |
|
| 27 |
#if !defined(_WIN32) && defined(EXEHEAD) |
| 28 |
typedef unsigned short TCHAR, _TUCHAR; |
| 29 |
#else |
| 30 |
// MinGW typedefs TCHAR and _TCHAR inside #ifndef _TCHAR_DEFINED |
| 31 |
// MSVC typedefs TCHAR inside #ifndef _TCHAR_DEFINED |
| 32 |
// and _TCHAR and _T*CHAR inside #ifndef __TCHAR_DEFINED. |
| 33 |
// We don't want to break MSVCs _TSCHAR and _TXCHAR so we don't protect our typedef... |
| 34 |
#if defined(_WIN32) && ((_MSC_VER>1 && (_MSC_VER<1400 || !defined(_NATIVE_WCHAR_T_DEFINED))) || !defined(_WCHAR_T_DEFINED)) |
| 35 |
// VC6 knows about __wchar_t but does not support it. /Zc:wchar_t is on by default starting with VC8. |
| 36 |
// VC7.1 supports __wchar_t but using it causes problems with conversions from WCHAR (unsigned short)? |
| 37 |
typedef unsigned short TCHAR, _TUCHAR; |
| 38 |
#else |
| 39 |
typedef wchar_t TCHAR, _TUCHAR; |
| 40 |
#endif |
| 41 |
#endif |
| 42 |
|
| 43 |
|
| 44 |
// program |
| 45 |
#define _tmain wmain |
| 46 |
#define _tWinMain wWinMain |
| 47 |
#define _tenviron _wenviron |
| 48 |
#define __targv __wargv |
| 49 |
|
| 50 |
// printfs |
| 51 |
#define _ftprintf fwprintf |
| 52 |
#define _sntprintf _snwprintf |
| 53 |
#if (defined(_MSC_VER) && (_MSC_VER<=1310||_MSC_FULL_VER<=140040310)) || defined(__MINGW32__) |
| 54 |
# define _stprintf swprintf |
| 55 |
#else |
| 56 |
# define _stprintf _swprintf |
| 57 |
#endif |
| 58 |
#define _tprintf wprintf |
| 59 |
#define _vftprintf vfwprintf |
| 60 |
#define _vsntprintf _vsnwprintf |
| 61 |
#if defined(_MSC_VER) && (_MSC_VER<=1310||_MSC_FULL_VER<=140040310) |
| 62 |
# define _vstprintf vswprintf |
| 63 |
#else |
| 64 |
# define _vstprintf _vswprintf |
| 65 |
#endif |
| 66 |
|
| 67 |
// scanfs |
| 68 |
#define _tscanf wscanf |
| 69 |
#define _stscanf swscanf |
| 70 |
|
| 71 |
// string manipulations |
| 72 |
#define _tcscat wcscat |
| 73 |
#define _tcschr wcschr |
| 74 |
#define _tcsclen wcslen |
| 75 |
#define _tcscpy wcscpy |
| 76 |
#define _tcsdup _wcsdup |
| 77 |
#define _tcslen wcslen |
| 78 |
#define _tcsrchr(s,c) ( wcsrchr((wchar_t*)(s), (c)) ) // bug #1085: If <cwchar> is included the compiler has problems picking the correct overloaded function |
| 79 |
#define _tcsstr wcsstr |
| 80 |
#define _tcstok wcstok |
| 81 |
|
| 82 |
// string comparisons |
| 83 |
#define _tcscmp wcscmp |
| 84 |
#define _tcsicmp _wcsicmp |
| 85 |
#define _tcsncicmp _wcsnicmp |
| 86 |
#define _tcsncmp wcsncmp |
| 87 |
#define _tcsnicmp _wcsnicmp |
| 88 |
|
| 89 |
// upper / lower |
| 90 |
#define _tcslwr _wcslwr |
| 91 |
#define _tcsupr _wcsupr |
| 92 |
#define _totlower towlower |
| 93 |
#define _totupper towupper |
| 94 |
|
| 95 |
// conversions to numbers |
| 96 |
#define _tcstoi64 _wcstoi64 |
| 97 |
#define _tcstol wcstol |
| 98 |
#define _tcstoul wcstoul |
| 99 |
#if !defined(_WIN32) || !defined(_MSC_VER) || (defined(_MSC_VER) && ((_MSC_VER<=1200) || defined(_DLL))) // _wtof does not exist in older versions of MSVCRT.dll |
| 100 |
# define _tstof my_wtof |
| 101 |
#else |
| 102 |
# define _tstof _wtof |
| 103 |
#endif |
| 104 |
#define _tstoi _wtoi |
| 105 |
#define _tstoi64 _wtoi64 |
| 106 |
#define _ttoi _wtoi |
| 107 |
#define _ttoi64 _wtoi64 |
| 108 |
#define _ttol _wtol |
| 109 |
|
| 110 |
// conversion from numbers to strings |
| 111 |
//Only VC has this? #define _itot _itow |
| 112 |
#define _ltot _ltow |
| 113 |
#define _i64tot _i64tow |
| 114 |
#define _ui64tot _ui64tow |
| 115 |
|
| 116 |
// file manipulations |
| 117 |
#define _tfopen _wfopen |
| 118 |
#define _topen _wopen |
| 119 |
#define _tremove _wremove |
| 120 |
#define _tunlink _wunlink |
| 121 |
#define _tstat _wstat |
| 122 |
|
| 123 |
// reading and writing to i/o |
| 124 |
#define _fgettc fgetwc |
| 125 |
#define _fgetts fgetws |
| 126 |
#define _fputts fputws |
| 127 |
#define _gettchar getwchar |
| 128 |
|
| 129 |
// directory |
| 130 |
#define _tchdir _wchdir |
| 131 |
|
| 132 |
// environment |
| 133 |
#define _tgetenv _wgetenv |
| 134 |
#define _tsystem _wsystem |
| 135 |
|
| 136 |
// time |
| 137 |
#define _tcsftime wcsftime |
| 138 |
|
| 139 |
#else // ANSI |
| 140 |
|
| 141 |
#ifndef _T |
| 142 |
#define _T(x) x |
| 143 |
#define _TEXT(x) x |
| 144 |
#endif |
| 145 |
|
| 146 |
typedef char TCHAR; |
| 147 |
typedef unsigned char _TUCHAR; |
| 148 |
|
| 149 |
|
| 150 |
// program |
| 151 |
#define _tmain main |
| 152 |
#define _tWinMain WinMain |
| 153 |
#define _tenviron environ |
| 154 |
#define __targv __argv |
| 155 |
|
| 156 |
// printfs |
| 157 |
#define _ftprintf fprintf |
| 158 |
#define _sntprintf _snprintf |
| 159 |
#define _stprintf sprintf |
| 160 |
#define _tprintf printf |
| 161 |
#define _vftprintf vfprintf |
| 162 |
#define _vsntprintf _vsnprintf |
| 163 |
#define _vstprintf vsprintf |
| 164 |
|
| 165 |
// scanfs |
| 166 |
#define _tscanf scanf |
| 167 |
#define _stscanf sscanf |
| 168 |
|
| 169 |
// string manipulations |
| 170 |
#define _tcscat strcat |
| 171 |
#define _tcschr strchr |
| 172 |
#define _tcsclen strlen |
| 173 |
#define _tcscnlen strnlen |
| 174 |
#define _tcscpy strcpy |
| 175 |
#define _tcsdup _strdup |
| 176 |
#define _tcslen strlen |
| 177 |
#define _tcsrchr strrchr |
| 178 |
#define _tcsstr strstr |
| 179 |
#define _tcstok strtok |
| 180 |
|
| 181 |
// string comparisons |
| 182 |
#define _tcscmp strcmp |
| 183 |
#define _tcsncmp strncmp |
| 184 |
#define _tcsncicmp _strnicmp |
| 185 |
#ifdef _WIN32 |
| 186 |
#define _tcsicmp _stricmp |
| 187 |
#define _tcsnicmp _strnicmp |
| 188 |
#else |
| 189 |
#define _tcsicmp strcasecmp |
| 190 |
#define _tcsnicmp strncasecmp |
| 191 |
#endif |
| 192 |
|
| 193 |
// upper / lower |
| 194 |
#define _tcslwr _strlwr |
| 195 |
#define _tcsupr _strupr |
| 196 |
|
| 197 |
#define _totupper toupper |
| 198 |
#define _totlower tolower |
| 199 |
|
| 200 |
// conversions to numbers |
| 201 |
#define _tcstol strtol |
| 202 |
#define _tcstoul strtoul |
| 203 |
#define _tstof atof |
| 204 |
#define _tstoi atoi |
| 205 |
#define _tstoi64 _atoi64 |
| 206 |
#define _tstoi64 _atoi64 |
| 207 |
#define _ttoi atoi |
| 208 |
#define _ttoi64 _atoi64 |
| 209 |
#define _ttol atol |
| 210 |
|
| 211 |
// conversion from numbers to strings |
| 212 |
#define _i64tot _i64toa |
| 213 |
#define _itot _itoa |
| 214 |
#define _ltot _ltoa |
| 215 |
#define _ui64tot _ui64toa |
| 216 |
|
| 217 |
// file manipulations |
| 218 |
#define _tfopen fopen |
| 219 |
#define _topen _open |
| 220 |
#define _tremove remove |
| 221 |
#define _tunlink _unlink |
| 222 |
#define _tstat stat // _stat on Windows? |
| 223 |
|
| 224 |
// reading and writing to i/o |
| 225 |
#define _fgettc fgetc |
| 226 |
#define _fgetts fgets |
| 227 |
#define _fputts fputs |
| 228 |
#define _gettchar getchar |
| 229 |
|
| 230 |
// directory |
| 231 |
#define _tchdir _chdir |
| 232 |
|
| 233 |
// environment |
| 234 |
#define _tgetenv getenv |
| 235 |
#define _tsystem system |
| 236 |
|
| 237 |
// time |
| 238 |
#define _tcsftime strftime |
| 239 |
|
| 240 |
#endif |
| 241 |
|
| 242 |
// is functions (the same in Unicode / ANSI on MinGW? MSVC does not agree!) |
| 243 |
#ifndef _istascii |
| 244 |
#if defined(_MSC_VER) && defined(_UNICODE) |
| 245 |
#define _istascii iswascii |
| 246 |
#else |
| 247 |
#define _istascii __isascii |
| 248 |
#endif |
| 249 |
#endif |