mbtowc.c (9771f1e24e2aadcee0298a295f5b1c3882b34fb0) mbtowc.c (f0c6c306f91a839c0ad2e84a3e1b84aa81b26c8f)
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

--- 23 unchanged lines hidden (view full) ---

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$");
39
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

--- 23 unchanged lines hidden (view full) ---

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$");
39
40#include <errno.h>
40#include <stdlib.h>
41#include <stddef.h>
42#include <rune.h>
43
44int
45mbtowc(pwc, s, n)
46 wchar_t *__restrict pwc;
47 const char *__restrict s;
48 size_t n;
49{
50 char const *e;
51 rune_t r;
52
53 if (s == 0 || *s == 0)
54 return (0); /* No support for state dependent encodings. */
55
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;
50{
51 char const *e;
52 rune_t r;
53
54 if (s == 0 || *s == 0)
55 return (0); /* No support for state dependent encodings. */
56
56 if ((r = sgetrune(s, n, &e)) == _INVALID_RUNE)
57 if ((r = sgetrune(s, n, &e)) == _INVALID_RUNE) {
58 errno = EILSEQ;
57 return (s - e);
59 return (s - e);
60 }
58 if (pwc)
59 *pwc = r;
60 return (e - s);
61}
61 if (pwc)
62 *pwc = r;
63 return (e - s);
64}