]> wimlib.net Git - wimlib/blob - include/wimlib_tchar.h
Implement setting of Windows-specific XML information
[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 ttempnam      _wtempnam
60 #  define tgetenv       _wgetenv
61 /* The following "tchar" functions do not have exact wide-character equivalents
62  * on Windows so require parameter rearrangement or redirection to a replacement
63  * function defined ourselves. */
64 #  define TSTRDUP       WCSDUP
65 #  define tmkdir(path, mode) _wmkdir(path)
66 #  define tstrerror_r   win32_strerror_r_replacement
67 #  define trename       win32_rename_replacement
68 #  define tglob         win32_wglob
69 #else /* __WIN32__ */
70 /* For non-Windows builds, the "tchar" type will be one byte and will specify a
71  * string in the locale-dependent multibyte encoding.  However, only UTF-8 is
72  * well supported in this library. */
73 typedef char tchar;
74 #  define TCHAR_IS_UTF16LE 0
75 #  define T(text) text /* In this case, strings of "tchar" are simply strings of
76                           char */
77 #  define TS "s"       /* Similarly, a string of "tchar" is printed just as a
78                           normal string. */
79 #  define TC "c"       /* Print a single character */
80 /* For non-Windows builds, replace the "tchar" functions with the regular old
81  * string functions. */
82 #  define tmemchr       memchr
83 #  define tmemcpy       memcpy
84 #  define tmemmove      memmove
85 #  define tmempcpy      mempcpy
86 #  define tstrcat       strcat
87 #  define tstrcpy       strcpy
88 #  define tprintf       printf
89 #  define tsprintf      sprintf
90 #  define tfprintf      fprintf
91 #  define tvfprintf     vfprintf
92 #  define tscanf        sscanf
93 #  define istalpha(c)   isalpha((unsigned char)(c))
94 #  define istspace(c)   isspace((unsigned char)(c))
95 #  define totlower(c)   tolower((unsigned char)(c))
96 #  define tstrcmp       strcmp
97 #  define tstrncmp      strncmp
98 #  define tstrchr       strchr
99 #  define tstrpbrk      strpbrk
100 #  define tstrrchr      strrchr
101 #  define tstrlen       strlen
102 #  define tmemcmp       memcmp
103 #  define tstrcasecmp   strcasecmp
104 #  define tstrftime     strftime
105 #  define tputchar      putchar
106 #  define tputc         putc
107 #  define tputs         puts
108 #  define tfputs        fputs
109 #  define tfopen        fopen
110 #  define topen         open
111 #  define tstat         stat
112 #  define tunlink       unlink
113 #  define tstrerror     strerror
114 #  define tstrtol       strtol
115 #  define tstrtod       strtod
116 #  define tstrtoul      strtoul
117 #  define tstrtoull     strtoull
118 #  define tmkdir        mkdir
119 #  define tstrdup       strdup
120 #  define ttempnam      tempnam
121 #  define tgetenv       getenv
122 #  define TSTRDUP       STRDUP
123 #  define tstrerror_r   strerror_r
124 #  define trename       rename
125 #  define taccess       access
126 #  define tglob         glob
127 #endif /* !__WIN32__ */
128
129 #endif /* _WIMLIB_TCHAR_H */