]> wimlib.net Git - wimlib/blob - include/wimlib_tchar.h
mount_image.c: add fallback definitions of RENAME_* constants
[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 /*
10  * For Windows builds, the "tchar" type will be 2 bytes and will be equivalent
11  * to "wchar_t" and "utf16lechar".  All indicate one coding unit of a string
12  * encoded in UTF-16LE with the additional possibility of unpaired surrogates.
13  */
14 typedef wchar_t tchar;
15 #  define TCHAR_IS_UTF16LE 1
16 #  define _T(text) L##text
17 #  define T(text) _T(text) /* Make a string literal into a wide string */
18 #  define TS "ls" /* Format a string of "tchar" */
19 #  define TC "lc" /* Format a "tchar" */
20
21 /* For Windows builds, the following definitions replace the "tchar" functions
22  * with the "wide-character" functions. */
23 #  define tmemchr       wmemchr
24 #  define tmemcpy       wmemcpy
25 #  define tmemmove      wmemmove
26 #  define tmempcpy      wmempcpy
27 #  define tstrcat       wcscat
28 #  define tstrcpy       wcscpy
29 #  define tprintf       wprintf
30 #  define tsprintf      swprintf
31 #  define tfprintf      fwprintf
32 #  define tvfprintf     vfwprintf
33 #  define tscanf        swscanf
34 #  define istalpha(c)   iswalpha((wchar_t)(c))
35 #  define istspace(c)   iswspace((wchar_t)(c))
36 #  define totlower(c)   towlower((wchar_t)(c))
37 #  define tstrcmp       wcscmp
38 #  define tstrncmp      wcsncmp
39 #  define tstrchr       wcschr
40 #  define tstrpbrk      wcspbrk
41 #  define tstrrchr      wcsrchr
42 #  define tstrstr       wcsstr
43 #  define tstrlen       wcslen
44 #  define tmemcmp       wmemcmp
45 #  define tstrcasecmp   _wcsicmp
46 #  define tstrftime     wcsftime
47 #  define tputchar      putwchar
48 #  define tputc         putwc
49 #  define tputs         _putws
50 #  define tfputs        fputws
51 #  define tfopen        _wfopen
52 #  define topen         _wopen
53 #  define tstat         _wstati64
54 #  define tstrtol       wcstol
55 #  define tstrtod       wcstod
56 #  define tstrtoul      wcstoul
57 #  define tstrtoull     wcstoull
58 #  define tunlink       _wunlink
59 #  define tstrerror     _wcserror
60 #  define taccess       _waccess
61 #  define tstrdup       wcsdup
62 #  define tgetenv       _wgetenv
63 /* The following "tchar" functions do not have exact wide-character equivalents
64  * on Windows so require parameter rearrangement or redirection to a replacement
65  * function defined ourselves. */
66 #  define TSTRDUP       WCSDUP
67 #  define tmkdir(path, mode) _wmkdir(path)
68 #  define tstrerror_r(errnum, buf, bufsize) \
69                         _wcserror_s((buf), (bufsize), (errnum))
70 #  define trename       win32_rename_replacement
71 #  define tglob         win32_wglob
72 #else /* _WIN32 */
73 /*
74  * For non-Windows builds, the "tchar" type will be one byte and will specify a
75  * string encoded in UTF-8 with the additional possibility of surrogate
76  * codepoints.
77  */
78 typedef char tchar;
79 #  define TCHAR_IS_UTF16LE 0
80 #  define T(text) text /* In this case, strings of "tchar" are simply strings of
81                           char */
82 #  define TS "s"       /* Similarly, a string of "tchar" is printed just as a
83                           normal string. */
84 #  define TC "c"       /* Print a single character */
85 /* For non-Windows builds, replace the "tchar" functions with the regular old
86  * string functions. */
87 #  define tmemchr       memchr
88 #  define tmemcpy       memcpy
89 #  define tmemmove      memmove
90 #  define tmempcpy      mempcpy
91 #  define tstrcat       strcat
92 #  define tstrcpy       strcpy
93 #  define tprintf       printf
94 #  define tsprintf      sprintf
95 #  define tfprintf      fprintf
96 #  define tvfprintf     vfprintf
97 #  define tscanf        sscanf
98 #  define istalpha(c)   isalpha((unsigned char)(c))
99 #  define istspace(c)   isspace((unsigned char)(c))
100 #  define totlower(c)   tolower((unsigned char)(c))
101 #  define tstrcmp       strcmp
102 #  define tstrncmp      strncmp
103 #  define tstrchr       strchr
104 #  define tstrpbrk      strpbrk
105 #  define tstrrchr      strrchr
106 #  define tstrstr       strstr
107 #  define tstrlen       strlen
108 #  define tmemcmp       memcmp
109 #  define tstrcasecmp   strcasecmp
110 #  define tstrftime     strftime
111 #  define tputchar      putchar
112 #  define tputc         putc
113 #  define tputs         puts
114 #  define tfputs        fputs
115 #  define tfopen        fopen
116 #  define topen         open
117 #  define tstat         stat
118 #  define tunlink       unlink
119 #  define tstrerror     strerror
120 #  define tstrtol       strtol
121 #  define tstrtod       strtod
122 #  define tstrtoul      strtoul
123 #  define tstrtoull     strtoull
124 #  define tmkdir        mkdir
125 #  define tstrdup       strdup
126 #  define tgetenv       getenv
127 #  define TSTRDUP       STRDUP
128 #  define tstrerror_r   strerror_r
129 #  define trename       rename
130 #  define taccess       access
131 #  define tglob         glob
132 #endif /* !_WIN32 */
133
134 #endif /* _WIMLIB_TCHAR_H */