NetBSD/sys/netsmb/iconv.c

104 lines
1.8 KiB
C
Raw Normal View History

/* $NetBSD: iconv.c,v 1.9 2005/05/29 21:26:02 christos Exp $ */
2002-01-05 23:29:38 +03:00
/* Public domain */
2001-11-13 03:56:55 +03:00
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: iconv.c,v 1.9 2005/05/29 21:26:02 christos Exp $");
2001-11-13 03:56:55 +03:00
#include <sys/param.h>
#include <sys/kernel.h>
#include <sys/systm.h>
#include <sys/errno.h>
#include <sys/malloc.h>
2002-01-04 05:39:37 +03:00
#include <netsmb/iconv.h>
int
iconv_open(const char *to, const char *from, void **handle)
{
return 0;
}
int
2002-01-04 05:39:37 +03:00
iconv_close(void *handle)
{
return 0;
}
int
2002-01-04 05:39:37 +03:00
iconv_conv(void *handle, const char **inbuf,
size_t *inbytesleft, char **outbuf, size_t *outbytesleft)
{
2002-01-04 05:39:37 +03:00
if (*inbytesleft > *outbytesleft)
return(E2BIG);
2002-01-04 05:39:37 +03:00
if (inbuf == NULL)
return(0); /* initial shift state */
(void)memcpy(*outbuf, *inbuf, *inbytesleft);
2002-01-04 05:39:37 +03:00
*outbytesleft -= *inbytesleft;
2002-01-04 05:39:37 +03:00
*inbuf += *inbytesleft;
*outbuf += *inbytesleft;
2002-01-04 05:39:37 +03:00
*inbytesleft = 0;
return 0;
}
char *
2004-04-21 22:16:14 +04:00
iconv_convstr(void *handle, char *dst, const char *src, size_t l)
{
char *p = dst;
size_t inlen, outlen;
int error;
2002-01-04 05:39:37 +03:00
if (handle == NULL) {
2004-04-21 22:16:14 +04:00
strlcpy(dst, src, l);
return dst;
}
inlen = outlen = strlen(src);
2002-01-04 05:39:37 +03:00
error = iconv_conv(handle, NULL, NULL, &p, &outlen);
if (error)
return NULL;
2002-01-04 05:39:37 +03:00
error = iconv_conv(handle, &src, &inlen, &p, &outlen);
if (error)
return NULL;
*p = 0;
return dst;
}
void *
2002-01-04 05:39:37 +03:00
iconv_convmem(void *handle, void *dst, const void *src, int size)
{
const char *s = src;
char *d = dst;
size_t inlen, outlen;
int error;
if (size == 0)
return dst;
2002-01-04 05:39:37 +03:00
if (handle == NULL) {
memcpy(dst, src, size);
return dst;
}
inlen = outlen = size;
2002-01-04 05:39:37 +03:00
error = iconv_conv(handle, NULL, NULL, &d, &outlen);
if (error)
return NULL;
2002-01-04 05:39:37 +03:00
error = iconv_conv(handle, &s, &inlen, &d, &outlen);
if (error)
return NULL;
return dst;
}
int
iconv_lookupcp(const char **cpp, const char *s)
{
for (; *cpp; cpp++)
if (strcmp(*cpp, s) == 0)
return 0;
return ENOENT;
}