diff options
author | Mike Frysinger <vapier@gentoo.org> | 2005-05-07 07:17:43 +0000 |
---|---|---|
committer | Mike Frysinger <vapier@gentoo.org> | 2005-05-07 07:17:43 +0000 |
commit | ea338fffb5e7e78ba215c65e50fb294755389bbf (patch) | |
tree | c9beac6e70d04c3ca149a8be37cf6795e0609135 /e2fsprogs/chattr.c | |
parent | 6adfd349e989346a40dd95672276eb15f4018b4a (diff) | |
download | busybox-w32-ea338fffb5e7e78ba215c65e50fb294755389bbf.tar.gz busybox-w32-ea338fffb5e7e78ba215c65e50fb294755389bbf.tar.bz2 busybox-w32-ea338fffb5e7e78ba215c65e50fb294755389bbf.zip |
patch by Tito which uses a lot more busybox functions to reduce size nicely
Diffstat (limited to 'e2fsprogs/chattr.c')
-rw-r--r-- | e2fsprogs/chattr.c | 46 |
1 files changed, 19 insertions, 27 deletions
diff --git a/e2fsprogs/chattr.c b/e2fsprogs/chattr.c index 5ba458934..1471c851d 100644 --- a/e2fsprogs/chattr.c +++ b/e2fsprogs/chattr.c | |||
@@ -31,9 +31,9 @@ | |||
31 | #include <ext2fs/ext2_fs.h> | 31 | #include <ext2fs/ext2_fs.h> |
32 | 32 | ||
33 | #ifdef __GNUC__ | 33 | #ifdef __GNUC__ |
34 | #define EXT2FS_ATTR(x) __attribute__(x) | 34 | # define EXT2FS_ATTR(x) __attribute__(x) |
35 | #else | 35 | #else |
36 | #define EXT2FS_ATTR(x) | 36 | # define EXT2FS_ATTR(x) |
37 | #endif | 37 | #endif |
38 | 38 | ||
39 | #include "e2fsbb.h" | 39 | #include "e2fsbb.h" |
@@ -122,7 +122,7 @@ static void change_attributes(const char * name) | |||
122 | STRUCT_STAT st; | 122 | STRUCT_STAT st; |
123 | 123 | ||
124 | if (LSTAT(name, &st) == -1) { | 124 | if (LSTAT(name, &st) == -1) { |
125 | bb_error_msg("while trying to stat %s", name); | 125 | bb_error_msg("stat %s failed", name); |
126 | return; | 126 | return; |
127 | } | 127 | } |
128 | if (S_ISLNK(st.st_mode) && recursive) | 128 | if (S_ISLNK(st.st_mode) && recursive) |
@@ -137,13 +137,13 @@ static void change_attributes(const char * name) | |||
137 | 137 | ||
138 | if (flags & OPT_SET_VER) | 138 | if (flags & OPT_SET_VER) |
139 | if (fsetversion(name, version) == -1) | 139 | if (fsetversion(name, version) == -1) |
140 | bb_error_msg("while setting version on %s", name); | 140 | bb_error_msg("setting version on %s", name); |
141 | 141 | ||
142 | if (flags & OPT_SET) { | 142 | if (flags & OPT_SET) { |
143 | fsflags = sf; | 143 | fsflags = sf; |
144 | } else { | 144 | } else { |
145 | if (fgetflags(name, &fsflags) == -1) { | 145 | if (fgetflags(name, &fsflags) == -1) { |
146 | bb_error_msg("while reading flags on %s", name); | 146 | bb_error_msg("reading flags on %s", name); |
147 | goto skip_setflags; | 147 | goto skip_setflags; |
148 | } | 148 | } |
149 | if (flags & OPT_REM) | 149 | if (flags & OPT_REM) |
@@ -154,7 +154,7 @@ static void change_attributes(const char * name) | |||
154 | fsflags &= ~EXT2_DIRSYNC_FL; | 154 | fsflags &= ~EXT2_DIRSYNC_FL; |
155 | } | 155 | } |
156 | if (fsetflags(name, fsflags) == -1) | 156 | if (fsetflags(name, fsflags) == -1) |
157 | bb_error_msg("while setting flags on %s", name); | 157 | bb_error_msg("setting flags on %s", name); |
158 | 158 | ||
159 | skip_setflags: | 159 | skip_setflags: |
160 | if (S_ISDIR(st.st_mode) && recursive) | 160 | if (S_ISDIR(st.st_mode) && recursive) |
@@ -167,11 +167,11 @@ static int chattr_dir_proc(const char *dir_name, struct dirent *de, | |||
167 | /*if (strcmp(de->d_name, ".") && strcmp(de->d_name, "..")) {*/ | 167 | /*if (strcmp(de->d_name, ".") && strcmp(de->d_name, "..")) {*/ |
168 | if (de->d_name[0] == '.' && (de->d_name[1] == '\0' || \ | 168 | if (de->d_name[0] == '.' && (de->d_name[1] == '\0' || \ |
169 | (de->d_name[1] == '.' && de->d_name[2] == '\0'))) { | 169 | (de->d_name[1] == '.' && de->d_name[2] == '\0'))) { |
170 | char *path; | 170 | char *path = concat_subpath_file(dir_name, de->d_name); |
171 | if (asprintf(&path, "%s/%s", dir_name, de->d_name) == -1) | 171 | if (path) { |
172 | bb_error_msg_and_die(bb_msg_memory_exhausted); | 172 | change_attributes(path); |
173 | change_attributes(path); | 173 | free(path); |
174 | free(path); | 174 | } |
175 | } | 175 | } |
176 | return 0; | 176 | return 0; |
177 | } | 177 | } |
@@ -196,10 +196,8 @@ int chattr_main(int argc, char **argv) | |||
196 | if (i >= argc) | 196 | if (i >= argc) |
197 | bb_show_usage(); | 197 | bb_show_usage(); |
198 | version = strtol(argv[i], &tmp, 0); | 198 | version = strtol(argv[i], &tmp, 0); |
199 | if (*tmp) { | 199 | if (*tmp) |
200 | bb_error_msg("bad version - %s", arg); | 200 | bb_error_msg_and_die("bad version '%s'", arg); |
201 | bb_show_usage(); | ||
202 | } | ||
203 | flags |= OPT_SET_VER; | 201 | flags |= OPT_SET_VER; |
204 | continue; | 202 | continue; |
205 | } | 203 | } |
@@ -212,18 +210,12 @@ int chattr_main(int argc, char **argv) | |||
212 | /* run sanity checks on all the arguments given us */ | 210 | /* run sanity checks on all the arguments given us */ |
213 | if (i >= argc) | 211 | if (i >= argc) |
214 | bb_show_usage(); | 212 | bb_show_usage(); |
215 | if ((flags & OPT_SET) && ((flags & OPT_ADD) || (flags & OPT_REM))) { | 213 | if ((flags & OPT_SET) && ((flags & OPT_ADD) || (flags & OPT_REM))) |
216 | bb_error_msg("= is incompatible with - and +"); | 214 | bb_error_msg_and_die("= is incompatible with - and +"); |
217 | return EXIT_FAILURE; | 215 | if ((rf & af) != 0) |
218 | } | 216 | bb_error_msg_and_die("Can't set and unset a flag"); |
219 | if ((rf & af) != 0) { | 217 | if (!flags) |
220 | bb_error_msg("Can't both set and unset same flag"); | 218 | bb_error_msg_and_die("Must use '-v', =, - or +"); |
221 | return EXIT_FAILURE; | ||
222 | } | ||
223 | if (!flags) { | ||
224 | bb_error_msg("Must use '-v', =, - or +"); | ||
225 | return EXIT_FAILURE; | ||
226 | } | ||
227 | 219 | ||
228 | /* now run chattr on all the files passed to us */ | 220 | /* now run chattr on all the files passed to us */ |
229 | while (i < argc) | 221 | while (i < argc) |