1995-03-30 12:47:27 +00:00
|
|
|
/***********************************************************
|
|
|
|
Copyright 1990, by Alfalfa Software Incorporated, Cambridge, Massachusetts.
|
2010-01-25 23:37:49 +00:00
|
|
|
Copyright 2010, Gabor Kovesdan <gabor@FreeBSD.org>
|
1995-03-30 12:47:27 +00:00
|
|
|
|
|
|
|
All Rights Reserved
|
|
|
|
|
|
|
|
Permission to use, copy, modify, and distribute this software and its
|
|
|
|
documentation for any purpose and without fee is hereby granted,
|
|
|
|
provided that the above copyright notice appear in all copies and that
|
|
|
|
both that copyright notice and this permission notice appear in
|
|
|
|
supporting documentation, and that Alfalfa's name not be used in
|
|
|
|
advertising or publicity pertaining to distribution of the software
|
|
|
|
without specific, written prior permission.
|
|
|
|
|
|
|
|
ALPHALPHA DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
|
|
|
|
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
|
|
|
|
ALPHALPHA BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
|
|
|
|
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
|
|
|
|
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
|
|
|
|
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
|
|
|
SOFTWARE.
|
|
|
|
|
|
|
|
If you make any modifications, bugfixes or other changes to this software
|
|
|
|
we'd appreciate it if you could send a copy to us so we can keep things
|
|
|
|
up-to-date. Many thanks.
|
|
|
|
Kee Hinckley
|
|
|
|
Alfalfa Software, Inc.
|
|
|
|
267 Allston St., #3
|
|
|
|
Cambridge, MA 02139 USA
|
|
|
|
nazgul@alfalfa.com
|
1995-05-30 05:51:47 +00:00
|
|
|
|
1995-03-30 12:47:27 +00:00
|
|
|
******************************************************************/
|
|
|
|
|
2002-03-22 21:53:29 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
1995-03-30 12:47:27 +00:00
|
|
|
|
2005-02-27 16:26:49 +00:00
|
|
|
#define _NLS_PRIVATE
|
1995-03-30 12:47:27 +00:00
|
|
|
|
2001-01-24 13:01:12 +00:00
|
|
|
#include "namespace.h"
|
1995-03-30 12:47:27 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
2005-02-27 16:26:49 +00:00
|
|
|
#include <sys/mman.h>
|
2010-01-25 23:37:49 +00:00
|
|
|
#include <sys/queue.h>
|
2005-02-27 16:26:49 +00:00
|
|
|
|
|
|
|
#include <arpa/inet.h> /* for ntohl() */
|
2002-10-27 17:44:33 +00:00
|
|
|
|
1998-07-14 18:27:43 +00:00
|
|
|
#include <errno.h>
|
1995-03-30 12:47:27 +00:00
|
|
|
#include <fcntl.h>
|
2002-10-27 17:44:33 +00:00
|
|
|
#include <limits.h>
|
1998-04-30 11:06:12 +00:00
|
|
|
#include <locale.h>
|
2000-09-01 12:19:00 +00:00
|
|
|
#include <nl_types.h>
|
2010-01-25 23:37:49 +00:00
|
|
|
#include <pthread.h>
|
1995-03-30 12:47:27 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
2001-01-24 13:01:12 +00:00
|
|
|
#include "un-namespace.h"
|
1995-03-30 12:47:27 +00:00
|
|
|
|
2002-08-04 14:03:59 +00:00
|
|
|
#include "../locale/setlocale.h" /* for ENCODING_LEN */
|
2000-09-01 12:19:00 +00:00
|
|
|
|
2000-09-04 12:09:40 +00:00
|
|
|
#define _DEFAULT_NLS_PATH "/usr/share/nls/%L/%N.cat:/usr/share/nls/%N/%L:/usr/local/share/nls/%L/%N.cat:/usr/local/share/nls/%N/%L"
|
|
|
|
|
2010-01-25 23:37:49 +00:00
|
|
|
#define RLOCK(fail) { int ret; \
|
|
|
|
if (__isthreaded && \
|
|
|
|
((ret = _pthread_rwlock_rdlock(&rwlock)) != 0)) { \
|
|
|
|
errno = ret; \
|
|
|
|
return (fail); \
|
|
|
|
}}
|
|
|
|
#define WLOCK(fail) { int ret; \
|
|
|
|
if (__isthreaded && \
|
|
|
|
((ret = _pthread_rwlock_wrlock(&rwlock)) != 0)) { \
|
|
|
|
errno = ret; \
|
|
|
|
return (fail); \
|
|
|
|
}}
|
|
|
|
#define UNLOCK { if (__isthreaded) \
|
|
|
|
_pthread_rwlock_unlock(&rwlock); }
|
|
|
|
|
2000-09-04 12:09:40 +00:00
|
|
|
#define NLERR ((nl_catd) -1)
|
2002-08-04 14:03:59 +00:00
|
|
|
#define NLRETERR(errc) { errno = errc; return (NLERR); }
|
2010-01-25 23:37:49 +00:00
|
|
|
#define SAVEFAIL(n, e) { WLOCK(NLERR); \
|
|
|
|
np = malloc(sizeof(struct catentry)); \
|
|
|
|
if (np != NULL) { \
|
|
|
|
np->name = strdup(n); \
|
|
|
|
np->caterrno = e; \
|
|
|
|
SLIST_INSERT_HEAD(&cache, np, list); \
|
|
|
|
} \
|
|
|
|
UNLOCK; \
|
|
|
|
}
|
|
|
|
|
|
|
|
static nl_catd load_msgcat(const char *, const char *, const char *);
|
|
|
|
|
|
|
|
static pthread_rwlock_t rwlock;
|
1995-03-30 12:47:27 +00:00
|
|
|
|
2010-01-25 23:37:49 +00:00
|
|
|
struct catentry {
|
|
|
|
SLIST_ENTRY(catentry) list;
|
|
|
|
char *name;
|
|
|
|
char *path;
|
|
|
|
int caterrno;
|
|
|
|
nl_catd catd;
|
|
|
|
char *lang;
|
|
|
|
int refcount;
|
|
|
|
};
|
|
|
|
|
|
|
|
SLIST_HEAD(listhead, catentry) cache =
|
|
|
|
SLIST_HEAD_INITIALIZER(cache);
|
1995-03-30 12:47:27 +00:00
|
|
|
|
2000-09-04 12:09:40 +00:00
|
|
|
nl_catd
|
2005-02-27 16:26:49 +00:00
|
|
|
catopen(const char *name, int type)
|
1995-03-30 12:47:27 +00:00
|
|
|
{
|
2010-01-25 23:44:00 +00:00
|
|
|
int spcleft, saverr;
|
|
|
|
char path[PATH_MAX];
|
|
|
|
char *nlspath, *lang, *base, *cptr, *pathP, *tmpptr;
|
|
|
|
char *cptr1, *plang, *pter, *pcode;
|
|
|
|
struct stat sbuf;
|
2010-01-25 23:37:49 +00:00
|
|
|
struct catentry *np;
|
2002-08-04 14:03:59 +00:00
|
|
|
|
|
|
|
if (name == NULL || *name == '\0')
|
|
|
|
NLRETERR(EINVAL);
|
|
|
|
|
|
|
|
if (strchr(name, '/') != NULL)
|
2010-01-25 23:37:49 +00:00
|
|
|
lang = NULL;
|
|
|
|
else {
|
2010-01-25 23:44:00 +00:00
|
|
|
if (type == NL_CAT_LOCALE)
|
|
|
|
lang = setlocale(LC_MESSAGES, NULL);
|
|
|
|
else
|
|
|
|
lang = getenv("LANG");
|
|
|
|
|
|
|
|
if (lang == NULL || *lang == '\0' || strlen(lang) > ENCODING_LEN ||
|
|
|
|
(lang[0] == '.' &&
|
|
|
|
(lang[1] == '\0' || (lang[1] == '.' && lang[2] == '\0'))) ||
|
|
|
|
strchr(lang, '/') != NULL)
|
|
|
|
lang = "C";
|
2010-01-25 23:37:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Try to get it from the cache first */
|
|
|
|
RLOCK(NLERR);
|
|
|
|
SLIST_FOREACH(np, &cache, list) {
|
|
|
|
if (strcmp(np->name, name) == 0) {
|
|
|
|
if (np->caterrno != 0) {
|
|
|
|
/* Found cached failing entry */
|
|
|
|
UNLOCK;
|
|
|
|
NLRETERR(np->caterrno);
|
|
|
|
} else if (strcmp(np->lang, lang) == 0) {
|
|
|
|
/* Found cached successful entry */
|
|
|
|
np->refcount++;
|
|
|
|
UNLOCK;
|
|
|
|
return (np->catd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
UNLOCK;
|
|
|
|
|
|
|
|
/* is it absolute path ? if yes, load immediately */
|
|
|
|
if (strchr(name, '/') != NULL)
|
|
|
|
return (load_msgcat(name, name, lang));
|
2002-08-04 14:03:59 +00:00
|
|
|
|
2002-08-12 11:47:19 +00:00
|
|
|
if ((plang = cptr1 = strdup(lang)) == NULL)
|
2002-08-04 14:03:59 +00:00
|
|
|
return (NLERR);
|
|
|
|
if ((cptr = strchr(cptr1, '@')) != NULL)
|
|
|
|
*cptr = '\0';
|
|
|
|
pter = pcode = "";
|
|
|
|
if ((cptr = strchr(cptr1, '_')) != NULL) {
|
|
|
|
*cptr++ = '\0';
|
|
|
|
pter = cptr1 = cptr;
|
|
|
|
}
|
|
|
|
if ((cptr = strchr(cptr1, '.')) != NULL) {
|
|
|
|
*cptr++ = '\0';
|
|
|
|
pcode = cptr;
|
|
|
|
}
|
2000-09-04 12:09:40 +00:00
|
|
|
|
2003-10-29 10:45:01 +00:00
|
|
|
if ((nlspath = getenv("NLSPATH")) == NULL || issetugid())
|
2002-08-04 14:03:59 +00:00
|
|
|
nlspath = _DEFAULT_NLS_PATH;
|
|
|
|
|
|
|
|
if ((base = cptr = strdup(nlspath)) == NULL) {
|
2002-08-12 11:47:19 +00:00
|
|
|
saverr = errno;
|
2002-08-04 14:03:59 +00:00
|
|
|
free(plang);
|
2002-08-12 11:47:19 +00:00
|
|
|
errno = saverr;
|
2002-08-04 14:03:59 +00:00
|
|
|
return (NLERR);
|
|
|
|
}
|
2000-09-04 12:09:40 +00:00
|
|
|
|
2002-08-04 14:03:59 +00:00
|
|
|
while ((nlspath = strsep(&cptr, ":")) != NULL) {
|
|
|
|
pathP = path;
|
|
|
|
if (*nlspath) {
|
|
|
|
for (; *nlspath; ++nlspath) {
|
|
|
|
if (*nlspath == '%') {
|
|
|
|
switch (*(nlspath + 1)) {
|
|
|
|
case 'l':
|
|
|
|
tmpptr = plang;
|
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
tmpptr = pter;
|
|
|
|
break;
|
|
|
|
case 'c':
|
|
|
|
tmpptr = pcode;
|
|
|
|
break;
|
|
|
|
case 'L':
|
|
|
|
tmpptr = lang;
|
|
|
|
break;
|
|
|
|
case 'N':
|
|
|
|
tmpptr = (char *)name;
|
|
|
|
break;
|
|
|
|
case '%':
|
|
|
|
++nlspath;
|
|
|
|
/* fallthrough */
|
|
|
|
default:
|
|
|
|
if (pathP - path >=
|
|
|
|
sizeof(path) - 1)
|
|
|
|
goto too_long;
|
|
|
|
*(pathP++) = *nlspath;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
++nlspath;
|
|
|
|
put_tmpptr:
|
|
|
|
spcleft = sizeof(path) -
|
|
|
|
(pathP - path) - 1;
|
2003-05-01 19:03:14 +00:00
|
|
|
if (strlcpy(pathP, tmpptr, spcleft) >=
|
2002-08-04 14:03:59 +00:00
|
|
|
spcleft) {
|
2005-02-01 16:04:55 +00:00
|
|
|
too_long:
|
2002-08-04 14:03:59 +00:00
|
|
|
free(plang);
|
|
|
|
free(base);
|
|
|
|
NLRETERR(ENAMETOOLONG);
|
|
|
|
}
|
|
|
|
pathP += strlen(tmpptr);
|
|
|
|
} else {
|
|
|
|
if (pathP - path >= sizeof(path) - 1)
|
|
|
|
goto too_long;
|
|
|
|
*(pathP++) = *nlspath;
|
|
|
|
}
|
2000-09-04 12:09:40 +00:00
|
|
|
}
|
2002-08-04 14:03:59 +00:00
|
|
|
*pathP = '\0';
|
|
|
|
if (stat(path, &sbuf) == 0) {
|
2000-09-05 14:04:21 +00:00
|
|
|
free(plang);
|
2000-09-01 11:56:31 +00:00
|
|
|
free(base);
|
2010-01-25 23:37:49 +00:00
|
|
|
return (load_msgcat(path, name, lang));
|
2000-09-04 12:09:40 +00:00
|
|
|
}
|
2002-08-04 14:03:59 +00:00
|
|
|
} else {
|
|
|
|
tmpptr = (char *)name;
|
|
|
|
--nlspath;
|
|
|
|
goto put_tmpptr;
|
1995-03-30 12:47:27 +00:00
|
|
|
}
|
|
|
|
}
|
2002-08-04 14:03:59 +00:00
|
|
|
free(plang);
|
|
|
|
free(base);
|
|
|
|
NLRETERR(ENOENT);
|
1995-03-30 12:47:27 +00:00
|
|
|
}
|
|
|
|
|
2005-02-27 16:26:49 +00:00
|
|
|
char *
|
|
|
|
catgets(nl_catd catd, int set_id, int msg_id, const char *s)
|
|
|
|
{
|
2010-01-25 23:44:00 +00:00
|
|
|
struct _nls_cat_hdr *cat_hdr;
|
|
|
|
struct _nls_set_hdr *set_hdr;
|
|
|
|
struct _nls_msg_hdr *msg_hdr;
|
|
|
|
int l, u, i, r;
|
2000-09-04 12:09:40 +00:00
|
|
|
|
2005-02-27 16:26:49 +00:00
|
|
|
if (catd == NULL || catd == NLERR) {
|
|
|
|
errno = EBADF;
|
|
|
|
/* LINTED interface problem */
|
2010-01-25 23:37:49 +00:00
|
|
|
return ((char *)s);
|
|
|
|
}
|
1995-03-30 12:47:27 +00:00
|
|
|
|
2010-01-25 23:37:49 +00:00
|
|
|
cat_hdr = (struct _nls_cat_hdr *)catd->__data;
|
|
|
|
set_hdr = (struct _nls_set_hdr *)(void *)((char *)catd->__data +
|
|
|
|
sizeof(struct _nls_cat_hdr));
|
2005-02-27 16:26:49 +00:00
|
|
|
|
|
|
|
/* binary search, see knuth algorithm b */
|
|
|
|
l = 0;
|
|
|
|
u = ntohl((u_int32_t)cat_hdr->__nsets) - 1;
|
|
|
|
while (l <= u) {
|
|
|
|
i = (l + u) / 2;
|
|
|
|
r = set_id - ntohl((u_int32_t)set_hdr[i].__setno);
|
|
|
|
|
|
|
|
if (r == 0) {
|
|
|
|
msg_hdr = (struct _nls_msg_hdr *)
|
|
|
|
(void *)((char *)catd->__data +
|
|
|
|
sizeof(struct _nls_cat_hdr) +
|
|
|
|
ntohl((u_int32_t)cat_hdr->__msg_hdr_offset));
|
|
|
|
|
|
|
|
l = ntohl((u_int32_t)set_hdr[i].__index);
|
|
|
|
u = l + ntohl((u_int32_t)set_hdr[i].__nmsgs) - 1;
|
|
|
|
while (l <= u) {
|
|
|
|
i = (l + u) / 2;
|
|
|
|
r = msg_id -
|
|
|
|
ntohl((u_int32_t)msg_hdr[i].__msgno);
|
|
|
|
if (r == 0) {
|
|
|
|
return ((char *) catd->__data +
|
|
|
|
sizeof(struct _nls_cat_hdr) +
|
|
|
|
ntohl((u_int32_t)
|
|
|
|
cat_hdr->__msg_txt_offset) +
|
|
|
|
ntohl((u_int32_t)
|
|
|
|
msg_hdr[i].__offset));
|
|
|
|
} else if (r < 0) {
|
|
|
|
u = i - 1;
|
|
|
|
} else {
|
|
|
|
l = i + 1;
|
|
|
|
}
|
2010-01-25 23:37:49 +00:00
|
|
|
}
|
1995-05-30 05:51:47 +00:00
|
|
|
|
2005-02-27 16:26:49 +00:00
|
|
|
/* not found */
|
|
|
|
goto notfound;
|
1995-05-30 05:51:47 +00:00
|
|
|
|
2005-02-27 16:26:49 +00:00
|
|
|
} else if (r < 0) {
|
|
|
|
u = i - 1;
|
|
|
|
} else {
|
|
|
|
l = i + 1;
|
|
|
|
}
|
2010-01-25 23:37:49 +00:00
|
|
|
}
|
1995-03-30 12:47:27 +00:00
|
|
|
|
2005-02-27 16:26:49 +00:00
|
|
|
notfound:
|
|
|
|
/* not found */
|
|
|
|
errno = ENOMSG;
|
|
|
|
/* LINTED interface problem */
|
2010-01-25 23:37:49 +00:00
|
|
|
return ((char *)s);
|
1995-03-30 12:47:27 +00:00
|
|
|
}
|
|
|
|
|
2000-09-04 12:09:40 +00:00
|
|
|
int
|
2005-02-01 16:04:55 +00:00
|
|
|
catclose(nl_catd catd)
|
1995-03-30 12:47:27 +00:00
|
|
|
{
|
2010-01-25 23:37:49 +00:00
|
|
|
struct catentry *np;
|
|
|
|
|
2002-08-04 14:03:59 +00:00
|
|
|
if (catd == NULL || catd == NLERR) {
|
|
|
|
errno = EBADF;
|
|
|
|
return (-1);
|
|
|
|
}
|
2005-02-01 16:04:55 +00:00
|
|
|
|
2010-01-25 23:37:49 +00:00
|
|
|
/* Remove from cache if not referenced any more */
|
|
|
|
WLOCK(-1);
|
|
|
|
SLIST_FOREACH(np, &cache, list) {
|
|
|
|
if ((np->catd->__size == catd->__size) &&
|
|
|
|
memcmp((const void *)np->catd, (const void *)catd, np->catd->__size) == 0) {
|
|
|
|
np->refcount--;
|
|
|
|
if (np->refcount == 0) {
|
2010-01-25 23:44:00 +00:00
|
|
|
munmap(catd->__data, (size_t)catd->__size);
|
|
|
|
free(catd);
|
2010-01-25 23:37:49 +00:00
|
|
|
SLIST_REMOVE(&cache, np, catentry, list);
|
|
|
|
free(np);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
UNLOCK;
|
2002-08-04 14:03:59 +00:00
|
|
|
return (0);
|
1995-03-30 12:47:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2005-02-27 16:26:49 +00:00
|
|
|
* Internal support functions
|
1995-03-30 12:47:27 +00:00
|
|
|
*/
|
|
|
|
|
2000-09-04 12:09:40 +00:00
|
|
|
static nl_catd
|
2010-01-25 23:37:49 +00:00
|
|
|
load_msgcat(const char *path, const char *name, const char *lang)
|
1995-03-30 12:47:27 +00:00
|
|
|
{
|
2010-01-25 23:44:00 +00:00
|
|
|
struct stat st;
|
|
|
|
nl_catd catd;
|
2010-01-25 23:37:49 +00:00
|
|
|
struct catentry *np;
|
2010-01-25 23:44:00 +00:00
|
|
|
void *data;
|
|
|
|
int fd;
|
2005-02-27 16:26:49 +00:00
|
|
|
|
2010-01-25 23:37:49 +00:00
|
|
|
/* path/name will never be NULL here */
|
|
|
|
|
|
|
|
/* One more try in cache; if it was not found by name,
|
|
|
|
it might still be found by absolute path. */
|
|
|
|
RLOCK(NLERR);
|
|
|
|
SLIST_FOREACH(np, &cache, list) {
|
|
|
|
if (strcmp(np->path, path) == 0) {
|
|
|
|
np->refcount++;
|
|
|
|
UNLOCK;
|
|
|
|
return (np->catd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
UNLOCK;
|
2005-02-27 16:26:49 +00:00
|
|
|
|
2010-01-25 23:37:49 +00:00
|
|
|
if ((fd = _open(path, O_RDONLY)) == -1) {
|
|
|
|
SAVEFAIL(name, errno);
|
2002-08-04 14:03:59 +00:00
|
|
|
return (NLERR);
|
2010-01-25 23:37:49 +00:00
|
|
|
}
|
2002-08-04 14:03:59 +00:00
|
|
|
|
2005-02-27 16:26:49 +00:00
|
|
|
if (_fstat(fd, &st) != 0) {
|
2010-01-25 23:37:49 +00:00
|
|
|
SAVEFAIL(name, errno);
|
2005-02-27 16:26:49 +00:00
|
|
|
_close(fd);
|
2002-08-04 14:03:59 +00:00
|
|
|
return (NLERR);
|
1997-05-10 04:40:40 +00:00
|
|
|
}
|
|
|
|
|
2005-02-27 16:26:49 +00:00
|
|
|
data = mmap(0, (size_t)st.st_size, PROT_READ, MAP_FILE|MAP_SHARED, fd,
|
|
|
|
(off_t)0);
|
|
|
|
_close(fd);
|
2002-08-04 14:03:59 +00:00
|
|
|
|
2010-01-25 23:37:49 +00:00
|
|
|
if (data == MAP_FAILED) {
|
|
|
|
SAVEFAIL(name, errno);
|
2005-02-27 16:26:49 +00:00
|
|
|
return (NLERR);
|
2010-01-25 23:37:49 +00:00
|
|
|
}
|
1995-03-30 12:47:27 +00:00
|
|
|
|
2005-02-27 16:26:49 +00:00
|
|
|
if (ntohl((u_int32_t)((struct _nls_cat_hdr *)data)->__magic) !=
|
|
|
|
_NLS_MAGIC) {
|
2010-01-25 23:37:49 +00:00
|
|
|
SAVEFAIL(name, errno);
|
2005-02-27 16:26:49 +00:00
|
|
|
munmap(data, (size_t)st.st_size);
|
|
|
|
NLRETERR(EINVAL);
|
1997-05-10 04:28:17 +00:00
|
|
|
}
|
2002-08-04 14:03:59 +00:00
|
|
|
|
2005-02-27 16:26:49 +00:00
|
|
|
if ((catd = malloc(sizeof (*catd))) == NULL) {
|
2010-01-25 23:37:49 +00:00
|
|
|
SAVEFAIL(name, errno);
|
2005-02-27 16:26:49 +00:00
|
|
|
munmap(data, (size_t)st.st_size);
|
|
|
|
return (NLERR);
|
2002-08-04 14:03:59 +00:00
|
|
|
}
|
|
|
|
|
2005-02-27 16:26:49 +00:00
|
|
|
catd->__data = data;
|
|
|
|
catd->__size = (int)st.st_size;
|
2010-01-25 23:37:49 +00:00
|
|
|
|
|
|
|
/* Caching opened catalog */
|
|
|
|
WLOCK(NLERR);
|
|
|
|
if ((np = malloc(sizeof(struct catentry))) != NULL) {
|
|
|
|
np->name = strdup(name);
|
|
|
|
np->path = strdup(path);
|
|
|
|
np->catd = catd;
|
|
|
|
np->lang = (lang == NULL) ? NULL : strdup(lang);
|
|
|
|
np->refcount = 1;
|
|
|
|
np->caterrno = 0;
|
|
|
|
SLIST_INSERT_HEAD(&cache, np, list);
|
|
|
|
}
|
|
|
|
UNLOCK;
|
2005-02-27 16:26:49 +00:00
|
|
|
return (catd);
|
1995-03-30 12:47:27 +00:00
|
|
|
}
|
2005-02-27 16:26:49 +00:00
|
|
|
|