Skip to content

Commit 7fc9938

Browse files
committedOct 21, 2024·
clar: support compilation without support for wchar_t
Some implementations of libc do not have proper support for `wchar_t`. One such library is uClibc, which only has optional support for this type. When not enabled, then the <wchar.h> header will be a mere stub that only contains a typedef for `wchar_t`, but nothing else. Drop our use of `wchar_t` on such platforms. Reported-by: Bagas Sanjaya <bagasdotme@gmail.com> Helped-by: Edgar Bonet <bonet@grenoble.cnrs.fr>
1 parent 0810a36 commit 7fc9938

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed
 

‎clar.c

+12
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@
2424
#include <sys/types.h>
2525
#include <sys/stat.h>
2626

27+
#if defined(__UCLIBC__) && ! defined(__UCLIBC_HAS_WCHAR__)
28+
/*
29+
* uClibc can optionally be built without wchar support, in which case
30+
* the installed <wchar.h> is a stub that only defines the `whar_t`
31+
* type but none of the functions typically declared by it.
32+
*/
33+
#else
34+
# define CLAR_HAVE_WCHAR
35+
#endif
36+
2737
#ifdef _WIN32
2838
# define WIN32_LEAN_AND_MEAN
2939
# include <windows.h>
@@ -766,6 +776,7 @@ void clar__assert_equal(
766776
}
767777
}
768778
}
779+
#ifdef CLAR_HAVE_WCHAR
769780
else if (!strcmp("%ls", fmt)) {
770781
const wchar_t *wcs1 = va_arg(args, const wchar_t *);
771782
const wchar_t *wcs2 = va_arg(args, const wchar_t *);
@@ -801,6 +812,7 @@ void clar__assert_equal(
801812
}
802813
}
803814
}
815+
#endif /* CLAR_HAVE_WCHAR */
804816
else if (!strcmp("%"PRIuMAX, fmt) || !strcmp("%"PRIxMAX, fmt)) {
805817
uintmax_t sz1 = va_arg(args, uintmax_t), sz2 = va_arg(args, uintmax_t);
806818
is_equal = (sz1 == sz2);

0 commit comments

Comments
 (0)
Please sign in to comment.