mirror of
https://github.com/freebsd/freebsd-src
synced 2024-10-06 00:20:29 +00:00
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.
This commit is contained in:
parent
1e5532d487
commit
542fc1042b
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=128946
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue