]> git.tdb.fi Git - pmount-gui.git/commitdiff
Minor refactoring
authorMikko Rasa <tdb@tdb.fi>
Sun, 9 Aug 2015 12:13:22 +0000 (15:13 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sun, 9 Aug 2015 12:40:53 +0000 (15:40 +0300)
main.c

diff --git a/main.c b/main.c
index 25ad7edd401bd7ad7f6aa49128c52effa5058262..2472f5db6057f2b1e2b4b31175f333e124f7a3ae 100644 (file)
--- 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)
        {