Commit Graph

57 Commits

Author SHA1 Message Date
Pedro F. Giffuni
8a16b7a18f General further adoption of SPDX licensing ID tags.
Mainly focus on files that use BSD 3-Clause license.

The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.

Special thanks to Wind River for providing access to "The Duke of
Highlander" tool: an older (2014) run over FreeBSD tree was useful as a
starting point.
2017-11-20 19:49:47 +00:00
Pedro F. Giffuni
be53a489c6 libc: minor indent(1) cleanups.
Illumos and Schillix is adopting some of the locale code and our style(9)
sometimes matches the Solaris cstyle, so the changes are also useful as a
way to reduce diffs.

No functional change.

Discussed with: Joerg Schilling
MFC after:	1 week
2017-08-26 16:11:21 +00:00
Warner Losh
fbbd9655e5 Renumber copyright clause 4
Renumber cluase 4 to 3, per what everybody else did when BSD granted
them permission to remove clause 3. My insistance on keeping the same
numbering for legal reasons is too pedantic, so give up on that point.

Submitted by:	Jan Schaumann <jschauma@stevens.edu>
Pull Request:	https://github.com/freebsd/freebsd/pull/96
2017-02-28 23:42:47 +00:00
Craig Rodrigues
c83f3fc4b4 Use ANSI C prototypes. Eliminates -Wold-style-definition warnings. 2015-09-20 20:50:18 +00:00
Jilles Tjoelker
571eea83bb libc: Eliminate some relative relocations in setlocale(). 2011-12-27 23:28:01 +00:00
David Chisnall
3c87aa1d3d Implement xlocale APIs from Darwin, mainly for use by libc++. This adds a
load of _l suffixed versions of various standard library functions that use
the global locale, making them take an explicit locale parameter.  Also
adds support for per-thread locales.  This work was funded by the FreeBSD
Foundation.

Please test any code you have that uses the C standard locale functions!

Reviewed by:    das (gdtoa changes)
Approved by:    dim (mentor)
2011-11-20 14:45:42 +00:00
Warner Losh
c879ae3536 Per Regents of the University of Calfornia letter, remove advertising
clause.

# If I've done so improperly on a file, please let me know.
2007-01-09 00:28:16 +00:00
Andrey A. Chernov
41ddc53bca LC_ALL not always take priority over other LC_*
Obtained from:  NetBSD
PR:             62047
2004-01-31 19:15:32 +00:00
Andrey A. Chernov
ad4688e131 Properly advance "x/y/z" form slash-pointers in some rare cases
PR:             60539
2003-12-24 10:16:46 +00:00
Tim J. Robbins
4539e95a0f Remove incomplete support for running FreeBSD userland on old NetBSD kernels
lacking the issetugid() and utrace() syscalls.
2003-10-29 10:45:01 +00:00
Andrey A. Chernov
68d429c3fc Reorganize wrapper around setrunelocale() to mark it as deprecated
in FreeBSD 6
2003-07-06 02:03:37 +00:00
Alexey Zelkin
fca2738d67 Reduce code duplication by separating _PathLocle detection code into
internal helper function.
2003-06-25 22:42:33 +00:00
Alexey Zelkin
93c847344b Move _PathLocale declaration to more logical place (setlocale.c) 2003-06-25 22:34:13 +00:00
Alexey Zelkin
d8d4841398 Catch up with _PATH_LOCALE move from rune.h to paths.h 2003-06-25 22:31:42 +00:00
Jacques Vidrine
d05090827f Back out the `hiding' of strlcpy and strlcat. Several people
vocally objected to this safety belt.
2003-05-01 19:03:14 +00:00
Jacques Vidrine
5723e501ab `Hide' strlcpy and strlcat (using the namespace.h / __weak_reference
technique) so that we don't wind up calling into an application's
version if the application defines them.

