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