diff options
author | Matt Kraai <kraai@debian.org> | 2000-10-13 18:03:21 +0000 |
---|---|---|
committer | Matt Kraai <kraai@debian.org> | 2000-10-13 18:03:21 +0000 |
commit | 9a6e67c9602ebe7e2e4463827ce8d02a237dbcc3 (patch) | |
tree | f1dc34f0a942929245b91cac57e7c0715445b4c2 /coreutils/ls.c | |
parent | 33fdae54d129212c65590ecd6e2f77a78c59e46c (diff) | |
download | busybox-w32-9a6e67c9602ebe7e2e4463827ce8d02a237dbcc3.tar.gz busybox-w32-9a6e67c9602ebe7e2e4463827ce8d02a237dbcc3.tar.bz2 busybox-w32-9a6e67c9602ebe7e2e4463827ce8d02a237dbcc3.zip |
Consolidate stat(2) and lstat(2) calls and error handling.
Diffstat (limited to 'coreutils/ls.c')
-rw-r--r-- | coreutils/ls.c | 59 |
1 files changed, 25 insertions, 34 deletions
diff --git a/coreutils/ls.c b/coreutils/ls.c index 28b2f954d..4377256f6 100644 --- a/coreutils/ls.c +++ b/coreutils/ls.c | |||
@@ -175,6 +175,29 @@ static unsigned short tabstops = 8; | |||
175 | 175 | ||
176 | static int status = EXIT_SUCCESS; | 176 | static int status = EXIT_SUCCESS; |
177 | 177 | ||
178 | static int my_stat(struct dnode *cur) | ||
179 | { | ||
180 | #ifdef BB_FEATURE_LS_FOLLOWLINKS | ||
181 | if (follow_links == TRUE) { | ||
182 | if (stat(cur->fullname, &cur->dstat)) { | ||
183 | errorMsg("%s: %s\n", cur->fullname, strerror(errno)); | ||
184 | status = EXIT_FAILURE; | ||
185 | free(cur->fullname); | ||
186 | free(cur); | ||
187 | return -1; | ||
188 | } | ||
189 | } else | ||
190 | #endif | ||
191 | if (lstat(cur->fullname, &cur->dstat)) { | ||
192 | errorMsg("%s: %s\n", cur->fullname, strerror(errno)); | ||
193 | status = EXIT_FAILURE; | ||
194 | free(cur->fullname); | ||
195 | free(cur); | ||
196 | return -1; | ||
197 | } | ||
198 | return 0; | ||
199 | } | ||
200 | |||
178 | static void newline(void) | 201 | static void newline(void) |
179 | { | 202 | { |
180 | if (column > 0) { | 203 | if (column > 0) { |
@@ -476,24 +499,8 @@ struct dnode **list_dir(char *path) | |||
476 | strcat(cur->fullname, "/"); | 499 | strcat(cur->fullname, "/"); |
477 | cur->name= cur->fullname + strlen(cur->fullname); | 500 | cur->name= cur->fullname + strlen(cur->fullname); |
478 | strcat(cur->fullname, entry->d_name); | 501 | strcat(cur->fullname, entry->d_name); |
479 | #ifdef BB_FEATURE_LS_FOLLOWLINKS | 502 | if (my_stat(cur)) |
480 | if (follow_links == TRUE) { | ||
481 | if (stat(cur->fullname, &cur->dstat)) { | ||
482 | errorMsg("%s: %s\n", cur->fullname, strerror(errno)); | ||
483 | status = EXIT_FAILURE; | ||
484 | free(cur->fullname); | ||
485 | free(cur); | ||
486 | continue; | ||
487 | } | ||
488 | } else | ||
489 | #endif | ||
490 | if (lstat(cur->fullname, &cur->dstat)) { /* get file stat info into node */ | ||
491 | errorMsg("%s: %s\n", cur->fullname, strerror(errno)); | ||
492 | status = EXIT_FAILURE; | ||
493 | free(cur->fullname); | ||
494 | free(cur); | ||
495 | continue; | 503 | continue; |
496 | } | ||
497 | cur->next= dn; | 504 | cur->next= dn; |
498 | dn= cur; | 505 | dn= cur; |
499 | nfiles++; | 506 | nfiles++; |
@@ -792,24 +799,8 @@ extern int ls_main(int argc, char **argv) | |||
792 | cur= (struct dnode *)xmalloc(sizeof(struct dnode)); | 799 | cur= (struct dnode *)xmalloc(sizeof(struct dnode)); |
793 | cur->fullname= xstrdup(av[oi]); | 800 | cur->fullname= xstrdup(av[oi]); |
794 | cur->name= cur->fullname; | 801 | cur->name= cur->fullname; |
795 | #ifdef BB_FEATURE_LS_FOLLOWLINKS | 802 | if (my_stat(cur)) |
796 | if (follow_links == TRUE) { | ||
797 | if (stat(av[oi], &cur->dstat)) { | ||
798 | errorMsg("%s: %s\n", av[oi], strerror(errno)); | ||
799 | status = EXIT_FAILURE; | ||
800 | free(cur->fullname); | ||
801 | free(cur); | ||
802 | continue; | ||
803 | } | ||
804 | } else | ||
805 | #endif | ||
806 | if (lstat(av[oi], &cur->dstat)) { /* get file info into node */ | ||
807 | errorMsg("%s: %s\n", av[oi], strerror(errno)); | ||
808 | status = EXIT_FAILURE; | ||
809 | free(cur->fullname); | ||
810 | free(cur); | ||
811 | continue; | 803 | continue; |
812 | } | ||
813 | cur->next= dn; | 804 | cur->next= dn; |
814 | dn= cur; | 805 | dn= cur; |
815 | nfiles++; | 806 | nfiles++; |