2005-11-29 06:11:58 +03:00
|
|
|
/* $NetBSD: setrunelocale.c,v 1.16 2005/11/29 03:11:59 christos Exp $ */
|
2000-12-21 14:29:47 +03:00
|
|
|
|
|
|
|
/*-
|
|
|
|
* Copyright (c)1999 Citrus Project,
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2000-12-21 21:22:56 +03:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 1998 The NetBSD Foundation, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Paul Kranenburg.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the NetBSD
|
|
|
|
* Foundation, Inc. and its contributors.
|
|
|
|
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2000-12-21 14:29:47 +03:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to Berkeley by
|
|
|
|
* Paul Borman at Krystal Technologies.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2003-08-07 20:42:00 +04:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
2000-12-21 14:29:47 +03:00
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
#if defined(LIBC_SCCS) && !defined(lint)
|
2005-11-29 06:11:58 +03:00
|
|
|
__RCSID("$NetBSD: setrunelocale.c,v 1.16 2005/11/29 03:11:59 christos Exp $");
|
2000-12-21 14:29:47 +03:00
|
|
|
#endif /* LIBC_SCCS and not lint */
|
|
|
|
|
2002-04-17 17:40:35 +04:00
|
|
|
#include "namespace.h"
|
2001-01-25 04:25:05 +03:00
|
|
|
|
2000-12-21 14:29:47 +03:00
|
|
|
#include "rune.h"
|
2001-01-03 18:23:26 +03:00
|
|
|
#include <assert.h>
|
2000-12-21 14:29:47 +03:00
|
|
|
#include <errno.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
refine i18n stuffs.
- add libc/citrus directory.
this directory contains the common stuffs not only for locale
but also other facilities relating to i18n (e.g. iconv).
- To keep the binary compatibility for the ctype modules easily,
the interface between libc and the modules is simplified.
- For the future integrated extension, module pool is renamed
from "/usr/lib/runemodule" to "/usr/lib/i18n".
In the future, this directory will contain the modules for "iconv",
"collation", etc.
- some cosmetic changes.
- Bug fix for runetype.h; __attribute__((__packed__)) is placed at
the wrong position and it is invalid unintentionally.
But, the all members of the structures seem well-aligned. Thus,
this bug causes no problem, hopefully.
HEADS UP:
- /usr/lib/rumemodule is obsoleted. If you use the multibyte locales,
you need to install /usr/lib/i18n/* from sys/lib/i18n_module .
- The binary compatibility of /usr/share/locale/*/LC_CTYPE is probably kept.
Perhaps, the bug fix about __packed__ mentioned above breaks the
compatibility... Be careful especially on 64bit platforms.
2002-03-18 01:14:05 +03:00
|
|
|
#include <stddef.h>
|
2000-12-21 14:29:47 +03:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <locale.h>
|
refine i18n stuffs.
- add libc/citrus directory.
this directory contains the common stuffs not only for locale
but also other facilities relating to i18n (e.g. iconv).
- To keep the binary compatibility for the ctype modules easily,
the interface between libc and the modules is simplified.
- For the future integrated extension, module pool is renamed
from "/usr/lib/runemodule" to "/usr/lib/i18n".
In the future, this directory will contain the modules for "iconv",
"collation", etc.
- some cosmetic changes.
- Bug fix for runetype.h; __attribute__((__packed__)) is placed at
the wrong position and it is invalid unintentionally.
But, the all members of the structures seem well-aligned. Thus,
this bug causes no problem, hopefully.
HEADS UP:
- /usr/lib/rumemodule is obsoleted. If you use the multibyte locales,
you need to install /usr/lib/i18n/* from sys/lib/i18n_module .
- The binary compatibility of /usr/share/locale/*/LC_CTYPE is probably kept.
Perhaps, the bug fix about __packed__ mentioned above breaks the
compatibility... Be careful especially on 64bit platforms.
2002-03-18 01:14:05 +03:00
|
|
|
#include <citrus/citrus_module.h>
|
|
|
|
#include <citrus/citrus_ctype.h>
|
2000-12-21 14:29:47 +03:00
|
|
|
#include "rune_local.h"
|
2002-03-19 01:58:44 +03:00
|
|
|
#include "multibyte.h"
|
2000-12-21 14:29:47 +03:00
|
|
|
|
|
|
|
struct localetable {
|
|
|
|
char path[PATH_MAX];
|
|
|
|
_RuneLocale *runelocale;
|
|
|
|
struct localetable *next;
|
|
|
|
};
|
2002-03-18 14:49:19 +03:00
|
|
|
static struct localetable *localetable_head;
|
2000-12-21 14:29:47 +03:00
|
|
|
|
|
|
|
_RuneLocale *
|
|
|
|
_findrunelocale(path)
|
|
|
|
char *path;
|
|
|
|
{
|
|
|
|
struct localetable *lt;
|
|
|
|
|
2001-01-03 18:23:26 +03:00
|
|
|
_DIAGASSERT(path != NULL);
|
|
|
|
|
2000-12-21 14:29:47 +03:00
|
|
|
/* ones which we have seen already */
|
2002-03-18 14:49:19 +03:00
|
|
|
for (lt = localetable_head; lt; lt = lt->next)
|
2000-12-21 14:29:47 +03:00
|
|
|
if (strcmp(path, lt->path) == 0)
|
|
|
|
return lt->runelocale;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
_newrunelocale(path)
|
|
|
|
char *path;
|
|
|
|
{
|
|
|
|
struct localetable *lt;
|
|
|
|
FILE *fp;
|
|
|
|
_RuneLocale *rl;
|
2001-01-25 04:25:05 +03:00
|
|
|
int ret;
|
2000-12-21 14:29:47 +03:00
|
|
|
|
2005-10-20 02:57:03 +04:00
|
|
|
_DIAGASSERT(path != NULL);
|
2001-01-03 18:23:26 +03:00
|
|
|
|
2005-10-20 02:57:03 +04:00
|
|
|
if (strlen(path) + 1 > sizeof(lt->path))
|
|
|
|
return EINVAL;
|
2000-12-21 14:29:47 +03:00
|
|
|
|
|
|
|
rl = _findrunelocale(path);
|
|
|
|
if (rl)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if ((fp = fopen(path, "r")) == NULL)
|
|
|
|
return ENOENT;
|
|
|
|
|
|
|
|
if ((rl = _Read_RuneMagi(fp)) != NULL)
|
|
|
|
goto found;
|
|
|
|
/* necessary for backward compatibility */
|
|
|
|
if ((rl = _Read_CTypeAsRune(fp)) != NULL)
|
|
|
|
goto found;
|
|
|
|
|
|
|
|
fclose(fp);
|
|
|
|
return EFTYPE;
|
|
|
|
|
|
|
|
found:
|
|
|
|
fclose(fp);
|
|
|
|
|
refine i18n stuffs.
- add libc/citrus directory.
this directory contains the common stuffs not only for locale
but also other facilities relating to i18n (e.g. iconv).
- To keep the binary compatibility for the ctype modules easily,
the interface between libc and the modules is simplified.
- For the future integrated extension, module pool is renamed
from "/usr/lib/runemodule" to "/usr/lib/i18n".
In the future, this directory will contain the modules for "iconv",
"collation", etc.
- some cosmetic changes.
- Bug fix for runetype.h; __attribute__((__packed__)) is placed at
the wrong position and it is invalid unintentionally.
But, the all members of the structures seem well-aligned. Thus,
this bug causes no problem, hopefully.
HEADS UP:
- /usr/lib/rumemodule is obsoleted. If you use the multibyte locales,
you need to install /usr/lib/i18n/* from sys/lib/i18n_module .
- The binary compatibility of /usr/share/locale/*/LC_CTYPE is probably kept.
Perhaps, the bug fix about __packed__ mentioned above breaks the
compatibility... Be careful especially on 64bit platforms.
2002-03-18 01:14:05 +03:00
|
|
|
rl->rl_citrus_ctype = NULL;
|
|
|
|
ret = _citrus_ctype_open(&rl->rl_citrus_ctype, rl->rl_encoding,
|
|
|
|
rl->rl_variable, rl->rl_variable_len,
|
|
|
|
_PRIVSIZE);
|
2000-12-21 14:29:47 +03:00
|
|
|
if (ret) {
|
|
|
|
_NukeRune(rl);
|
|
|
|
return ret;
|
|
|
|
}
|
refine i18n stuffs.
- add libc/citrus directory.
this directory contains the common stuffs not only for locale
but also other facilities relating to i18n (e.g. iconv).
- To keep the binary compatibility for the ctype modules easily,
the interface between libc and the modules is simplified.
- For the future integrated extension, module pool is renamed
from "/usr/lib/runemodule" to "/usr/lib/i18n".
In the future, this directory will contain the modules for "iconv",
"collation", etc.
- some cosmetic changes.
- Bug fix for runetype.h; __attribute__((__packed__)) is placed at
the wrong position and it is invalid unintentionally.
But, the all members of the structures seem well-aligned. Thus,
this bug causes no problem, hopefully.
HEADS UP:
- /usr/lib/rumemodule is obsoleted. If you use the multibyte locales,
you need to install /usr/lib/i18n/* from sys/lib/i18n_module .
- The binary compatibility of /usr/share/locale/*/LC_CTYPE is probably kept.
Perhaps, the bug fix about __packed__ mentioned above breaks the
compatibility... Be careful especially on 64bit platforms.
2002-03-18 01:14:05 +03:00
|
|
|
if (__MB_LEN_MAX_RUNTIME <
|
|
|
|
_citrus_ctype_get_mb_cur_max(rl->rl_citrus_ctype)) {
|
2000-12-21 14:29:47 +03:00
|
|
|
_NukeRune(rl);
|
refine i18n stuffs.
- add libc/citrus directory.
this directory contains the common stuffs not only for locale
but also other facilities relating to i18n (e.g. iconv).
- To keep the binary compatibility for the ctype modules easily,
the interface between libc and the modules is simplified.
- For the future integrated extension, module pool is renamed
from "/usr/lib/runemodule" to "/usr/lib/i18n".
In the future, this directory will contain the modules for "iconv",
"collation", etc.
- some cosmetic changes.
- Bug fix for runetype.h; __attribute__((__packed__)) is placed at
the wrong position and it is invalid unintentionally.
But, the all members of the structures seem well-aligned. Thus,
this bug causes no problem, hopefully.
HEADS UP:
- /usr/lib/rumemodule is obsoleted. If you use the multibyte locales,
you need to install /usr/lib/i18n/* from sys/lib/i18n_module .
- The binary compatibility of /usr/share/locale/*/LC_CTYPE is probably kept.
Perhaps, the bug fix about __packed__ mentioned above breaks the
compatibility... Be careful especially on 64bit platforms.
2002-03-18 01:14:05 +03:00
|
|
|
return EINVAL;
|
2000-12-21 14:29:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* register it */
|
|
|
|
lt = malloc(sizeof(struct localetable));
|
2002-03-18 14:49:19 +03:00
|
|
|
if (lt == NULL) {
|
|
|
|
_NukeRune(rl);
|
|
|
|
return ENOMEM;
|
|
|
|
}
|
2000-12-21 14:29:47 +03:00
|
|
|
strlcpy(lt->path, path, sizeof(lt->path));
|
|
|
|
lt->runelocale = rl;
|
2002-03-18 14:49:19 +03:00
|
|
|
lt->next = localetable_head;
|
|
|
|
localetable_head = lt;
|
2000-12-21 14:29:47 +03:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
static int
|
|
|
|
delrunelocale(path)
|
|
|
|
char *path;
|
|
|
|
{
|
|
|
|
struct localetable *lt, *prev;
|
|
|
|
_RuneLocale *rl;
|
|
|
|
|
2001-01-03 18:23:26 +03:00
|
|
|
_DIAGASSERT(path != NULL);
|
|
|
|
|
2000-12-21 14:29:47 +03:00
|
|
|
prev = NULL;
|
2002-03-18 14:49:19 +03:00
|
|
|
for (lt = localetable_head; lt; prev = lt, lt = prev->next)
|
2000-12-21 14:29:47 +03:00
|
|
|
if (strcmp(path, lt->path) == 0)
|
|
|
|
break;
|
|
|
|
if (!lt)
|
|
|
|
return ENOENT;
|
|
|
|
|
|
|
|
/* remove runelocale registeration */
|
|
|
|
if (prev)
|
|
|
|
prev->next = lt->next;
|
|
|
|
else
|
2002-03-18 14:49:19 +03:00
|
|
|
localetable_head = lt->next;
|
2000-12-21 14:29:47 +03:00
|
|
|
lt->next = NULL;
|
|
|
|
free(lt);
|
|
|
|
|
|
|
|
/* cleanup everything */
|
|
|
|
rl = lt->runelocale;
|
refine i18n stuffs.
- add libc/citrus directory.
this directory contains the common stuffs not only for locale
but also other facilities relating to i18n (e.g. iconv).
- To keep the binary compatibility for the ctype modules easily,
the interface between libc and the modules is simplified.
- For the future integrated extension, module pool is renamed
from "/usr/lib/runemodule" to "/usr/lib/i18n".
In the future, this directory will contain the modules for "iconv",
"collation", etc.
- some cosmetic changes.
- Bug fix for runetype.h; __attribute__((__packed__)) is placed at
the wrong position and it is invalid unintentionally.
But, the all members of the structures seem well-aligned. Thus,
this bug causes no problem, hopefully.
HEADS UP:
- /usr/lib/rumemodule is obsoleted. If you use the multibyte locales,
you need to install /usr/lib/i18n/* from sys/lib/i18n_module .
- The binary compatibility of /usr/share/locale/*/LC_CTYPE is probably kept.
Perhaps, the bug fix about __packed__ mentioned above breaks the
compatibility... Be careful especially on 64bit platforms.
2002-03-18 01:14:05 +03:00
|
|
|
dlclose(rl->rl_rune_RuneModule);
|
|
|
|
rl->rl_rune_RuneModule = NULL;
|
2000-12-21 14:29:47 +03:00
|
|
|
_NukeRune(rl);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
int
|
|
|
|
_xpg4_setrunelocale(encoding)
|
2005-11-29 06:11:58 +03:00
|
|
|
const char *encoding;
|
2000-12-21 14:29:47 +03:00
|
|
|
{
|
|
|
|
char path[PATH_MAX];
|
|
|
|
_RuneLocale *rl;
|
|
|
|
int error;
|
|
|
|
|
2001-01-03 18:23:26 +03:00
|
|
|
_DIAGASSERT(encoding != NULL);
|
|
|
|
|
2000-12-21 14:29:47 +03:00
|
|
|
if (!strcmp(encoding, "C") || !strcmp(encoding, "POSIX")) {
|
|
|
|
rl = &_DefaultRuneLocale;
|
|
|
|
goto found;
|
|
|
|
}
|
|
|
|
|
|
|
|
snprintf(path, sizeof(path), "%s/%s/LC_CTYPE", _PathLocale, encoding);
|
|
|
|
|
|
|
|
error = _newrunelocale(path);
|
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
rl = _findrunelocale(path);
|
|
|
|
if (!rl)
|
|
|
|
return ENOENT;
|
|
|
|
|
|
|
|
found:
|
|
|
|
_CurrentRuneLocale = rl;
|
refine i18n stuffs.
- add libc/citrus directory.
this directory contains the common stuffs not only for locale
but also other facilities relating to i18n (e.g. iconv).
- To keep the binary compatibility for the ctype modules easily,
the interface between libc and the modules is simplified.
- For the future integrated extension, module pool is renamed
from "/usr/lib/runemodule" to "/usr/lib/i18n".
In the future, this directory will contain the modules for "iconv",
"collation", etc.
- some cosmetic changes.
- Bug fix for runetype.h; __attribute__((__packed__)) is placed at
the wrong position and it is invalid unintentionally.
But, the all members of the structures seem well-aligned. Thus,
this bug causes no problem, hopefully.
HEADS UP:
- /usr/lib/rumemodule is obsoleted. If you use the multibyte locales,
you need to install /usr/lib/i18n/* from sys/lib/i18n_module .
- The binary compatibility of /usr/share/locale/*/LC_CTYPE is probably kept.
Perhaps, the bug fix about __packed__ mentioned above breaks the
compatibility... Be careful especially on 64bit platforms.
2002-03-18 01:14:05 +03:00
|
|
|
__mb_cur_max = _citrus_ctype_get_mb_cur_max(rl->rl_citrus_ctype);
|
|
|
|
|
2000-12-21 14:29:47 +03:00
|
|
|
return 0;
|
|
|
|
}
|