Simplify code by having PRT_uuid_to_type() return -1 when
authorkrw <krw@openbsd.org>
Wed, 29 Mar 2023 14:20:50 +0000 (14:20 +0000)
committerkrw <krw@openbsd.org>
Wed, 29 Mar 2023 14:20:50 +0000 (14:20 +0000)
no type can be found. 0 is a valid type!

No functional change.

sbin/fdisk/cmd.c
sbin/fdisk/part.c

index 4a26377..ffeb1d0 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: cmd.c,v 1.170 2023/03/26 16:23:58 krw Exp $   */
+/*     $OpenBSD: cmd.c,v 1.171 2023/03/29 14:20:50 krw Exp $   */
 
 /*
  * Copyright (c) 1997 Tobias Weingartner
@@ -594,24 +594,18 @@ ask_uuid(const struct uuid *olduuid)
        char                     lbuf[LINEBUFSZ];
        char                    *dflt = NULL;
        uint32_t                 status;
-       int                      num = 0;
-
-       uuid = *olduuid;
-       if (uuid_is_nil(&uuid, NULL) == 0) {
-               num = PRT_uuid_to_type(&uuid);
-               if (num == 0) {
-                       uuid_to_string(&uuid, &dflt, &status);
-                       if (status != uuid_s_ok) {
-                               printf("uuid_to_string() failed\n");
-                               goto done;
-                       }
-               }
-       }
-       if (dflt == NULL) {
-               if (asprintf(&dflt, "%X", num) == -1) {
-                       warn("asprintf()");
+       int                      num;
+
+       num = PRT_uuid_to_type(olduuid);
+       if (num == -1) {
+               uuid_to_string(olduuid, &dflt, &status);
+               if (status != uuid_s_ok) {
+                       printf("uuid_to_string() failed\n");
                        goto done;
                }
+       } else if (asprintf(&dflt, "%X", num) == -1) {
+               warn("asprintf()");
+               goto done;
        }
 
        for (;;) {
index 03702be..3597e32 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: part.c,v 1.139 2023/03/26 16:23:58 krw Exp $  */
+/*     $OpenBSD: part.c,v 1.140 2023/03/29 14:20:50 krw Exp $  */
 
 /*
  * Copyright (c) 1997 Tobias Weingartner
@@ -527,7 +527,7 @@ PRT_uuid_to_type(const struct uuid *uuid)
 
        gt = find_gpt_type(uuid);
        if (gt == NULL)
-               return 0;
+               return -1;
        else
                return gt->gt_type;
 }