aboutsummaryrefslogtreecommitdiff
path: root/lib/libc/nls
diff options
context:
space:
mode:
authorAndrey A. Chernov <ache@FreeBSD.org>2000-09-03 21:05:10 +0000
committerAndrey A. Chernov <ache@FreeBSD.org>2000-09-03 21:05:10 +0000
commit08ba69b8a44a37429c4e08fd186d8b2b9120e4b7 (patch)
treef701891d3f82aca943a8434912eb9309caf95e76 /lib/libc/nls
parentd3d40e9ffbc10685b24971f8228c97c0e3f68be1 (diff)
downloadsrc-08ba69b8a44a37429c4e08fd186d8b2b9120e4b7.tar.gz
src-08ba69b8a44a37429c4e08fd186d8b2b9120e4b7.zip
Rewrite using stdio. It cause program speedup since eliminates lots of small
read() syscalls. It not cause static binary size increasing because stdio already picked via setlocale() called from catopen()
Notes
Notes: svn path=/head/; revision=65417
Diffstat (limited to 'lib/libc/nls')
-rw-r--r--lib/libc/nls/msgcat.c27
-rw-r--r--lib/libc/nls/msgcat.h2
2 files changed, 15 insertions, 14 deletions
diff --git a/lib/libc/nls/msgcat.c b/lib/libc/nls/msgcat.c
index 501dd6bd7355..cfa0b9b5a5bf 100644
--- a/lib/libc/nls/msgcat.c
+++ b/lib/libc/nls/msgcat.c
@@ -259,7 +259,7 @@ __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);
}
@@ -277,7 +277,8 @@ nl_catd catd;
return -1;
}
- if (cat->loadType != MCLoadAll) _close(cat->fd);
+ if (cat->loadType != MCLoadAll)
+ (void) fclose(cat->fp);
for (i = 0; i < cat->numSets; ++i) {
set = cat->sets + i;
if (!set->invalid) {
@@ -313,14 +314,14 @@ __const char *catpath;
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();
@@ -347,7 +348,7 @@ __const char *catpath;
nextSet = header.firstSet;
for (i = 0; i < cat->numSets; ++i) {
- if (lseek(cat->fd, nextSet, 0) == -1) {
+ if (fseeko(cat->fp, nextSet, SEEK_SET) == -1) {
for (j = 0; j < i; j++) {
set = cat->sets + j;
if (!set->invalid) {
@@ -361,7 +362,7 @@ __const char *catpath;
/* read in the set header */
set = cat->sets + i;
- if (_read(cat->fd, set, sizeof(*set)) != sizeof(*set)) {
+ if (fread(set, sizeof(*set), 1, cat->fp) != 1) {
for (j = 0; j < i; j++) {
set = cat->sets + j;
if (!set->invalid) {
@@ -400,8 +401,8 @@ __const char *catpath;
nextSet = set->nextSet;
}
if (cat->loadType == MCLoadAll) {
- _close(cat->fd);
- cat->fd = -1;
+ (void) fclose(cat->fp);
+ cat->fp = NULL;
}
return((nl_catd) cat);
}
@@ -414,14 +415,14 @@ MCSetT *set;
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) {
@@ -430,7 +431,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) {
diff --git a/lib/libc/nls/msgcat.h b/lib/libc/nls/msgcat.h
index ee6799d30466..f13d88823110 100644
--- a/lib/libc/nls/msgcat.h
+++ b/lib/libc/nls/msgcat.h
@@ -130,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 */