[PATCH 1/6] Use glib's implementation of linked lists

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



---
 loader/driverdisk.c |   46 ++++++++--------------------------------------
 loader/driverdisk.h |   10 +---------
 loader/loader.c     |    6 +++---
 3 files changed, 12 insertions(+), 50 deletions(-)

diff --git a/loader/driverdisk.c b/loader/driverdisk.c
index 074428e..a8c191d 100644
--- a/loader/driverdisk.c
+++ b/loader/driverdisk.c
@@ -786,49 +786,14 @@ static void getDDFromDev(struct loaderData_s * loaderData, char * dev) {
     unlink("/tmp/drivers");
 }
 
-/*
- * Utility functions to maintain linked-list of device names
- * */
-
-struct ddlist* ddlist_add(struct ddlist *list, const char* device)
-{
-  struct ddlist* item;
-
-  item = (struct ddlist*)malloc(sizeof(struct ddlist));
-  if(item==NULL){
-    return list;
-  }
-
-  item->device = strdup(device);
-  item->next = list;
-
-  return item;
-}
-
-int ddlist_free(struct ddlist *list)
-{
-  struct ddlist *next;
-  int count = 0;
-
-  while(list!=NULL){
-    next = list->next;
-    free(list->device);
-    free(list);
-    list = next;
-    count++;
-  }
-
-  return count;
-}
-
 
 /*
  * Look for partition with specific label (part of #316481)
  */
-struct ddlist* findDriverDiskByLabel(void)
+GSList* findDriverDiskByLabel(void)
 {
     char *ddLabel = "OEMDRV";
-    struct ddlist *ddDevice = NULL;
+    GSList *ddDevice = NULL;
     blkid_cache bCache;
     
     int res;
@@ -844,6 +809,11 @@ struct ddlist* findDriverDiskByLabel(void)
       return NULL;
     }
 
+    if((ddDevice = g_slist_alloc())==NULL){
+      logMessage(ERROR, _("Cannot allocate space for list of devices"));
+      return NULL;
+    }
+
     bIter = blkid_dev_iterate_begin(bCache);
     blkid_dev_set_search(bIter, "LABEL", ddLabel);
     while((res = blkid_dev_next(bIter, &bDev))!=0){
@@ -851,7 +821,7 @@ struct ddlist* findDriverDiskByLabel(void)
         if(!bDev)
           continue;
         logMessage(DEBUGLVL, _("Adding driver disc %s to the list of available DDs."), blkid_dev_devname(bDev));
-        ddDevice = ddlist_add(ddDevice, blkid_dev_devname(bDev));
+        ddDevice = g_slist_prepend(ddDevice, blkid_dev_devname(bDev));
         /*blkid_free_dev(bDev); -- probably taken care of by the put cache call.. it is not exposed in the API */
     }
     blkid_dev_iterate_end(bIter);
diff --git a/loader/driverdisk.h b/loader/driverdisk.h
index 3e442fb..3a9d24b 100644
--- a/loader/driverdisk.h
+++ b/loader/driverdisk.h
@@ -46,15 +46,7 @@ void getDDFromSource(struct loaderData_s * loaderData, char * src);
 
 int loadDriverDiskFromPartition(struct loaderData_s *loaderData, char* device);
 
-struct ddlist {
-  char* device;
-  struct ddlist* next;
-};
-
-struct ddlist* ddlist_add(struct ddlist *list, const char* device);
-int ddlist_free(struct ddlist *list);
-
-struct ddlist* findDriverDiskByLabel(void);
+GSList* findDriverDiskByLabel(void);
 
 int modprobeNormalmode();
 int modprobeDDmode();
diff --git a/loader/loader.c b/loader/loader.c
index 3159513..4d7d5d7 100644
--- a/loader/loader.c
+++ b/loader/loader.c
@@ -1789,7 +1789,7 @@ int main(int argc, char ** argv) {
     struct loaderData_s loaderData;
 
     char *path;
-    struct ddlist *dd, *dditer;
+    GSList *dd, *dditer;
 
     gchar *cmdLine = NULL, *ksFile = NULL, *virtpcon = NULL;
     gboolean testing = FALSE, mediacheck = FALSE;
@@ -1972,9 +1972,9 @@ int main(int argc, char ** argv) {
             else{
                 logMessage(INFO, "Automatic driver disk loader succeeded for %s.", dditer->device);
             }
-            dditer = dditer->next;
+            dditer = g_slist_next(dditer);
         }
-        ddlist_free(dd);
+        g_slist_free(dd);
     }
 
     if (FL_MODDISK(flags)) {
-- 
1.6.4.4

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list

[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux