Simplify pathname building, in which a bug was noted by Larry Doolittle,
a patch was provided by Vladimir Oleynik, and am improved patch commited by me.
This commit is contained in:
parent
ee0d93ed04
commit
782ab3ccf8
@ -543,16 +543,16 @@ static struct dnode **list_dir(char *path)
|
|||||||
}
|
}
|
||||||
while ((entry = readdir(dir)) != NULL) {
|
while ((entry = readdir(dir)) != NULL) {
|
||||||
/* are we going to list the file- it may be . or .. or a hidden file */
|
/* are we going to list the file- it may be . or .. or a hidden file */
|
||||||
if ((strcmp(entry->d_name, ".")==0) && !(disp_opts & DISP_DOT)) continue;
|
if ((strcmp(entry->d_name, ".")==0) && !(disp_opts & DISP_DOT))
|
||||||
if ((strcmp(entry->d_name, "..")==0) && !(disp_opts & DISP_DOT)) continue;
|
continue;
|
||||||
if ((entry->d_name[0] == '.') && !(disp_opts & DISP_HIDDEN)) continue;
|
if ((strcmp(entry->d_name, "..")==0) && !(disp_opts & DISP_DOT))
|
||||||
|
continue;
|
||||||
|
if ((entry->d_name[0] == '.') && !(disp_opts & DISP_HIDDEN))
|
||||||
|
continue;
|
||||||
cur= (struct dnode *)xmalloc(sizeof(struct dnode));
|
cur= (struct dnode *)xmalloc(sizeof(struct dnode));
|
||||||
cur->fullname = xmalloc(strlen(path)+1+strlen(entry->d_name)+1);
|
cur->fullname = concat_path_file(path, entry->d_name);
|
||||||
strcpy(cur->fullname, path);
|
cur->name = cur->fullname +
|
||||||
if (cur->fullname[strlen(cur->fullname)-1] != '/')
|
(strlen(cur->fullname) - strlen(entry->d_name));
|
||||||
strcat(cur->fullname, "/");
|
|
||||||
cur->name= cur->fullname + strlen(cur->fullname);
|
|
||||||
strcat(cur->fullname, entry->d_name);
|
|
||||||
if (my_stat(cur))
|
if (my_stat(cur))
|
||||||
continue;
|
continue;
|
||||||
cur->next= dn;
|
cur->next= dn;
|
||||||
|
18
ls.c
18
ls.c
@ -543,16 +543,16 @@ static struct dnode **list_dir(char *path)
|
|||||||
}
|
}
|
||||||
while ((entry = readdir(dir)) != NULL) {
|
while ((entry = readdir(dir)) != NULL) {
|
||||||
/* are we going to list the file- it may be . or .. or a hidden file */
|
/* are we going to list the file- it may be . or .. or a hidden file */
|
||||||
if ((strcmp(entry->d_name, ".")==0) && !(disp_opts & DISP_DOT)) continue;
|
if ((strcmp(entry->d_name, ".")==0) && !(disp_opts & DISP_DOT))
|
||||||
if ((strcmp(entry->d_name, "..")==0) && !(disp_opts & DISP_DOT)) continue;
|
continue;
|
||||||
if ((entry->d_name[0] == '.') && !(disp_opts & DISP_HIDDEN)) continue;
|
if ((strcmp(entry->d_name, "..")==0) && !(disp_opts & DISP_DOT))
|
||||||
|
continue;
|
||||||
|
if ((entry->d_name[0] == '.') && !(disp_opts & DISP_HIDDEN))
|
||||||
|
continue;
|
||||||
cur= (struct dnode *)xmalloc(sizeof(struct dnode));
|
cur= (struct dnode *)xmalloc(sizeof(struct dnode));
|
||||||
cur->fullname = xmalloc(strlen(path)+1+strlen(entry->d_name)+1);
|
cur->fullname = concat_path_file(path, entry->d_name);
|
||||||
strcpy(cur->fullname, path);
|
cur->name = cur->fullname +
|
||||||
if (cur->fullname[strlen(cur->fullname)-1] != '/')
|
(strlen(cur->fullname) - strlen(entry->d_name));
|
||||||
strcat(cur->fullname, "/");
|
|
||||||
cur->name= cur->fullname + strlen(cur->fullname);
|
|
||||||
strcat(cur->fullname, entry->d_name);
|
|
||||||
if (my_stat(cur))
|
if (my_stat(cur))
|
||||||
continue;
|
continue;
|
||||||
cur->next= dn;
|
cur->next= dn;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user