Back to index

glibc  2.9
broken_cur_max.c
Go to the documentation of this file.
00001 /* Return number of characters in multibyte representation for current
00002    character set.
00003    Copyright (C) 1996, 1999 Free Software Foundation, Inc.
00004    This file is part of the GNU C Library.
00005    Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
00006 
00007    The GNU C Library is free software; you can redistribute it and/or
00008    modify it under the terms of the GNU Lesser General Public
00009    License as published by the Free Software Foundation; either
00010    version 2.1 of the License, or (at your option) any later version.
00011 
00012    The GNU C Library is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015    Lesser General Public License for more details.
00016 
00017    You should have received a copy of the GNU Lesser General Public
00018    License along with the GNU C Library; if not, write to the Free
00019    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00020    02111-1307 USA.  */
00021 
00022 #include <langinfo.h>
00023 #include <locale.h>
00024 #include <stdlib.h>
00025 #include "localeinfo.h"
00026 
00027 
00028 /* This is a gross hack to get broken programs running.
00029 
00030    ISO C provides no mean to find out how many bytes the wide
00031    character representation really uses.  But it defines MB_CUR_LEN to
00032    return the information for the multi-byte character representation.
00033    Many programmers don't know the difference between the two and
00034    think this means the same.  But assuming all characters have a size
00035    of MB_CUR_LEN after they have been processed by `mbrtowc' is wrong.
00036    Instead the maximum number of characters used for the conversion is
00037    MB_CUR_LEN.
00038 
00039    It is known that some Motif applications have this problem.  To
00040    cure this one has to make sure the glibc uses the function in this
00041    file instead of the one in locale/mb_cur_max.c.  This can either be
00042    done by linking with this file or by using the LD_PRELOAD feature
00043    of the dynamic linker.  */
00044 size_t
00045 __ctype_get_mb_cur_max (void)
00046 {
00047   union locale_data_value u;
00048 
00049   u.string = nl_langinfo (_NL_CTYPE_MB_CUR_MAX);
00050   return ((size_t []) { 1, 1, 1, 2, 2, 3, 4 })[u.word];
00051 }