From df183f17b1467b0672c6c7e0ab6f0c8cb895edc6 Mon Sep 17 00:00:00 2001 From: Alexander Kuleshov Date: Wed, 23 Dec 2015 20:22:06 +0600 Subject: [PATCH] boot0cfg: use getdevpath() instead of custom function We are using mkrdev function in the boot0cfg.c to prduce a device path from the given command line argument. The provides the getdevpath() function that does the same but in more general way. Let's use function from the libc instead of custom. --- usr.sbin/boot0cfg/boot0cfg.c | 28 ++++++---------------------- 1 file changed, 6 insertions(+), 22 deletions(-) diff --git a/usr.sbin/boot0cfg/boot0cfg.c b/usr.sbin/boot0cfg/boot0cfg.c index 4694f17f03..a9f47ae08f 100644 --- a/usr.sbin/boot0cfg/boot0cfg.c +++ b/usr.sbin/boot0cfg/boot0cfg.c @@ -38,6 +38,7 @@ #include #include #include +#include #define MBRSIZE 512 /* master boot record size */ @@ -77,7 +78,6 @@ static void display_mbr(u_int8_t *); static int boot0version(const u_int8_t *); static int boot0bs(const u_int8_t *); static void stropt(const char *, int *, int *); -static char *mkrdev(const char *); static int argtoi(const char *, int, int, int); static void usage(void); @@ -139,7 +139,11 @@ main(int argc, char *argv[]) argv += optind; if (argc != 1) usage(); - disk = mkrdev(*argv); + + disk = getdevpath(*argv, 0); + if (!disk) + err(1, "cannot open disk %s", disk); + up = B_flag || d_arg != -1 || m_arg != -1 || o_flag || s_arg != -1 || t_arg != -1; @@ -391,26 +395,6 @@ stropt(const char *arg, int *xa, int *xo) free(s); } -/* - * Produce a device path for a "canonical" name, where appropriate. - */ -static char * -mkrdev(const char *fname) -{ - char buf[MAXPATHLEN]; - char *s; - - if (!strchr(fname, '/')) { - snprintf(buf, sizeof(buf), "%s%s", _PATH_DEV, fname); - s = strdup(buf); - } else - s = strdup(fname); - - if (s == NULL) - errx(1, "No more memory"); - return s; -} - /* * Convert and check an option argument. */ -- 2.41.0