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