Whamcloud - gitweb
Fix missing space typo's in partinfo and resize2fs
[tools/e2fsprogs.git] / misc / lsattr.c
index 9b9dc54..093f50f 100644 (file)
@@ -17,6 +17,8 @@
  * 98/12/29    - Display version info only when -V specified (G M Sipe)
  */
 
+#define _LARGEFILE64_SOURCE
+
 #include <sys/types.h>
 #include <dirent.h>
 #ifdef HAVE_ERRNO_H
@@ -35,22 +37,36 @@ extern char *optarg;
 #include <string.h>
 #include <sys/param.h>
 #include <sys/stat.h>
-#include <linux/ext2_fs.h>
 
+#include "ext2fs/ext2_fs.h"
 #include "et/com_err.h"
 #include "e2p/e2p.h"
 
 #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 = 0;
-static int dirs_opt = 0;
-static unsigned pf_options = 0;
-static int recursive = 0;
-static int verbose = 0;
-static int generation_opt = 0;
+static int all;
+static int dirs_opt;
+static unsigned pf_options;
+static int recursive;
+static int verbose;
+static int generation_opt;
+
+#ifdef _LFS64_LARGEFILE
+#define LSTAT          lstat64
+#define STRUCT_STAT    struct stat64
+#else
+#define LSTAT          lstat
+#define STRUCT_STAT    struct stat
+#endif
 
 static void usage(void)
 {
@@ -63,24 +79,27 @@ static void list_attributes (const char * name)
        unsigned long flags;
        unsigned long generation;
 
-       if (fgetflags (name, &flags) == -1)
+       if (fgetflags (name, &flags) == -1) {
                com_err (program_name, errno, _("While reading flags on %s"),
                         name);
-       else if (fgetversion (name, &generation) == -1)
-               com_err (program_name, errno, _("While reading version on %s"),
-                        name);
-       else
-       {
-               if (generation_opt)
-                       printf ("%5lu ", generation);
-               if (pf_options & PFOPT_LONG) {
-                       printf("%-28s ", name);
-                       print_flags(stdout, flags, pf_options);
-                       fputc('\n', stdout);
-               } else {
-                       print_flags(stdout, flags, pf_options);
-                       printf(" %s\n", name);
+               return;
+       }
+       if (generation_opt) {
+               if (fgetversion (name, &generation) == -1) {
+                       com_err (program_name, errno,
+                                _("While reading version on %s"),
+                                name);
+                       return;
                }
+               printf ("%5lu ", generation);
+       }
+       if (pf_options & PFOPT_LONG) {
+               printf("%-28s ", name);
+               print_flags(stdout, flags, pf_options);
+               fputc('\n', stdout);
+       } else {
+               print_flags(stdout, flags, pf_options);
+               printf(" %s\n", name);
        }
 }
 
@@ -88,9 +107,9 @@ static int lsattr_dir_proc (const char *, struct dirent *, void *);
 
 static void lsattr_args (const char * name)
 {
-       struct stat st;
+       STRUCT_STAT     st;
 
-       if (lstat (name, &st) == -1)
+       if (LSTAT (name, &st) == -1)
                com_err (program_name, errno, _("while trying to stat %s"),
                         name);
        else {
@@ -101,15 +120,20 @@ static void lsattr_args (const char * name)
        }
 }
 
-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;
+       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 (lstat (path, &st) == -1)
+       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 {
                if (de->d_name[0] != '.' || all) {
@@ -134,6 +158,7 @@ int main (int argc, char ** argv)
 
 #ifdef ENABLE_NLS
        setlocale(LC_MESSAGES, "");
+       setlocale(LC_CTYPE, "");
        bindtextdomain(NLS_CAT_NAME, LOCALEDIR);
        textdomain(NLS_CAT_NAME);
 #endif
@@ -165,9 +190,8 @@ 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);
+               fprintf (stderr, "lsattr %s (%s)\n",
+                        E2FSPROGS_VERSION, E2FSPROGS_DATE);
        if (optind > argc - 1)
                lsattr_args (".");
        else