From 619d21ff42670c43a8392c81aa62a495242655af Mon Sep 17 00:00:00 2001 From: Antonio Ospite Date: Sat, 26 Mar 2011 13:28:41 +0100 Subject: [PATCH] Move call to basename() into misc_get_minor() The use of basename() is a detail about how we find the minor number, so let's keep it private. Signed-off-by: Antonio Ospite --- mkmisc.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/mkmisc.c b/mkmisc.c index 4e6b0bc..fb548e4 100644 --- a/mkmisc.c +++ b/mkmisc.c @@ -60,11 +60,13 @@ static int misc_get_major(void) return -1; } -static int misc_get_minor(char *node) +static int misc_get_minor(char *device) { FILE *fp; int minor; char name[64]; + char *path; + char *node; fp = fopen("/proc/misc", "r"); if (fp == NULL) { @@ -72,12 +74,17 @@ static int misc_get_minor(char *node) return -1; } + path = strdup(device); + node = basename(path); + while (fscanf(fp, "%d %64s", &minor, name) == 2) { if (strcmp(name, node) == 0) { + free(path); fclose(fp); return minor; } } + free(path); fclose(fp); return -1; @@ -85,8 +92,6 @@ static int misc_get_minor(char *node) static int mkmisc(char *device) { - char *path; - char *node; int major; int minor; dev_t dev; @@ -98,16 +103,11 @@ static int mkmisc(char *device) return major; } - path = strdup(device); - node = basename(path); - - minor = misc_get_minor(node); + minor = misc_get_minor(device); if (minor < 0) { fprintf(stderr, "Cannot get misc minor for %s\n", device); - free(path); return minor; } - free(path); if (verbose) printf("Creating device: %s, major: %d, minor: %d\n", -- 2.1.4