big5.c (128081) | big5.c (128155) |
---|---|
1/*- 2 * Copyright (c) 2002-2004 Tim J. Robbins. All rights reserved. 3 * Copyright (c) 1993 4 * The Regents of the University of California. All rights reserved. 5 * 6 * This code is derived from software contributed to Berkeley by 7 * Paul Borman at Krystal Technologies. 8 * --- 25 unchanged lines hidden (view full) --- 34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 35 * SUCH DAMAGE. 36 */ 37 38#if defined(LIBC_SCCS) && !defined(lint) 39static char sccsid[] = "@(#)big5.c 8.1 (Berkeley) 6/4/93"; 40#endif /* LIBC_SCCS and not lint */ 41#include <sys/param.h> | 1/*- 2 * Copyright (c) 2002-2004 Tim J. Robbins. All rights reserved. 3 * Copyright (c) 1993 4 * The Regents of the University of California. All rights reserved. 5 * 6 * This code is derived from software contributed to Berkeley by 7 * Paul Borman at Krystal Technologies. 8 * --- 25 unchanged lines hidden (view full) --- 34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 35 * SUCH DAMAGE. 36 */ 37 38#if defined(LIBC_SCCS) && !defined(lint) 39static char sccsid[] = "@(#)big5.c 8.1 (Berkeley) 6/4/93"; 40#endif /* LIBC_SCCS and not lint */ 41#include <sys/param.h> |
42__FBSDID("$FreeBSD: head/lib/libc/locale/big5.c 128081 2004-04-10 00:27:52Z tjr $"); | 42__FBSDID("$FreeBSD: head/lib/libc/locale/big5.c 128155 2004-04-12 13:09:18Z tjr $"); |
43 | 43 |
44#include <errno.h> |
|
44#include <runetype.h> 45#include <stdlib.h> 46#include <string.h> 47#include <wchar.h> 48 49extern size_t (*__mbrtowc)(wchar_t * __restrict, const char * __restrict, 50 size_t, mbstate_t * __restrict); 51extern int (*__mbsinit)(const mbstate_t *); --- 43 unchanged lines hidden (view full) --- 95{ 96 _BIG5State *bs; 97 wchar_t wc; 98 int i, len, ocount; 99 size_t ncopy; 100 101 bs = (_BIG5State *)ps; 102 | 45#include <runetype.h> 46#include <stdlib.h> 47#include <string.h> 48#include <wchar.h> 49 50extern size_t (*__mbrtowc)(wchar_t * __restrict, const char * __restrict, 51 size_t, mbstate_t * __restrict); 52extern int (*__mbsinit)(const mbstate_t *); --- 43 unchanged lines hidden (view full) --- 96{ 97 _BIG5State *bs; 98 wchar_t wc; 99 int i, len, ocount; 100 size_t ncopy; 101 102 bs = (_BIG5State *)ps; 103 |
104 if (bs->count < 0 || bs->count > sizeof(bs->bytes)) { 105 errno = EINVAL; 106 return ((size_t)-1); 107 } 108 |
|
103 if (s == NULL) { 104 s = ""; 105 n = 1; 106 pwc = NULL; 107 } 108 109 ncopy = MIN(MIN(n, MB_CUR_MAX), sizeof(bs->bytes) - bs->count); 110 memcpy(bs->bytes + bs->count, s, ncopy); --- 11 unchanged lines hidden (view full) --- 122 wc = (wc << 8) | (unsigned char)*s++; 123 if (pwc != NULL) 124 *pwc = wc; 125 bs->count = 0; 126 return (wc == L'\0' ? 0 : len - ocount); 127} 128 129size_t | 109 if (s == NULL) { 110 s = ""; 111 n = 1; 112 pwc = NULL; 113 } 114 115 ncopy = MIN(MIN(n, MB_CUR_MAX), sizeof(bs->bytes) - bs->count); 116 memcpy(bs->bytes + bs->count, s, ncopy); --- 11 unchanged lines hidden (view full) --- 128 wc = (wc << 8) | (unsigned char)*s++; 129 if (pwc != NULL) 130 *pwc = wc; 131 bs->count = 0; 132 return (wc == L'\0' ? 0 : len - ocount); 133} 134 135size_t |
130_BIG5_wcrtomb(char * __restrict s, wchar_t wc, 131 mbstate_t * __restrict ps __unused) | 136_BIG5_wcrtomb(char * __restrict s, wchar_t wc, mbstate_t * __restrict ps) |
132{ | 137{ |
138 _BIG5State *bs; |
|
133 | 139 |
140 bs = (_BIG5State *)ps; 141 142 if (bs->count != 0) { 143 errno = EINVAL; 144 return ((size_t)-1); 145 } 146 |
|
134 if (s == NULL) 135 /* Reset to initial shift state (no-op) */ 136 return (1); 137 if (wc & 0x8000) { 138 *s++ = (wc >> 8) & 0xff; 139 *s = wc & 0xff; 140 return (2); 141 } 142 *s = wc & 0xff; 143 return (1); 144} | 147 if (s == NULL) 148 /* Reset to initial shift state (no-op) */ 149 return (1); 150 if (wc & 0x8000) { 151 *s++ = (wc >> 8) & 0xff; 152 *s = wc & 0xff; 153 return (2); 154 } 155 *s = wc & 0xff; 156 return (1); 157} |