mbtowc.c (103012) | mbtowc.c (106032) |
---|---|
1/*- 2 * Copyright (c) 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Paul Borman at Krystal Technologies. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 21 unchanged lines hidden (view full) --- 30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34 * SUCH DAMAGE. 35 */ 36 37#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Paul Borman at Krystal Technologies. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 21 unchanged lines hidden (view full) --- 30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34 * SUCH DAMAGE. 35 */ 36 37#include <sys/cdefs.h> |
38__FBSDID("$FreeBSD: head/lib/libc/locale/mbtowc.c 103012 2002-09-06 11:24:06Z tjr $"); | 38__FBSDID("$FreeBSD: head/lib/libc/locale/mbtowc.c 106032 2002-10-27 10:41:21Z tjr $"); |
39 40#include <errno.h> 41#include <stdlib.h> 42#include <stddef.h> 43#include <rune.h> 44 45int | 39 40#include <errno.h> 41#include <stdlib.h> 42#include <stddef.h> 43#include <rune.h> 44 45int |
46mbtowc(pwc, s, n) 47 wchar_t * __restrict pwc; 48 const char * __restrict s; 49 size_t n; | 46mbtowc(wchar_t * __restrict pwc, const char * __restrict s, size_t n) |
50{ | 47{ |
51 char const *e; | 48 const char *e; |
52 rune_t r; 53 | 49 rune_t r; 50 |
54 if (s == 0 || *s == 0) 55 return (0); /* No support for state dependent encodings. */ | 51 if (s == NULL || *s == '\0') 52 /* No support for state dependent encodings. */ 53 return (0); |
56 57 if ((r = sgetrune(s, n, &e)) == _INVALID_RUNE) { 58 errno = EILSEQ; 59 return (s - e); 60 } | 54 55 if ((r = sgetrune(s, n, &e)) == _INVALID_RUNE) { 56 errno = EILSEQ; 57 return (s - e); 58 } |
61 if (pwc) | 59 if (pwc != NULL) |
62 *pwc = r; 63 return (e - s); 64} | 60 *pwc = r; 61 return (e - s); 62} |