summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>1996-06-10 06:21:50 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>1996-06-10 06:21:50 +0000
commitbe87ca8f925f66bcca2026f65192c33bc3cb1ea4 (patch)
tree0029a5a48080c89cd0f3612c1cbe2ca61a70bb3a
parent560842d4cf949f39d53e6861b2bb97cb706fe5bf (diff)
exit nicely, error out nicely
-rw-r--r--lib/libc/nls/catgets.c6
-rw-r--r--lib/libc/nls/catopen.c40
2 files changed, 24 insertions, 22 deletions
diff --git a/lib/libc/nls/catgets.c b/lib/libc/nls/catgets.c
index 248e6ffd4ef..1dbf56d9e47 100644
--- a/lib/libc/nls/catgets.c
+++ b/lib/libc/nls/catgets.c
@@ -1,4 +1,4 @@
-/* $NetBSD: catgets.c,v 1.8 1996/05/13 23:29:38 jtc Exp $ */
+/* $NetBSD: catgets.c,v 1.8.4.1 1996/05/28 20:06:20 jtc Exp $ */
/*-
* Copyright (c) 1996 The NetBSD Foundation, Inc.
@@ -38,6 +38,7 @@
#define _NLS_PRIVATE
+#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <nl_types.h>
@@ -54,7 +55,8 @@ _catgets(catd, set_id, msg_id, s)
struct _nls_msg_hdr *msg_hdr;
int l, u, i, r;
- if (catd == (nl_catd) 0 || catd == (nl_catd) -1) {
+ if (catd == (nl_catd) -1) {
+ errno = EBADF;
return (char *) s;
}
diff --git a/lib/libc/nls/catopen.c b/lib/libc/nls/catopen.c
index 225f35515b6..677bb63e8a1 100644
--- a/lib/libc/nls/catopen.c
+++ b/lib/libc/nls/catopen.c
@@ -1,4 +1,4 @@
-/* $NetBSD: catopen.c,v 1.6 1996/05/13 23:29:39 jtc Exp $ */
+/* $NetBSD: catopen.c,v 1.6.4.2 1996/05/28 22:46:56 jtc Exp $ */
/*-
* Copyright (c) 1996 The NetBSD Foundation, Inc.
@@ -61,6 +61,7 @@ _catopen(name, oflag)
struct stat st;
nl_catd catd;
int fd;
+ void *data;
struct _nls_cat_hdr *cat_hdr;
@@ -70,7 +71,7 @@ _catopen(name, oflag)
/* absolute or relative path? */
if (strchr (name, '/')) {
if (stat (name, &st)) {
- return (nl_catd) 0;
+ return (nl_catd) -1;
}
path = name;
} else {
@@ -113,38 +114,37 @@ _catopen(name, oflag)
}
}
- return (nl_catd) 0;
+ return (nl_catd) -1;
}
load_msgcat:
if ((fd = open (path, O_RDONLY)) == -1)
- return (nl_catd) 0;
+ return (nl_catd) -1;
if (fstat(fd, &st) != 0) {
close (fd);
- return (nl_catd) 0;
- }
-
- if ((catd = malloc (sizeof (*catd))) == 0) {
- close (fd);
- return (nl_catd) 0;
+ return (nl_catd) -1;
}
- catd->__data = mmap(0, (size_t) st.st_size, PROT_READ, MAP_SHARED, fd, 0);
+ data = mmap(0, (size_t) st.st_size, PROT_READ, MAP_SHARED, fd, 0);
close (fd);
- if (catd->__data == (void *) -1) {
- free (catd);
- return (nl_catd) 0;
+ if (data == (void *) -1) {
+ munmap(data, (size_t) st.st_size);
+ return (nl_catd) -1;
+ }
+
+ if (ntohl(((struct _nls_cat_hdr *) data)->__magic) != _NLS_MAGIC) {
+ munmap(data, (size_t) st.st_size);
+ return (nl_catd) -1;
}
- catd->__size = st.st_size;
- cat_hdr = (struct _nls_cat_hdr *) catd->__data;
- if (ntohl(cat_hdr->__magic) != _NLS_MAGIC) {
- free (catd);
- close (fd);
- return (nl_catd) 0;
+ if ((catd = malloc (sizeof (*catd))) == 0) {
+ munmap(data, (size_t) st.st_size);
+ return (nl_catd) -1;
}
+ catd->__data = data;
+ catd->__size = st.st_size;
return catd;
}