summaryrefslogtreecommitdiff
path: root/lib/libc
diff options
context:
space:
mode:
authorAndrey A. Chernov <ache@FreeBSD.org>2000-09-07 16:46:33 +0000
committerAndrey A. Chernov <ache@FreeBSD.org>2000-09-07 16:46:33 +0000
commitcc13a2cc6d1aa0085feb1f206d0b73ee09bfdc2e (patch)
tree09517871208a8a7a4c78fe9ecd21f7a66c5a1ee7 /lib/libc
parent94e00feef2e1df6a6bfff127a34f3a1ff9fdb997 (diff)
Notes
Diffstat (limited to 'lib/libc')
-rw-r--r--lib/libc/nls/Makefile.inc2
-rw-r--r--lib/libc/nls/catclose.317
-rw-r--r--lib/libc/nls/catclose.c25
-rw-r--r--lib/libc/nls/catgets.35
-rw-r--r--lib/libc/nls/catgets.c28
-rw-r--r--lib/libc/nls/catopen.361
-rw-r--r--lib/libc/nls/catopen.c26
-rw-r--r--lib/libc/nls/msgcat.c467
-rw-r--r--lib/libc/nls/msgcat.h23
9 files changed, 307 insertions, 347 deletions
diff --git a/lib/libc/nls/Makefile.inc b/lib/libc/nls/Makefile.inc
index 56a664da510a..06e7de7727f5 100644
--- a/lib/libc/nls/Makefile.inc
+++ b/lib/libc/nls/Makefile.inc
@@ -3,7 +3,7 @@
.PATH: ${.CURDIR}/../libc/nls
-SRCS+= catclose.c catgets.c catopen.c msgcat.c
+SRCS+= msgcat.c
.if ${LIB} == "c"
MAN3+= catclose.3 catgets.3 catopen.3
diff --git a/lib/libc/nls/catclose.3 b/lib/libc/nls/catclose.3
index d62aa13a5b81..7405852a8740 100644
--- a/lib/libc/nls/catclose.3
+++ b/lib/libc/nls/catclose.3
@@ -1,5 +1,3 @@
-.\" $FreeBSD$
-.\"
.\" Copyright (c) 1994 Winning Strategies, Inc.
.\" All rights reserved.
.\"
@@ -28,6 +26,7 @@
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
+.\" $FreeBSD$
.Dd May 29, 1994
.Dt CATCLOSE 3
.Os
@@ -45,6 +44,20 @@ The
.Fn catclose
function closes the message catalog specified by the argument
.Fa catd .
+.Sh RETURN VALUES
+Upon successful completion,
+.Fn catclose
+returns 0.
+Otherwise, -1 is returned and
+.Va errno
+is set to indicate the error.
+.Sh ERRORS
+.Bl -tag -width Er
+.It Bq Er EBADF
+An invalid message catalog descriptor was passed by the
+.Fa catd
+argument.
+.El
.Sh SEE ALSO
.Xr gencat 1 ,
.Xr catgets 3 ,
diff --git a/lib/libc/nls/catclose.c b/lib/libc/nls/catclose.c
deleted file mode 100644
index a7326669059d..000000000000
--- a/lib/libc/nls/catclose.c
+++ /dev/null
@@ -1,25 +0,0 @@
-/* $FreeBSD$ */
-
-/*
- * Written by J.T. Conklin, 10/05/94
- * Public domain.
- */
-
-#include <sys/cdefs.h>
-
-#ifdef __indr_reference
-__indr_reference(_catclose,catclose);
-#else
-
-#include <nl_types.h>
-
-extern int _catclose __P((nl_catd));
-
-int
-catclose(catd)
- nl_catd catd;
-{
- return _catclose(catd);
-}
-
-#endif
diff --git a/lib/libc/nls/catgets.3 b/lib/libc/nls/catgets.3
index b55d70858d17..fda5f367b184 100644
--- a/lib/libc/nls/catgets.3
+++ b/lib/libc/nls/catgets.3
@@ -1,5 +1,3 @@
-.\" $FreeBSD$
-.\"
.\" Copyright (c) 1994 Winning Strategies, Inc.
.\" All rights reserved.
.\"
@@ -28,6 +26,7 @@
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
+.\" $FreeBSD$
.Dd May 29, 1994
.Dt CATGETS 3
.Os
@@ -53,7 +52,7 @@ The argument
.Fa s
points to a default message which is returned if the function
is unable to retrieve the specified message.
-.Sh RETURN VALUE
+.Sh RETURN VALUES
If the specified message was retrieved successfully,
.Fn catgets
returns a pointer to an internal buffer containing the message string;
diff --git a/lib/libc/nls/catgets.c b/lib/libc/nls/catgets.c
deleted file mode 100644
index 037b6ff684da..000000000000
--- a/lib/libc/nls/catgets.c
+++ /dev/null
@@ -1,28 +0,0 @@
-/* $FreeBSD$ */
-
-/*
- * Written by J.T. Conklin, 10/05/94
- * Public domain.
- */
-
-#include <sys/cdefs.h>
-
-#ifdef __indr_reference
-__indr_reference(_catgets,catgets);
-#else
-
-#include <nl_types.h>
-
-extern char * _catgets __P((nl_catd, int, int, __const char *));
-
-char *
-catgets(catd, set_id, msg_id, s)
- nl_catd catd;
- int set_id;
- int msg_id;
- __const char *s;
-{
- return _catgets(catd, set_id, msg_id, s);
-}
-
-#endif
diff --git a/lib/libc/nls/catopen.3 b/lib/libc/nls/catopen.3
index 17958f6bb44f..272fe7e0d319 100644
--- a/lib/libc/nls/catopen.3
+++ b/lib/libc/nls/catopen.3
@@ -1,5 +1,3 @@
-.\" $FreeBSD$
-.\"
.\" Copyright (c) 1994 Winning Strategies, Inc.
.\" All rights reserved.
.\"
@@ -28,6 +26,7 @@
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
+.\" $FreeBSD$
.Dd May 29, 1994
.Dt CATOPEN 3
.Os
@@ -56,8 +55,48 @@ specifies the full pathname for the message catalog, otherwise the value
of the environment variable
.Ev NLSPATH
is used with
+the following substitutions:
+.Bl -tag -width XXX
+.It \&%N
+The value of the
.Fa name
-substituted for %N.
+argument.
+.It \&%L
+The value of the
+.Ev LANG
+environment variable or the
+.Dv LC_MESSAGES
+category (see below).
+.It \&%l
+The language element from the
+.Ev LANG
+environment variable or from the
+.Dv LC_MESSAGES
+category.
+.It \&%t
+The territory element from the
+.Ev LANG
+environment variable or from the
+.Dv LC_MESSAGES
+category.
+.It \&%c
+The codeset element from the
+.Ev LANG
+environment variable or from the
+.Dv LC_MESSAGES
+category.
+.It \&%%
+A single % character.
+.El
+.Pp
+An empty string is substituted for undefined values.
+.Pp
+Path names templates defined in
+.Ev NLSPATH
+are separated by colons
+.No ( Sq \&: ) .
+A leading or two adjacent colons
+is equivalent to specifying %N.
.Pp
If the
.Fa oflag
@@ -80,10 +119,10 @@ environment variable
determines the message catalog locale.
.Pp
A message catalog descriptor
-remains valid in a process until that process closes it, or a
-successful call to one of the
+remains valid in a process until that process closes it, or
+until a successful call to one of the
.Xr exec 3
-functions.
+function.
.Sh RETURN VALUE
Upon successful completion,
.Fn catopen
@@ -93,6 +132,16 @@ Otherwise, (nl_catd) -1 is returned and
is set to indicate the error.
.Sh ERRORS
.Bl -tag -width Er
+.It Bq Er EINVAL
+Argument
+.Fa name
+does not point to a valid message catalog.
+.It Bq Er ENAMETOOLONG
+An entire path to the message catalog exceeded 1024 characters.
+.It Bq Er ENOENT
+The named message catalog does not exists, or the
+.Fa name
+argument points to an empty string.
.It Bq Er ENOMEM
Insufficient memory is available.
.El
diff --git a/lib/libc/nls/catopen.c b/lib/libc/nls/catopen.c
deleted file mode 100644
index c5ab394c8081..000000000000
--- a/lib/libc/nls/catopen.c
+++ /dev/null
@@ -1,26 +0,0 @@
-/* $FreeBSD$ */
-
-/*
- * Written by J.T. Conklin, 10/05/94
- * Public domain.
- */
-
-#include <sys/cdefs.h>
-
-#ifdef __indr_reference
-__indr_reference(_catopen,catopen);
-#else
-
-#include <nl_types.h>
-
-extern nl_catd _catopen __P((__const char *, int));
-
-nl_catd
-catopen(name, oflag)
- __const char *name;
- int oflag;
-{
- return _catopen(name, oflag);
-}
-
-#endif
diff --git a/lib/libc/nls/msgcat.c b/lib/libc/nls/msgcat.c
index ee97058b4690..1dbdf4ffc428 100644
--- a/lib/libc/nls/msgcat.c
+++ b/lib/libc/nls/msgcat.c
@@ -33,138 +33,147 @@ up-to-date. Many thanks.
******************************************************************/
#if defined(LIBC_SCCS) && !defined(lint)
-static char *rcsid = "$NetBSD: msgcat.c,v 1.11 1995/02/27 13:06:51 cgd Exp $";
+static char *rcsid = "$FreeBSD$";
#endif /* LIBC_SCCS and not lint */
-/* Edit History
-
-03/06/91 4 schulert remove working directory from nlspath
-01/18/91 2 hamilton #if not rescanned
-01/12/91 3 schulert conditionally use prototypes
-11/03/90 1 hamilton Alphalpha->Alfalfa & OmegaMail->Poste
-10/15/90 2 schulert > #include <unistd.h> if MIPS
-08/13/90 1 schulert move from ua to omu
-*/
-
/*
* We need a better way of handling errors than printing text. I need
* to add an error handling routine.
*/
-#include "nl_types.h"
-#include "msgcat.h"
-
#include <sys/types.h>
#include <sys/stat.h>
+#include <sys/syslimits.h>
#include <errno.h>
#include <fcntl.h>
#include <locale.h>
+#include <nl_types.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-#ifndef True
-# define True ~0
-# define False 0
-#endif
+#include "msgcat.h"
-/* take care of sysv diffs */
-#ifndef MAXPATHLEN
-#define MAXPATHLEN 1024
-#endif
+#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"
-#ifndef FD_CLOEXEC
-#define FD_CLOEXEC 1
-#endif
+#define TRUE 1
+#define FALSE 0
-#define NLERR ((nl_catd) -1)
+#define NLERR ((nl_catd) -1)
+#define NLRETERR(errc) errno = errc; return(NLERR);
static nl_catd loadCat();
static int loadSet();
+static void __nls_free_resources();
-nl_catd _catopen( name, type)
-__const char *name;
-int type;
+nl_catd
+catopen( name, type)
+ __const char *name;
+ int type;
{
- char path[MAXPATHLEN];
- __const char *catpath = NULL;
- char *nlspath;
- char *lang;
- char *base, *cptr, *pathP;
- int spcleft;
- long len;
- struct stat sbuf;
-
- if (!name || !*name) {
- errno = EINVAL;
- return(NLERR);
- }
-
- if (strchr(name, '/')) {
- catpath = name;
- if (stat(catpath, &sbuf)) return(NLERR);
- } else {
- if (type == NL_CAT_LOCALE)
- lang = setlocale(LC_MESSAGES, NULL);
- else {
- if ((lang = (char *) getenv("LANG")) == NULL)
- lang = "C";
- }
- if ((nlspath = (char *) getenv("NLSPATH")) == NULL
+ int spcleft;
+ char path[PATH_MAX];
+ char *nlspath, *lang, *base, *cptr, *pathP, *tmpptr;
+ char *cptr1, *plang, *pter, *pcode;
+ struct stat sbuf;
+
+ if (name == NULL || *name == '\0') {
+ NLRETERR(ENOENT);
+ }
+
+ /* is it absolute path ? if yes, load immidiately */
+ if (strchr(name, '/'))
+ return loadCat(name);
+
+ if (type == NL_CAT_LOCALE)
+ lang = setlocale(LC_MESSAGES, NULL);
+ else
+ lang = getenv("LANG");
+ if (lang == NULL || *lang == '\0' || strchr(lang, '/') != NULL)
+ lang = "C";
+
+ if ((plang = cptr1 = strdup(lang)) == NULL)
+ 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;
+ }
+
+ if ((nlspath = getenv("NLSPATH")) == NULL
#ifndef __NETBSD_SYSCALLS
- || issetugid()
+ || issetugid()
#endif
- )
- nlspath = "/usr/share/nls/%L/%N.cat:/usr/share/nls/%N/%L:/usr/local/share/nls/%L/%N.cat:/usr/local/share/nls/%N/%L";
-
- len = strlen(nlspath);
- base = cptr = malloc(len + 2);
- if (!base) return(NLERR);
- strcpy(cptr, nlspath);
- cptr[len] = ':';
- cptr[len+1] = '\0';
-
- for (nlspath = cptr; *cptr; ++cptr) {
- if (*cptr == ':') {
- *cptr = '\0';
- for (pathP = path; *nlspath; ++nlspath) {
- if (*nlspath == '%') {
- spcleft = sizeof(path) - (pathP - path);
- if (*(nlspath + 1) == 'L') {
- ++nlspath;
- if (strlcpy(pathP, lang, spcleft) >= spcleft) {
- errno = ENAMETOOLONG;
- return(NLERR);
- }
- pathP += strlen(lang);
- } else if (*(nlspath + 1) == 'N') {
- ++nlspath;
- if (strlcpy(pathP, name, spcleft) >= spcleft) {
- errno = ENAMETOOLONG;
- return(NLERR);
- }
- pathP += strlen(name);
- } else *(pathP++) = *nlspath;
- } else *(pathP++) = *nlspath;
+ )
+ nlspath = _DEFAULT_NLS_PATH;
+
+ if ((base = cptr = strdup(nlspath)) == NULL) {
+ free(plang);
+ return (NLERR);
+ }
+
+ 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:
+ *(pathP++) = *nlspath;
+ continue;
+ }
+ ++nlspath;
+ put_tmpptr:
+ spcleft = sizeof(path) - (pathP - path) - 1;
+ if (strlcpy(pathP, tmpptr, spcleft) >= spcleft) {
+ free(plang);
+ free(base);
+ NLRETERR(ENAMETOOLONG);
+ }
+ pathP += strlen(tmpptr);
+ } else
+ *(pathP++) = *nlspath;
}
*pathP = '\0';
if (stat(path, &sbuf) == 0) {
- catpath = path;
- break;
+ free(plang);
+ free(base);
+ return loadCat(path);
}
- nlspath = cptr+1;
- }
- }
- free(base);
-
- if (!catpath) {
- errno = ENOENT;
- return(NLERR);
+ } else {
+ tmpptr = (char*)name;
+ --nlspath;
+ goto put_tmpptr;
}
- }
-
- return(loadCat(catpath));
+ }
+ free(plang);
+ free(base);
+ NLRETERR(ENOENT);
}
/*
@@ -187,86 +196,66 @@ int type;
* >=9 >=10 >=11
*
*/
-static MCSetT *MCGetSet( cat, setId)
-MCCatT *cat;
-int setId;
+
+#define LOOKUP(PARENT, CHILD, ID, NUM, SET) { \
+ lo = 0; \
+ if (ID - 1 < PARENT->NUM) { \
+ cur = ID - 1; hi = ID; \
+ } else { \
+ hi = PARENT->NUM; cur = (hi - lo) / 2; \
+ } \
+ while (TRUE) { \
+ CHILD = PARENT->SET + cur; \
+ if (CHILD->ID == ID) break; \
+ if (CHILD->ID < ID) { \
+ lo = cur+1; \
+ if (hi > cur+(ID-CHILD->ID)+1) \
+ hi = cur+(ID-CHILD->ID)+1; \
+ dir = 1; \
+ } else { \
+ hi = cur; dir = -1; \
+ } \
+ if (lo >= hi) return(NULL); \
+ if (hi - lo == 1) cur += dir; \
+ else cur += ((hi - lo) / 2) * dir; \
+ } \
+ }
+
+static MCSetT*
+MCGetSet( cat, setId)
+ MCCatT *cat;
+ int setId;
{
MCSetT *set;
long lo, hi, cur, dir;
- if (!cat || setId <= 0) return(NULL);
-
- lo = 0;
- if (setId - 1 < cat->numSets) {
- cur = setId - 1;
- hi = setId;
- } else {
- hi = cat->numSets;
- cur = (hi - lo) / 2;
- }
-
- while (True) {
- set = cat->sets + cur;
- if (set->setId == setId) break;
- if (set->setId < setId) {
- lo = cur+1;
- if (hi > cur + (setId - set->setId) + 1) hi = cur+(setId-set->setId)+1;
- dir = 1;
- } else {
- hi = cur;
- dir = -1;
- }
- if (lo >= hi) return(NULL);
- if (hi - lo == 1) cur += dir;
- else cur += ((hi - lo) / 2) * dir;
- }
- if (set->invalid)
- (void) loadSet(cat, set);
+ if (cat == NULL || setId <= 0) return(NULL);
+ LOOKUP(cat, set, setId, numSets, sets);
+ if (set->invalid && loadSet(cat, set) <= 0)
+ return(NULL);
return(set);
}
-static MCMsgT *MCGetMsg( set, msgId)
-MCSetT *set;
-int msgId;
+static MCMsgT*
+MCGetMsg( set, msgId)
+ MCSetT *set;
+ int msgId;
{
MCMsgT *msg;
long lo, hi, cur, dir;
- if (!set || set->invalid || msgId <= 0) return(NULL);
-
- lo = 0;
- if (msgId - 1 < set->numMsgs) {
- cur = msgId - 1;
- hi = msgId;
- } else {
- hi = set->numMsgs;
- cur = (hi - lo) / 2;
- }
-
- while (True) {
- msg = set->u.msgs + cur;
- if (msg->msgId == msgId) break;
- if (msg->msgId < msgId) {
- lo = cur+1;
- if (hi > cur + (msgId - msg->msgId) + 1) hi = cur+(msgId-msg->msgId)+1;
- dir = 1;
- } else {
- hi = cur;
- dir = -1;
- }
- if (lo >= hi) return(NULL);
- if (hi - lo == 1) cur += dir;
- else cur += ((hi - lo) / 2) * dir;
- }
+ if (set == NULL || set->invalid || msgId <= 0) return(NULL);
+ LOOKUP(set, msg, msgId, numMsgs, u.msgs);
return(msg);
}
-char *_catgets( catd, setId, msgId, dflt)
-nl_catd catd;
-int setId;
-int msgId;
-__const char *dflt;
+char*
+catgets( catd, setId, msgId, dflt)
+ nl_catd catd;
+ int setId;
+ int msgId;
+ __const char *dflt;
{
MCMsgT *msg;
MCCatT *cat = (MCCatT *) catd;
@@ -275,36 +264,30 @@ __const char *dflt;
if (catd == NULL || catd == NLERR)
return((char *)dflt);
msg = MCGetMsg(MCGetSet(cat, setId), msgId);
- if (msg) cptr = msg->msg.str;
+ if (msg != NULL) cptr = msg->msg.str;
else cptr = dflt;
return((char *)cptr);
}
-int _catclose( catd)
-nl_catd catd;
+int
+catclose( catd)
+ nl_catd catd;
{
MCCatT *cat = (MCCatT *) catd;
- MCSetT *set;
- int i;
if (catd == NULL || catd == NLERR) {
- errno = EBADF;
- return -1;
+ errno = EBADF; return(-1);
}
- if (cat->loadType != MCLoadAll) _close(cat->fd);
- for (i = 0; i < cat->numSets; ++i) {
- set = cat->sets + i;
- if (!set->invalid) {
- free(set->data.str);
- free(set->u.msgs);
- }
- }
- free(cat->sets);
+#if 0
+ if (cat->loadType != MCLoadAll)
+#endif
+ (void) fclose(cat->fp);
+ __nls_free_resources(cat, cat->numSets);
free(cat);
- return 0;
+ return(0);
}
/*
@@ -312,132 +295,142 @@ nl_catd catd;
*/
/* Note that only malloc failures are allowed to return an error */
-#define ERRNAME "Message Catalog System"
-#define CORRUPT() {fprintf(stderr, "%s: corrupt file.\n", ERRNAME); free(cat); errno = EINVAL; return(NLERR);}
-#define NOSPACE() {fprintf(stderr, "%s: no more memory.\n", ERRNAME); free(cat); return(NLERR);}
+static char* _errowner = "Message Catalog System";;
+#define CORRUPT() { \
+ fprintf(stderr, "%s: currupt file.", _errowner); \
+ free(cat); \
+ NLRETERR(EINVAL); \
+ }
+
+#define NOSPACE() { \
+ fprintf(stderr, "%s: no more memory.", _errowner); \
+ free(cat); \
+ return(NLERR); \
+ }
+
+static void
+__nls_free_resources(cat, i)
+ MCCatT *cat;
+ int i;
+{
+ MCSetT *set;
+ int j;
+
+ for (j = 0; j < i; j++) {
+ set = cat->sets + j;
+ if (!set->invalid) {
+ free(set->data.str);
+ free(set->u.msgs);
+ }
+ }
+ free(cat->sets);
+}
-static nl_catd loadCat(catpath)
-__const char *catpath;
+static nl_catd
+loadCat(catpath)
+ __const char *catpath;
{
MCHeaderT header;
MCCatT *cat;
MCSetT *set;
- long i, j;
+ long i;
off_t nextSet;
cat = (MCCatT *) malloc(sizeof(MCCatT));
- if (!cat) return(NLERR);
+ if (cat == NULL) return(NLERR);
cat->loadType = MCLoadBySet;
- if ((cat->fd = _open(catpath, O_RDONLY)) < 0) {
+ if ((cat->fp = fopen(catpath, "r")) == NULL) {
free(cat);
return(NLERR);
}
- (void)_fcntl(cat->fd, F_SETFD, FD_CLOEXEC);
+ (void) _fcntl(fileno(cat->fp), F_SETFD, FD_CLOEXEC);
- if (_read(cat->fd, &header, sizeof(header)) != sizeof(header))
+ if (fread(&header, sizeof(header), 1, cat->fp) != 1)
CORRUPT();
if (strncmp(header.magic, MCMagic, MCMagicLen) != 0) CORRUPT();
if (header.majorVer != MCMajorVer) {
free(cat);
- fprintf(stderr, "%s: %s is version %ld, we need %ld.\n", ERRNAME,
+ fprintf(stderr, "%s: %s is version %ld, we need %ld.\n", _errowner,
catpath, header.majorVer, MCMajorVer);
- errno = EINVAL;
- return(NLERR);
+ NLRETERR(EINVAL);
}
if (header.numSets <= 0) {
free(cat);
- fprintf(stderr, "%s: %s has %ld sets!\n", ERRNAME, catpath,
+ fprintf(stderr, "%s: %s has %ld sets!\n", _errowner, catpath,
header.numSets);
- errno = EINVAL;
- return(NLERR);
+ NLRETERR(EINVAL);
}
cat->numSets = header.numSets;
cat->sets = (MCSetT *) malloc(sizeof(MCSetT) * header.numSets);
- if (!cat->sets) NOSPACE();
+ if (cat->sets == NULL) NOSPACE();
nextSet = header.firstSet;
for (i = 0; i < cat->numSets; ++i) {
- if (lseek(cat->fd, nextSet, 0) == -1) {
- for (j = 0; j < i; j++) {
- set = cat->sets + j;
- if (!set->invalid) {
- free(set->data.str);
- free(set->u.msgs);
- }
- }
- free(cat->sets);
+ if (fseeko(cat->fp, nextSet, SEEK_SET) == -1) {
+ __nls_free_resources(cat, i);
CORRUPT();
}
/* read in the set header */
set = cat->sets + i;
- if (_read(cat->fd, set, sizeof(*set)) != sizeof(*set)) {
- for (j = 0; j < i; j++) {
- set = cat->sets + j;
- if (!set->invalid) {
- free(set->data.str);
- free(set->u.msgs);
- }
- }
- free(cat->sets);
+ if (fread(set, sizeof(*set), 1, cat->fp) != 1) {
+ __nls_free_resources(cat, i);
CORRUPT();
}
/* if it's invalid, skip over it (and backup 'i') */
-
if (set->invalid) {
--i;
nextSet = set->nextSet;
continue;
}
+#if 0
if (cat->loadType == MCLoadAll) {
int res;
if ((res = loadSet(cat, set)) <= 0) {
- for (j = 0; j < i; j++) {
- set = cat->sets + j;
- if (!set->invalid) {
- free(set->data.str);
- free(set->u.msgs);
- }
- }
- free(cat->sets);
+ __nls_free_resources(cat, i);
if (res < 0) NOSPACE();
CORRUPT();
}
- } else set->invalid = True;
+ } else
+#endif
+ set->invalid = TRUE;
nextSet = set->nextSet;
}
+#if 0
if (cat->loadType == MCLoadAll) {
- _close(cat->fd);
- cat->fd = -1;
+ (void) fclose(cat->fp);
+ cat->fp = NULL;
}
+#endif
return((nl_catd) cat);
}
-static int loadSet(cat, set)
-MCCatT *cat;
-MCSetT *set;
+static int
+loadSet(cat, set)
+ MCCatT *cat;
+ MCSetT *set;
{
MCMsgT *msg;
int i;
/* Get the data */
- if (lseek(cat->fd, set->data.off, 0) == -1) return(0);
+ if (fseeko(cat->fp, set->data.off, SEEK_SET) == -1) return(0);
if ((set->data.str = malloc(set->dataLen)) == NULL) return(-1);
- if (_read(cat->fd, set->data.str, set->dataLen) != set->dataLen) {
+ if (fread(set->data.str, set->dataLen, 1, cat->fp) != 1) {
free(set->data.str); return(0);
}
/* Get the messages */
- if (lseek(cat->fd, set->u.firstMsg, 0) == -1) {
+ if (fseeko(cat->fp, set->u.firstMsg, SEEK_SET) == -1) {
free(set->data.str); return(0);
}
if ((set->u.msgs = (MCMsgT *) malloc(sizeof(MCMsgT) * set->numMsgs)) == NULL) {
@@ -446,7 +439,7 @@ MCSetT *set;
for (i = 0; i < set->numMsgs; ++i) {
msg = set->u.msgs + i;
- if (_read(cat->fd, msg, sizeof(*msg)) != sizeof(*msg)) {
+ if (fread(msg, sizeof(*msg), 1, cat->fp) != 1) {
free(set->u.msgs); free(set->data.str); return(0);
}
if (msg->invalid) {
@@ -455,6 +448,6 @@ MCSetT *set;
}
msg->msg.str = (char *) (set->data.str + msg->msg.off);
}
- set->invalid = False;
+ set->invalid = FALSE;
return(1);
}
diff --git a/lib/libc/nls/msgcat.h b/lib/libc/nls/msgcat.h
index 0a4c1643c940..f13d88823110 100644
--- a/lib/libc/nls/msgcat.h
+++ b/lib/libc/nls/msgcat.h
@@ -1,8 +1,7 @@
/* $FreeBSD$ */
-/* -*-c++-*- */
-
-#ifndef __msgcath
+#ifndef _MSGCAT_H_
+#define _MSGCAT_H_
/***********************************************************
@@ -44,23 +43,12 @@ up-to-date. Many thanks.
* On disk data structures
*/
-/* Edit History
-
-02/25/91 2 nazgul Byte order flags, upped the version number
-11/03/90 1 hamilton Alphalpha->Alfalfa & OmegaMail->Poste
-08/13/90 1 schulert move from ua to omu
-*/
-
/* For or'd constants */
#define MCMakeId(s,m) (unsigned long) ( ((unsigned short)s << (sizeof(short)*8)) \
| (unsigned short)m )
#define MCSetId(id) (unsigned int) ( id >> (sizeof(short) * 8) )
#define MCMsgId(id) (unsigned int) ( (id << (sizeof(short) * 8)) \
>> (sizeof(short) * 8) )
-#undef S
-#undef UI
-#undef UL
-
#define MCMagicLen 8
#define MCMagic "*nazgul*"
#define MCLastMsg 0
@@ -142,7 +130,7 @@ typedef struct _MCSetT {
*/
typedef struct {
long loadType; /* How to load the messages (see MSLoadType) */
- int fd; /* File descriptor of catalog (if load-on-demand) */
+ FILE *fp; /* File descriptor of catalog (if load-on-demand) */
long numSets; /* Number of sets */
MCSetT *sets; /* Pointer to the sets */
off_t firstSet; /* Offset of first set on disk */
@@ -164,7 +152,4 @@ typedef struct {
#define MC68KByteOrder 0x01
#define MCn86ByteOrder 0x02
-
-
-
-#endif
+#endif /* !_MSGCAT_H_ */