OSDN Git Service

Ignore quotes in safe_print().
[android-x86/external-e2fsprogs.git] / misc / blkid.c
index 4bbf9fb..472f017 100644 (file)
@@ -9,6 +9,7 @@
  * %End-Header%
  */
 
+#include "config.h"
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
@@ -37,7 +38,7 @@ extern int optind;
 #include "ext2fs/ext2fs.h"
 #include "blkid/blkid.h"
 
-const char *progname = "blkid";
+static const char *progname = "blkid";
 
 static void print_version(FILE *out)
 {
@@ -86,7 +87,9 @@ static void safe_print(const char *cp, int len)
                        fputc('^', stdout);
                        ch ^= 0x40; /* ^@, ^A, ^B; ^? for DEL */
                }
-               fputc(ch, stdout);
+               if (ch != '"') {
+                       fputc(ch, stdout);
+               }
        }
 }
 
@@ -99,19 +102,27 @@ static int get_terminal_width(void)
        struct winsize  w_win;
 #endif
         const char     *cp;
+       int width = 80;
 
 #ifdef TIOCGSIZE
-       if (ioctl (0, TIOCGSIZE, &t_win) == 0)
-               return (t_win.ts_cols);
+       if (ioctl (0, TIOCGSIZE, &t_win) == 0) {
+               width = t_win.ts_cols;
+               goto got_it;
+       }
 #endif
 #ifdef TIOCGWINSZ
-       if (ioctl (0, TIOCGWINSZ, &w_win) == 0)
-               return (w_win.ws_col);
+       if (ioctl (0, TIOCGWINSZ, &w_win) == 0) {
+               width = w_win.ws_col;
+               goto got_it;
+       }
 #endif
         cp = getenv("COLUMNS");
        if (cp)
-               return strtol(cp, NULL, 10);
-       return 80;
+               width = atoi(cp);
+got_it:
+       if (width > 4096)
+               return 4096;    /* sanity check */
+       return width;
 }
 
 static int pretty_print_word(const char *str, int max_len,
@@ -126,9 +137,9 @@ static int pretty_print_word(const char *str, int max_len,
                len = 0;
        } else if (len > max_len)
                ret = len - max_len;
-       do
+       do {
                fputc(' ', stdout);
-       while (len++ < max_len);
+       while (len++ < max_len);
        return ret;
 }
 
@@ -141,20 +152,21 @@ static void pretty_print_line(const char *device, const char *fs_type,
        static int term_width = -1;
        int len, w;
 
-       if (term_width < 0)
+       if (term_width < 0) {
                term_width = get_terminal_width();
 
-       if (term_width > 80) {
-               term_width -= 80;
-               w = term_width / 10;
-               if (w > 8)
-                       w = 8;
-               term_width -= 2*w;
-               label_len += w;
-               fs_type_len += w;
-               w = term_width/2;
-               device_len += w;
-               mtpt_len +=w;
+               if (term_width > 80) {
+                       term_width -= 80;
+                       w = term_width / 10;
+                       if (w > 8)
+                               w = 8;
+                       term_width -= 2*w;
+                       label_len += w;
+                       fs_type_len += w;
+                       w = term_width/2;
+                       device_len += w;
+                       mtpt_len +=w;
+               }
        }
 
        len = pretty_print_word(device, device_len, 0, 1);
@@ -170,7 +182,6 @@ static void pretty_print_dev(blkid_dev dev)
        blkid_tag_iterate       iter;
        const char              *type, *value, *devname;
        const char              *uuid = "", *fs_type = "", *label = "";
-       char                    *cp;
        int                     len, mount_flags;
        char                    mtpt[80];
        errcode_t               retval;
@@ -284,10 +295,7 @@ int main(int argc, char **argv)
        while ((c = getopt (argc, argv, "c:f:ghlLo:s:t:w:v")) != EOF)
                switch (c) {
                case 'c':
-                       if (optarg && !*optarg)
-                               read = NULL;
-                       else
-                               read = optarg;
+                       read = optarg;
                        if (!write)
                                write = read;
                        break;
@@ -340,13 +348,11 @@ int main(int argc, char **argv)
                        version = 1;
                        break;
                case 'w':
-                       if (optarg && !*optarg)
-                               write = NULL;
-                       else
-                               write = optarg;
+                       write = optarg;
                        break;
                case 'h':
                        err = 0;
+                       /* fallthrough */
                default:
                        usage(err);
                }
@@ -420,10 +426,8 @@ int main(int argc, char **argv)
        }
 
 exit:
-       if (search_type)
-               free(search_type);
-       if (search_value)
-               free(search_value);
+       free(search_type);
+       free(search_value);
        blkid_put_cache(cache);
        return err;
 }