]> git.ipfire.org Git - thirdparty/util-linux.git/blobdiff - misc-utils/uuidparse.c
misc: consolidate version printing and close_stdout()
[thirdparty/util-linux.git] / misc-utils / uuidparse.c
index 5fa34b23d2241346cf7ab621009532a9c4c9e2d2..eae0b71a15cad495881ee4db62899b2e4b8dacc1 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,
@@ -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);
@@ -226,17 +224,11 @@ static void fill_table_row(struct libscols_table *tb, char const *const uuid)
                        }
                        if (variant == UUID_VARIANT_DCE && type == 1) {
                                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 +273,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 +304,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 +321,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: