summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorkientzle <kientzle@FreeBSD.org>2004-05-05 06:33:00 +0000
committerkientzle <kientzle@FreeBSD.org>2004-05-05 06:33:00 +0000
commit48b874ba981b29af474a600e287b49f46975fad4 (patch)
tree4ea4083c8635c55de7ad1ab92da89c05a09dd5b8 /lib
parent623bf9e27ce12baa6cb5557d093b51c92000821d (diff)
downloadFreeBSD-src-48b874ba981b29af474a600e287b49f46975fad4.zip
FreeBSD-src-48b874ba981b29af474a600e287b49f46975fad4.tar.gz
A minor refactoring to simplify portability: assign the filename
length to a separate variable so that it will be easier to adapt to systems that don't have d_namlen in struct dirent.
Diffstat (limited to 'lib')
-rw-r--r--lib/libc/gen/fts-compat.c12
-rw-r--r--lib/libc/gen/fts.c12
2 files changed, 14 insertions, 10 deletions
diff --git a/lib/libc/gen/fts-compat.c b/lib/libc/gen/fts-compat.c
index d69ef7a..e8ebaf3 100644
--- a/lib/libc/gen/fts-compat.c
+++ b/lib/libc/gen/fts-compat.c
@@ -599,6 +599,7 @@ fts_build(sp, type)
FTSENT *cur, *tail;
DIR *dirp;
void *oldaddr;
+ size_t dnamlen;
int cderrno, descend, len, level, maxlen, nlinks, oflag, saved_errno,
nostat, doadjust;
char *cp;
@@ -704,14 +705,15 @@ fts_build(sp, type)
/* Read the directory, attaching each entry to the `link' pointer. */
doadjust = 0;
for (head = tail = NULL, nitems = 0; dirp && (dp = readdir(dirp));) {
+ dnamlen = dp->d_namlen;
if (!ISSET(FTS_SEEDOT) && ISDOT(dp->d_name))
continue;
- if ((p = fts_alloc(sp, dp->d_name, (int)dp->d_namlen)) == NULL)
+ if ((p = fts_alloc(sp, dp->d_name, (int)dnamlen)) == NULL)
goto mem1;
- if (dp->d_namlen >= maxlen) { /* include space for NUL */
+ if (dnamlen >= maxlen) { /* include space for NUL */
oldaddr = sp->fts_path;
- if (fts_palloc(sp, dp->d_namlen + len + 1)) {
+ if (fts_palloc(sp, dnamlen + len + 1)) {
/*
* No more memory for path or structures. Save
* errno, free up the current structure and the
@@ -736,7 +738,7 @@ mem1: saved_errno = errno;
maxlen = sp->fts_pathlen - len;
}
- if (len + dp->d_namlen >= USHRT_MAX) {
+ if (len + dnamlen >= USHRT_MAX) {
/*
* In an FTSENT, fts_pathlen is a u_short so it is
* possible to wraparound here. If we do, free up
@@ -753,7 +755,7 @@ mem1: saved_errno = errno;
}
p->fts_level = level;
p->fts_parent = sp->fts_cur;
- p->fts_pathlen = len + dp->d_namlen;
+ p->fts_pathlen = len + dnamlen;
#ifdef FTS_WHITEOUT
if (dp->d_type == DT_WHT)
diff --git a/lib/libc/gen/fts.c b/lib/libc/gen/fts.c
index d69ef7a..e8ebaf3 100644
--- a/lib/libc/gen/fts.c
+++ b/lib/libc/gen/fts.c
@@ -599,6 +599,7 @@ fts_build(sp, type)
FTSENT *cur, *tail;
DIR *dirp;
void *oldaddr;
+ size_t dnamlen;
int cderrno, descend, len, level, maxlen, nlinks, oflag, saved_errno,
nostat, doadjust;
char *cp;
@@ -704,14 +705,15 @@ fts_build(sp, type)
/* Read the directory, attaching each entry to the `link' pointer. */
doadjust = 0;
for (head = tail = NULL, nitems = 0; dirp && (dp = readdir(dirp));) {
+ dnamlen = dp->d_namlen;
if (!ISSET(FTS_SEEDOT) && ISDOT(dp->d_name))
continue;
- if ((p = fts_alloc(sp, dp->d_name, (int)dp->d_namlen)) == NULL)
+ if ((p = fts_alloc(sp, dp->d_name, (int)dnamlen)) == NULL)
goto mem1;
- if (dp->d_namlen >= maxlen) { /* include space for NUL */
+ if (dnamlen >= maxlen) { /* include space for NUL */
oldaddr = sp->fts_path;
- if (fts_palloc(sp, dp->d_namlen + len + 1)) {
+ if (fts_palloc(sp, dnamlen + len + 1)) {
/*
* No more memory for path or structures. Save
* errno, free up the current structure and the
@@ -736,7 +738,7 @@ mem1: saved_errno = errno;
maxlen = sp->fts_pathlen - len;
}
- if (len + dp->d_namlen >= USHRT_MAX) {
+ if (len + dnamlen >= USHRT_MAX) {
/*
* In an FTSENT, fts_pathlen is a u_short so it is
* possible to wraparound here. If we do, free up
@@ -753,7 +755,7 @@ mem1: saved_errno = errno;
}
p->fts_level = level;
p->fts_parent = sp->fts_cur;
- p->fts_pathlen = len + dp->d_namlen;
+ p->fts_pathlen = len + dnamlen;
#ifdef FTS_WHITEOUT
if (dp->d_type == DT_WHT)
OpenPOWER on IntegriCloud