1/* Return number of characters in multibyte representation for current
2 character set.
3 Copyright (C) 1996-2022 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
5
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
10
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <https://www.gnu.org/licenses/>. */
19
20#include <langinfo.h>
21#include <locale.h>
22#include <stdlib.h>
23#include "localeinfo.h"
24
25
26/* This is a gross hack to get broken programs running.
27
28 ISO C provides no mean to find out how many bytes the wide
29 character representation really uses. But it defines MB_CUR_LEN to
30 return the information for the multi-byte character representation.
31 Many programmers don't know the difference between the two and
32 think this means the same. But assuming all characters have a size
33 of MB_CUR_LEN after they have been processed by `mbrtowc' is wrong.
34 Instead the maximum number of characters used for the conversion is
35 MB_CUR_LEN.
36
37 It is known that some Motif applications have this problem. To
38 cure this one has to make sure the glibc uses the function in this
39 file instead of the one in locale/mb_cur_max.c. This can either be
40 done by linking with this file or by using the LD_PRELOAD feature
41 of the dynamic linker. */
42size_t
43__ctype_get_mb_cur_max (void)
44{
45 union locale_data_value u;
46
47 u.string = nl_langinfo (item: _NL_CTYPE_MB_CUR_MAX);
48 return ((size_t []) { 1, 1, 1, 2, 2, 3, 4 })[u.word];
49}
50

source code of glibc/locale/broken_cur_max.c