svn commit: [25574] trunk/busybox: e2fsprogs/old_e2fsprogs include libbb lo etc...

vda at busybox.net vda at busybox.net
Mon Mar 9 00:12:38 UTC 2009


Author: vda
Date: 2009-03-09 00:12:37 +0000 (Mon, 09 Mar 2009)
New Revision: 25574

Log:
*: move get_sock_lsa and xwrite_str to libbb, use where appropriate

function                                             old     new   delta
get_sock_lsa                                           -      72     +72
buffer_fill_and_print                                179     196     +17
parse_expr                                           824     832      +8
read_base64                                          343     348      +5
nameval                                              202     206      +4
fbset_main                                          1694    1698      +4
expand                                              1849    1853      +4
udhcp_send_kernel_packet                             249     252      +3
udhcp_get_option                                     223     222      -1
chat_main                                           1246    1245      -1
pack_gzip                                           1661    1659      -2
doset                                                299     297      -2
bb__parsespent                                       119     117      -2
test_main                                            260     257      -3
qgravechar                                           109     106      -3
tcpudpsvd_main                                      1834    1830      -4
sysctl_display_all                                   589     580      -9
xopen_xwrite_close                                    44      33     -11
prs                                                   30      18     -12
find_main                                            418     406     -12
full_write2_str                                       25      12     -13
adduser_main                                         667     654     -13
evaltreenr                                           817     802     -15
evaltree                                             817     802     -15
tftpd_main                                           526     493     -33
ftpd_main                                           2050    1990     -60
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 7/18 up/down: 117/-211)         Total: -94 bytes



Modified:
   trunk/busybox/e2fsprogs/old_e2fsprogs/e2fsck.c
   trunk/busybox/include/libbb.h
   trunk/busybox/libbb/appletlib.c
   trunk/busybox/libbb/write.c
   trunk/busybox/libbb/xconnect.c
   trunk/busybox/libbb/xfuncs_printf.c
   trunk/busybox/loginutils/adduser.c
   trunk/busybox/loginutils/getty.c
   trunk/busybox/modutils/modutils-24.c
   trunk/busybox/networking/ftpd.c
   trunk/busybox/networking/tftp.c
   trunk/busybox/procps/sysctl.c
   trunk/busybox/shell/msh.c


