place.
Allows single-digit partition id's in '-b' as a side benefit.
-/* $OpenBSD: cmd.c,v 1.140 2021/08/24 12:34:04 krw Exp $ */
+/* $OpenBSD: cmd.c,v 1.141 2021/08/28 11:55:17 krw Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
char lbuf[100], *cp;
int num = -1, status;
- do {
- printf("Partition id ('0' to disable) [01 - FF]: [%X] ", dflt);
+ for (;;) {
+ printf("Partition id ('0' to disable) [01 - FF]: [%02X] ", dflt);
printf("(? for help) ");
string_from_line(lbuf, sizeof(lbuf), TRIMMED);
+ if (strlen(lbuf) == 0)
+ return dflt;
if (strcmp(lbuf, "?") == 0) {
PRT_printall();
continue;
return 0x100;
}
- /* Convert */
- cp = lbuf;
- num = strtol(lbuf, &cp, 16);
+ num = hex_octet(lbuf);
+ if (num != -1)
+ return num;
- /* Make sure only number present */
- if (cp == lbuf)
- num = dflt;
- if (*cp != '\0') {
- printf("'%s' is not a valid number.\n", lbuf);
- num = -1;
- } else if (num == 0) {
- break;
- } else if (num < 0 || num > 0xff) {
- printf("'%x' is out of range.\n", num);
- }
- } while (num < 0 || num > 0xff);
-
- return num;
+ printf("'%s' is not a valid partition id.\n", lbuf);
+ }
}
char *
-/* $OpenBSD: fdisk.c,v 1.134 2021/08/10 18:17:48 krw Exp $ */
+/* $OpenBSD: fdisk.c,v 1.135 2021/08/28 11:55:17 krw Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
{
const char *errstr;
char *poffset, *ptype;
+ int partitiontype;
uint32_t blockcount, blockoffset;
- uint8_t partitiontype;
blockoffset = BLOCKALIGNMENT;
partitiontype = DOSPTYP_EFISYS;
if (ptype == NULL)
goto done;
- if (strlen(ptype) != 2 || !(isxdigit(*ptype) && isxdigit(*(ptype + 1))))
- errx(1, "Block type is not 2 digit hex value");
-
- partitiontype = strtol(ptype, NULL, 16);
+ partitiontype = hex_octet(ptype);
+ if (partitiontype == -1)
+ errx(1, "Block type is not a 1-2 digit hex value");
done:
disk.dk_bootprt.prt_ns = blockcount;
-/* $OpenBSD: misc.c,v 1.81 2021/08/24 12:34:04 krw Exp $ */
+/* $OpenBSD: misc.c,v 1.82 2021/08/28 11:55:17 krw Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
return utf;
}
+
+int
+hex_octet(char *buf)
+{
+ char *cp;
+ long num;
+
+ cp = buf;
+ num = strtol(buf, &cp, 16);
+
+ if (cp == buf || *cp != '\0')
+ return -1;
+
+ if (num < 0 || num > 0xff)
+ return -1;
+
+ return num;
+}
-/* $OpenBSD: misc.h,v 1.43 2021/08/24 12:55:06 krw Exp $ */
+/* $OpenBSD: misc.h,v 1.44 2021/08/28 11:55:17 krw Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
int unit_lookup(const char *);
void string_from_line(char *, const size_t, const int);
int ask_yn(const char *);
+int hex_octet(char *);
uint64_t getuint64(const char *, uint64_t, const uint64_t, const uint64_t);
char *utf16le_to_string(const uint16_t *);
uint16_t *string_to_utf16le(const char *);