]> wimlib.net Git - wimlib/blob - include/wimlib_tchar.h
5a2038f07508de2904492d1a19f8efc3febf053b
[wimlib] / include / wimlib_tchar.h
1 #ifndef _WIMLIB_TCHAR_H
2 #define _WIMLIB_TCHAR_H
3
4 /* Functions to act on "tchar" strings, which have a platform-dependent encoding
5  * and character size. */
6
7 #ifdef __WIN32__
8 #include <wchar.h>
9 /* For Windows builds, the "tchar" type will be 2 bytes and will be equivalent
10  * to "wchar_t" and "utf16lechar".  All indicate one code unit of a UTF16-LE
11  * string. */
12 typedef wchar_t tchar;
13 #  define TCHAR_IS_UTF16LE 1
14 #  define _T(text) L##text
15 #  define T(text) _T(text) /* Make a string literal into a wide string */
16 #  define TS "ls" /* Format a string of "tchar" */
17 #  define TC "lc" /* Format a "tchar" */
18
19 /* For Windows builds, the following definitions replace the "tchar" functions
20  * with the "wide-character" functions. */
21 #  define tmemchr       wmemchr
22 #  define tmemcpy       wmemcpy
23 #  define tmemmove      wmemmove
24 #  define tmempcpy      wmempcpy
25 #  define tstrcat       wcscat
26 #  define tstrcpy       wcscpy
27 #  define tprintf       wprintf
28 #  define tsprintf      swprintf
29 #  define tfprintf      fwprintf
30 #  define tvfprintf     vfwprintf
31 #  define tscanf        swscanf
32 #  define istalpha(c)   iswalpha((wchar_t)(c))
33 #  define istspace(c)   iswspace((wchar_t)(c))
34 #  define totlower(c)   towlower((wchar_t)(c))
35 #  define tstrcmp       wcscmp
36 #  define tstrncmp      wcsncmp
37 #  define tstrchr       wcschr
38 #  define tstrpbrk      wcspbrk
39 #  define tstrrchr      wcsrchr
40 #  define tstrlen       wcslen
41 #  define tmemcmp       wmemcmp
42 #  define tstrcasecmp   _wcsicmp
43 #  define tstrftime     wcsftime
44 #  define tputchar      putwchar
45 #  define tputc         putwc
46 #  define tputs         _putws
47 #  define tfputs        fputws
48 #  define tfopen        _wfopen
49 #  define topen         _wopen
50 #  define tstat         _wstati64
51 #  define tstrtol       wcstol
52 #  define tstrtod       wcstod
53 #  define tstrtoul      wcstoul
54 #  define tstrtoull     wcstoull
55 #  define tunlink       _wunlink
56 #  define tstrerror     _wcserror
57 #  define taccess       _waccess
58 #  define tstrdup       wcsdup
59 #  define tgetenv       _wgetenv
60 /* The following "tchar" functions do not have exact wide-character equivalents
61  * on Windows so require parameter rearrangement or redirection to a replacement
62  * function defined ourselves. */
63 #  define TSTRDUP       WCSDUP
64 #  define tmkdir(path, mode) _wmkdir(path)
65 #  define tstrerror_r   win32_strerror_r_replacement
66 #  define trename       win32_rename_replacement
67 #  define tglob         win32_wglob
68 #else /* __WIN32__ */
69 /* For non-Windows builds, the "tchar" type will be one byte and will specify a
70  * string in the locale-dependent multibyte encoding.  However, only UTF-8 is
71  * well supported in this library. */
72 typedef char tchar;
73 #  define TCHAR_IS_UTF16LE 0
74 #  define T(text) text /* In this case, strings of "tchar" are simply strings of
75                           char */
76 #  define TS "s"       /* Similarly, a string of "tchar" is printed just as a
77                           normal string. */
78 #  define TC "c"       /* Print a single character */
79 /* For non-Windows builds, replace the "tchar" functions with the regular old
80  * string functions. */
81 #  define tmemchr       memchr
82 #  define tmemcpy       memcpy
83 #  define tmemmove      memmove
84 #  define tmempcpy      mempcpy
85 #  define tstrcat       strcat
86 #  define tstrcpy       strcpy
87 #  define tprintf       printf
88 #  define tsprintf      sprintf
89 #  define tfprintf      fprintf
90 #  define tvfprintf     vfprintf
91 #  define tscanf        sscanf
92 #  define istalpha(c)   isalpha((unsigned char)(c))
93 #  define istspace(c)   isspace((unsigned char)(c))
94 #  define totlower(c)   tolower((unsigned char)(c))
95 #  define tstrcmp       strcmp
96 #  define tstrncmp      strncmp
97 #  define tstrchr       strchr
98 #  define tstrpbrk      strpbrk
99 #  define tstrrchr      strrchr
100 #  define tstrlen       strlen
101 #  define tmemcmp       memcmp
102 #  define tstrcasecmp   strcasecmp
103 #  define tstrftime     strftime
104 #  define tputchar      putchar
105 #  define tputc         putc
106 #  define tputs         puts
107 #  define tfputs        fputs
108 #  define tfopen        fopen
109 #  define topen         open
110 #  define tstat         stat
111 #  define tunlink       unlink
112 #  define tstrerror     strerror
113 #  define tstrtol       strtol
114 #  define tstrtod       strtod
115 #  define tstrtoul      strtoul
116 #  define tstrtoull     strtoull
117 #  define tmkdir        mkdir
118 #  define tstrdup       strdup
119 #  define tgetenv       getenv
120 #  define TSTRDUP       STRDUP
121 #  define tstrerror_r   strerror_r
122 #  define trename       rename
123 #  define taccess       access
124 #  define tglob         glob
125 #endif /* !__WIN32__ */
126
127 #endif /* _WIMLIB_TCHAR_H */