diff options
author | Matt Kraai <kraai@debian.org> | 2000-09-22 03:11:47 +0000 |
---|---|---|
committer | Matt Kraai <kraai@debian.org> | 2000-09-22 03:11:47 +0000 |
commit | a2f2a8f8c0c2c9881f9548c045c19b2b5fb11b5d (patch) | |
tree | a13729cc01ffdf98749c1a7e6d830607bfcd40dd | |
parent | 810d38f8508fc4c9a7677dfa938a48f0de3fbb19 (diff) |
Add support for the -L option to ls.
-rw-r--r-- | busybox.def.h | 3 | ||||
-rw-r--r-- | coreutils/ls.c | 19 | ||||
-rw-r--r-- | ls.c | 19 |
3 files changed, 41 insertions, 0 deletions
diff --git a/busybox.def.h b/busybox.def.h index 9d046ab73..42ec9064e 100644 --- a/busybox.def.h +++ b/busybox.def.h @@ -169,6 +169,9 @@ // enable ls -R #define BB_FEATURE_LS_RECURSIVE // +// enable ls -L +#define BB_FEATURE_LS_FOLLOWLINKS +// // Change ping implementation -- simplified, featureless, but really small. //#define BB_FEATURE_SIMPLE_PING // diff --git a/coreutils/ls.c b/coreutils/ls.c index b818003a8..0e08f7683 100644 --- a/coreutils/ls.c +++ b/coreutils/ls.c @@ -159,6 +159,9 @@ static unsigned int sort_order= SORT_FORWARD; #ifdef BB_FEATURE_LS_TIMESTAMPS static unsigned int time_fmt= TIME_MOD; #endif +#ifdef BB_FEATURE_LS_FOLLOWLINKS +static unsigned int follow_links=FALSE; +#endif static unsigned short column = 0; #ifdef BB_FEATURE_AUTOWIDTH @@ -474,6 +477,16 @@ struct dnode **list_dir(char *path) cur= (struct dnode *)xmalloc(sizeof(struct dnode)); cur->fullname= xstrdup(fullname); cur->name= cur->fullname + (int)(fnend - fullname) ; +#ifdef BB_FEATURE_LS_FOLLOWLINKS + if (follow_links == TRUE) { + if (stat(fullname, &cur->dstat)) { + errorMsg("%s: %s\n", fullname, strerror(errno)); + free(cur->fullname); + free(cur); + continue; + } + } else +#endif if (lstat(fullname, &cur->dstat)) { /* get file stat info into node */ errorMsg("%s: %s\n", fullname, strerror(errno)); free(cur->fullname); @@ -682,6 +695,9 @@ extern int ls_main(int argc, char **argv) #ifdef BB_FEATURE_LS_TIMESTAMPS "cetu" #endif +#ifdef BB_FEATURE_LS_FOLLOWLINKS +"L" +#endif )) > 0) { switch (opt) { case '1': style_fmt = STYLE_SINGLE; break; @@ -714,6 +730,9 @@ extern int ls_main(int argc, char **argv) case 't': sort_opts= SORT_MTIME; break; case 'u': time_fmt = TIME_ACCESS; sort_opts= SORT_ATIME; break; #endif +#ifdef BB_FEATURE_LS_FOLLOWLINKS + case 'L': follow_links= TRUE; break; +#endif #ifdef BB_FEATURE_AUTOWIDTH case 'T': tabstops= atoi(optarg); break; case 'w': terminal_width= atoi(optarg); break; @@ -159,6 +159,9 @@ static unsigned int sort_order= SORT_FORWARD; #ifdef BB_FEATURE_LS_TIMESTAMPS static unsigned int time_fmt= TIME_MOD; #endif +#ifdef BB_FEATURE_LS_FOLLOWLINKS +static unsigned int follow_links=FALSE; +#endif static unsigned short column = 0; #ifdef BB_FEATURE_AUTOWIDTH @@ -474,6 +477,16 @@ struct dnode **list_dir(char *path) cur= (struct dnode *)xmalloc(sizeof(struct dnode)); cur->fullname= xstrdup(fullname); cur->name= cur->fullname + (int)(fnend - fullname) ; +#ifdef BB_FEATURE_LS_FOLLOWLINKS + if (follow_links == TRUE) { + if (stat(fullname, &cur->dstat)) { + errorMsg("%s: %s\n", fullname, strerror(errno)); + free(cur->fullname); + free(cur); + continue; + } + } else +#endif if (lstat(fullname, &cur->dstat)) { /* get file stat info into node */ errorMsg("%s: %s\n", fullname, strerror(errno)); free(cur->fullname); @@ -682,6 +695,9 @@ extern int ls_main(int argc, char **argv) #ifdef BB_FEATURE_LS_TIMESTAMPS "cetu" #endif +#ifdef BB_FEATURE_LS_FOLLOWLINKS +"L" +#endif )) > 0) { switch (opt) { case '1': style_fmt = STYLE_SINGLE; break; @@ -714,6 +730,9 @@ extern int ls_main(int argc, char **argv) case 't': sort_opts= SORT_MTIME; break; case 'u': time_fmt = TIME_ACCESS; sort_opts= SORT_ATIME; break; #endif +#ifdef BB_FEATURE_LS_FOLLOWLINKS + case 'L': follow_links= TRUE; break; +#endif #ifdef BB_FEATURE_AUTOWIDTH case 'T': tabstops= atoi(optarg); break; case 'w': terminal_width= atoi(optarg); break; |