standards/172805: Fix catopen(3)'s EINVAL usage and document EFTYPE
Zhihao Yuan
lichray at gmail.com
Wed Oct 17 05:40:00 UTC 2012
>Number: 172805
>Category: standards
>Synopsis: Fix catopen(3)'s EINVAL usage and document EFTYPE
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: freebsd-standards
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: doc-bug
>Submitter-Id: current-users
>Arrival-Date: Wed Oct 17 05:40:00 UTC 2012
>Closed-Date:
>Last-Modified:
>Originator: Zhihao Yuan
>Release: FreeBSD 8.3-STABLE amd64
>Organization:
Northern Illinois University
>Environment:
System: FreeBSD elitebook.hp 8.3-STABLE FreeBSD 8.3-STABLE #4 r240363: Tue Sep 11 10:40:15 CDT 2012 lichray at elitebook.hp:/usr/obj/usr/src/sys/HOUKAGO amd64
>Description:
1. catopen("", 0) should set errno to ENOENT;
2. Document EFTYPE. POSIX says nothing about how to report a corrupt
catalog. NetBSD and OpenBSD do nothing (errno == 0), while we set
EFTYPE. Document it.
3. Fix errno under a rare condition (fstat(2) fails after open(2)).
>How-To-Repeat:
>Fix:
--- catopen3.patch begins here ---
diff --git lib/libc/nls/catopen.3 lib/libc/nls/catopen.3
index 7a16ee5..219c2cb 100644
--- lib/libc/nls/catopen.3
+++ lib/libc/nls/catopen.3
@@ -27,7 +27,7 @@
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
.\" $FreeBSD$
-.Dd February 12, 2005
+.Dd October 17, 2012
.Dt CATOPEN 3
.Os
.Sh NAME
@@ -132,10 +132,13 @@ Otherwise, (nl_catd) -1 is returned and
is set to indicate the error.
.Sh ERRORS
.Bl -tag -width Er
+.It Bq Er EFTYPE
+The named message catalog is corrupt.
.It Bq Er EINVAL
Argument
.Fa name
-does not point to a valid message catalog, or catalog is corrupt.
+points to
+.Dv NULL .
.It Bq Er ENAMETOOLONG
An entire path to the message catalog exceeded 1024 characters.
.It Bq Er ENOENT
@@ -154,4 +157,4 @@ Insufficient memory is available.
The
.Fn catopen
function conforms to
-.St -p1003.1-2001 .
+.St -p1003.1-2008 .
diff --git lib/libc/nls/msgcat.c lib/libc/nls/msgcat.c
index 44b1440..2c77788 100644
--- lib/libc/nls/msgcat.c
+++ lib/libc/nls/msgcat.c
@@ -119,8 +119,10 @@ catopen(const char *name, int type)
char path[PATH_MAX];
/* sanity checking */
- if (name == NULL || *name == '\0')
+ if (name == NULL)
NLRETERR(EINVAL);
+ if (*name == '\0')
+ NLRETERR(ENOENT);
if (strchr(name, '/') != NULL)
/* have a pathname */
@@ -367,6 +369,7 @@ load_msgcat(const char *path, const char *name, const char *lang)
struct catentry *np;
void *data;
int fd;
+ int saved_errno;
/* path/name will never be NULL here */
@@ -390,9 +393,10 @@ load_msgcat(const char *path, const char *name, const char *lang)
}
if (_fstat(fd, &st) != 0) {
+ saved_errno = errno;
_close(fd);
- SAVEFAIL(name, lang, EFTYPE);
- NLRETERR(EFTYPE);
+ SAVEFAIL(name, lang, saved_errno);
+ NLRETERR(saved_errno);
}
/*
@@ -408,7 +412,7 @@ load_msgcat(const char *path, const char *name, const char *lang)
if ((data = mmap(0, (size_t)st.st_size, PROT_READ,
MAP_FILE|MAP_SHARED, fd, (off_t)0)) == MAP_FAILED) {
- int saved_errno = errno;
+ saved_errno = errno;
_close(fd);
SAVEFAIL(name, lang, saved_errno);
NLRETERR(saved_errno);
--- catopen3.patch ends here ---
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the freebsd-standards
mailing list