Inspired by:	qpopper's interfering and buggy version of strlcpy
2003-04-29 21:13:50 +00:00
Andrey A. Chernov
76692b8025 Rewrite locale loading procedures, so any load failure will not affect
currently cached data.  It allows a number of nice things, like: removing
fallback code from single locale loading, remove memory leak when LC_CTYPE
data loaded again and again, efficient cache use, not only for
setlocale(locale1); setlocale(locale1), but for setlocale(locale1);
setlocale("C"); setlocale(locale1) too (i.e.  data file loaded only once).
2002-08-08 05:51:54 +00:00
Andrey A. Chernov
3a317a1229 Reject encoding > ENCODING_LEN at early stage instead of truncating it.
Use ptr == NULL instead of !ptr in few places.
Move saverr declaration to global section.
2002-08-05 09:58:45 +00:00
Andrey A. Chernov
10bc1114ce Rewrite loadlocale() to eliminate LOAD_CATEGORY macro to save space. 2002-08-04 04:29:54 +00:00
Andrey A. Chernov
5740f28044 Preserve errno in fallback code 2002-08-03 15:56:25 +00:00
Andrey A. Chernov
a17eafe2a8 1) Use errno to indicate faulure reason.
2) Move incomplete check for / in locale name from env section to
loadlocale(), add check for "." and ".." too.
It allows to check any argument, not env only.
3) Redesing LOAD_CATEGORY macro to eliminate code duplication.
4) Try harder in fallback code: if old locale can't be restored,
load "C" locale
5) White space formatting, long lines, etc.
2002-08-03 09:04:44 +00:00
Andrey A. Chernov
4e7b46d8e2 Sligtly modify previous out-of-bounds fix: just break instead of
return(NULL) for upward compatibility with more LC_* categories may be
implemented in future.
2002-08-02 13:36:54 +00:00
Andrey A. Chernov
ef1e7a2656 Prevent out of bounds writting for too many slashes case.
Replace strnpy + ='\0' with strlcpy

MFC after:	1 day
2002-08-02 01:04:49 +00:00
David E. O'Brien
333fc21e3c Fix the style of the SCM ID's.
I believe have made all of libc .c's as consistent as possible.
2002-03-22 21:53:29 +00:00
David E. O'Brien
c05ac53b8b Remove __P() usage. 2002-03-21 22:49:10 +00:00
Alexey Zelkin
a2fb0481d7 get __time_load_locale() prototype from include file, rather than declare
own
2002-01-24 15:38:59 +00:00
Ruslan Ermilov
efbe286b68 Removed duplicate $FreeBSD$. 2001-03-02 13:00:26 +00:00
Ruslan Ermilov
825d095dd3 Fix setlocale() to conform to the ISO C and POSIX standards.
The below text is quoted from the latest POSIX draft:

: The values of locale categories shall be determined by a precedence
: order; the first condition met below determines the value:
:
: 1. If the LC_ALL environment variable is defined and is not null,
:    the value of LC_ALL shall be used.
: 2. If the LC_* environment variable (LC_COLLATE, LC_CTYPE, LC_MESSAGES,
:    LC_MONETARY, LC_NUMERIC, LC_TIME) is defined and is not null, the
:    value of the environment variable shall be used to initialize the
:    category that corresponds to the environment variable.
: 3. If the LANG environment variable is defined and is not null, the
:    value of the LANG environment variable shall be used.
: 4. If the LANG environment variable is not set or is set to the empty
:    string, the implementation-defined default locale shall be used.

The conditions 1 and 2 were interchanged, i.e., LC_* were looked first,
then LC_ALL, then LANG (note that LC_ALL and LANG were essentially the
same, providing the default, with LC_ALL taking precedence over LANG).
Now, LC_ALL and LANG serve the different purposes.  LC_ALL overrides
any LC_*, and LANG provides the default fallback.

Testcase:

/usr/bin/env LC_ALL=C LC_TIME=de_DE.ISO_8859-1 /bin/date

Should return date in the "C" locale format.

Inspired by:	date(1) reference page in the Draft
2001-03-02 12:45:52 +00:00
Alexey Zelkin
90423ececf Make FreeBSD locale support complete: add support for rest locale categories
LC_MONETARY, LC_NUMERIC and LC_MESSAGES. Remove stub functions since they
don't need anymore.

Reviewed by:	silence on -i18n
2001-02-08 16:58:53 +00:00
Kris Kennaway
b777873ec1 Disallow '/' characters in LC_* environment variables which might
be used to point to a bad locale file. This is only believed to be a
minor security risk - the only risk is if some program uses the result
of a localized string as a format specifier in a vulnerable function
like sprintf(). No such code is believed to exist in the FreeBSD base
system, although it is possible that badly written third party code
would do that.

Submitted by:	imp
Approved by:	ache
2000-09-08 07:29:48 +00:00
Warner Losh
12b92015dd The comparison against 0 should be against LC_ALL. category isn't a
boolean and it is LC_ALL that's special.

