]> wimlib.net Git - wimlib/blob - include/wimlib_tchar.h
imagex-mount.1.in: Fix typo
[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 /* The following "tchar" functions do not have exact wide-character equivalents
55  * on Windows so require parameter rearrangement or redirection to a replacement
56  * function defined ourselves. */
57 #  define TSTRDUP       WCSDUP
58 #  define tmkdir(path, mode) _wmkdir(path)
59 #  define tstrerror_r   win32_strerror_r_replacement
60 #  define trename       win32_rename_replacement
61 #  define ttruncate     win32_truncate_replacement
62 #else /* __WIN32__ */
63 /* For non-Windows builds, the "tchar" type will be one byte and will specify a
64  * string in the locale-dependent multibyte encoding.  However, only UTF-8 is
65  * well supported in this library. */
66 typedef char tchar;
67 #  define TCHAR_IS_UTF16LE 0
68 #  define T(text) text /* In this case, strings of "tchar" are simply strings of
69                           char */
70 #  define TS "s"       /* Similarly, a string of "tchar" is printed just as a
71                           normal string. */
72 #  define TC "c"       /* Print a single character */
73 #  define WS "W"       /* UTF-16LE strings must be printed using a special
74                           extension implemented by wimlib itself.  Note that
75                           "ls" will not work here because a string of wide
76                           characters on non-Windows systems is typically not
77                           UTF-16LE. */
78 /* For non-Windows builds, replace the "tchar" functions with the regular old
79  * string functions. */
80 #  define tmemchr       memchr
81 #  define tmemcpy       memcpy
82 #  define tmempcpy      mempcpy
83 #  define tstrcpy       strcpy
84 #  define tprintf       printf
85 #  define tsprintf      sprintf
86 #  define tfprintf      fprintf
87 #  define tvfprintf     vfprintf
88 #  define istalpha      isalpha
89 #  define istspace      isspace
90 #  define tstrcmp       strcmp
91 #  define tstrchr       strchr
92 #  define tstrpbrk      strpbrk
93 #  define tstrrchr      strrchr
94 #  define tstrlen       strlen
95 #  define tmemcmp       memcmp
96 #  define tstrcasecmp   strcasecmp
97 #  define tstrftime     strftime
98 #  define tputchar      putchar
99 #  define tputc         putc
100 #  define tputs         puts
101 #  define tfputs        fputs
102 #  define tfopen        fopen
103 #  define topen         open
104 #  define tstat         stat
105 #  define tunlink       unlink
106 #  define tstrerror     strerror
107 #  define tstrtol       strtol
108 #  define tstrtod       strtod
109 #  define tstrtoul      strtoul
110 #  define tmkdir        mkdir
111 #  define tstrdup       strdup
112 #  define TSTRDUP       STRDUP
113 #  define tstrerror_r   strerror_r
114 #  define trename       rename
115 #  define ttruncate     truncate
116 #  define taccess       access
117 #endif /* !__WIN32__ */
118
119 #endif /* _WIMLIB_TCHAR_H */