Changeset View
Changeset View
Standalone View
Standalone View
bin/ls/ls.c
| Show First 20 Lines • Show All 701 Lines • ▼ Show 20 Lines | case FTS_D: | ||||
| (void)printname(p->fts_path); | (void)printname(p->fts_path); | ||||
| puts(":"); | puts(":"); | ||||
| } else if (argc > 1) { | } else if (argc > 1) { | ||||
| (void)printname(p->fts_path); | (void)printname(p->fts_path); | ||||
| puts(":"); | puts(":"); | ||||
| output = 1; | output = 1; | ||||
| } | } | ||||
| chp = fts_children(ftsp, ch_options); | chp = fts_children(ftsp, ch_options); | ||||
| if (chp == NULL && errno != 0) { | |||||
des: The `errno` check is redundant, `chp == NULL && errno == 0` can only happen if a) `ftsp` is not… | |||||
kevansAuthorUnsubmitted Done Inline ActionsThe manpage claims it returns NULL and errno will be set to 0 if the directory is empty. I don't see how that is falls within your two cases, because an empty directory would otherwise get an FTS_D + FTD_DP pair just like a non-empty. kevans: The manpage claims it returns NULL and errno will be set to 0 if the directory is empty. I… | |||||
desUnsubmitted Done Inline ActionsAh, I failed to consider that the directory might be empty. des: Ah, I failed to consider that the directory might be empty. | |||||
| warn("%s", p->fts_path); | |||||
| rval = 1; | |||||
| /* | |||||
| * Avoid further errors on this entry. We won't | |||||
| * always get an FTS_ERR/FTS_DNR for errors | |||||
| * in fts_children(), because opendir could | |||||
| * have failed early on and that only flags an | |||||
| * error for fts_read() when we try to recurse | |||||
| * into it. We catch both the non-recursive and | |||||
| * the recursive case here. | |||||
| */ | |||||
| (void)fts_set(ftsp, p, FTS_SKIP); | |||||
| break; | |||||
| } | |||||
| display(p, chp, options); | display(p, chp, options); | ||||
| if (!f_recursive && chp != NULL) | if (!f_recursive && chp != NULL) | ||||
| (void)fts_set(ftsp, p, FTS_SKIP); | (void)fts_set(ftsp, p, FTS_SKIP); | ||||
| break; | break; | ||||
| default: | default: | ||||
| break; | break; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 337 Lines • Show Last 20 Lines | |||||
The errno check is redundant, chp == NULL && errno == 0 can only happen if a) ftsp is not of type FTS_D or b) FTS_STOP is set on ftsp. Neither is possible here.