diff options
author | Matt Kraai | 2001-04-23 01:07:00 +0000 |
---|---|---|
committer | Matt Kraai | 2001-04-23 01:07:00 +0000 |
commit | 782ab3ccf85360e86e4559aff51bd1e8ca38b36a (patch) | |
tree | cfb9f9c8bac1f4a67ec2089c86d971284b375578 | |
parent | ee0d93ed04b608ae128ac18c89f0057eb0eb5ee4 (diff) | |
download | busybox-782ab3ccf85360e86e4559aff51bd1e8ca38b36a.zip busybox-782ab3ccf85360e86e4559aff51bd1e8ca38b36a.tar.gz |
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.
-rw-r--r-- | coreutils/ls.c | 18 | ||||
-rw-r--r-- | ls.c | 18 |
2 files changed, 18 insertions, 18 deletions
diff --git a/coreutils/ls.c b/coreutils/ls.c index 8f4cae1..d24ba98 100644 --- a/coreutils/ls.c +++ b/coreutils/ls.c @@ -543,16 +543,16 @@ static struct dnode **list_dir(char *path) } while ((entry = readdir(dir)) != NULL) { /* 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)) continue; - if ((entry->d_name[0] == '.') && !(disp_opts & DISP_HIDDEN)) continue; + if ((strcmp(entry->d_name, ".")==0) && !(disp_opts & DISP_DOT)) + 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->fullname = xmalloc(strlen(path)+1+strlen(entry->d_name)+1); - strcpy(cur->fullname, path); - if (cur->fullname[strlen(cur->fullname)-1] != '/') - strcat(cur->fullname, "/"); - cur->name= cur->fullname + strlen(cur->fullname); - strcat(cur->fullname, entry->d_name); + cur->fullname = concat_path_file(path, entry->d_name); + cur->name = cur->fullname + + (strlen(cur->fullname) - strlen(entry->d_name)); if (my_stat(cur)) continue; cur->next= dn; @@ -543,16 +543,16 @@ static struct dnode **list_dir(char *path) } while ((entry = readdir(dir)) != NULL) { /* 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)) continue; - if ((entry->d_name[0] == '.') && !(disp_opts & DISP_HIDDEN)) continue; + if ((strcmp(entry->d_name, ".")==0) && !(disp_opts & DISP_DOT)) + 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->fullname = xmalloc(strlen(path)+1+strlen(entry->d_name)+1); - strcpy(cur->fullname, path); - if (cur->fullname[strlen(cur->fullname)-1] != '/') - strcat(cur->fullname, "/"); - cur->name= cur->fullname + strlen(cur->fullname); - strcat(cur->fullname, entry->d_name); + cur->fullname = concat_path_file(path, entry->d_name); + cur->name = cur->fullname + + (strlen(cur->fullname) - strlen(entry->d_name)); if (my_stat(cur)) continue; cur->next= dn; |