]> git.ipfire.org Git - thirdparty/glibc.git/blame - locale/broken_cur_max.c
NEWS: Add advisories.
[thirdparty/glibc.git] / locale / broken_cur_max.c
CommitLineData
6259ec0d
UD
1/* Return number of characters in multibyte representation for current
2 character set.
dff8da6b 3 Copyright (C) 1996-2024 Free Software Foundation, Inc.
6259ec0d 4 This file is part of the GNU C Library.
6259ec0d
UD
5
6 The GNU C Library is free software; you can redistribute it and/or
41bdb6e2
AJ
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.
6259ec0d
UD
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
41bdb6e2 14 Lesser General Public License for more details.
6259ec0d 15
41bdb6e2 16 You should have received a copy of the GNU Lesser General Public
59ba27a6 17 License along with the GNU C Library; if not, see
5a82c748 18 <https://www.gnu.org/licenses/>. */
6259ec0d
UD
19
20#include <langinfo.h>
21#include <locale.h>
22#include <stdlib.h>
23#include "localeinfo.h"
24
25
b7398be5 26/* This is a gross hack to get broken programs running.
6259ec0d
UD
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
b7398be5 32 think this means the same. But assuming all characters have a size
6259ec0d 33 of MB_CUR_LEN after they have been processed by `mbrtowc' is wrong.
b7398be5
UD
34 Instead the maximum number of characters used for the conversion is
35 MB_CUR_LEN.
6259ec0d
UD
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. */
b7398be5 42size_t
6259ec0d
UD
43__ctype_get_mb_cur_max (void)
44{
ba737b94 45 union locale_data_value u;
6259ec0d 46
ba737b94
UD
47 u.string = nl_langinfo (_NL_CTYPE_MB_CUR_MAX);
48 return ((size_t []) { 1, 1, 1, 2, 2, 3, 4 })[u.word];
6259ec0d 49}