2006-10-12 05:30:41 +04:00
|
|
|
/* $NetBSD: iconv.c,v 1.11 2006/10/12 01:32:46 christos Exp $ */
|
2002-01-05 23:29:38 +03:00
|
|
|
|
|
|
|
/* Public domain */
|
2000-12-07 06:48:09 +03:00
|
|
|
|
2001-11-13 03:56:55 +03:00
|
|
|
#include <sys/cdefs.h>
|
2006-10-12 05:30:41 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: iconv.c,v 1.11 2006/10/12 01:32:46 christos Exp $");
|
2001-11-13 03:56:55 +03:00
|
|
|
|
2000-12-07 06:48:09 +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>
|
2000-12-07 06:48:09 +03:00
|
|
|
|
|
|
|
int
|
2006-10-12 05:30:41 +04:00
|
|
|
iconv_open(const char *to __unused, const char *from __unused,
|
|
|
|
void **handle __unused)
|
2000-12-07 06:48:09 +03:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2006-10-12 05:30:41 +04:00
|
|
|
iconv_close(void *handle __unused)
|
2000-12-07 06:48:09 +03:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2006-10-12 05:30:41 +04:00
|
|
|
iconv_conv(void *handle __unused, const char **inbuf,
|
|
|
|
size_t *inbytesleft, char **outbuf, size_t *outbytesleft)
|
2000-12-07 06:48:09 +03:00
|
|
|
{
|
2002-01-04 05:39:37 +03:00
|
|
|
if (*inbytesleft > *outbytesleft)
|
|
|
|
return(E2BIG);
|
2000-12-07 06:48:09 +03:00
|
|
|
|
2002-01-04 05:39:37 +03:00
|
|
|
if (inbuf == NULL)
|
|
|
|
return(0); /* initial shift state */
|
2000-12-07 06:48:09 +03:00
|
|
|
|
2005-05-30 01:26:02 +04:00
|
|
|
(void)memcpy(*outbuf, *inbuf, *inbytesleft);
|
2000-12-07 06:48:09 +03:00
|
|
|
|
2002-01-04 05:39:37 +03:00
|
|
|
*outbytesleft -= *inbytesleft;
|
2000-12-07 06:48:09 +03:00
|
|
|
|
2002-01-04 05:39:37 +03:00
|
|
|
*inbuf += *inbytesleft;
|
|
|
|
*outbuf += *inbytesleft;
|
2000-12-07 06:48:09 +03:00
|
|
|
|
2002-01-04 05:39:37 +03:00
|
|
|
*inbytesleft = 0;
|
|
|
|
|
|
|
|
return 0;
|
2000-12-07 06:48:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
2004-04-21 22:16:14 +04:00
|
|
|
iconv_convstr(void *handle, char *dst, const char *src, size_t l)
|
2000-12-07 06:48:09 +03:00
|
|
|
{
|
|
|
|
char *p = dst;
|
2003-02-19 15:01:37 +03:00
|
|
|
size_t inlen, outlen;
|
|
|
|
int error;
|
2000-12-07 06:48:09 +03:00
|
|
|
|
2002-01-04 05:39:37 +03:00
|
|
|
if (handle == NULL) {
|
2004-04-21 22:16:14 +04:00
|
|
|
strlcpy(dst, src, l);
|
2000-12-07 06:48:09 +03:00
|
|
|
return dst;
|
|
|
|
}
|
|
|
|
inlen = outlen = strlen(src);
|
2002-01-04 05:39:37 +03:00
|
|
|
error = iconv_conv(handle, NULL, NULL, &p, &outlen);
|
2000-12-07 06:48:09 +03:00
|
|
|
if (error)
|
|
|
|
return NULL;
|
2002-01-04 05:39:37 +03:00
|
|
|
error = iconv_conv(handle, &src, &inlen, &p, &outlen);
|
2000-12-07 06:48:09 +03:00
|
|
|
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)
|
2000-12-07 06:48:09 +03:00
|
|
|
{
|
|
|
|
const char *s = src;
|
|
|
|
char *d = dst;
|
2003-02-19 15:01:37 +03:00
|
|
|
size_t inlen, outlen;
|
|
|
|
int error;
|
2000-12-07 06:48:09 +03:00
|
|
|
|
|
|
|
if (size == 0)
|
|
|
|
return dst;
|
2002-01-04 05:39:37 +03:00
|
|
|
if (handle == NULL) {
|
2000-12-07 06:48:09 +03:00
|
|
|
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);
|
2000-12-07 06:48:09 +03:00
|
|
|
if (error)
|
|
|
|
return NULL;
|
2002-01-04 05:39:37 +03:00
|
|
|
error = iconv_conv(handle, &s, &inlen, &d, &outlen);
|
2000-12-07 06:48:09 +03:00
|
|
|
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;
|
|
|
|
}
|