Changeset View
Changeset View
Standalone View
Standalone View
lib/libc/gen/fts.c
Show First 20 Lines • Show All 509 Lines • ▼ Show 20 Lines | fts_set(FTS *sp, FTSENT *p, int instr) | ||||
p->fts_instr = instr; | p->fts_instr = instr; | ||||
return (0); | return (0); | ||||
} | } | ||||
FTSENT * | FTSENT * | ||||
fts_children(FTS *sp, int instr) | fts_children(FTS *sp, int instr) | ||||
{ | { | ||||
FTSENT *p; | FTSENT *p; | ||||
int fd; | int fd, rc, serrno; | ||||
if (instr != 0 && instr != FTS_NAMEONLY) { | if (instr != 0 && instr != FTS_NAMEONLY) { | ||||
errno = EINVAL; | errno = EINVAL; | ||||
return (NULL); | return (NULL); | ||||
} | } | ||||
/* Set current node pointer. */ | /* Set current node pointer. */ | ||||
p = sp->fts_cur; | p = sp->fts_cur; | ||||
Show All 39 Lines | fts_children(FTS *sp, int instr) | ||||
*/ | */ | ||||
if (p->fts_level != FTS_ROOTLEVEL || p->fts_accpath[0] == '/' || | if (p->fts_level != FTS_ROOTLEVEL || p->fts_accpath[0] == '/' || | ||||
ISSET(FTS_NOCHDIR)) | ISSET(FTS_NOCHDIR)) | ||||
return (sp->fts_child = fts_build(sp, instr)); | return (sp->fts_child = fts_build(sp, instr)); | ||||
if ((fd = _open(".", O_RDONLY | O_CLOEXEC, 0)) < 0) | if ((fd = _open(".", O_RDONLY | O_CLOEXEC, 0)) < 0) | ||||
return (NULL); | return (NULL); | ||||
sp->fts_child = fts_build(sp, instr); | sp->fts_child = fts_build(sp, instr); | ||||
if (fchdir(fd)) { | serrno = (sp->fts_child == NULL) ? errno : 0; | ||||
rc = fchdir(fd); | |||||
if (serrno == 0) | |||||
serrno = errno; | |||||
jilles: This should probably be
```
serrno = sp->fts_child == NULL ? errno : 0;
```
since fts_build()… | |||||
cse_cem_gmail_comAuthorUnsubmitted Done Inline ActionsThis is maybe now bogus. In particular, the sequence:
cse_cem_gmail_com: This is maybe now bogus. In particular, the sequence:
1. fts_build() succeeds but sets errno… | |||||
(void)_close(fd); | (void)_close(fd); | ||||
errno = serrno; | |||||
if (rc < 0) | |||||
return (NULL); | return (NULL); | ||||
} | |||||
(void)_close(fd); | |||||
return (sp->fts_child); | return (sp->fts_child); | ||||
} | } | ||||
#ifndef fts_get_clientptr | #ifndef fts_get_clientptr | ||||
#error "fts_get_clientptr not defined" | #error "fts_get_clientptr not defined" | ||||
#endif | #endif | ||||
void * | void * | ||||
▲ Show 20 Lines • Show All 597 Lines • Show Last 20 Lines |
This should probably be
since fts_build() may set errno to a non-zero value even if it does not fail (e.g. if symlinks are being followed and there is a dangling symlink (FTS_SLNONE)).