1 // -*- C++ -*-
2 //===------------------- support/ibm/locale_mgmt_aix.h --------------------===//
3 //
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #ifndef _LIBCPP_SUPPORT_IBM_LOCALE_MGMT_AIX_H
11 #define _LIBCPP_SUPPORT_IBM_LOCALE_MGMT_AIX_H
12 
13 #if defined(_AIX)
14 #include "cstdlib"
15 
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19 
20 #if !defined(_AIX71)
21 // AIX 7.1 and higher has these definitions.  Definitions and stubs
22 // are provied here as a temporary workaround on AIX 6.1.
23 
24 #define LC_COLLATE_MASK         1
25 #define LC_CTYPE_MASK           2
26 #define LC_MESSAGES_MASK        4
27 #define LC_MONETARY_MASK        8
28 #define LC_NUMERIC_MASK         16
29 #define LC_TIME_MASK            32
30 #define LC_ALL_MASK             (LC_COLLATE_MASK | LC_CTYPE_MASK | \
31                                  LC_MESSAGES_MASK | LC_MONETARY_MASK |\
32                                  LC_NUMERIC_MASK | LC_TIME_MASK)
33 
34 typedef void* locale_t;
35 
36 // The following are stubs.  They are not supported on AIX 6.1.
37 static inline
newlocale(int category_mask,const char * locale,locale_t base)38 locale_t newlocale(int category_mask, const char *locale, locale_t base)
39 {
40   _LC_locale_t *newloc, *loc;
41   if ((loc = (_LC_locale_t *)__xopen_locale(locale)) == NULL)
42   {
43     errno = EINVAL;
44     return (locale_t)0;
45   }
46   if ((newloc = (_LC_locale_t *)calloc(1, sizeof(_LC_locale_t))) == NULL)
47   {
48     errno = ENOMEM;
49     return (locale_t)0;
50   }
51   if (!base)
52     base = (_LC_locale_t *)__xopen_locale("C");
53   memcpy(newloc, base, sizeof (_LC_locale_t));
54   if (category_mask & LC_COLLATE_MASK)
55     newloc->lc_collate = loc->lc_collate;
56   if (category_mask & LC_CTYPE_MASK)
57     newloc->lc_ctype = loc->lc_ctype;
58   //if (category_mask & LC_MESSAGES_MASK)
59   //  newloc->lc_messages = loc->lc_messages;
60   if (category_mask & LC_MONETARY_MASK)
61     newloc->lc_monetary = loc->lc_monetary;
62   if (category_mask & LC_TIME_MASK)
63     newloc->lc_time = loc->lc_time;
64   if (category_mask & LC_NUMERIC_MASK)
65     newloc->lc_numeric = loc->lc_numeric;
66   return (locale_t)newloc;
67 }
68 static inline
freelocale(locale_t locobj)69 void freelocale(locale_t locobj)
70 {
71   free(locobj);
72 }
73 static inline
uselocale(locale_t newloc)74 locale_t uselocale(locale_t newloc)
75 {
76   return (locale_t)0;
77 }
78 #endif // !defined(_AIX71)
79 
80 #ifdef __cplusplus
81 }
82 #endif
83 #endif // defined(_AIX)
84 #endif // _LIBCPP_SUPPORT_IBM_LOCALE_MGMT_AIX_H
85