]>
git.proxmox.com Git - mirror_edk2.git/blob - StdLib/LibC/Locale/ctypeio.c
2 Internal C-type locale functions.
4 Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php.
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13 Copyright (c) 1997 Christos Zoulas. All rights reserved.
15 Redistribution and use in source and binary forms, with or without
16 modification, are permitted provided that the following conditions
18 1. Redistributions of source code must retain the above copyright
19 notice, this list of conditions and the following disclaimer.
20 2. Redistributions in binary form must reproduce the above copyright
21 notice, this list of conditions and the following disclaimer in the
22 documentation and/or other materials provided with the distribution.
23 3. All advertising materials mentioning features or use of this software
24 must display the following acknowledgement:
25 This product includes software developed by Christos Zoulas.
26 4. The name of the author may not be used to endorse or promote products
27 derived from this software without specific prior written permission.
29 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
30 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
31 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
32 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
33 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
34 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
38 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 NetBSD: ctypeio.c,v 1.7 2005/11/29 03:11:59 christos Exp
42 #include <LibConfig.h>
43 #include <sys/EfiCdefs.h>
44 #if defined(LIBC_SCCS) && !defined(lint)
45 __RCSID("$NetBSD: ctypeio.c,v 1.7 2005/11/29 03:11:59 christos Exp $");
46 #endif /* LIBC_SCCS and not lint */
48 #include <sys/types.h>
54 #define _CTYPE_PRIVATE
59 __loadctype(const char *name
)
62 char id
[sizeof(_CTYPE_ID
) - 1];
64 unsigned short *new_ctype
= NULL
;
65 unsigned char *new_toupper
= NULL
, *new_tolower
= NULL
;
67 _DIAGASSERT(name
!= NULL
);
69 if ((fp
= fopen(name
, "r")) == NULL
)
72 if (fread(id
, sizeof(id
), 1, fp
) != 1)
75 if (memcmp(id
, _CTYPE_ID
, sizeof(id
)) != 0)
78 if (fread(&i
, sizeof(u_int32_t
), 1, fp
) != 1)
81 if ((i
= ntohl(i
)) != _CTYPE_REV
)
84 if (fread(&len
, sizeof(u_int32_t
), 1, fp
) != 1)
87 if ((len
= ntohl(len
)) != _CTYPE_NUM_CHARS
)
90 if ((new_ctype
= malloc(sizeof(UINT16
) * (1 + len
))) == NULL
)
94 if (fread(&new_ctype
[1], sizeof(UINT16
), len
, fp
) != len
)
97 if ((new_toupper
= malloc(sizeof(UINT8
) * (1 + len
))) == NULL
)
100 new_toupper
[0] = (UINT8
)EOF
;
101 if (fread(&new_toupper
[1], sizeof(UINT8
), len
, fp
) != len
)
104 if ((new_tolower
= malloc(sizeof(UINT8
) * (1 + len
))) == NULL
)
107 new_tolower
[0] = (UINT8
)EOF
;
108 if (fread(&new_tolower
[1], sizeof(UINT8
), len
, fp
) != len
)
111 #if BYTE_ORDER == LITTLE_ENDIAN
112 for (i
= 1; i
<= len
; i
++) {
113 new_ctype
[i
] = ntohs(new_ctype
[i
]);
118 if (_cClass
!= _C_CharClassTable
)
119 free(__UNCONST(_cClass
));
121 if (_uConvT
!= _C_ToUpperTable
)
122 free(__UNCONST(_uConvT
));
123 _uConvT
= new_toupper
;
124 if (_lConvT
!= _C_ToLowerTable
)
125 free(__UNCONST(_lConvT
));
126 _lConvT
= new_tolower
;
140 unsigned short *new_ctype
,
141 unsigned char *new_toupper
,
142 unsigned char *new_tolower
146 u_int32_t i
, len
= _CTYPE_NUM_CHARS
;
148 _DIAGASSERT(name
!= NULL
);
149 _DIAGASSERT(new_ctype
!= NULL
);
150 _DIAGASSERT(new_toupper
!= NULL
);
151 _DIAGASSERT(new_tolower
!= NULL
);
153 if ((fp
= fopen(name
, "w")) == NULL
)
156 if (fwrite(_CTYPE_ID
, sizeof(_CTYPE_ID
) - 1, 1, fp
) != 1)
159 i
= htonl(_CTYPE_REV
);
160 if (fwrite(&i
, sizeof(u_int32_t
), 1, fp
) != 1)
164 if (fwrite(&i
, sizeof(u_int32_t
), 1, fp
) != 1)
167 #if BYTE_ORDER == LITTLE_ENDIAN
168 for (i
= 1; i
<= len
; i
++) {
169 new_ctype
[i
] = htons(new_ctype
[i
]);
172 if (fwrite(&new_ctype
[1], sizeof(UINT16
), len
, fp
) != len
)
175 if (fwrite(&new_toupper
[1], sizeof(UINT8
), len
, fp
) != len
)
178 if (fwrite(&new_tolower
[1], sizeof(UINT8
), len
, fp
) != len
)