2 identical versions of the same function, variable names and everything

31 bytes saved in bloatcheck

-   Oliver Webb <aquahobby...@proton.me>
From 684ec909bc8922260f1196985095545900d2ae2e Mon Sep 17 00:00:00 2001
From: Oliver Webb <aquahobby...@proton.me>
Date: Tue, 26 Mar 2024 14:58:23 -0500
Subject: [PATCH] Codeshare 2 identicle versions of "llist_add[_node]" to
 lib/llist.c

---
 lib/lib.h               |  1 +
 lib/llist.c             | 10 ++++++++++
 toys/pending/last.c     | 13 ++-----------
 toys/pending/modprobe.c | 10 ----------
 4 files changed, 13 insertions(+), 21 deletions(-)

diff --git a/lib/lib.h b/lib/lib.h
index da20dd10..f19c258d 100644
--- a/lib/lib.h
+++ b/lib/lib.h
@@ -31,6 +31,7 @@ struct dev_ino {
 
 void llist_free_arg(void *node);
 void llist_free_double(void *node);
+void llist_add(struct arg_list **old, void *data);
 void llist_traverse(void *list, void (*using)(void *node));
 void *llist_pop(void *list);  // actually void **list
 void *dlist_pop(void *list);  // actually struct double_list **list
diff --git a/lib/llist.c b/lib/llist.c
index 63a98bb6..57ee1473 100644
--- a/lib/llist.c
+++ b/lib/llist.c
@@ -23,6 +23,16 @@ void llist_free_double(void *node)
   free(d);
 }
 
+// Add new node at the beginning of the list.
+void llist_add(struct arg_list **old, void *data)
+{
+  struct arg_list *new = xmalloc(sizeof(struct arg_list));
+
+  new->arg = (char*)data;
+  new->next = *old;
+  *old = new;
+}
+
 // Call a function (such as free()) on each element of a linked list.
 void llist_traverse(void *list, void (*using)(void *node))
 {
diff --git a/toys/pending/last.c b/toys/pending/last.c
index 4730a675..1a34eb80 100644
--- a/toys/pending/last.c
+++ b/toys/pending/last.c
@@ -41,15 +41,6 @@ static void free_list()
   }
 }
 
-static void llist_add_node(struct arg_list **old, void *data)
-{
-  struct arg_list *new = xmalloc(sizeof(struct arg_list));
-
-  new->arg = (char*)data;
-  new->next = *old;
-  *old = new;
-}
-
 // Find a node and dlink it from the list.
 static struct arg_list *find_and_dlink(struct arg_list **list, char *devname)
 {
@@ -178,9 +169,9 @@ void last_main(void)
             ut.ut_line, pwidth, pwidth, ut.ut_host,
             toybuf, toybuf+18, toybuf+28);
       }
-      llist_add_node(&TT.list, memcpy(xmalloc(sizeof(ut)), &ut, sizeof(ut)));
+      llist_add(&TT.list, memcpy(xmalloc(sizeof(ut)), &ut, sizeof(ut)));
     } else if (ut.ut_type == DEAD_PROCESS && *ut.ut_line)
-      llist_add_node(&TT.list, memcpy(xmalloc(sizeof(ut)), &ut, sizeof(ut)));
+      llist_add(&TT.list, memcpy(xmalloc(sizeof(ut)), &ut, sizeof(ut)));
 
     loc -= sizeof(ut);
     if(loc < 0) break;
diff --git a/toys/pending/modprobe.c b/toys/pending/modprobe.c
index 4db3ddef..288c0cd3 100644
--- a/toys/pending/modprobe.c
+++ b/toys/pending/modprobe.c
@@ -95,16 +95,6 @@ static void *llist_popme(struct arg_list **head)
   return data;
 }
 
-// Add new node at the beginning of the list.
-static void llist_add(struct arg_list **old, void *data)
-{
-  struct arg_list *new = xmalloc(sizeof(struct arg_list));
-
-  new->arg = (char*)data;
-  new->next = *old;
-  *old = new;
-}
-
 // Add new node at tail of list.
 static void llist_add_tail(struct arg_list **head, void *data)
 {
-- 
2.44.0

_______________________________________________
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net

Reply via email to