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