wctob.c (6155c34adf50d3d025ec0e862bb34746ea8c0a21) wctob.c (e9fb70115fcb6811107e65763e62cac4f4304fcd)
1/*-
1/*-
2 * Copyright (c) 2002-2004 Tim J. Robbins.
2 * Copyright (c) 2002 Tim J. Robbins.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright

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

22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
28__FBSDID("$FreeBSD$");
29
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright

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

22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
28__FBSDID("$FreeBSD$");
29
30#include <limits.h>
31#include <stdio.h>
30#include <rune.h>
32#include <wchar.h>
31#include <wchar.h>
33#include "mblocal.h"
34
35int
36wctob(wint_t c)
37{
32
33int
34wctob(wint_t c)
35{
38 static const mbstate_t initial;
39 mbstate_t mbs = initial;
40 char buf[MB_LEN_MAX];
36 char cc;
41
37
42 if (c == WEOF || __wcrtomb(buf, c, &mbs) != 1)
38 if (c == WEOF || sputrune(c, &cc, 1, NULL) != 1)
43 return (EOF);
39 return (EOF);
44 return ((unsigned char)*buf);
40 return ((unsigned char)cc);
45}
41}