1 /*
2 Copyright (c) 1996 - 2002 FreeBSD Project
3 Copyright (c) 1991, 1993
4 The Regents of the University of California. All rights reserved.
5
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions
8 are met:
9 1. Redistributions of source code must retain the above copyright
10 notice, this list of conditions and the following disclaimer.
11 2. Redistributions in binary form must reproduce the above copyright
12 notice, this list of conditions and the following disclaimer in the
13 documentation and/or other materials provided with the distribution.
14 4. Neither the name of the University nor the names of its contributors
15 may be used to endorse or promote products derived from this software
16 without specific prior written permission.
17
18 THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 SUCH DAMAGE.
29 */
30 /*
31 FUNCTION
32 <<uselocale>>---free resources allocated for a locale object
33
34 INDEX
35 uselocale
36
37 INDEX
38 _uselocale_r
39
40 SYNOPSIS
41 #include <locale.h>
42 locale_t uselocale(locale_t <[locobj]>);
43
44 locale_t _uselocale_r(void *<[reent]>, locale_t <[locobj]>);
45
46 DESCRIPTION
47 The <<uselocale>> function shall set the current locale for the current
48 thread to the locale represented by newloc.
49
50 The value for the newloc argument shall be one of the following:
51
52 1. A value returned by the <<newlocale>> or <<duplocale>> functions
53
54 2. The special locale object descriptor LC_GLOBAL_LOCALE
55
56 3. (locale_t) <<0>>
57
58 Once the <<uselocale>> function has been called to install a thread-local
59 locale, the behavior of every interface using data from the current
60 locale shall be affected for the calling thread. The current locale for
61 other threads shall remain unchanged.
62
63 If the newloc argument is (locale_t) <<0>>, the object returned is the
64 current locale or LC_GLOBAL_LOCALE if there has been no previous call to
65 <<uselocale>> for the current thread.
66
67 If the newloc argument is LC_GLOBAL_LOCALE, the thread shall use the
68 global locale determined by the <<setlocale>> function.
69
70 RETURNS
71 Upon successful completion, the <<uselocale>> function shall return the
72 locale handle from the previous call for the current thread, or
73 LC_GLOBAL_LOCALE if there was no such previous call. Otherwise,
74 <<uselocale>> shall return (locale_t) <<0>> and set errno to indicate
75 the error.
76
77
78 PORTABILITY
79 <<uselocale>> is POSIX-1.2008.
80 */
81
82 #define _DEFAULT_SOURCE
83 #include <newlib.h>
84 #include <stdlib.h>
85 #include "setlocale.h"
86
87 #ifndef _REENT_ONLY
88
89 struct __locale_t *
uselocale(struct __locale_t * newloc)90 uselocale (struct __locale_t *newloc)
91 {
92 struct __locale_t *current_locale;
93
94 (void) newloc;
95 current_locale = __get_current_locale();
96 #ifdef __HAVE_LOCALE_INFO__
97 if (newloc == LC_GLOBAL_LOCALE)
98 _locale = NULL;
99 else if (newloc)
100 _locale = newloc;
101 #endif
102 return current_locale;
103 }
104
105 #endif
106