Subject: bin/31258: tools/compat doesn't check for pre-existence of strmode()
To: None <gnats-admin@netbsd.org, netbsd-bugs@netbsd.org>
From: None <wiml@hhhh.org>
List: netbsd-bugs
Date: 09/09/2005 07:57:52
>Number:         31258
>Category:       bin
>Synopsis:       tools/compat doesn't check for pre-existence of strmode()
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Sep 09 07:57:52 +0000 2005
>Originator:     Wim Lewis
>Release:        CVS head 7-September-2005
>Organization:
HHHH
>Environment:
OpenBSD underhill.hhhh.org 3.7 UNDERHILL#0 i386

>Description:
The compat directory always builds strmode(), even if the host machine already has it. (If the host machine's declaration differs slightly from netbsd's, then the build fails. Otherwise it's a less serious bug.)

I've attached a patch which adds strmode() to the list of functions that are checked and adds the needed #if/#endif pairs in libc.

However, I wonder if it might not be better to use a mechanism like AC_LIBOBJ for the compat library, instead of putting #ifs around all those functions in libc.

>How-To-Repeat:
Build from head on OpenBSD-3.7.

This causes a failure, not just a warning, because OpenBSD's libc's strmode() takes an int as its first arg (although mode_t does exist --- go figure.) Presumably other cross-builds will fail in similar ways.

>Fix:
Index: tools/compat/configure.ac
===================================================================
RCS file: /cvsroot/src/tools/compat/configure.ac,v
retrieving revision 1.50
diff -u -r1.50 configure.ac
--- tools/compat/configure.ac   2 Mar 2005 18:08:44 -0000       1.50
+++ tools/compat/configure.ac   8 Sep 2005 19:40:54 -0000
@@ -117,8 +117,8 @@
        fgetln flock fparseln futimes getopt getopt_long group_from_gid \
        heapsort isblank issetugid lchflags lchmod lchown lutimes mkstemp \
        mkdtemp poll pread putc_unlocked pwcache_userdb pwrite random setenv \
-       setgroupent setprogname setpassent snprintf strlcat strlcpy strsep \
-       strsuftoll strtoll \
+       setgroupent setprogname setpassent snprintf strlcat strlcpy strmode \
+       strsep strsuftoll strtoll \
        user_from_uid vasprintf vasnprintf vsnprintf)

 AC_CHECK_FUNCS([htobe16 htobe32 htobe64 htole16 htole32 htole64 be16toh be32toh be64toh le16toh le32toh le64toh],,, [
Index: lib/libc/string/strmode.c
===================================================================
RCS file: /cvsroot/src/lib/libc/string/strmode.c,v
retrieving revision 1.16
diff -u -r1.16 strmode.c
--- lib/libc/string/strmode.c   20 Jun 2004 22:20:15 -0000      1.16
+++ lib/libc/string/strmode.c   8 Sep 2005 19:40:54 -0000
@@ -29,6 +29,10 @@
  * SUCH DAMAGE.
  */

+#if HAVE_NBTOOL_CONFIG_H
+#include "nbtool_config.h"
+#endif
+
 #include <sys/cdefs.h>
 #if defined(LIBC_SCCS) && !defined(lint)
 #if 0
@@ -45,6 +49,7 @@
 #include <assert.h>
 #include <unistd.h>

+#if !HAVE_STRMODE
 void
 strmode(mode, p)
        mode_t mode;
@@ -176,3 +181,4 @@
        *p++ = ' ';             /* will be a '+' if ACL's implemented */
        *p = '\0';
 }
+#endif