/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (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
*/
/*
*/
/*
*
*/
#include "lint.h"
#include "libc.h"
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <nl_types.h>
#include <locale.h>
#include <limits.h>
#include <errno.h>
#include "../i18n/_loc_path.h"
#include "nlspath_checks.h"
#define UNSAFE_F 0
static char *replace_nls_option(char *, char *, char *, char *, char *,
char *, char *, int *);
static nl_catd process_nls_path(char *, int);
{
nl_catd p;
if (!name) { /* Null pointer */
return ((nl_catd)-1);
} else if (!*name) { /* Empty string */
return ((nl_catd)-1);
/* If name contains '/', then it is complete file name */
} else { /* Normal case */
}
if (p == NULL) { /* Opening catalog file failed */
return ((nl_catd)-1);
} else {
return (p);
}
}
static nl_catd
int *ltc_defined)
{
char *l;
char *t;
char *c;
char *s;
nl_catd p;
l = t = c = NULL;
/*
* Extract language, territory, and codeset codes from a locale
* name of the following naming convention:
*
* language[_territory][.codeset][@modifier]
*/
if (locale) {
l = s = libc_strdup(locale);
if (s == NULL)
return (NULL);
while (*s != '\0') {
if (*s == '_') {
*s++ = '\0';
t = s;
continue;
} else if (*s == '.') {
*s++ = '\0';
c = s;
continue;
} else if (*s == '@') {
*s = '\0';
break;
}
s++;
}
}
/*
* Process templates in NLSPATH.
* Unqualified pathnames are unsafe for file_open().
*/
s = nlspath;
while (*s) {
if (*s == ':') {
if (p != NULL) {
if (l)
libc_free(l);
return (p);
}
s++;
continue;
}
if (p != NULL) {
if (l)
libc_free(l);
return (p);
}
if (*s == '\0')
break;
s++;
}
if (l)
libc_free(l);
return (NULL);
}
static nl_catd
{
return (NULL);
saved += len_locale;
*saved = '\0';
}
/*
* This routine will try to find the catalog file by processing NLSPATH
* environment variable and then from the system default location. If
* the current locale name will not yield a catalog file, it will also try to
* obtain alternative locales names, i.e., obsoleted Solaris locale names and
* canonical locale name for the current locale name, if any, and then
* search again the catalog file with the alternative locale names.
*
* It will return a catd id if it finds a valid catalog file; otherwise, NULL.
*/
static nl_catd
{
char *nlspath;
char *locale;
char *canonical;
char *saved;
nl_catd p;
int ltc_defined;
int start;
int end;
/*
* locale=language_territory.codeset
* XPG4 uses LC_MESSAGES.
* XPG3 uses LANG.
* From the following two lines, choose one depending on XPG3 or 4.
*
* Chose XPG4. If oflag == NL_CAT_LOCALE, use LC_MESSAGES.
*/
if (oflag == NL_CAT_LOCALE)
else
ltc_defined = 0;
if (nlspath) {
<c_defined);
if (p != NULL)
return (p);
}
/*
* Implementation dependent default location of XPG3.
* If C locale, do not translate message.
*/
return (NULL);
p = libc_malloc(sizeof (struct _nl_catd_struct));
if (p == NULL) {
/* malloc failed */
return (NULL);
}
p->__size = 0;
p->__trust = 1;
return (p);
}
if (p != NULL)
return (p);
/*
* As the last resort, search again with obsoleted Solaris locale
* names and possibly also the canonical locale name for the current
* locale name as specified in PSARC/2009/594.
*/
if (start != -1) {
if (ltc_defined == 1) {
(char *)__lc_obs_msg_lc_list[start],
nlspath, <c_defined);
if (p != NULL)
return (p);
}
if (p != NULL)
return (p);
}
}
if (ltc_defined == 1) {
nlspath, <c_defined);
if (p != NULL)
return (p);
}
if (p != NULL)
return (p);
}
return (NULL);
}
/*
* This routine will replace substitution parameters in NLSPATH
* with appropriate values. Returns expanded path.
*/
static char *
{
char *t, *u;
char *limit;
t = path;
while (*s && *s != ':') {
if (t < limit) {
/*
* %% is considered a single % character (XPG).
* %L : LC_MESSAGES (XPG4) LANG(XPG3)
* %l : The language element from the current locale.
* (XPG3, XPG4)
*/
if (*s != '%')
*t++ = *s;
else if (*++s == 'N') {
u = name;
while (*u && t < limit)
*t++ = *u++;
} else if (*s == 'L') {
if (locale) {
u = locale;
while (*u && t < limit)
*t++ = *u++;
}
*ltc_defined = 1;
} else if (*s == 'l') {
if (lang) {
u = lang;
while (*u && *u != '_' && t < limit)
*t++ = *u++;
}
*ltc_defined = 1;
} else if (*s == 't') {
if (territory) {
u = territory;
while (*u && *u != '.' && t < limit)
*t++ = *u++;
}
*ltc_defined = 1;
} else if (*s == 'c') {
if (codeset) {
u = codeset;
while (*u && t < limit)
*t++ = *u++;
}
*ltc_defined = 1;
} else {
if (t < limit)
*t++ = *s;
}
}
++s;
}
*t = '\0';
return (s);
}
/*
* This routine will open file, mmap it, and return catd id.
*/
static nl_catd
{
int fd;
void *addr;
int trust;
if (fd == -1) {
return (NULL);
}
if (addr == MAP_FAILED) {
return (NULL);
}
/* check MAGIC number of catalogue file */
return (NULL);
}
/* malloc failed */
return (NULL);
}
return (tmp_catd);
}
int
{
if (catd &&
}
}
return (0);
}