]> wimlib.net Git - wimlib/blob - include/wimlib_tchar.h
3ec85fc58007002ba70abb32a7f79a96a28fd912
[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 #  define WS "ls" /* Format a UTF-16LE string (same as above) */
19
20 /* For Windows builds, the following definitions replace the "tchar" functions
21  * with the "wide-character" functions. */
22 #  define tmemchr       wmemchr
23 #  define tmemcpy       wmemcpy
24 #  define tmempcpy      wmempcpy
25 #  define tstrcpy       wcscpy
26 #  define tprintf       wprintf
27 #  define tsprintf      swprintf
28 #  define tfprintf      fwprintf
29 #  define tvfprintf     vfwprintf
30 #  define istalpha      iswalpha
31 #  define istspace      iswspace
32 #  define tstrcmp       wcscmp
33 #  define tstrchr       wcschr
34 #  define tstrpbrk      wcspbrk
35 #  define tstrrchr      wcsrchr
36 #  define tstrlen       wcslen
37 #  define tmemcmp       wmemcmp
38 #  define tstrcasecmp   _wcsicmp
39 #  define tstrftime     wcsftime
40 #  define tputchar      putwchar
41 #  define tputc         putwc
42 #  define tputs         _putws
43 #  define tfputs        fputws
44 #  define tfopen        _wfopen
45 #  define topen         _wopen
46 #  define tstat         _wstati64
47 #  define tstrtol       wcstol
48 #  define tstrtod       wcstod
49 #  define tstrtoul      wcstoul
50 #  define tunlink       _wunlink
51 #  define tstrerror     _wcserror
52 #  define taccess       _waccess
53 #  define tstrdup       wcsdup
54 #  define ttempnam      _wtempnam
55 /* The following "tchar" functions do not have exact wide-character equivalents
56  * on Windows so require parameter rearrangement or redirection to a replacement
57  * function defined ourselves. */
58 #  define TSTRDUP       WCSDUP
59 #  define tmkdir(path, mode) _wmkdir(path)
60 #  define tstrerror_r   win32_strerror_r_replacement
61 #  define trename       win32_rename_replacement
62 #  define ttruncate     win32_truncate_replacement
63 #else /* __WIN32__ */
64 /* For non-Windows builds, the "tchar" type will be one byte and will specify a
65  * string in the locale-dependent multibyte encoding.  However, only UTF-8 is
66  * well supported in this library. */
67 typedef char tchar;
68 #  define TCHAR_IS_UTF16LE 0
69 #  define T(text) text /* In this case, strings of "tchar" are simply strings of
70                           char */
71 #  define TS "s"       /* Similarly, a string of "tchar" is printed just as a
72                           normal string. */
73 #  define TC "c"       /* Print a single character */
74 #  define WS "W"       /* UTF-16LE strings must be printed using a special
75                           extension implemented by wimlib itself.  Note that
76                           "ls" will not work here because a string of wide
77                           characters on non-Windows systems is typically not
78                           UTF-16LE. */
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 tmempcpy      mempcpy
84 #  define tstrcpy       strcpy
85 #  define tprintf       printf
86 #  define tsprintf      sprintf
87 #  define tfprintf      fprintf
88 #  define tvfprintf     vfprintf
89 #  define istalpha      isalpha
90 #  define istspace      isspace
91 #  define tstrcmp       strcmp
92 #  define tstrchr       strchr
93 #  define tstrpbrk      strpbrk
94 #  define tstrrchr      strrchr
95 #  define tstrlen       strlen
96 #  define tmemcmp       memcmp
97 #  define tstrcasecmp   strcasecmp
98 #  define tstrftime     strftime
99 #  define tputchar      putchar
100 #  define tputc         putc
101 #  define tputs         puts
102 #  define tfputs        fputs
103 #  define tfopen        fopen
104 #  define topen         open
105 #  define tstat         stat
106 #  define tunlink       unlink
107 #  define tstrerror     strerror
108 #  define tstrtol       strtol
109 #  define tstrtod       strtod
110 #  define tstrtoul      strtoul
111 #  define tmkdir        mkdir
112 #  define tstrdup       strdup
113 #  define ttempnam      tempnam
114 #  define TSTRDUP       STRDUP
115 #  define tstrerror_r   strerror_r
116 #  define trename       rename
117 #  define ttruncate     truncate
118 #  define taccess       access
119 #endif /* !__WIN32__ */
120
121 #endif /* _WIMLIB_TCHAR_H */