svn commit: trunk/busybox: miscutils networking networking/libiprou etc...

landley at busybox.net landley at busybox.net
Mon May 29 06:43:58 UTC 2006


Author: landley
Date: 2006-05-28 23:43:55 -0700 (Sun, 28 May 2006)
New Revision: 15216

Log:
Size reductions, mostly switching things to use libbb functions.


Modified:
   trunk/busybox/miscutils/strings.c
   trunk/busybox/networking/dnsd.c
   trunk/busybox/networking/ifupdown.c
   trunk/busybox/networking/interface.c
   trunk/busybox/networking/libiproute/ll_map.c
   trunk/busybox/networking/nameif.c


Changeset:
Modified: trunk/busybox/miscutils/strings.c
===================================================================
--- trunk/busybox/miscutils/strings.c	2006-05-29 05:51:12 UTC (rev 15215)
+++ trunk/busybox/miscutils/strings.c	2006-05-29 06:43:55 UTC (rev 15216)
@@ -41,7 +41,7 @@
 	argv += optind;
 
 	n = bb_xgetlarg(n_arg, 10, 1, INT_MAX);
-	string = xcalloc(n + 1, 1);
+	string = xzalloc(n + 1);
 	n--;
 
 	if (argc == 0) {

Modified: trunk/busybox/networking/dnsd.c
===================================================================
--- trunk/busybox/networking/dnsd.c	2006-05-29 05:51:12 UTC (rev 15215)
+++ trunk/busybox/networking/dnsd.c	2006-05-29 06:43:55 UTC (rev 15216)
@@ -82,8 +82,7 @@
 /*
  * Convert host name from C-string to dns length/string.
  */
-static void
-convname(char *a, uint8_t *q)
+static void convname(char *a, uint8_t *q)
 {
 	int i = (q[0] == '.') ? 0 : 1;
 	for(; i < MAX_HOST_LEN-1 && *q; i++, q++)
@@ -95,8 +94,7 @@
 /*
  * Insert length of substrings insetad of dots
  */
-static void
-undot(uint8_t * rip)
+static void undot(uint8_t * rip)
 {
 	int i = 0, s = 0;
 	while(rip[i]) i++;
@@ -111,8 +109,7 @@
 /*
  * Append message to log file
  */
-static void
-log_message(char *filename, char *message)
+static void log_message(char *filename, char *message)
 {
 	FILE *logfile;
 	if (!daemonmode)
@@ -133,8 +130,7 @@
  * converting to a length/string substring for that label.
  */
 
-static int
-getfileentry(FILE * fp, struct dns_entry *s, int verb)
+static int getfileentry(FILE * fp, struct dns_entry *s, int verb)
 {
 	unsigned int a,b,c,d;
 	char *r, *name;
@@ -168,19 +164,16 @@
 /*
  * Read hostname/IP records from file
  */
-static void
-dnsentryinit(int verb)
+static void dnsentryinit(int verb)
 {
 	FILE *fp;
 	struct dns_entry *m, *prev;
 	prev = dnsentry = NULL;
 
-	if(!(fp = fopen(fileconf, "r")))
-		bb_perror_msg_and_die("open %s",fileconf);
+	fp = bb_xfopen(fileconf, "r");
 
 	while (1) {
-		if(!(m = (struct dns_entry *)malloc(sizeof(struct dns_entry))))
-			bb_perror_msg_and_die("malloc dns_entry");
+		m = xmalloc(sizeof(struct dns_entry));
 
 		m->next = NULL;
 		if (getfileentry(fp, m, verb))
@@ -199,8 +192,7 @@
 /*
  * Set up UDP socket
  */
-static int
-listen_socket(char *iface_addr, int listen_port)
+static int listen_socket(char *iface_addr, int listen_port)
 {
 	struct sockaddr_in a;
 	char msg[100];
@@ -228,8 +220,7 @@
  * Look query up in dns records and return answer if found
  * qs is the query string, first byte the string length
  */
-static int
-table_lookup(uint16_t type, uint8_t * as, uint8_t * qs)
+static int table_lookup(uint16_t type, uint8_t * as, uint8_t * qs)
 {
 	int i;
 	struct dns_entry *d=dnsentry;
@@ -269,8 +260,7 @@
  * Decode message and generate answer
  */
 #define eret(s) do { fprintf (stderr, "%s\n", s); return -1; } while (0)
-static int
-process_packet(uint8_t * buf)
+static int process_packet(uint8_t * buf)
 {
 	struct dns_head *head;
 	struct dns_prop *qprop;
@@ -367,8 +357,7 @@
 /*
  * Exit on signal
  */
-static void
-interrupt(int x)
+static void interrupt(int x)
 {
 	unlink(LOCK_FILE);
 	write(2, "interrupt exiting\n", 18);

Modified: trunk/busybox/networking/ifupdown.c
===================================================================
--- trunk/busybox/networking/ifupdown.c	2006-05-29 05:51:12 UTC (rev 15215)
+++ trunk/busybox/networking/ifupdown.c	2006-05-29 06:43:55 UTC (rev 15216)
@@ -629,10 +629,7 @@
 
 	enum { NONE, IFACE, MAPPING } currently_processing = NONE;
 
-	defn = xmalloc(sizeof(struct interfaces_file_t));
-	defn->autointerfaces = NULL;
-	defn->mappings = NULL;
-	defn->ifaces = NULL;
+	defn = xzalloc(sizeof(struct interfaces_file_t));
 
 	f = bb_xfopen(filename, "r");
 
@@ -647,10 +644,7 @@
 
 		if (strcmp(firstword, "mapping") == 0) {
 #ifdef CONFIG_FEATURE_IFUPDOWN_MAPPING
-			currmap = xmalloc(sizeof(struct mapping_defn_t));
-			currmap->max_matches = 0;
-			currmap->n_matches = 0;
-			currmap->match = NULL;
+			currmap = xzalloc(sizeof(struct mapping_defn_t));
 
 			while ((firstword = next_word(&buf_ptr)) != NULL) {
 				if (currmap->max_matches == currmap->n_matches) {
@@ -690,7 +684,7 @@
 					NULL
 				};
 
-				currif = xmalloc(sizeof(struct interface_defn_t));
+				currif = xzalloc(sizeof(struct interface_defn_t));
 				iface_name = next_word(&buf_ptr);
 				address_family_name = next_word(&buf_ptr);
 				method_name = next_word(&buf_ptr);
@@ -724,9 +718,6 @@
 					return NULL;
 				}
 
-				currif->max_options = 0;
-				currif->n_options = 0;
-				currif->option = NULL;
 
 				{
 					llist_t *iface_list;
@@ -845,10 +836,8 @@
 	char *here;
 	char *there;
 
-	result = xmalloc(strlen(format) + strlen(name) + strlen(value) + 1);
+	result = bb_xasprintf(format, name, value);
 
-	sprintf(result, format, name, value);
-
 	for (here = there = result; *there != '=' && *there; there++) {
 		if (*there == '-')
 			*there = '_';
@@ -878,11 +867,9 @@
 			*ppch = NULL;
 		}
 		free(__myenviron);
-		__myenviron = NULL;
 	}
-	__myenviron = xmalloc(sizeof(char *) * (n_env_entries + 1 /* for final NULL */ ));
+	__myenviron = xzalloc(sizeof(char *) * (n_env_entries + 1 /* for final NULL */ ));
 	environend = __myenviron;
-	*environend = NULL;
 
 	for (i = 0; i < iface->n_options; i++) {
 		if (strcmp(iface->option[i].name, "up") == 0
@@ -892,19 +879,13 @@
 			continue;
 		}
 		*(environend++) = setlocalenv("IF_%s=%s", iface->option[i].name, iface->option[i].value);
-		*environend = NULL;
 	}
 
 	*(environend++) = setlocalenv("%s=%s", "IFACE", iface->iface);
-	*environend = NULL;
 	*(environend++) = setlocalenv("%s=%s", "ADDRFAM", iface->address_family->name);
-	*environend = NULL;
 	*(environend++) = setlocalenv("%s=%s", "METHOD", iface->method->name);
-	*environend = NULL;
 	*(environend++) = setlocalenv("%s=%s", "MODE", mode);
-	*environend = NULL;
 	*(environend++) = setlocalenv("%s=%s", "PATH", "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin");
-	*environend = NULL;
 }
 
 static int doit(char *str)
@@ -1069,7 +1050,7 @@
 			free(logical);
 			logical = new_logical;
 		} else {
-			/* If we are UNABLE to read a line of output, discard are
+			/* If we are UNABLE to read a line of output, discard our
 			 * freshly allocated memory. */
 			free(new_logical);
 		}
@@ -1177,36 +1158,13 @@
 		if (cmds == iface_up) {
 			target_list = defn->autointerfaces;
 		} else {
-#if 0
 			/* iface_down */
-			llist_t *new_item;
 			const llist_t *list = state_list;
 			while (list) {
-				new_item = xmalloc(sizeof(llist_t));
-				new_item->data = bb_xstrdup(list->data);
-				new_item->link = NULL;
-				list = target_list;
-				if (list == NULL)
-					target_list = new_item;
-				else {
-					while (list->link) {
-						list = list->link;
-					}
-					list = new_item;
-				}
-				list = list->link;
-			}
-			target_list = defn->autointerfaces;
-#else
-
-			/* iface_down */
-			const llist_t *list = state_list;
-			while (list) {
 				llist_add_to_end(&target_list, bb_xstrdup(list->data));
 				list = list->link;
 			}
 			target_list = defn->autointerfaces;
-#endif
 		}
 	} else {
 		llist_add_to_end(&target_list, argv[optind]);
@@ -1308,8 +1266,7 @@
 			llist_t *iface_state = find_iface_state(state_list, iface);
 
 			if (cmds == iface_up) {
-				char *newiface = xmalloc(strlen(iface) + 1 + strlen(liface) + 1);
-				sprintf(newiface, "%s=%s", iface, liface);
+				char *newiface = bb_xasprintf("%s=%s", iface, liface);
 				if (iface_state == NULL) {
 					llist_add_to_end(&state_list, newiface);
 				} else {
@@ -1318,17 +1275,7 @@
 				}
 			} else {
 				/* Remove an interface from the linked list */
-				if (iface_state) {
-					llist_t *l = iface_state->link;
-					free(iface_state->data);
-					iface_state->data = NULL;
-					iface_state->link = NULL;
-					if (l) {
-						iface_state->data = l->data;
-						iface_state->link = l->link;
-					}
-					free(l);
-				}
+				free(llist_pop(&iface_state));
 			}
 		}
 	}

Modified: trunk/busybox/networking/interface.c
===================================================================
--- trunk/busybox/networking/interface.c	2006-05-29 05:51:12 UTC (rev 15215)
+++ trunk/busybox/networking/interface.c	2006-05-29 06:43:55 UTC (rev 15216)
@@ -76,7 +76,6 @@
 
 #define _PATH_PROCNET_DEV               "/proc/net/dev"
 #define _PATH_PROCNET_IFINET6           "/proc/net/if_inet6"
-#define new(p) ((p) = xcalloc(1,sizeof(*(p))))
 
 #if HAVE_AFINET6
 
@@ -789,7 +788,8 @@
 		if (n < 0)
 			break;
 	}
-	new(new);
+
+	new = xzalloc(sizeof(*new));
 	safe_strncpy(new->name, name, IFNAMSIZ);
 	nextp = ife ? &ife->next : &int_list;
 	new->prev = ife;

Modified: trunk/busybox/networking/libiproute/ll_map.c
===================================================================
--- trunk/busybox/networking/libiproute/ll_map.c	2006-05-29 05:51:12 UTC (rev 15215)
+++ trunk/busybox/networking/libiproute/ll_map.c	2006-05-29 06:43:55 UTC (rev 15216)
@@ -17,6 +17,7 @@
 
 #include "libnetlink.h"
 #include "ll_map.h"
+#include "libbb.h"
 
 struct idxmap
 {
@@ -57,9 +58,7 @@
 			break;
 
 	if (im == NULL) {
-		im = malloc(sizeof(*im));
-		if (im == NULL)
-			return 0;
+		im = xmalloc(sizeof(*im));
 		im->next = *imp;
 		im->index = ifi->ifi_index;
 		*imp = im;

Modified: trunk/busybox/networking/nameif.c
===================================================================
--- trunk/busybox/networking/nameif.c	2006-05-29 05:51:12 UTC (rev 15215)
+++ trunk/busybox/networking/nameif.c	2006-05-29 06:43:55 UTC (rev 15216)
@@ -105,7 +105,7 @@
 
 			if (strlen(*a) > IF_NAMESIZE)
 				serror("interface name `%s' too long", *a);
-			ch = xcalloc(1, sizeof(mactable_t));
+			ch = xzalloc(sizeof(mactable_t));
 			ch->ifname = bb_xstrdup(*a++);
 			ch->mac = cc_macaddr(*a++);
 			if (clist)
@@ -126,7 +126,7 @@
 				continue;
 			}
 			name_length = strcspn(line_ptr, " \t");
-			ch = xcalloc(1, sizeof(mactable_t));
+			ch = xzalloc(sizeof(mactable_t));
 			ch->ifname = bb_xstrndup(line_ptr, name_length);
 			if (name_length > IF_NAMESIZE)
 				serror("interface name `%s' too long", ch->ifname);




More information about the busybox-cvs mailing list