From: Mikko Rasa Date: Sun, 9 Aug 2015 12:13:22 +0000 (+0300) Subject: Minor refactoring X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=ccbbca646ac2845444b6d9e300e6aec4c13a87cb;p=pmount-gui.git Minor refactoring --- diff --git a/main.c b/main.c index 25ad7ed..2472f5d 100644 --- a/main.c +++ b/main.c @@ -224,25 +224,25 @@ char **get_fstab_devices(void) return get_mount_entries("/etc/fstab", &is_user_mountable); } -int is_in_array(char **names, char *devname) +int is_in_array(char **array, char *str) { int i; - if(!names || !devname) + if(!array || !str) return 0; - for(i=0; names[i]; ++i) - if(!strcmp(devname, names[i])) + for(i=0; array[i]; ++i) + if(!strcmp(str, array[i])) return 1; return 0; } -void free_device_names(char **names) +void free_string_array(char **array) { int i; - if(!names) + if(!array) return; - for(i=0; names[i]; ++i) - free(names[i]); - free(names); + for(i=0; array[i]; ++i) + free(array[i]); + free(array); } int is_removable(char *devpath) @@ -293,18 +293,18 @@ int check_buses(char *devpath, char **buses) char linkbuf[256]; strcpy(ptr, "/subsystem"); len = readlink(fnbuf, linkbuf, sizeof(linkbuf)-1); - *ptr = 0; if(len!=-1) { - int i; linkbuf[len] = 0; for(; (len>0 && linkbuf[len-1]!='/'); --len) ; if(verbosity>=2) + { + *ptr = 0; printf(" Subsystem of %s is %s\n", fnbuf, linkbuf+len); - for(i=0; buses[i]; ++i) - if(strcmp(linkbuf+len, buses[i])==0) - return 1; + } + if(is_in_array(buses, linkbuf+len)) + return 1; } } @@ -501,7 +501,7 @@ Device *get_devices(void) } free(nodes); - free_device_names(mounted); + free_string_array(mounted); if(devices) {