NetBSD/sys/netsmb/iconv.c

104 lines
1.8 KiB
C
Raw Normal View History

/* $NetBSD: iconv.c,v 1.6 2003/02/19 12:01:37 martin 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.6 2003/02/19 12:01:37 martin 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 */
2002-01-04 05:39:37 +03:00
memcpy((void *)*inbuf, (void *)*outbuf, *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 *
2002-01-04 05:39:37 +03:00
iconv_convstr(void *handle, char *dst, const char *src)
{
char *p = dst;
size_t inlen, outlen;
int error;
2002-01-04 05:39:37 +03:00
if (handle == NULL) {
strcpy(dst, src);
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;
}