diff options
author | Mike Frysinger <vapier@gentoo.org> | 2005-04-25 04:10:35 +0000 |
---|---|---|
committer | Mike Frysinger <vapier@gentoo.org> | 2005-04-25 04:10:35 +0000 |
commit | d2a64d2fc2b6c6666fc48c531387e72d12c3214a (patch) | |
tree | 216a67c4df7767ffa57a1c36cbeb745607c8ffd3 /e2fsprogs/lsattr.c | |
parent | 560047ce86411972eee9f44197ebcca1f903c128 (diff) | |
download | busybox-w32-d2a64d2fc2b6c6666fc48c531387e72d12c3214a.tar.gz busybox-w32-d2a64d2fc2b6c6666fc48c531387e72d12c3214a.tar.bz2 busybox-w32-d2a64d2fc2b6c6666fc48c531387e72d12c3214a.zip |
bbify to shrink size
Diffstat (limited to 'e2fsprogs/lsattr.c')
-rw-r--r-- | e2fsprogs/lsattr.c | 148 |
1 files changed, 49 insertions, 99 deletions
diff --git a/e2fsprogs/lsattr.c b/e2fsprogs/lsattr.c index 0f1c6f22c..be5723c43 100644 --- a/e2fsprogs/lsattr.c +++ b/e2fsprogs/lsattr.c | |||
@@ -39,99 +39,87 @@ | |||
39 | #define EXT2FS_ATTR(x) | 39 | #define EXT2FS_ATTR(x) |
40 | #endif | 40 | #endif |
41 | 41 | ||
42 | static int all; | 42 | #define OPT_RECUR 1 |
43 | static int dirs_opt; | 43 | #define OPT_ALL 2 |
44 | static unsigned pf_options; | 44 | #define OPT_DIRS_OPT 4 |
45 | static int recursive; | 45 | #define OPT_PF_LONG 8 |
46 | static int verbose; | 46 | #define OPT_GENERATION 16 |
47 | static int generation_opt; | 47 | static int flags; |
48 | 48 | ||
49 | #ifdef _LFS64_LARGEFILE | 49 | #ifdef CONFIG_LFS |
50 | #define LSTAT lstat64 | 50 | # define LSTAT lstat64 |
51 | #define STRUCT_STAT struct stat64 | 51 | # define STRUCT_STAT struct stat64 |
52 | #else | 52 | #else |
53 | #define LSTAT lstat | 53 | # define LSTAT lstat |
54 | #define STRUCT_STAT struct stat | 54 | # define STRUCT_STAT struct stat |
55 | #endif | 55 | #endif |
56 | 56 | ||
57 | #if 0 | 57 | static void list_attributes(const char *name) |
58 | static void usage(void) | ||
59 | { | 58 | { |
60 | fprintf(stderr, _("Usage: %s [-RVadlv] [files...]\n"), program_name); | 59 | unsigned long fsflags; |
61 | exit(1); | ||
62 | } | ||
63 | #endif | ||
64 | |||
65 | static void list_attributes (const char * name) | ||
66 | { | ||
67 | unsigned long flags; | ||
68 | unsigned long generation; | 60 | unsigned long generation; |
69 | 61 | ||
70 | if (fgetflags (name, &flags) == -1) { | 62 | if (fgetflags(name, &fsflags) == -1) { |
71 | com_err (program_name, errno, _("While reading flags on %s"), | 63 | bb_perror_msg("While reading flags on %s", name); |
72 | name); | ||
73 | return; | 64 | return; |
74 | } | 65 | } |
75 | if (generation_opt) { | 66 | if (flags & OPT_GENERATION) { |
76 | if (fgetversion (name, &generation) == -1) { | 67 | if (fgetversion(name, &generation) == -1) { |
77 | com_err (program_name, errno, | 68 | bb_perror_msg("While reading version on %s", name); |
78 | _("While reading version on %s"), | ||
79 | name); | ||
80 | return; | 69 | return; |
81 | } | 70 | } |
82 | printf ("%5lu ", generation); | 71 | printf("%5lu ", generation); |
83 | } | 72 | } |
84 | if (pf_options & PFOPT_LONG) { | 73 | if (flags & OPT_PF_LONG) { |
85 | printf("%-28s ", name); | 74 | printf("%-28s ", name); |
86 | print_flags(stdout, flags, pf_options); | 75 | print_flags(stdout, fsflags, PFOPT_LONG); |
87 | fputc('\n', stdout); | 76 | fputc('\n', stdout); |
88 | } else { | 77 | } else { |
89 | print_flags(stdout, flags, pf_options); | 78 | print_flags(stdout, fsflags, 0); |
90 | printf(" %s\n", name); | 79 | printf(" %s\n", name); |
91 | } | 80 | } |
92 | } | 81 | } |
93 | 82 | ||
94 | static int lsattr_dir_proc (const char *, struct dirent *, void *); | 83 | static int lsattr_dir_proc(const char *, struct dirent *, void *); |
95 | 84 | ||
96 | static void lsattr_args (const char * name) | 85 | static void lsattr_args(const char *name) |
97 | { | 86 | { |
98 | STRUCT_STAT st; | 87 | STRUCT_STAT st; |
99 | 88 | ||
100 | if (LSTAT (name, &st) == -1) | 89 | if (LSTAT(name, &st) == -1) |
101 | com_err (program_name, errno, _("while trying to stat %s"), | 90 | bb_perror_msg("while trying to stat %s", name); |
102 | name); | ||
103 | else { | 91 | else { |
104 | if (S_ISDIR(st.st_mode) && !dirs_opt) | 92 | if (S_ISDIR(st.st_mode) && !(flags & OPT_DIRS_OPT)) |
105 | iterate_on_dir (name, lsattr_dir_proc, NULL); | 93 | iterate_on_dir(name, lsattr_dir_proc, NULL); |
106 | else | 94 | else |
107 | list_attributes (name); | 95 | list_attributes(name); |
108 | } | 96 | } |
109 | } | 97 | } |
110 | 98 | ||
111 | static int lsattr_dir_proc (const char * dir_name, struct dirent * de, | 99 | static int lsattr_dir_proc(const char *dir_name, struct dirent *de, |
112 | void * private EXT2FS_ATTR((unused))) | 100 | void *private EXT2FS_ATTR((unused))) |
113 | { | 101 | { |
114 | STRUCT_STAT st; | 102 | STRUCT_STAT st; |
115 | char *path; | 103 | char *path; |
116 | int dir_len = strlen(dir_name); | 104 | int dir_len = strlen(dir_name); |
117 | 105 | ||
118 | path = malloc(dir_len + strlen (de->d_name) + 2); | 106 | path = malloc(dir_len + strlen(de->d_name) + 2); |
119 | 107 | ||
120 | if (dir_len && dir_name[dir_len-1] == '/') | 108 | if (dir_len && dir_name[dir_len-1] == '/') |
121 | sprintf (path, "%s%s", dir_name, de->d_name); | 109 | sprintf(path, "%s%s", dir_name, de->d_name); |
122 | else | 110 | else |
123 | sprintf (path, "%s/%s", dir_name, de->d_name); | 111 | sprintf(path, "%s/%s", dir_name, de->d_name); |
124 | if (LSTAT (path, &st) == -1) | 112 | if (LSTAT(path, &st) == -1) |
125 | perror (path); | 113 | bb_perror_msg(path); |
126 | else { | 114 | else { |
127 | if (de->d_name[0] != '.' || all) { | 115 | if (de->d_name[0] != '.' || (flags & OPT_ALL)) { |
128 | list_attributes (path); | 116 | list_attributes(path); |
129 | if (S_ISDIR(st.st_mode) && recursive && | 117 | if (S_ISDIR(st.st_mode) && (flags & OPT_RECUR) && |
130 | strcmp(de->d_name, ".") && | 118 | strcmp(de->d_name, ".") && |
131 | strcmp(de->d_name, "..")) { | 119 | strcmp(de->d_name, "..")) { |
132 | printf ("\n%s:\n", path); | 120 | printf("\n%s:\n", path); |
133 | iterate_on_dir (path, lsattr_dir_proc, NULL); | 121 | iterate_on_dir(path, lsattr_dir_proc, NULL); |
134 | printf ("\n"); | 122 | printf("\n"); |
135 | } | 123 | } |
136 | } | 124 | } |
137 | } | 125 | } |
@@ -139,55 +127,17 @@ static int lsattr_dir_proc (const char * dir_name, struct dirent * de, | |||
139 | return 0; | 127 | return 0; |
140 | } | 128 | } |
141 | 129 | ||
142 | int lsattr_main (int argc, char ** argv) | 130 | int lsattr_main(int argc, char **argv) |
143 | { | 131 | { |
144 | int c; | ||
145 | int i; | 132 | int i; |
146 | 133 | ||
147 | #ifdef ENABLE_NLS | 134 | flags = bb_getopt_ulflags(argc, argv, "Radlv"); |
148 | setlocale(LC_MESSAGES, ""); | ||
149 | setlocale(LC_CTYPE, ""); | ||
150 | bindtextdomain(NLS_CAT_NAME, LOCALEDIR); | ||
151 | textdomain(NLS_CAT_NAME); | ||
152 | #endif | ||
153 | #if 0 | ||
154 | if (argc && *argv) | ||
155 | program_name = *argv; | ||
156 | #endif | ||
157 | while ((c = getopt (argc, argv, "Radlv")) != EOF) | ||
158 | switch (c) | ||
159 | { | ||
160 | case 'R': | ||
161 | recursive = 1; | ||
162 | break; | ||
163 | case 'V': | ||
164 | verbose = 1; | ||
165 | break; | ||
166 | case 'a': | ||
167 | all = 1; | ||
168 | break; | ||
169 | case 'd': | ||
170 | dirs_opt = 1; | ||
171 | break; | ||
172 | case 'l': | ||
173 | pf_options = PFOPT_LONG; | ||
174 | break; | ||
175 | case 'v': | ||
176 | generation_opt = 1; | ||
177 | break; | ||
178 | default: | ||
179 | usage(); | ||
180 | } | ||
181 | 135 | ||
182 | #if 0 | ||
183 | if (verbose) | ||
184 | fprintf (stderr, "lsattr %s (%s)\n", | ||
185 | E2FSPROGS_VERSION, E2FSPROGS_DATE); | ||
186 | #endif | ||
187 | if (optind > argc - 1) | 136 | if (optind > argc - 1) |
188 | lsattr_args ("."); | 137 | lsattr_args("."); |
189 | else | 138 | else |
190 | for (i = optind; i < argc; i++) | 139 | for (i = optind; i < argc; i++) |
191 | lsattr_args (argv[i]); | 140 | lsattr_args(argv[i]); |
192 | exit(0); | 141 | |
142 | return EXIT_SUCCESS; | ||
193 | } | 143 | } |