]> git.ipfire.org Git - thirdparty/util-linux.git/blobdiff - sys-utils/zramctl.c
Merge branch 'patch-23' of https://github.com/mariobl/util-linux
[thirdparty/util-linux.git] / sys-utils / zramctl.c
index 69267c860c3fe15410e15ac42ab7c3f0b87a35f7..cc32ab4f69c8b9d3dce16125dee9acf55b13e7c3 100644 (file)
@@ -163,10 +163,8 @@ static void zram_set_devname(struct zram *z, const char *devname, size_t n)
 
        if (!devname)
                snprintf(z->devname, sizeof(z->devname), "/dev/zram%zu", n);
-       else {
-               strncpy(z->devname, devname, sizeof(z->devname));
-               z->devname[sizeof(z->devname) - 1] = '\0';
-       }
+       else
+               xstrncpy(z->devname, devname, sizeof(z->devname));
 
        DBG(fprintf(stderr, "set devname: %s", z->devname));
        ul_unref_path(z->sysfs);
@@ -293,7 +291,7 @@ static struct path_cxt *zram_get_control(void)
 
 static int zram_control_add(struct zram *z)
 {
-       int n;
+       int n = 0;
        struct path_cxt *ctl;
 
        if (!zram_has_control(z) || !(ctl = zram_get_control()))
@@ -387,7 +385,9 @@ static char *get_mm_stat(struct zram *z, size_t idx, int bytes)
                ul_path_read_string(sysfs, &str, name);
                return str;
 
-       } else if (ul_path_read_u64(sysfs, &num, name) == 0)
+       }
+
+       if (ul_path_read_u64(sysfs, &num, name) == 0)
                return size_to_human_string(SIZE_SUFFIX_1LETTER, num);
 
        return NULL;
@@ -547,7 +547,7 @@ static void __attribute__((__noreturn__)) usage(void)
        fputs(_("Set up and control zram devices.\n"), out);
 
        fputs(USAGE_OPTIONS, out);
-       fputs(_(" -a, --algorithm lzo|lz4|lz4hc|deflate|842   compression algorithm to use\n"), out);
+       fputs(_(" -a, --algorithm <alg>     compression algorithm to use\n"), out);
        fputs(_(" -b, --bytes               print sizes in bytes rather than in human readable format\n"), out);
        fputs(_(" -f, --find                find a free device\n"), out);
        fputs(_(" -n, --noheadings          don't print headings\n"), out);
@@ -559,13 +559,20 @@ static void __attribute__((__noreturn__)) usage(void)
        fputs(_(" -t, --streams <number>    number of compression streams\n"), out);
 
        fputs(USAGE_SEPARATOR, out);
-       printf(USAGE_HELP_OPTIONS(27));
+       fprintf(out, USAGE_HELP_OPTIONS(27));
+
+       fputs(USAGE_ARGUMENTS, out);
+       fprintf(out, USAGE_ARG_SIZE(_("<size>")));
+
+       fputs(_(" <alg> specify algorithm, supported are:\n"), out);
+       fputs(_("   lzo, lz4, lz4hc, deflate, 842 and zstd\n"), out);
+       fputs(_("   (List may be inaccurate, consult man page.)\n"), out);
 
        fputs(USAGE_COLUMNS, out);
        for (i = 0; i < ARRAY_SIZE(infos); i++)
                fprintf(out, " %11s  %s\n", infos[i].name, _(infos[i].help));
 
-       printf(USAGE_MAN_TAIL("zramctl(8)"));
+       fprintf(out, USAGE_MAN_TAIL("zramctl(8)"));
        exit(EXIT_SUCCESS);
 }
 
@@ -616,7 +623,7 @@ int main(int argc, char **argv)
        setlocale(LC_ALL, "");
        bindtextdomain(PACKAGE, LOCALEDIR);
        textdomain(PACKAGE);
-       atexit(close_stdout);
+       close_stdout_atexit();
 
        while ((c = getopt_long(argc, argv, "a:bfho:nrs:t:V", longopts, NULL)) != -1) {
 
@@ -659,9 +666,9 @@ int main(int argc, char **argv)
                case 'n':
                        no_headings = 1;
                        break;
+
                case 'V':
-                       printf(UTIL_LINUX_VERSION);
-                       return EXIT_SUCCESS;
+                       print_version(EXIT_SUCCESS);
                case 'h':
                        usage();
                default: