aboutsummaryrefslogtreecommitdiff
path: root/newlib/libc/locale
AgeCommit message (Collapse)AuthorFilesLines
2024-01-31getlocalename_l: implement per SUS Base Specifications Issue 8 draftCorinna Vinschen2-0/+78
#include <locale.h> const char *getlocalename_l(int category, locale_t locobj); Most notably, we need a per-thread space to store the string returned if locobj is LC_GLOBAL_LOCALE. No errors are defined for getlocalename_l. So we can't use buffer allocation which might lead to an ENOMEM error. We have to use a "static" buffer in the per-thread state. Note that the feature test macro in locale.h is not quite correct. This needs to be fixed as soon as the Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-01-22newlib: docs: add "Function " to every function nodeMike Frysinger1-1/+1
When creating a split manual with one-node-per-page, the main index.html ends up getting clobbered by the page for the index() function because it uses "@node index" which, for html, also creates an index.html page. To remedy this, add "Function " to every function node so now we output "Function-index.html" and avoid clobbering. It also namespaces every other function and helps make sure we don't clobber anything else. Otherwise, there isn't really much rendering difference as @node text is mostly internal. Node title text comes from @section instead.
2023-11-24newlib: nl_langinfo: Fix a bug of time stuff.Takashi Yano1-4/+4
Previously, e.g. nl_langinfo(_NL_TIME_WMONTH_1) returns "February" due to the bug. Similarly, nl_langinfo(_NL_TIME_WWDAY_1) returns "Mon". This occurs because wide char month and weekday arrays are pointed off-by-one (e.g. the array wmon[12] is reffered as wmon[1-12] rather than wmon[0-11]). This patch fixes that. Fixes: d47d5b850bed ("Extend locale support to maintain wide char values of native strings") Reviewed-by: Corinna Vinschen <corinna@vinschen.de> Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2023-09-11Reentrancy, use _REENT_ERRNO()Pekka Seppänen2-12/+12
Use _REENT_ERRNO() macro to access errno. This encapsulation is required, as errno might be either _errno member of struct _reent, _tls_errno or any such implementation detail.
2023-05-17fix __time_load_locale return codeAlexey Lapshin1-1/+3
- add explicit __HAVE_LOCALE_INFO__ check
2023-03-24newlocale: set errno to ENOENT if __loadlocale failsCorinna Vinschen1-1/+4
__loadlocale never sets errno, but newlocale is supposed to return ENOENT if the locale isn't valid. Fixes: aefd8b5b518b ("Implement newlocale, freelocale, duplocale, uselocale") Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-03-16Cygwin: add support for GB18030 codesetCorinna Vinschen1-4/+11
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-02-24Cygwin: convert Windows locale handling from LCID to ISO5646 stringsCorinna Vinschen1-1/+1
Since Windows Vista, locale handling is converted from using numeric locale identifiers (LCID) to using ISO5646 locale strings. In the meantime Windows introduced new locales which don't even have a LCID attached. Those were unusable in Cygwin because locale information for these locales required to call the new locale functions taking a locale string. Convert Cygwin to drop LCIDs and use Windows ISO5646 locales instead. The last place using LCIDs is the __set_charset_from_locale function. Checking numerically is easier and uslay faster than checking strings. However, this function is clearly a TODO
2023-02-24Cygwin: support KOI8-T codesetCorinna Vinschen2-5/+12
Used on Linux as default codeset for Tajik. There's no matching Windows codepage, so fake it as CP103. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-02-06setlocale: create LC_ALL string when changing localeCorinna Vinschen1-4/+10
This patch is for the sake of gnulib. gnulib implements some form of a thread-safe setlocale variant called setlocale_null_r, which is supposed to return the locale strings in a thread-safe manner. This only succeeds if the system's setlocale already handles this thread-safe, otherwise gnulib adds some locking on its own. Newlib's setlocale always writes the global string array holding the LC_ALL value anew on each invocation of setlocale(LC_ALL, NULL). Since that doesn't allow to call setlocale(LC_ALL, NULL) in a thread-safe manner, so locking in gnulib is required. And here's the problem... The lock is decorated as dllexport when building for Cygwin. This collides with the default behaviour of ld to export all symbols. If it finds one decorated symbol, it will only export this symbol to the DLL import lib. Change setlocale so that it writes the global string array holding the LC_ALL value at the time the locale gets changed. On setlocale(LC_ALL, NULL), just return the pointer to the global LC_ALL string array, just as in GLibc. The burden of doing so is negligibly for all targets, but adds thread-safety for gnulib's setlocal_null_r() function, and gnulib can drop the lock entirely when building for Cygwin. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-12-03Cygwin: fix LC_CTYPE in global locale to be a real C.UTF-8 localeCorinna Vinschen3-1/+21
https://cygwin.com/pipermail/cygwin/2022-December/252571.html Cygwin's default locale is "C.UTF-8" as far as LC_CTYPE settings are concerned. However, while __global_locale contains fixed mbtowc and wctomb pointers, the lc_ctype_T pointer is still pointing to _C_ctype_locale, representing the standard "C" locale. The problem with this is that the codeset name as well as MB_CUR_MAX is wrong. Fix this by introducing a new lc_ctype_T structure called _C_utf8_ctype_locale, setting the default codeset to "UTF-8" and MB_CUR_MAX to 6. Use this as lc_ctype_T pointer in __global_locale by default on Cygwin. Fixes: a6a477fa8190 ("POSIX-1.2008 per-thread locales, groundwork part 1") Co-Authored-By: Takashi Yano <takashi.yano@nifty.ne.jp> Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-08-12newlocale: fix crash when trying to write to __C_localeCorinna Vinschen1-1/+2
This simple testcase: locale_t st = newlocale(LC_ALL_MASK, "C", (locale_t)0); locale_t st2 = newlocale(LC_CTYPE_MASK, "en_US.UTF-8", st); is sufficient to reproduce a crash in _newlocale_r. After the first call to newlocale, `st' points to __C_locale, which is const. When using `st' as locale base in the second call, _newlocale_r tries to set pointers inside base to NULL. This is bad if base is __C_locale, obviously. Add a test to avoid trying to overwrite pointer values inside base if base is __C_locale. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-07-13Add --enable-newlib-reent-thread-local optionMatt Joyce1-0/+4
By default, Newlib uses a huge object of type struct _reent to store thread-specific data. This object is returned by __getreent() if the __DYNAMIC_REENT__ Newlib configuration option is defined. The reentrancy structure contains for example errno and the standard input, output, and error file streams. This means that if an application only uses errno it has a dependency on the file stream support even if it does not use it. This is an issue for lower end targets and applications which need to qualify the software according to safety standards (for example ECSS-E-ST-40C, ECSS-Q-ST-80C, IEC 61508, ISO 26262, DO-178, DO-330, DO-333). If the new _REENT_THREAD_LOCAL configuration option is enabled, then struct _reent is replaced by dedicated thread-local objects for each struct _reent member. The thread-local objects are defined in translation units which use the corresponding object.
2022-07-13Add _REENT_LOCALE(ptr)Matt Joyce2-4/+4
Add a _REENT_LOCALE() macro to encapsulate access to the _locale member of struct reent. This will help to replace the struct member with a thread-local storage object in a follow up patch.
2022-03-16newlib: libc: merge build up a directoryMike Frysinger3-661/+20
Convert all the libc/ subdir makes into the top-level Makefile. This allows us to build all of libc from the top Makefile without using any recursive make calls. This is faster and avoids the funky lib.a logic where we unpack subdir archives to repack into a single libc.a. The machine override logic is maintained though by way of Makefile include ordering, and source file accumulation in libc_a_SOURCES. There's a few dummy.c files that are no longer necessary since we aren't doing the lib.a accumulating, so punt them. The winsup code has been pulling the internal newlib ssp library out, but that doesn't exist anymore, so change that to pull the objects.
2022-02-25newlib: libc: move configure into top-levelMike Frysinger1-13/+30
This kills off the last configure script under libc/ and folds it into the top newlib configure script. The a lot of the logic was already in the top configure script, so move what's left into a libc/acinclude.m4 file.
2022-02-18newlib: libc: delete crt0.o duplicationMike Frysinger1-1/+0
The crt0.o was handled in a subdir-by-subdir basis: it would be compiled in one (e.g. libc/sys/$arch/), then copied up one level (libc/sys/), then copied up another (libc/) before finally being copied & installed in the top newlib dir. The libc/sys/ copy was cleaned up, and then the top dir was changed to copy it directly out of the libc/sys/$arch/ dir. But the libc/sys/ copy to libc/ was left behind. Clean that up now too.
2022-02-15newlib/libgloss: drop unused $(CROSS_CFLAGS)Mike Frysinger2-2/+2
This is used in a bunch of places, but nowhere is it ever set, and nowhere can I find any documentation, nor can I find any other project using it. So delete the flags to simplify.
2022-02-15newlib: phoenix: merge configure up to top-levelMike Frysinger1-1/+2
Merge sys/phoenix/ configure logic into libc/ itself. This kills off the last lingering script in this tree (other than libc itself).
2022-02-09newlib: drop support for $oextMike Frysinger1-1/+0
This was needed only to support libtool in case objects ended in .lo instead of .o, but we dropped libtool, so drop this too.
2022-02-09newlib: drop support for $aextMike Frysinger1-1/+0
This was needed only to support libtool in case the library ended in .la instead of .a, but we dropped libtool, so drop this too.
2022-02-09newlib: drop libtool supportMike Frysinger2-115/+19
This was only ever used for i?86-pc-linux-gnu targets, but that's been broken for years, and has since been dropped. So clean this up too. This also deletes the funky objectlist logic since it only existed for the libtool libraries. Since it was the only thing left in the small Makefile.shared file, we can punt that too.
2022-02-08newlib: switch to AM_PROG_ARMike Frysinger1-0/+1
Now that we require automake-1.15, we can use this macro rather than do the tool search ourselves.
2022-02-08newlib: switch to standard AC_PROG_CCMike Frysinger1-6/+1
Now that we use AC_NO_EXECUTABLES, and we require a recent version of autoconf, we don't need to define our own copies of these macros. So switch to the standard AC_PROG_CC.
2022-02-05newlib: drop shared documentation rulesMike Frysinger1-34/+1
Now that the top-level makefile handles these, don't need to copy these into every single subdir.
2022-02-05newlib: move man page generation into top-level buildMike Frysinger2-13/+2
This allows building the libc & libm pages in parallel, and drops the duplication in the subdirs with the chew/chapter settings. The unused rules in Makefile.shared are left in place to minimize noise in the change.
2022-02-04newlib: libc: move manual into top-level buildMike Frysinger3-18/+20
This doesn't migrate all the docs, just the libc's manual (pdf/info). This is to show the basic form of migrating the chew files. For subdirs that didn't have any docs, I've stripped their settings for clarity. If someone wanted to suddenly add docs, they can add the corresponding Makefile.inc files easily.
2022-02-04newlib: libc: include all chapters all the time in the manualMike Frysinger1-5/+0
THe stdio subdir is actually required by the documentation. The stdio/def is handled dynamically, but libc.texi always expects it to be included, and fails if it isn't. So making it required when building docs is safe. The xdr subdir is handled dynamically, but it doesn't include any docs, so the dynamic logic isn't (currently) adding any value. So making it required when building docs is safe. That leaves: iconv, stdio64, posix, and signal subdirs. The chapters have a little disclaimer saying they are system-dependent, but even then, imo having stable manuals regardless of the target is preferable, and we can add more disclaimer language to these chapters if we want. This doesn't touch the man page codepaths, just the info/pdf.
2022-01-29newlib: export abs_newlib_basedir for all subdirsMike Frysinger1-0/+1
When using the top-level configure script but subdir Makefiles, the newlib_basedir value gets a bit out of sync: it's relative to where configure lives, not where the Makefile lives. Move the abs setting from the top-level configure script into acinclude.m4 so we can rely on it being available everywhere. Although this commit doesn't use it anywhere, just lays the groundwork.
2022-01-26newlib: libc: merge machine/ configure scripts up a levelMike Frysinger1-1/+6
The machine configure scripts are all effectively stub scripts that pass the higher level options to its own makefile. There were only three doing custom tests. The rest were all effectively the same as the libc/ configure script. So instead of recursively running configure in all of these subdirs, generate their makefiles from the top-level configure. For the few unique ones, deploy a pattern of including subdir logic via m4: m4_include([machine/nds32/acinclude.m4]) Some of the generated machine makefiles have a bunch of extra stuff added to them, but that's because they were inconsistent in their configure libtool calls. The top-level has it, so it exports some new vars to the ones that weren't already.
2022-01-26newlib: libc: merge sys/ trampoline up a levelMike Frysinger1-0/+1
The sys/{configure,Makefile} files exist to fan out to the specific sys/$arch/ subdir, and to possibly generate a crt0. We already have all that same info in the libc/ dir itself, so by moving the recursive configure and make calls into it, we can cut off some of this logic entirely and save the overhead. For arches that don't have a sys subdir, it means they can skip the logic entirely. The sys subdir itself is kept for the crt0 logic, for now. We'll try and clean that up next.
2022-01-26newlib: libc: merge machine/ trampoline up a levelMike Frysinger1-0/+1
The machine/{configure,Makefile} files exist only to fan out to the specific machine/$arch/ subdir. We already have all that same info in the libc/ dir itself, so by moving the recursive configure and make calls into it, we can cut off this logic entirely and save the overhead. For arches that don't have a machine subdir, it means they can skip the logic entirely. Although there's prob not too many of those.
2022-01-21newlib: punt unused LIBC_EXTRA_LIB settingsMike Frysinger1-3/+0
This was added decades ago, but the commit message lacks any explanation, and it was unused when it was merged. It's still unused today. So punt it all.
2022-01-14newlib: update to automake-1.15Mike Frysinger1-78/+146
This matches what the other GNU toolchain projects have done already. The generated diff in practice isn't terribly large. This will allow more use of subdir local.mk includes due to fixes & improvements that came after the 1.11 release series.
2022-01-14require autoconf-2.69 exactlyMike Frysinger1-1/+4
The newlib & libgloss dirs are already generated using autoconf-2.69. To avoid merging new code and/or accidental regeneration using diff versions, leverage config/override.m4 to pin to 2.69 exactly. This matches what gcc/binutils/gdb are already doing. The README file already says to use autoconf-2.69. To accomplish this, it's just as simple as adding -I flags to the top-level config/ dir when running aclocal. This is because the override.m4 file overrides AC_INIT to first require the specific autoconf version before calling the real AC_INIT.
2022-01-05newlib: migrate from INCLUDES to AM_CPPFLAGSMike Frysinger2-2/+2
Since automake deprecated the INCLUDES name in favor of AM_CPPFLAGS, change all existing users over. The generated code is the same since the two variables have been used in the same exact places by design. There are other cleanups to be done, but lets focus on just renaming here so we can upgrade to a newer automake version w/out triggering new warnings.
2021-12-29newlib: Regenerate autotools filesJon Turney1-4/+3
2021-12-29newlib: Remove automake option 'cygnus'Jon Turney1-2/+0
The 'cygnus' option was removed from automake 1.13 in 2012, so the presence of this option prevents that or a later version of automake being used. A check-list of the effects of '--cygnus' from the automake 1.12 documentation, and steps taken (where possible) to preserve those effects (See also this thread [1] for discussion on that): [1] https://lists.gnu.org/archive/html/bug-automake/2012-03/msg00048.html 1. The foreign strictness is implied. Already present in AM_INIT_AUTOMAKE in newlib/acinclude.m4 2. The options no-installinfo, no-dependencies and no-dist are implied. Already present in AM_INIT_AUTOMAKE in newlib/acinclude.m4 Future work: Remove no-dependencies and any explicit header dependencies, and use automatic dependency tracking instead. Are there explicit rules which are now redundant to removing no-installinfo and no-dist? 3. The macro AM_MAINTAINER_MODE is required. Already present in newlib/acinclude.m4 Note that maintainer-mode is still disabled by default. 4. Info files are always created in the build directory, and not in the source directory. This appears to be an error in the automake documentation describing '--cygnus' [2]. newlib's info files are generated in the source directory, and no special steps are needed to keep doing that. [2] https://lists.gnu.org/archive/html/bug-automake/2012-04/msg00028.html 5. texinfo.tex is not required if a Texinfo source file is specified. (The assumption is that the file will be supplied, but in a place that automake cannot find.) This effect is overriden by an explicit setting of the TEXINFO_TEX variable (the directory part of which is fed into texi2X via the TEXINPUTS environment variable). 6. Certain tools will be searched for in the build tree as well as in the user's PATH. These tools are runtest, expect, makeinfo and texi2dvi. For obscure automake reasons, this effect of '--cygnus' is not active for makeinfo in newlib's configury. However, there appears to be top-level configury which selects in-tree runtest, expect and makeinfo, if present. So, if that works as it appears, this effect is preserved. If not, this may cause problem if anyone is building those tools in-tree. This effect is not preserved for texi2dvi. This may cause problems if anyone is building texinfo in-tree. If needed, explicit checks for those tools looking in places relative to $(top_srcdir)/../ as well as in PATH could be added. 7. The check target doesn't depend on all. This effect is not preseved. The check target now depends on the all target. This concern seems somewhat academic given the current state of the testsuite. Also note that this doesn't touch libgloss.
2021-12-29newlib: Regenerate autotools filesJon Turney1-2/+2
2021-12-09newlib: Regenerate all autotools filesJon Turney1-38/+58
Regenerate all aclocal.m4, configure and Makefile.in files.
2021-11-06libgloss/newlib: update configure.ac in Makefile.in filesMike Frysinger1-1/+1
The maintainer rules refer to configure.in directly, so update that after renaming all the configure.ac files.
2021-04-13Add build mechanism to share common header files between machinesCorinna Vinschen1-0/+1
So far the build mechanism in newlib only allowed to either define machine-specific headers, or headers shared between all machines. In some cases, architectures are sufficiently alike to share header files between them, but not with other architectures. A good example is ix86 vs. x86_64, which share certain traits with each other, but not with other architectures. Introduce a new configure variable called "shared_machine_dir". This dir can then be used for headers shared between architectures. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2020-10-13drop ambiguous-wide behaviour from Unicode CJK localesThomas Wolff1-13/+5
2020-09-04loadlocale: don't casecmp digitsCorinna Vinschen1-1/+1
strcmp is sufficient here Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2020-02-18Locale modifier "@cjksingle" to enforce single-width CJK width.Thomas Wolff1-2/+11
This option follows a proposal in the Terminals Working Group Specifications (https://gitlab.freedesktop.org/terminal-wg/specifications/issues/9#note_406682). It makes locale width consistent with the corresponding mintty feature.
2018-10-10newlib: Drop incorrect const qualifier from __loadlocale parameterCorinna Vinschen2-3/+3
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-09-06Use !__HAVE_LOCALE_INFO__ define to use _ctype_ directly [v2]Keith Packard2-0/+10
When __HAVE_LOCALE_INFO__ is not selected, directly access the existing _ctype_ variable from __locale_ctype_ptr() and __locale_ctype_ptr_l(), eliminating the need for any locale or reent structure Signed-off-by: Keith Packard <keithp@keithp.com> v2: locale: fix conflict with __locale_ctype_ptr macro If we are building without __HAVE_LOCALE_INFO__, there is a macro providing __locale_ctype_ptr which in turn fouls up this declaration. Signed-off-by: Michael Lyle <mlyle@lyle.org>
2018-08-08newlib: newlocale: fix typo rendering ctype_ptr invalidCorinna Vinschen1-1/+1
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-03-05Locale modifier @cjkwide to adjust ambiguous-width in non-CJK localesThomas Wolff1-16/+23
Locale modifier @cjkwide makes Unicode "ambiguous width" characters wide. So ambiguous width characters can be enforced to have width 2 even in non-CJK locales. This gives e.g. users of "Powerline symbols" the opportunity to adjust their width to the desired behaviour (and the behaviour apparently expected by some tools) without having to set a CJK locale and without losing consistence of terminal character width with wcwidth/wcswidth locale width.
2018-01-17ansification: remove _DEFUNYaakov Selkowitz2-6/+3
Signed-off-by: Yaakov Selkowitz <yselkowi@redhat.com>