From 150ec50282b159d83657dd5dea329ff5d113747c 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 53e7e95..e98b083 100644 --- a/usr.sbin/boot0cfg/boot0cfg.c +++ b/usr.sbin/boot0cfg/boot0cfg.c @@ -39,6 +39,7 @@ #include #include #include +#include #define MBRSIZE 512 /* master boot record size */ @@ -78,7 +79,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); @@ -140,7 +140,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; @@ -390,26 +394,6 @@ stropt(const char *arg, int *xa, int *xo) } /* - * 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. */ static int -- 2.6.3