nfsmount: remove some really old code (for kernels 1.x!) + small cleanups.
[oweals/busybox.git] / e2fsprogs / lsattr.c
index d3896637db86358020f9e48d225a8a8c6086baf7..5c20d25f381510f58fcfadcee90160d56e50b051 100644 (file)
@@ -1,3 +1,4 @@
+/* vi: set sw=4 ts=4: */
 /*
  * lsattr.c            - List file attributes on an ext2 file system
  *
 #include <sys/param.h>
 #include <sys/stat.h>
 
-#include <ext2fs/ext2_fs.h>
+#include "ext2fs/ext2_fs.h"
 #include "e2fsbb.h"
 #include "e2p/e2p.h"
 
-#ifdef __GNUC__
-#define EXT2FS_ATTR(x) __attribute__(x)
-#else
-#define EXT2FS_ATTR(x)
-#endif
-
 #define OPT_RECUR 1
 #define OPT_ALL 2
 #define OPT_DIRS_OPT 4
@@ -59,25 +54,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 +82,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
@@ -96,19 +92,13 @@ static void lsattr_args(const char *name)
        }
 }
 
-static int lsattr_dir_proc(const char *dir_name, struct dirent *de, 
-                           void *private EXT2FS_ATTR((unused)))
+static int lsattr_dir_proc(const char *dir_name, struct dirent *de,
+                          void *private)
 {
        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_perror_msg_and_die("asprintf failed");
+       path = concat_path_file(dir_name, de->d_name);
 
        if (LSTAT(path, &st) == -1)
                bb_perror_msg(path);
@@ -116,7 +106,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");