]> git.ipfire.org Git - thirdparty/util-linux.git/blobdiff - misc-utils/uuidparse.c
hwclock: free temporary variable before return
[thirdparty/util-linux.git] / misc-utils / uuidparse.c
index 5fa34b23d2241346cf7ab621009532a9c4c9e2d2..33d961c922cd123621826990e33212c048f3990e 100644 (file)
@@ -45,6 +45,7 @@
 #include <string.h>
 #include <time.h>
 #include <unistd.h>
+#include <uuid.h>
 
 #include "c.h"
 #include "closestream.h"
 #include "optutils.h"
 #include "strutils.h"
 #include "timeutils.h"
-#include "uuid.h"
 #include "xalloc.h"
 
-#define UUID_STR_LEN 37
-
 /* column IDs */
 enum {
        COL_UUID = 0,
@@ -99,17 +97,17 @@ static void __attribute__((__noreturn__)) usage(void)
        fprintf(stdout, _(" %s [options] <uuid ...>\n"), program_invocation_short_name);
 
        fputs(USAGE_OPTIONS, stdout);
-       puts(_(" -J, --json             use JSON output format"));
-       puts(_(" -n, --noheadings       don't print headings"));
-       puts(_(" -o, --output <list>    COLUMNS to display (see below)"));
-       puts(_(" -r, --raw              use the raw output format"));
-       printf(USAGE_HELP_OPTIONS(24));
+       fputsln(_(" -J, --json             use JSON output format"), stdout);
+       fputsln(_(" -n, --noheadings       don't print headings"), stdout);
+       fputsln(_(" -o, --output <list>    COLUMNS to display (see below)"), stdout);
+       fputsln(_(" -r, --raw              use the raw output format"), stdout);
+       fprintf(stdout, USAGE_HELP_OPTIONS(24));
 
        fputs(USAGE_COLUMNS, stdout);
        for (i = 0; i < ARRAY_SIZE(infos); i++)
                fprintf(stdout, " %8s  %s\n", infos[i].name, _(infos[i].help));
 
-       printf(USAGE_MAN_TAIL("uuidparse(1)"));
+       fprintf(stdout, USAGE_MAN_TAIL("uuidparse(1)"));
        exit(EXIT_SUCCESS);
 }
 
@@ -146,7 +144,7 @@ static void fill_table_row(struct libscols_table *tb, char const *const uuid)
        size_t i;
        uuid_t buf;
        int invalid = 0;
-       int variant, type;
+       int variant = -1, type = -1;
 
        assert(tb);
        assert(uuid);
@@ -193,26 +191,28 @@ static void fill_table_row(struct libscols_table *tb, char const *const uuid)
                                str = xstrdup(_("invalid"));
                                break;
                        }
+                       if (variant != UUID_VARIANT_DCE)
+                               break;
                        switch (type) {
-                       case 0:
-                               if (strspn(uuid, "0-") == 36)
+                       case UUID_TYPE_DCE_NIL:
+                               if (uuid_is_null(buf))
                                        str = xstrdup(_("nil"));
                                else
                                        str = xstrdup(_("unknown"));
                                break;
-                       case 1:
+                       case UUID_TYPE_DCE_TIME:
                                str = xstrdup(_("time-based"));
                                break;
-                       case 2:
+                       case UUID_TYPE_DCE_SECURITY:
                                str = xstrdup("DCE");
                                break;
-                       case 3:
+                       case UUID_TYPE_DCE_MD5:
                                str = xstrdup(_("name-based"));
                                break;
-                       case 4:
+                       case UUID_TYPE_DCE_RANDOM:
                                str = xstrdup(_("random"));
                                break;
-                       case 5:
+                       case UUID_TYPE_DCE_SHA1:
                                str = xstrdup(_("sha1-based"));
                                break;
                        default:
@@ -224,19 +224,13 @@ static void fill_table_row(struct libscols_table *tb, char const *const uuid)
                                str = xstrdup(_("invalid"));
                                break;
                        }
-                       if (variant == UUID_VARIANT_DCE && type == 1) {
+                       if (variant == UUID_VARIANT_DCE && type == UUID_TYPE_DCE_TIME) {
                                struct timeval tv;
-                               char date_buf[ISO_8601_BUFSIZ + 4];
+                               char date_buf[ISO_BUFSIZ];
 
                                uuid_time(buf, &tv);
-                               strtimeval_iso(&tv,
-                                              ISO_8601_DATE |
-                                                ISO_8601_TIME |
-                                                ISO_8601_COMMAUSEC |
-                                                ISO_8601_TIMEZONE |
-                                                ISO_8601_SPACE,
-                                              date_buf,
-                                              sizeof(date_buf));
+                               strtimeval_iso(&tv, ISO_TIMESTAMP_COMMA,
+                                              date_buf, sizeof(date_buf));
                                str = xstrdup(date_buf);
                        }
                        break;
@@ -281,8 +275,7 @@ static void print_output(struct control const *const ctrl, int argc,
        if (i == 0) {
                char uuid[UUID_STR_LEN];
 
-               while (scanf(" %" stringify_value(UUID_STR_LEN)
-                            "[^ \t\n]%*c", uuid) && !feof(stdin))
+               while (scanf(" %36[^ \t\n]%*c", uuid) && !feof(stdin))
                        fill_table_row(tb, uuid);
        }
        scols_print_table(tb);
@@ -313,7 +306,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, "Jno:rVh", longopts, NULL)) != -1) {
                err_exclusive_options(c, longopts, excl, excl_st);
@@ -330,9 +323,9 @@ int main(int argc, char **argv)
                case 'r':
                        ctrl.raw = 1;
                        break;
+
                case 'V':
-                       printf(UTIL_LINUX_VERSION);
-                       return EXIT_SUCCESS;
+                       print_version(EXIT_SUCCESS);
                case 'h':
                        usage();
                default: