From: Antonio Ospite Date: Sat, 26 Mar 2011 12:28:41 +0000 (+0100) Subject: Move call to basename() into misc_get_minor() X-Git-Url: https://git.ao2.it/mkmisc.git/commitdiff_plain/619d21ff42670c43a8392c81aa62a495242655af?ds=inline 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 --- 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",