summaryrefslogtreecommitdiffstats
path: root/usr.sbin/config/main.c
diff options
context:
space:
mode:
authored <ed@FreeBSD.org>2011-07-03 20:59:57 +0000
committered <ed@FreeBSD.org>2011-07-03 20:59:57 +0000
commitbf26f471edbd2d0ab6c20a80e4e6dd78fb78b55b (patch)
tree6a1ad97bd96a1d0f360de7d6c929f3289b70c204 /usr.sbin/config/main.c
parent300a95bf76e162113e6631c5538072e8a1aec2bb (diff)
downloadFreeBSD-src-bf26f471edbd2d0ab6c20a80e4e6dd78fb78b55b.zip
FreeBSD-src-bf26f471edbd2d0ab6c20a80e4e6dd78fb78b55b.tar.gz
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) MFC after: 3 weeks
Diffstat (limited to 'usr.sbin/config/main.c')
-rw-r--r--usr.sbin/config/main.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/usr.sbin/config/main.c b/usr.sbin/config/main.c
index b1d4b5d..ceee035 100644
--- a/usr.sbin/config/main.c
+++ b/usr.sbin/config/main.c
@@ -577,7 +577,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");
@@ -591,12 +591,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 */
OpenPOWER on IntegriCloud