/*
* 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
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
*
*/
#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 *);
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);
}
}
/*
* This routine will process NLSPATH environment variable.
* It will return catd id whenever it finds valid catalog.
*/
static nl_catd
{
nl_catd p;
/*
* 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 {
}
if (nlspath) {
/*
* extract lang, territory and codeset from locale name
*/
if (locale) {
if (!lang) {
/* strdup failed */
return (NULL);
}
while (s && *s) {
if (*s == '_') {
s1 = s;
} else if (*s == '.') {
s2 = s;
}
s++;
}
} /* if (locale) */
/*
* March through NLSPATH until finds valid cat file
*/
s = nlspath;
while (*s) {
if (*s == ':') {
/* unqualified pathname is unsafe */
if (p != NULL) {
if (lang)
return (p);
}
++s;
continue;
}
/* replace Substitution field */
if (p != NULL) {
if (lang)
return (p);
}
if (*s)
++s;
} /* while */
} /* if (nlspath) */
/* lang is not used any more, free it */
if (lang)
/*
* 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);
}
s = _DFLT_LOC_PATH;
t = pathname;
while (*t++ = *s++)
continue;
t--;
s = locale;
*t++ = *s++;
s = "/LC_MESSAGES/";
*t++ = *s++;
s = name;
*t++ = *s++;
*t = NULL;
}
/*
* This routine will replace substitution parameters in NLSPATH
* with appropiate values. Returns expanded pathname.
*/
static char *
{
char *t, *u;
t = pathname;
while (*s && *s != ':') {
/*
* %% 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;
*t++ = *u++;
} else if (*s == 'L') {
if (locale) {
u = locale;
*t++ = *u++;
}
} else if (*s == 'l') {
if (lang) {
u = lang;
while (*u && *u != '_' &&
*t++ = *u++;
}
} else if (*s == 't') {
if (territory) {
u = territory;
while (*u && *u != '.' &&
*t++ = *u++;
}
} else if (*s == 'c') {
if (codeset) {
u = codeset;
*t++ = *u++;
}
} else {
*t++ = *s;
}
}
++s;
}
*t = NULL;
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);
}