aboutsummaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2009-03-09 00:12:37 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2009-03-09 00:12:37 +0000
commit73c571a5fff95d0f50f4fc509c35fedca73122bc (patch)
tree8e3be82bbd3f7307b57f146fa2ef8ea422391137 /libbb
parent5e4fda0affaa0a80a5ff33dd72c702b8f905be33 (diff)
downloadbusybox-w32-73c571a5fff95d0f50f4fc509c35fedca73122bc.tar.gz
busybox-w32-73c571a5fff95d0f50f4fc509c35fedca73122bc.tar.bz2
busybox-w32-73c571a5fff95d0f50f4fc509c35fedca73122bc.zip
*: 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
Diffstat (limited to 'libbb')
-rw-r--r--libbb/appletlib.c2
-rw-r--r--libbb/write.c5
-rw-r--r--libbb/xconnect.c18
-rw-r--r--libbb/xfuncs_printf.c4
4 files changed, 23 insertions, 6 deletions
diff --git a/libbb/appletlib.c b/libbb/appletlib.c
index 13cdb819f..80380ae08 100644
--- a/libbb/appletlib.c
+++ b/libbb/appletlib.c
@@ -99,7 +99,7 @@ static const char *unpack_usage_messages(void)
99 99
100static void full_write2_str(const char *str) 100static void full_write2_str(const char *str)
101{ 101{
102 full_write(STDERR_FILENO, str, strlen(str)); 102 xwrite_str(STDERR_FILENO, str);
103} 103}
104 104
105void FAST_FUNC bb_show_usage(void) 105void FAST_FUNC bb_show_usage(void)
diff --git a/libbb/write.c b/libbb/write.c
index 37f461720..116e4d153 100644
--- a/libbb/write.c
+++ b/libbb/write.c
@@ -10,11 +10,10 @@
10#include "libbb.h" 10#include "libbb.h"
11 11
12/* Open file and write string str to it, close file. 12/* Open file and write string str to it, close file.
13 * Die on any open or write-error. */ 13 * Die on any open or write error. */
14void FAST_FUNC xopen_xwrite_close(const char* file, const char* str) 14void FAST_FUNC xopen_xwrite_close(const char* file, const char* str)
15{ 15{
16 int fd = xopen(file, O_WRONLY); 16 int fd = xopen(file, O_WRONLY);
17 17 xwrite_str(fd, str);
18 xwrite(fd, str, strlen(str));
19 close(fd); 18 close(fd);
20} 19}
diff --git a/libbb/xconnect.c b/libbb/xconnect.c
index 2eb4cb9be..975844500 100644
--- a/libbb/xconnect.c
+++ b/libbb/xconnect.c
@@ -35,6 +35,19 @@ int FAST_FUNC setsockopt_bindtodevice(int fd, const char *iface)
35 return r; 35 return r;
36} 36}
37 37
38len_and_sockaddr* FAST_FUNC get_sock_lsa(int fd)
39{
40 len_and_sockaddr *lsa;
41 socklen_t len = 0;
42
43 /* Can be optimized to do only one getsockname() */
44 if (getsockname(fd, NULL, &len) != 0)
45 return NULL;
46 lsa = xzalloc(LSA_LEN_SIZE + len);
47 lsa->len = len;
48 getsockname(fd, &lsa->u.sa, &lsa->len);
49 return lsa;
50}
38 51
39void FAST_FUNC xconnect(int s, const struct sockaddr *s_addr, socklen_t addrlen) 52void FAST_FUNC xconnect(int s, const struct sockaddr *s_addr, socklen_t addrlen)
40{ 53{
@@ -51,8 +64,9 @@ void FAST_FUNC xconnect(int s, const struct sockaddr *s_addr, socklen_t addrlen)
51 64
52/* Return port number for a service. 65/* Return port number for a service.
53 * If "port" is a number use it as the port. 66 * If "port" is a number use it as the port.
54 * If "port" is a name it is looked up in /etc/services, if it isnt found return 67 * If "port" is a name it is looked up in /etc/services,
55 * default_port */ 68 * if it isnt found return default_port
69 */
56unsigned FAST_FUNC bb_lookup_port(const char *port, const char *protocol, unsigned default_port) 70unsigned FAST_FUNC bb_lookup_port(const char *port, const char *protocol, unsigned default_port)
57{ 71{
58 unsigned port_nr = default_port; 72 unsigned port_nr = default_port;
diff --git a/libbb/xfuncs_printf.c b/libbb/xfuncs_printf.c
index cd0f84dea..6d0fa6e8d 100644
--- a/libbb/xfuncs_printf.c
+++ b/libbb/xfuncs_printf.c
@@ -208,6 +208,10 @@ void FAST_FUNC xwrite(int fd, const void *buf, size_t count)
208 bb_error_msg_and_die("short write"); 208 bb_error_msg_and_die("short write");
209 } 209 }
210} 210}
211void FAST_FUNC xwrite_str(int fd, const char *str)
212{
213 xwrite(fd, str, strlen(str));
214}
211 215
212// Die with an error message if we can't lseek to the right spot. 216// Die with an error message if we can't lseek to the right spot.
213off_t FAST_FUNC xlseek(int fd, off_t offset, int whence) 217off_t FAST_FUNC xlseek(int fd, off_t offset, int whence)