xref: /titanic_50/usr/src/lib/libfakekernel/common/kiconv.c (revision b819cea2f73f98c5662230cc9affc8cc84f77fcf)
1*b819cea2SGordon Ross /*
2*b819cea2SGordon Ross  * This file and its contents are supplied under the terms of the
3*b819cea2SGordon Ross  * Common Development and Distribution License ("CDDL"), version 1.0.
4*b819cea2SGordon Ross  * You may only use this file in accordance with the terms of version
5*b819cea2SGordon Ross  * 1.0 of the CDDL.
6*b819cea2SGordon Ross  *
7*b819cea2SGordon Ross  * A full copy of the text of the CDDL should have accompanied this
8*b819cea2SGordon Ross  * source.  A copy of the CDDL is also available via the Internet at
9*b819cea2SGordon Ross  * http://www.illumos.org/license/CDDL.
10*b819cea2SGordon Ross  */
11*b819cea2SGordon Ross 
12*b819cea2SGordon Ross /*
13*b819cea2SGordon Ross  * Copyright 2013 Nexenta Systems, Inc.  All rights reserved.
14*b819cea2SGordon Ross  */
15*b819cea2SGordon Ross 
16*b819cea2SGordon Ross 
17*b819cea2SGordon Ross #include <sys/types.h>
18*b819cea2SGordon Ross #include <sys/time.h>
19*b819cea2SGordon Ross #include <sys/systm.h>
20*b819cea2SGordon Ross #include <sys/errno.h>
21*b819cea2SGordon Ross #include <sys/kiconv.h>
22*b819cea2SGordon Ross 
23*b819cea2SGordon Ross #include <errno.h>
24*b819cea2SGordon Ross #include <iconv.h>
25*b819cea2SGordon Ross 
26*b819cea2SGordon Ross 
27*b819cea2SGordon Ross kiconv_t
kiconv_open(const char * tocode,const char * fromcode)28*b819cea2SGordon Ross kiconv_open(const char *tocode, const char *fromcode)
29*b819cea2SGordon Ross {
30*b819cea2SGordon Ross 	return (iconv_open(tocode, fromcode));
31*b819cea2SGordon Ross }
32*b819cea2SGordon Ross 
33*b819cea2SGordon Ross int
kiconv_close(kiconv_t handle)34*b819cea2SGordon Ross kiconv_close(kiconv_t handle)
35*b819cea2SGordon Ross {
36*b819cea2SGordon Ross 	if (iconv_close(handle) < 0)
37*b819cea2SGordon Ross 		return (EBADF);
38*b819cea2SGordon Ross 
39*b819cea2SGordon Ross 	return (0);
40*b819cea2SGordon Ross }
41*b819cea2SGordon Ross 
42*b819cea2SGordon Ross size_t
kiconv(kiconv_t handle,char ** inbuf,size_t * inbytesleft,char ** outbuf,size_t * outbytesleft,int * errno_out)43*b819cea2SGordon Ross kiconv(
44*b819cea2SGordon Ross     kiconv_t handle,
45*b819cea2SGordon Ross     char **inbuf,
46*b819cea2SGordon Ross     size_t *inbytesleft,
47*b819cea2SGordon Ross     char **outbuf,
48*b819cea2SGordon Ross     size_t *outbytesleft,
49*b819cea2SGordon Ross     int *errno_out)
50*b819cea2SGordon Ross {
51*b819cea2SGordon Ross 	size_t code;
52*b819cea2SGordon Ross 
53*b819cea2SGordon Ross 	code = iconv(handle, (const char **)inbuf, inbytesleft,
54*b819cea2SGordon Ross 	    outbuf, outbytesleft);
55*b819cea2SGordon Ross 	*errno_out = errno;
56*b819cea2SGordon Ross 	return (code);
57*b819cea2SGordon Ross }
58