iconv.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include "synonyms.h"
#include <stdlib.h>
#include <stdio.h>
#include <dlfcn.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <alloca.h>
#include "iconv.h"
#include "iconvP.h"
#include "../i18n/_loc_path.h"
static iconv_p iconv_open_all(const char *, const char *, char *);
static iconv_p iconv_open_private(const char *, const char *);
static iconv_p iconv_search_alias(const char *, const char *, char *);
/*
* These functions are implemented using a shared object and the dlopen()
* functions. Then, the actual conversion algorithm for a particular
* conversion is implemented as a shared object in a separate file in
* a loadable conversion module and linked dynamically at run time.
* The loadable conversion module resides in
* where fromcode is the source encoding and tocode is the target encoding.
* The module has 3 entries: _icv_open(), _icv_iconv(), _icv_close().
*/
{
char *ipath;
return ((iconv_t)-1);
/*
*/
return ((iconv_t)-1);
}
/* found a valid module for this conversion */
return (cd);
}
/*
* Now, try using the encoding name aliasing table
*/
/* no valid module for this conversion found */
/* errno set by iconv_search_alias */
return ((iconv_t)-1);
}
/* found a valid module for this conversion */
return (cd);
}
static size_t
{
char *p, *sp, *q;
p = addr;
while (q > p) {
if (*p == '#') {
/*
* Line beginning with '#' is a comment
*/
p++;
while ((q > p) && (*p++ != '\n'))
;
continue;
}
/* skip leading spaces */
while ((q > p) &&
((*p == ' ') || (*p == '\t')))
p++;
if (q <= p)
break;
sp = p;
while ((q > p) && (*p != ' ') &&
(*p != '\t') && (*p != '\n'))
p++;
if (q <= p) {
/* invalid entry */
break;
}
if (*p == '\n') {
/* invalid entry */
p++;
continue;
}
/*
* didn't match
*/
/* skip remaining chars in this line */
p++;
while ((q > p) && (*p++ != '\n'))
;
continue;
}
/* matching entry found */
/* skip spaces */
while ((q > p) &&
((*p == ' ') || (*p == '\t')))
p++;
if (q <= p)
break;
sp = p;
while ((q > p) && (*p != ' ') &&
(*p != '\t') && (*p != '\n'))
p++;
if (can_len == 0) {
while ((q > p) && (*p++ != '\n'))
;
continue;
}
return (can_len);
/* NOTREACHED */
}
return (0);
}
static iconv_p
{
int len;
/*
* First, try using the geniconvtbl conversion, which is
* performed by /usr/lib/iconv/geniconvtbl.so with
* the conversion table file:
* /usr/lib/iconv/geniconvtbl/binarytables/fromcode%tocode.bt
*
* If the geniconvtbl conversion cannot be done,
* try the conversion by the individual shared object.
*/
/*
* from%to.bt exists in the table dir
*/
/* found a valid module for this conversion */
return (cv);
}
}
/*
* errno will be set by iconv_open_private on error
*/
}
/* no valid module for this conversion found */
return ((iconv_p)-1);
}
static iconv_p
{
char *p;
char *to_canonical, *from_canonical;
int fd;
if (fd == -1) {
/*
* if no alias file found,
* errno will be set to EINVAL.
*/
return ((iconv_p)-1);
}
/* use errno set by fstat64 */
return ((iconv_p)-1);
}
if (addr == MAP_FAILED) {
/* use errno set by mmap */
return ((iconv_p)-1);
}
p = (char *)addr;
if (tolen) {
} else {
to_canonical = (char *)tocode;
}
p = (char *)addr;
if (fromlen) {
} else {
from_canonical = (char *)fromcode;
}
return ((iconv_p)-1);
}
/* errno set by iconv_open_all on error */
return (cv);
}
static iconv_p
{
return ((iconv_p)-1);
/* dlopen does not define error no */
return ((iconv_p)-1);
}
/* gets address of _icv_open */
"_icv_open")) == NULL) {
/* dlsym does not define errno */
return ((iconv_p)-1);
}
/*
* gets address of _icv_iconv in the loadable conversion module
* and stores it in cdpath->_icv_iconv
*/
"_icv_iconv")) == NULL) {
/* dlsym does not define errno */
return ((iconv_p)-1);
}
/*
* gets address of _icv_close in the loadable conversion module
* and stores it in cd->_icv_close
*/
"_icv_close")) == NULL) {
/* dlsym does not define errno */
return ((iconv_p)-1);
}
/*
* initialize the state of the actual _icv_iconv conversion routine
* For the normal iconv module, NULL will be passed as an argument
* although the _iconv_open() of the module won't use that.
*/
/* this module does not satisfy this conversion */
return ((iconv_p)-1);
}
return (cdpath);
}
int
{
return (-1);
}
return (0);
}
{
/* check if cd is valid */
return ((size_t)-1);
}
/* direct conversion */
}