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 | |
parent | 6adfd349e989346a40dd95672276eb15f4018b4a (diff) |
patch by Tito which uses a lot more busybox functions to reduce size nicely
Diffstat (limited to 'e2fsprogs')
-rw-r--r-- | e2fsprogs/chattr.c | 46 | ||||
-rw-r--r-- | e2fsprogs/lsattr.c | 40 |
2 files changed, 37 insertions, 49 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 @@ #include <ext2fs/ext2_fs.h> #ifdef __GNUC__ -#define EXT2FS_ATTR(x) __attribute__(x) +# define EXT2FS_ATTR(x) __attribute__(x) #else -#define EXT2FS_ATTR(x) +# define EXT2FS_ATTR(x) #endif #include "e2fsbb.h" @@ -122,7 +122,7 @@ static void change_attributes(const char * name) STRUCT_STAT st; if (LSTAT(name, &st) == -1) { - bb_error_msg("while trying to stat %s", name); + bb_error_msg("stat %s failed", name); return; } if (S_ISLNK(st.st_mode) && recursive) @@ -137,13 +137,13 @@ static void change_attributes(const char * name) if (flags & OPT_SET_VER) if (fsetversion(name, version) == -1) - bb_error_msg("while setting version on %s", name); + bb_error_msg("setting version on %s", name); if (flags & OPT_SET) { fsflags = sf; } else { if (fgetflags(name, &fsflags) == -1) { - bb_error_msg("while reading flags on %s", name); + bb_error_msg("reading flags on %s", name); goto skip_setflags; } if (flags & OPT_REM) @@ -154,7 +154,7 @@ static void change_attributes(const char * name) fsflags &= ~EXT2_DIRSYNC_FL; } if (fsetflags(name, fsflags) == -1) - bb_error_msg("while setting flags on %s", name); + bb_error_msg("setting flags on %s", name); skip_setflags: if (S_ISDIR(st.st_mode) && recursive) @@ -167,11 +167,11 @@ static int chattr_dir_proc(const char *dir_name, struct dirent *de, /*if (strcmp(de->d_name, ".") && strcmp(de->d_name, "..")) {*/ if (de->d_name[0] == '.' && (de->d_name[1] == '\0' || \ (de->d_name[1] == '.' && de->d_name[2] == '\0'))) { - char *path; - if (asprintf(&path, "%s/%s", dir_name, de->d_name) == -1) - bb_error_msg_and_die(bb_msg_memory_exhausted); - change_attributes(path); - free(path); + char *path = concat_subpath_file(dir_name, de->d_name); + if (path) { + change_attributes(path); + free(path); + } } return 0; } @@ -196,10 +196,8 @@ int chattr_main(int argc, char **argv) if (i >= argc) bb_show_usage(); version = strtol(argv[i], &tmp, 0); - if (*tmp) { - bb_error_msg("bad version - %s", arg); - bb_show_usage(); - } + if (*tmp) + bb_error_msg_and_die("bad version '%s'", arg); flags |= OPT_SET_VER; continue; } @@ -212,18 +210,12 @@ int chattr_main(int argc, char **argv) /* run sanity checks on all the arguments given us */ if (i >= argc) bb_show_usage(); - if ((flags & OPT_SET) && ((flags & OPT_ADD) || (flags & OPT_REM))) { - bb_error_msg("= is incompatible with - and +"); - return EXIT_FAILURE; - } - if ((rf & af) != 0) { - bb_error_msg("Can't both set and unset same flag"); - return EXIT_FAILURE; - } - if (!flags) { - bb_error_msg("Must use '-v', =, - or +"); - return EXIT_FAILURE; - } + if ((flags & OPT_SET) && ((flags & OPT_ADD) || (flags & OPT_REM))) + bb_error_msg_and_die("= is incompatible with - and +"); + if ((rf & af) != 0) + bb_error_msg_and_die("Can't set and unset a flag"); + if (!flags) + bb_error_msg_and_die("Must use '-v', =, - or +"); /* now run chattr on all the files passed to us */ while (i < argc) 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 @@ #include "e2p/e2p.h" #ifdef __GNUC__ -#define EXT2FS_ATTR(x) __attribute__(x) +# define EXT2FS_ATTR(x) __attribute__(x) #else -#define EXT2FS_ATTR(x) +# define EXT2FS_ATTR(x) #endif #define OPT_RECUR 1 @@ -59,25 +59,26 @@ static void list_attributes(const char *name) unsigned long fsflags; unsigned long generation; - if (fgetflags(name, &fsflags) == -1) { - bb_perror_msg("While reading flags on %s", name); - return; - } + if (fgetflags(name, &fsflags) == -1) + goto read_err; if (flags & OPT_GENERATION) { - if (fgetversion(name, &generation) == -1) { - bb_perror_msg("While reading version on %s", name); - return; - } + if (fgetversion(name, &generation) == -1) + goto read_err; printf("%5lu ", generation); } + if (flags & OPT_PF_LONG) { printf("%-28s ", name); print_flags(stdout, fsflags, PFOPT_LONG); - fputc('\n', stdout); + printf("\n"); } else { print_flags(stdout, fsflags, 0); printf(" %s\n", name); } + + return; +read_err: + bb_perror_msg("reading %s", name); } static int lsattr_dir_proc(const char *, struct dirent *, void *); @@ -86,9 +87,9 @@ static void lsattr_args(const char *name) { STRUCT_STAT st; - if (LSTAT(name, &st) == -1) - bb_perror_msg("while trying to stat %s", name); - else { + if (LSTAT(name, &st) == -1) { + bb_perror_msg("stating %s", name); + } else { if (S_ISDIR(st.st_mode) && !(flags & OPT_DIRS_OPT)) iterate_on_dir(name, lsattr_dir_proc, NULL); else @@ -101,14 +102,8 @@ static int lsattr_dir_proc(const char *dir_name, struct dirent *de, { STRUCT_STAT st; char *path; - int i = strlen(dir_name); - if (i && dir_name[i-1] == '/') - i = asprintf(&path, "%s%s", dir_name, de->d_name); - else - i = asprintf(&path, "%s/%s", dir_name, de->d_name); - if (i == -1) - bb_error_msg_and_die(bb_msg_memory_exhausted); + path = concat_path_file(dir_name, de->d_name); if (LSTAT(path, &st) == -1) bb_perror_msg(path); @@ -116,7 +111,8 @@ static int lsattr_dir_proc(const char *dir_name, struct dirent *de, if (de->d_name[0] != '.' || (flags & OPT_ALL)) { list_attributes(path); if (S_ISDIR(st.st_mode) && (flags & OPT_RECUR) && - strcmp(de->d_name, ".") && strcmp(de->d_name, "..")) { + (de->d_name[0] != '.' && (de->d_name[1] != '\0' || + (de->d_name[1] != '.' && de->d_name[2] != '\0')))) { printf("\n%s:\n", path); iterate_on_dir(path, lsattr_dir_proc, NULL); printf("\n"); |