diff options
author | vapier <vapier@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2005-05-07 07:17:43 +0000 |
---|---|---|
committer | vapier <vapier@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2005-05-07 07:17:43 +0000 |
commit | beabe60650d0ffc26de94462182c9073578c18eb (patch) | |
tree | c9beac6e70d04c3ca149a8be37cf6795e0609135 /e2fsprogs/lsattr.c | |
parent | 56d644269abd8326142d1e8b0453a5120065128c (diff) | |
download | busybox-w32-beabe60650d0ffc26de94462182c9073578c18eb.tar.gz busybox-w32-beabe60650d0ffc26de94462182c9073578c18eb.tar.bz2 busybox-w32-beabe60650d0ffc26de94462182c9073578c18eb.zip |
patch by Tito which uses a lot more busybox functions to reduce size nicely
git-svn-id: svn://busybox.net/trunk/busybox@10262 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'e2fsprogs/lsattr.c')
-rw-r--r-- | e2fsprogs/lsattr.c | 40 |
1 files changed, 18 insertions, 22 deletions
diff --git a/e2fsprogs/lsattr.c b/e2fsprogs/lsattr.c index 62b9535c2..475a66f67 100644 --- a/e2fsprogs/lsattr.c +++ b/e2fsprogs/lsattr.c | |||
@@ -34,9 +34,9 @@ | |||
34 | #include "e2p/e2p.h" | 34 | #include "e2p/e2p.h" |
35 | 35 | ||
36 | #ifdef __GNUC__ | 36 | #ifdef __GNUC__ |
37 | #define EXT2FS_ATTR(x) __attribute__(x) | 37 | # define EXT2FS_ATTR(x) __attribute__(x) |
38 | #else | 38 | #else |
39 | #define EXT2FS_ATTR(x) | 39 | # define EXT2FS_ATTR(x) |
40 | #endif | 40 | #endif |
41 | 41 | ||
42 | #define OPT_RECUR 1 | 42 | #define OPT_RECUR 1 |
@@ -59,25 +59,26 @@ static void list_attributes(const char *name) | |||
59 | unsigned long fsflags; | 59 | unsigned long fsflags; |
60 | unsigned long generation; | 60 | unsigned long generation; |
61 | 61 | ||
62 | if (fgetflags(name, &fsflags) == -1) { | 62 | if (fgetflags(name, &fsflags) == -1) |
63 | bb_perror_msg("While reading flags on %s", name); | 63 | goto read_err; |
64 | return; | ||
65 | } | ||
66 | if (flags & OPT_GENERATION) { | 64 | if (flags & OPT_GENERATION) { |
67 | if (fgetversion(name, &generation) == -1) { | 65 | if (fgetversion(name, &generation) == -1) |
68 | bb_perror_msg("While reading version on %s", name); | 66 | goto read_err; |
69 | return; | ||
70 | } | ||
71 | printf("%5lu ", generation); | 67 | printf("%5lu ", generation); |
72 | } | 68 | } |
69 | |||
73 | if (flags & OPT_PF_LONG) { | 70 | if (flags & OPT_PF_LONG) { |
74 | printf("%-28s ", name); | 71 | printf("%-28s ", name); |
75 | print_flags(stdout, fsflags, PFOPT_LONG); | 72 | print_flags(stdout, fsflags, PFOPT_LONG); |
76 | fputc('\n', stdout); | 73 | printf("\n"); |
77 | } else { | 74 | } else { |
78 | print_flags(stdout, fsflags, 0); | 75 | print_flags(stdout, fsflags, 0); |
79 | printf(" %s\n", name); | 76 | printf(" %s\n", name); |
80 | } | 77 | } |
78 | |||
79 | return; | ||
80 | read_err: | ||
81 | bb_perror_msg("reading %s", name); | ||
81 | } | 82 | } |
82 | 83 | ||
83 | static int lsattr_dir_proc(const char *, struct dirent *, void *); | 84 | static int lsattr_dir_proc(const char *, struct dirent *, void *); |
@@ -86,9 +87,9 @@ static void lsattr_args(const char *name) | |||
86 | { | 87 | { |
87 | STRUCT_STAT st; | 88 | STRUCT_STAT st; |
88 | 89 | ||
89 | if (LSTAT(name, &st) == -1) | 90 | if (LSTAT(name, &st) == -1) { |
90 | bb_perror_msg("while trying to stat %s", name); | 91 | bb_perror_msg("stating %s", name); |
91 | else { | 92 | } else { |
92 | if (S_ISDIR(st.st_mode) && !(flags & OPT_DIRS_OPT)) | 93 | if (S_ISDIR(st.st_mode) && !(flags & OPT_DIRS_OPT)) |
93 | iterate_on_dir(name, lsattr_dir_proc, NULL); | 94 | iterate_on_dir(name, lsattr_dir_proc, NULL); |
94 | else | 95 | else |
@@ -101,14 +102,8 @@ static int lsattr_dir_proc(const char *dir_name, struct dirent *de, | |||
101 | { | 102 | { |
102 | STRUCT_STAT st; | 103 | STRUCT_STAT st; |
103 | char *path; | 104 | char *path; |
104 | int i = strlen(dir_name); | ||
105 | 105 | ||
106 | if (i && dir_name[i-1] == '/') | 106 | path = concat_path_file(dir_name, de->d_name); |
107 | i = asprintf(&path, "%s%s", dir_name, de->d_name); | ||
108 | else | ||
109 | i = asprintf(&path, "%s/%s", dir_name, de->d_name); | ||
110 | if (i == -1) | ||
111 | bb_error_msg_and_die(bb_msg_memory_exhausted); | ||
112 | 107 | ||
113 | if (LSTAT(path, &st) == -1) | 108 | if (LSTAT(path, &st) == -1) |
114 | bb_perror_msg(path); | 109 | bb_perror_msg(path); |
@@ -116,7 +111,8 @@ static int lsattr_dir_proc(const char *dir_name, struct dirent *de, | |||
116 | if (de->d_name[0] != '.' || (flags & OPT_ALL)) { | 111 | if (de->d_name[0] != '.' || (flags & OPT_ALL)) { |
117 | list_attributes(path); | 112 | list_attributes(path); |
118 | if (S_ISDIR(st.st_mode) && (flags & OPT_RECUR) && | 113 | if (S_ISDIR(st.st_mode) && (flags & OPT_RECUR) && |
119 | strcmp(de->d_name, ".") && strcmp(de->d_name, "..")) { | 114 | (de->d_name[0] != '.' && (de->d_name[1] != '\0' || |
115 | (de->d_name[1] != '.' && de->d_name[2] != '\0')))) { | ||
120 | printf("\n%s:\n", path); | 116 | printf("\n%s:\n", path); |
121 | iterate_on_dir(path, lsattr_dir_proc, NULL); | 117 | iterate_on_dir(path, lsattr_dir_proc, NULL); |
122 | printf("\n"); | 118 | printf("\n"); |