Someone submitted this to me a long time ago, but I can't find the
mail now.
2000-09-04 03:43:24 +00:00
Andrey A. Chernov
8b96e6c916 Megre XPG4 code into libc 2000-06-03 12:24:08 +00:00
Andrey A. Chernov
5d1706df0d Fix dead loop if locale contains / and not all categories specified
PR:		14742
Submitted by:	peter@wahoo.com.tw
1999-11-09 11:09:16 +00:00
Peter Wemm
7f3dea244c $Id$ -> $FreeBSD$ 1999-08-28 00:22:10 +00:00
Andrey A. Chernov
0b5e953b91 Basic support for LC_MESSAGES 1998-04-29 22:39:56 +00:00
John Birrell
c61e516832 Add #ifndef __NETBSD_SYSCALLS around calls to issetugid() which
do not exist in NetBSD 1.3.
1998-01-15 09:58:08 +00:00
Andrey A. Chernov
21b4da0751 Restore PATH_LOCALE functionality using issetugid() call now 1997-04-07 08:54:38 +00:00
Peter Wemm
7e546392b5 Revert $FreeBSD$ to $Id$ 1997-02-22 15:12:41 +00:00
Andrey A. Chernov
e799281533 Move _PathLocale to data-only file, so setrunelocale() not pick up
whole setlocale.c module now.

Should go into 2.2
1997-02-09 09:29:27 +00:00
Joerg Wunsch
cc551f25f4 Do Andrey's homework :) before merging this into 2.2:
. add idempotency #ifdef
. avoid sloppy common-style external declaration.
1997-02-08 14:04:30 +00:00
Andrey A. Chernov
63407d3487 Use symbolic constants instead of hardcoded digits
Add range check for setrunelocale since it can be called
directly.
Remove _startup_setlocale compatibility function

Should go into 2.2
1997-02-06 09:11:06 +00:00
Paul Traina
b6b0d266cd Fix yet another setlocale() bug.
Submitted by:	Wojtek Pilorz <wpilorz@celebris.bdk.lublin.pl>
1997-02-06 08:31:42 +00:00
Andrey A. Chernov
d81a091605 Update the comment why range checking not needed
Fix setrunelocale fail if called directly without prior setlocale
call

Should go in 2.2
1997-02-05 19:17:10 +00:00
David Greenman
5979500afc Killed getenv of PATH_LOCALE per Andrey's suggestion. It was intended
for debugging locale stuff, but was rarely if ever used...and of course
just bit a big chunk out of our collective hind-ends.
1997-02-05 09:53:25 +00:00
Andrey A. Chernov
2b3e51b901 Add yet one comment saying that range checking already done
to stop people "fixing" it by snprintf
1997-02-03 08:29:32 +00:00
Jordan K. Hubbard
1130b656e5 Make the long-awaited change from $Id$ to $FreeBSD$
This will make a number of things easier in the future, as well as (finally!)
avoiding the Id-smashing problem which has plagued developers for so long.

Boy, I'm glad we're not using sup anymore.  This update would have been
insane otherwise.
1997-01-14 07:20:47 +00:00
Andrey A. Chernov
e2900279d2 Add rcsid[]
Since locale reading code not resistent against stack overflowing or
similar intruder attacks, don't allow PATH_LOCALE env variable action
for s-bit programs (non-standard locale path setting)
1996-11-27 22:30:44 +00:00
Andrey A. Chernov
40c0625e97 Add Id
Optimize/improve recently added locale restoration on failure
1996-11-26 08:00:17 +00:00
Andrey A. Chernov
c8f931a80e PATH_LOCALE: use this non-standard env variable first time only, i.e.
strdup() it to prevent unsetenv() or setenv() effects. Check its length to
not allow user to overflow internal locale buffer. Move PATH_LOCALE
handling code into one place.

POSIX: make better stub for LC_MONETARY & LC_NUMERIC, now it check
locale directory existance instead of refusing all non-C non-POSIX
locales. POSIX treats empty locale env variable as unset variable
while our old code treats it as "C" locale, fix it. Implement previous locale
restoring, if locale setting fails. Old code assumes success if some
of LC_ALL subset is successed even other fails, POSIX treats it as
failure with previous locale restoring, fix it.

Remove unneccessary length checking in currentlocale()
1996-11-26 02:49:53 +00:00
Andrey A. Chernov
24c9187962 Use fake (empty) startup_setlocale for XPG4 1995-10-23 02:25:53 +00:00