]> wimlib.net Git - wimlib/blob - include/wimlib_tchar.h
wildcard.c: Don't use broken PathMatchSpec()
[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 tstrncmp      wcsncmp
34 #  define tstrchr       wcschr
35 #  define tstrpbrk      wcspbrk
36 #  define tstrrchr      wcsrchr
37 #  define tstrlen       wcslen
38 #  define tmemcmp       wmemcmp
39 #  define tstrcasecmp   _wcsicmp
40 #  define tstrftime     wcsftime
41 #  define tputchar      putwchar
42 #  define tputc         putwc
43 #  define tputs         _putws
44 #  define tfputs        fputws
45 #  define tfopen        _wfopen
46 #  define topen         _wopen
47 #  define tstat         _wstati64
48 #  define tstrtol       wcstol
49 #  define tstrtod       wcstod
50 #  define tstrtoul      wcstoul
51 #  define tunlink       _wunlink
52 #  define tstrerror     _wcserror
53 #  define taccess       _waccess
54 #  define tstrdup       wcsdup
55 #  define ttempnam      _wtempnam
56 #  define tgetenv       _wgetenv
57 #  define totlower(c)   towlower((wchar_t)(c))
58 /* The following "tchar" functions do not have exact wide-character equivalents
59  * on Windows so require parameter rearrangement or redirection to a replacement
60  * function defined ourselves. */
61 #  define TSTRDUP       WCSDUP
62 #  define tmkdir(path, mode) _wmkdir(path)
63 #  define tstrerror_r   win32_strerror_r_replacement
64 #  define trename       win32_rename_replacement
65 #  define ttruncate     win32_truncate_replacement
66 #  define tglob         win32_wglob
67 #else /* __WIN32__ */
68 /* For non-Windows builds, the "tchar" type will be one byte and will specify a
69  * string in the locale-dependent multibyte encoding.  However, only UTF-8 is
70  * well supported in this library. */
71 typedef char tchar;
72 #  define TCHAR_IS_UTF16LE 0
73 #  define T(text) text /* In this case, strings of "tchar" are simply strings of
74                           char */
75 #  define TS "s"       /* Similarly, a string of "tchar" is printed just as a
76                           normal string. */
77 #  define TC "c"       /* Print a single character */
78 #  define WS "W"       /* UTF-16LE strings must be printed using a special
79                           extension implemented by wimlib itself.  Note that
80                           "ls" will not work here because a string of wide
81                           characters on non-Windows systems is typically not
82                           UTF-16LE. */
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 tmempcpy      mempcpy
88 #  define tstrcpy       strcpy
89 #  define tprintf       printf
90 #  define tsprintf      sprintf
91 #  define tfprintf      fprintf
92 #  define tvfprintf     vfprintf
93 #  define istalpha      isalpha
94 #  define istspace      isspace
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 tmkdir        mkdir
117 #  define tstrdup       strdup
118 #  define ttempnam      tempnam
119 #  define tgetenv       getenv
120 #  define totlower(c)   tolower((unsigned char)(c))
121 #  define TSTRDUP       STRDUP
122 #  define tstrerror_r   strerror_r
123 #  define trename       rename
124 #  define ttruncate     truncate
125 #  define taccess       access
126 #  define tglob         glob
127 #endif /* !__WIN32__ */
128
129 #endif /* _WIMLIB_TCHAR_H */