Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 24 Jul 2011 19:13:54 +0000 (UTC)
From:      Ed Schouten <ed@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org
Subject:   svn commit: r224295 - stable/8/usr.sbin/config
Message-ID:  <201107241913.p6OJDse4021008@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: ed
Date: Sun Jul 24 19:13:54 2011
New Revision: 224295
URL: http://svn.freebsd.org/changeset/base/224295

Log:
  MFC r223744:
  
    Improve portability of config(8).
  
    - Use strlen(dp->d_name) instead of the unportable dp->d_namlen. Rename
      i to len to make it slightly more descriptive and prevent negative
      indexing of the array.
    - Replace index() by strchr().
  
    This supposedly fixes compilation on GNU systems.
  
  Submitted by:	Robert Millan <rmh debian org> (original patch)

Modified:
  stable/8/usr.sbin/config/main.c
Directory Properties:
  stable/8/usr.sbin/config/   (props changed)
  stable/8/usr.sbin/config/SMM.doc/   (props changed)

Modified: stable/8/usr.sbin/config/main.c
==============================================================================
--- stable/8/usr.sbin/config/main.c	Sun Jul 24 18:27:09 2011	(r224294)
+++ stable/8/usr.sbin/config/main.c	Sun Jul 24 19:13:54 2011	(r224295)
@@ -604,7 +604,7 @@ cleanheaders(char *p)
 	struct dirent *dp;
 	struct file_list *fl;
 	struct hdr_list *hl;
-	int i;
+	size_t len;
 
 	remember("y.tab.h");
 	remember("setdefs.h");
@@ -618,12 +618,13 @@ cleanheaders(char *p)
 	if ((dirp = opendir(p)) == NULL)
 		err(EX_OSERR, "opendir %s", p);
 	while ((dp = readdir(dirp)) != NULL) {
-		i = dp->d_namlen - 2;
+		len = strlen(dp->d_name);
 		/* Skip non-headers */
-		if (dp->d_name[i] != '.' || dp->d_name[i + 1] != 'h')
+		if (len < 2 || dp->d_name[len - 2] != '.' ||
+		    dp->d_name[len - 1] != 'h')
 			continue;
 		/* Skip special stuff, eg: bus_if.h, but check opt_*.h */
-		if (index(dp->d_name, '_') &&
+		if (strchr(dp->d_name, '_') &&
 		    strncmp(dp->d_name, "opt_", 4) != 0)
 			continue;
 		/* Check if it is a target file */



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201107241913.p6OJDse4021008>