Changeset:
Modified: trunk/busybox/e2fsprogs/old_e2fsprogs/e2fsck.c
===================================================================
--- trunk/busybox/e2fsprogs/old_e2fsprogs/e2fsck.c	2009-03-08 23:46:48 UTC (rev 25573)
+++ trunk/busybox/e2fsprogs/old_e2fsprogs/e2fsck.c	2009-03-09 00:12:37 UTC (rev 25574)
@@ -12892,7 +12892,7 @@
 
 	if (ctx->progress_fd) {
 		sprintf(buf, "%d %lu %lu\n", pass, cur, max);
-		write(ctx->progress_fd, buf, strlen(buf));
+		xwrite_str(ctx->progress_fd, buf);
 	} else {
 		percent = calc_percent(&e2fsck_tbl, pass, cur, max);
 		e2fsck_simple_progress(ctx, ctx->device_name,

Modified: trunk/busybox/include/libbb.h
===================================================================
--- trunk/busybox/include/libbb.h	2009-03-08 23:46:48 UTC (rev 25573)
+++ trunk/busybox/include/libbb.h	2009-03-09 00:12:37 UTC (rev 25574)
@@ -489,6 +489,8 @@
 int create_and_connect_stream_or_die(const char *peer, int port) FAST_FUNC;
 /* Connect to peer identified by lsa */
 int xconnect_stream(const len_and_sockaddr *lsa) FAST_FUNC;
+/* Get local address of bound or accepted socket */
+len_and_sockaddr *get_sock_lsa(int fd) FAST_FUNC;
 /* Return malloc'ed len_and_sockaddr with socket address of host:port
  * Currently will return IPv4 or IPv6 sockaddrs only
  * (depending on host), but in theory nothing prevents e.g.
@@ -607,6 +609,7 @@
 // if some data was written before error occurred
 extern ssize_t full_write(int fd, const void *buf, size_t count) FAST_FUNC;
 extern void xwrite(int fd, const void *buf, size_t count) FAST_FUNC;
+extern void xwrite_str(int fd, const char *str) FAST_FUNC;
 extern void xopen_xwrite_close(const char* file, const char *str) FAST_FUNC;
 
 /* Reads and prints to stdout till eof, then closes FILE. Exits on error: */

Modified: trunk/busybox/libbb/appletlib.c
===================================================================
--- trunk/busybox/libbb/appletlib.c	2009-03-08 23:46:48 UTC (rev 25573)
+++ trunk/busybox/libbb/appletlib.c	2009-03-09 00:12:37 UTC (rev 25574)
@@ -99,7 +99,7 @@
 
 static void full_write2_str(const char *str)
 {
-	full_write(STDERR_FILENO, str, strlen(str));
+	xwrite_str(STDERR_FILENO, str);
 }
 
 void FAST_FUNC bb_show_usage(void)

Modified: trunk/busybox/libbb/write.c
===================================================================
--- trunk/busybox/libbb/write.c	2009-03-08 23:46:48 UTC (rev 25573)
+++ trunk/busybox/libbb/write.c	2009-03-09 00:12:37 UTC (rev 25574)
@@ -10,11 +10,10 @@
 #include "libbb.h"
 
 /* Open file and write string str to it, close file.
- * Die on any open or write-error.  */
+ * Die on any open or write error.  */
 void FAST_FUNC xopen_xwrite_close(const char* file, const char* str)
 {
 	int fd = xopen(file, O_WRONLY);
-
-	xwrite(fd, str, strlen(str));
+	xwrite_str(fd, str);
 	close(fd);
 }

Modified: trunk/busybox/libbb/xconnect.c
===================================================================
--- trunk/busybox/libbb/xconnect.c	2009-03-08 23:46:48 UTC (rev 25573)
+++ trunk/busybox/libbb/xconnect.c	2009-03-09 00:12:37 UTC (rev 25574)
@@ -35,7 +35,20 @@
 	return r;
 }
 
+len_and_sockaddr* FAST_FUNC get_sock_lsa(int fd)
+{
+	len_and_sockaddr *lsa;
+	socklen_t len = 0;
 
+	/* Can be optimized to do only one getsockname() */
+	if (getsockname(fd, NULL, &len) != 0)
+		return NULL;
+	lsa = xzalloc(LSA_LEN_SIZE + len);
+	lsa->len = len;
+	getsockname(fd, &lsa->u.sa, &lsa->len);
+	return lsa;
+}
+
 void FAST_FUNC xconnect(int s, const struct sockaddr *s_addr, socklen_t addrlen)
 {
 	if (connect(s, s_addr, addrlen) < 0) {
@@ -51,8 +64,9 @@
 
 /* Return port number for a service.
  * If "port" is a number use it as the port.
- * If "port" is a name it is looked up in /etc/services, if it isnt found return
- * default_port */
+ * If "port" is a name it is looked up in /etc/services,
+ * if it isnt found return default_port
+ */
 unsigned FAST_FUNC bb_lookup_port(const char *port, const char *protocol, unsigned default_port)
 {
 	unsigned port_nr = default_port;

Modified: trunk/busybox/libbb/xfuncs_printf.c
===================================================================
--- trunk/busybox/libbb/xfuncs_printf.c	2009-03-08 23:46:48 UTC (rev 25573)
+++ trunk/busybox/libbb/xfuncs_printf.c	2009-03-09 00:12:37 UTC (rev 25574)
@@ -208,6 +208,10 @@
 			bb_error_msg_and_die("short write");
 	}
 }
+void FAST_FUNC xwrite_str(int fd, const char *str)
+{
+	xwrite(fd, str, strlen(str));
+}
 
 // Die with an error message if we can't lseek to the right spot.
 off_t FAST_FUNC xlseek(int fd, off_t offset, int whence)

Modified: trunk/busybox/loginutils/adduser.c
===================================================================
--- trunk/busybox/loginutils/adduser.c	2009-03-08 23:46:48 UTC (rev 25573)
+++ trunk/busybox/loginutils/adduser.c	2009-03-09 00:12:37 UTC (rev 25574)
@@ -145,7 +145,7 @@
 				/*99999,*/              /* sp->sp_max */
 				/*7*/                   /* sp->sp_warn */
 		);
-		xwrite(fd, s, strlen(s));
+		xwrite_str(fd, s);
 		close(fd);
 	}
 #endif

Modified: trunk/busybox/loginutils/getty.c
===================================================================
--- trunk/busybox/loginutils/getty.c	2009-03-08 23:46:48 UTC (rev 25573)
+++ trunk/busybox/loginutils/getty.c	2009-03-09 00:12:37 UTC (rev 25574)
@@ -713,6 +713,7 @@
 	/* Write the modem init string and DON'T flush the buffers */
 	if (options.flags & F_INITSTRING) {
 		debug("writing init string\n");
+		/* todo: use xwrite_str? */
 		full_write(STDOUT_FILENO, options.initstring, strlen(options.initstring));
 	}
 

Modified: trunk/busybox/modutils/modutils-24.c
===================================================================
--- trunk/busybox/modutils/modutils-24.c	2009-03-08 23:46:48 UTC (rev 25573)
+++ trunk/busybox/modutils/modutils-24.c	2009-03-09 00:12:37 UTC (rev 25574)
@@ -3513,7 +3513,7 @@
 		buf[sizeof(buf)-1] = '\0';
 		oldval = strtoul(buf, NULL, 10);
 		sprintf(buf, "%d\n", oldval | taint);
