1 /* $NetBSD: ctypeio.c,v 1.1 2009/01/02 00:20:23 tnozaki Exp $ */
4 * Copyright (c) 1997 Christos Zoulas. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #include <sys/cdefs.h>
28 #if defined(LIBC_SCCS) && !defined(lint)
29 __RCSID("$NetBSD: ctypeio.c,v 1.1 2009/01/02 00:20:23 tnozaki Exp $");
30 #endif /* LIBC_SCCS and not lint */
32 #include <sys/types.h>
34 #define _CTYPE_PRIVATE
45 __savectype(const char *name
, unsigned char *new_ctype
,
46 short *new_toupper
, short *new_tolower
)
49 uint32_t i
, len
= _CTYPE_NUM_CHARS
;
51 _DIAGASSERT(name
!= NULL
);
52 _DIAGASSERT(new_ctype
!= NULL
);
53 _DIAGASSERT(new_toupper
!= NULL
);
54 _DIAGASSERT(new_tolower
!= NULL
);
56 if ((fp
= fopen(name
, "w")) == NULL
)
59 if (fwrite(_CTYPE_ID
, sizeof(_CTYPE_ID
) - 1, 1, fp
) != 1)
62 i
= htonl(_CTYPE_REV
);
63 if (fwrite(&i
, sizeof(uint32_t), 1, fp
) != 1)
67 if (fwrite(&i
, sizeof(uint32_t), 1, fp
) != 1)
70 if (fwrite(&new_ctype
[1], sizeof(uint8_t), len
, fp
) != len
)
73 #if BYTE_ORDER == LITTLE_ENDIAN
74 for (i
= 1; i
<= len
; i
++) {
75 new_toupper
[i
] = htons(new_toupper
[i
]);
76 new_tolower
[i
] = htons(new_tolower
[i
]);
79 if (fwrite(&new_toupper
[1], sizeof(int16_t), len
, fp
) != len
)
82 if (fwrite(&new_tolower
[1], sizeof(int16_t), len
, fp
) != len
)