X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=misc%2Flsattr.c;h=e5e59690f493c7f2c5b7b119ae77d1f1ec865248;hb=304e11c2c1878ef392095d10bf5e93f7ea7131e4;hp=2d8de6971caa20ab3377d2d22c2717a6111b8f31;hpb=b705640ae162093d40fc9f77e716bec891561ffe;p=tools%2Fe2fsprogs.git diff --git a/misc/lsattr.c b/misc/lsattr.c index 2d8de69..e5e5969 100644 --- a/misc/lsattr.c +++ b/misc/lsattr.c @@ -19,6 +19,7 @@ #define _LARGEFILE64_SOURCE +#include "config.h" #include #include #ifdef HAVE_ERRNO_H @@ -45,6 +46,12 @@ extern char *optarg; #include "../version.h" #include "nls-enable.h" +#ifdef __GNUC__ +#define EXT2FS_ATTR(x) __attribute__(x) +#else +#define EXT2FS_ATTR(x) +#endif + static const char * program_name = "lsattr"; static int all; @@ -68,7 +75,7 @@ static void usage(void) exit(1); } -static void list_attributes (const char * name) +static int list_attributes (const char * name) { unsigned long flags; unsigned long generation; @@ -76,14 +83,14 @@ static void list_attributes (const char * name) if (fgetflags (name, &flags) == -1) { com_err (program_name, errno, _("While reading flags on %s"), name); - return; + return -1; } if (generation_opt) { if (fgetversion (name, &generation) == -1) { com_err (program_name, errno, _("While reading version on %s"), name); - return; + return -1; } printf ("%5lu ", generation); } @@ -95,33 +102,42 @@ static void list_attributes (const char * name) print_flags(stdout, flags, pf_options); printf(" %s\n", name); } + return 0; } static int lsattr_dir_proc (const char *, struct dirent *, void *); -static void lsattr_args (const char * name) +static int lsattr_args (const char * name) { STRUCT_STAT st; + int retval = 0; - if (LSTAT (name, &st) == -1) + if (LSTAT (name, &st) == -1) { com_err (program_name, errno, _("while trying to stat %s"), name); - else { + retval = -1; + } else { if (S_ISDIR(st.st_mode) && !dirs_opt) - iterate_on_dir (name, lsattr_dir_proc, NULL); + retval = iterate_on_dir (name, lsattr_dir_proc, NULL); else - list_attributes (name); + retval = list_attributes (name); } + return retval; } -static int lsattr_dir_proc (const char * dir_name, struct dirent * de, void * private) +static int lsattr_dir_proc (const char * dir_name, struct dirent * de, + void * private EXT2FS_ATTR((unused))) { STRUCT_STAT st; char *path; + int dir_len = strlen(dir_name); - path = malloc(strlen (dir_name) + 1 + strlen (de->d_name) + 1); + path = malloc(dir_len + strlen (de->d_name) + 2); - sprintf (path, "%s/%s", dir_name, de->d_name); + if (dir_len && dir_name[dir_len-1] == '/') + sprintf (path, "%s%s", dir_name, de->d_name); + else + sprintf (path, "%s/%s", dir_name, de->d_name); if (LSTAT (path, &st) == -1) perror (path); else { @@ -144,11 +160,14 @@ int main (int argc, char ** argv) { int c; int i; + int err, retval = 0; #ifdef ENABLE_NLS setlocale(LC_MESSAGES, ""); + setlocale(LC_CTYPE, ""); bindtextdomain(NLS_CAT_NAME, LOCALEDIR); textdomain(NLS_CAT_NAME); + set_com_err_gettext(gettext); #endif if (argc && *argv) program_name = *argv; @@ -178,13 +197,17 @@ int main (int argc, char ** argv) } if (verbose) - fprintf (stderr, _("lsattr %s, %s for EXT2 FS %s, %s\n"), - E2FSPROGS_VERSION, E2FSPROGS_DATE, - EXT2FS_VERSION, EXT2FS_DATE); - if (optind > argc - 1) - lsattr_args ("."); - else - for (i = optind; i < argc; i++) - lsattr_args (argv[i]); - exit(0); + fprintf (stderr, "lsattr %s (%s)\n", + E2FSPROGS_VERSION, E2FSPROGS_DATE); + if (optind > argc - 1) { + if (lsattr_args (".") == -1) + retval = 1; + } else { + for (i = optind; i < argc; i++) { + err = lsattr_args (argv[i]); + if (err) + retval = 1; + } + } + exit(retval); }