-		write(fd, buf, strlen(buf));
+		xwrite_str(fd, buf);
 	}
 }
 

Modified: trunk/busybox/networking/ftpd.c
===================================================================
--- trunk/busybox/networking/ftpd.c	2009-03-08 23:46:48 UTC (rev 25573)
+++ trunk/busybox/networking/ftpd.c	2009-03-09 00:12:37 UTC (rev 25574)
@@ -107,14 +107,6 @@
 #define G (*(struct globals*)&bb_common_bufsiz1)
 #define INIT_G() do { } while (0)
 
-
-// libbb candidate?
-static void
-xwrite_str(int fd, const char *str)
-{
-	xwrite(fd, str, strlen(str));
-}
-
 static char *
 replace_text(const char *str, const char from, const char *to)
 {
@@ -918,20 +910,6 @@
 }
 #endif /* ENABLE_FEATURE_FTP_WRITE */
 
-/* TODO: libbb candidate (tftp has another copy) */
-static len_and_sockaddr *get_sock_lsa(int s)
-{
-	len_and_sockaddr *lsa;
-	socklen_t len = 0;
-
-	if (getsockname(s, NULL, &len) != 0)
-		return NULL;
-	lsa = xzalloc(LSA_LEN_SIZE + len);
-	lsa->len = len;
-	getsockname(s, &lsa->u.sa, &lsa->len);
-	return lsa;
-}
-
 int ftpd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
 int ftpd_main(int argc UNUSED_PARAM, char **argv)
 {

Modified: trunk/busybox/networking/tftp.c
===================================================================
--- trunk/busybox/networking/tftp.c	2009-03-08 23:46:48 UTC (rev 25573)
+++ trunk/busybox/networking/tftp.c	2009-03-09 00:12:37 UTC (rev 25574)
@@ -622,21 +622,6 @@
 #endif /* ENABLE_TFTP */
 
 #if ENABLE_TFTPD
-
-/* TODO: libbb candidate? */
-static len_and_sockaddr *get_sock_lsa(int s)
-{
-	len_and_sockaddr *lsa;
-	socklen_t len = 0;
-
-	if (getsockname(s, NULL, &len) != 0)
-		return NULL;
-	lsa = xzalloc(LSA_LEN_SIZE + len);
-	lsa->len = len;
-	getsockname(s, &lsa->u.sa, &lsa->len);
-	return lsa;
-}
-
 int tftpd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
 int tftpd_main(int argc UNUSED_PARAM, char **argv)
 {

Modified: trunk/busybox/procps/sysctl.c
===================================================================
--- trunk/busybox/procps/sysctl.c	2009-03-08 23:46:48 UTC (rev 25573)
+++ trunk/busybox/procps/sysctl.c	2009-03-09 00:12:37 UTC (rev 25574)
@@ -21,11 +21,6 @@
 static int sysctl_handle_preload_file(const char *filename);
 static void sysctl_dots_to_slashes(char *name);
 
-static void dwrite_str(int fd, const char *buf)
-{
-	write(fd, buf, strlen(buf));
-}
-
 enum {
 	FLAG_SHOW_KEYS       = 1 << 0,
 	FLAG_SHOW_KEY_ERRORS = 1 << 1,
@@ -147,7 +142,7 @@
 	}
 
 	if (option_mask32 & FLAG_WRITE) {
-		dwrite_str(fd, value);
+		xwrite_str(fd, value);
 		close(fd);
 		if (option_mask32 & FLAG_SHOW_KEYS)
 			printf("%s = ", outname);

Modified: trunk/busybox/shell/msh.c
===================================================================
--- trunk/busybox/shell/msh.c	2009-03-08 23:46:48 UTC (rev 25573)
+++ trunk/busybox/shell/msh.c	2009-03-09 00:12:37 UTC (rev 25574)
@@ -743,7 +743,7 @@
 static void prs(const char *s)
 {
 	if (*s)
-		write(STDERR_FILENO, s, strlen(s));
+		xwrite_str(STDERR_FILENO, s);
 }
 
 static void prn(unsigned u)
@@ -3600,7 +3600,7 @@
 	cp = args[1];
 	if (cp == NULL) {
 		for (vp = vlist; vp; vp = vp->next)
-			varput(vp->name, 1);
+			varput(vp->name, STDOUT_FILENO);
 		return 0;
 	}
 	if (*cp == '-') {
@@ -3639,8 +3639,8 @@
 static void varput(char *s, int out)
 {
 	if (isalnum(*s) || *s == '_') {
-		write(out, s, strlen(s));
-		write(out, "\n", 1);
+		xwrite_str(out, s);
+		xwrite(out, "\n", 1);
 	}
 }
 



More information about the busybox-cvs mailing list