diff options
| author | Denis Vlasenko <vda.linux@googlemail.com> | 2009-03-09 00:12:37 +0000 |
|---|---|---|
| committer | Denis Vlasenko <vda.linux@googlemail.com> | 2009-03-09 00:12:37 +0000 |
| commit | 73c571a5fff95d0f50f4fc509c35fedca73122bc (patch) | |
| tree | 8e3be82bbd3f7307b57f146fa2ef8ea422391137 | |
| parent | 5e4fda0affaa0a80a5ff33dd72c702b8f905be33 (diff) | |
| download | busybox-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
| -rw-r--r-- | e2fsprogs/old_e2fsprogs/e2fsck.c | 2 | ||||
| -rw-r--r-- | include/libbb.h | 3 | ||||
| -rw-r--r-- | libbb/appletlib.c | 2 | ||||
| -rw-r--r-- | libbb/write.c | 5 | ||||
| -rw-r--r-- | libbb/xconnect.c | 18 | ||||
| -rw-r--r-- | libbb/xfuncs_printf.c | 4 | ||||
| -rw-r--r-- | loginutils/adduser.c | 2 | ||||
| -rw-r--r-- | loginutils/getty.c | 1 | ||||
| -rw-r--r-- | modutils/modutils-24.c | 2 | ||||
| -rw-r--r-- | networking/ftpd.c | 22 | ||||
| -rw-r--r-- | networking/tftp.c | 15 | ||||
| -rw-r--r-- | procps/sysctl.c | 7 | ||||
| -rw-r--r-- | shell/msh.c | 8 |
13 files changed, 35 insertions, 56 deletions
diff --git a/e2fsprogs/old_e2fsprogs/e2fsck.c b/e2fsprogs/old_e2fsprogs/e2fsck.c index 6ade0db16..d1f8d1ecb 100644 --- a/e2fsprogs/old_e2fsprogs/e2fsck.c +++ b/e2fsprogs/old_e2fsprogs/e2fsck.c | |||
| @@ -12892,7 +12892,7 @@ static int e2fsck_update_progress(e2fsck_t ctx, int pass, | |||
| 12892 | 12892 | ||
| 12893 | if (ctx->progress_fd) { | 12893 | if (ctx->progress_fd) { |
| 12894 | sprintf(buf, "%d %lu %lu\n", pass, cur, max); | 12894 | sprintf(buf, "%d %lu %lu\n", pass, cur, max); |
| 12895 | write(ctx->progress_fd, buf, strlen(buf)); | 12895 | xwrite_str(ctx->progress_fd, buf); |
| 12896 | } else { | 12896 | } else { |
| 12897 | percent = calc_percent(&e2fsck_tbl, pass, cur, max); | 12897 | percent = calc_percent(&e2fsck_tbl, pass, cur, max); |
| 12898 | e2fsck_simple_progress(ctx, ctx->device_name, | 12898 | e2fsck_simple_progress(ctx, ctx->device_name, |
diff --git a/include/libbb.h b/include/libbb.h index 3e21cbf90..7d6ea9029 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
| @@ -489,6 +489,8 @@ int create_and_bind_dgram_or_die(const char *bindaddr, int port) FAST_FUNC; | |||
| 489 | int create_and_connect_stream_or_die(const char *peer, int port) FAST_FUNC; | 489 | int create_and_connect_stream_or_die(const char *peer, int port) FAST_FUNC; |
| 490 | /* Connect to peer identified by lsa */ | 490 | /* Connect to peer identified by lsa */ |
| 491 | int xconnect_stream(const len_and_sockaddr *lsa) FAST_FUNC; | 491 | int xconnect_stream(const len_and_sockaddr *lsa) FAST_FUNC; |
| 492 | /* Get local address of bound or accepted socket */ | ||
| 493 | len_and_sockaddr *get_sock_lsa(int fd) FAST_FUNC; | ||
| 492 | /* Return malloc'ed len_and_sockaddr with socket address of host:port | 494 | /* Return malloc'ed len_and_sockaddr with socket address of host:port |
| 493 | * Currently will return IPv4 or IPv6 sockaddrs only | 495 | * Currently will return IPv4 or IPv6 sockaddrs only |
| 494 | * (depending on host), but in theory nothing prevents e.g. | 496 | * (depending on host), but in theory nothing prevents e.g. |
| @@ -607,6 +609,7 @@ extern ssize_t safe_write(int fd, const void *buf, size_t count) FAST_FUNC; | |||
| 607 | // if some data was written before error occurred | 609 | // if some data was written before error occurred |
| 608 | extern ssize_t full_write(int fd, const void *buf, size_t count) FAST_FUNC; | 610 | extern ssize_t full_write(int fd, const void *buf, size_t count) FAST_FUNC; |
| 609 | extern void xwrite(int fd, const void *buf, size_t count) FAST_FUNC; | 611 | extern void xwrite(int fd, const void *buf, size_t count) FAST_FUNC; |
| 612 | extern void xwrite_str(int fd, const char *str) FAST_FUNC; | ||
| 610 | extern void xopen_xwrite_close(const char* file, const char *str) FAST_FUNC; | 613 | extern void xopen_xwrite_close(const char* file, const char *str) FAST_FUNC; |
| 611 | 614 | ||
| 612 | /* Reads and prints to stdout till eof, then closes FILE. Exits on error: */ | 615 | /* Reads and prints to stdout till eof, then closes FILE. Exits on error: */ |
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 | ||
| 100 | static void full_write2_str(const char *str) | 100 | static 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 | ||
| 105 | void FAST_FUNC bb_show_usage(void) | 105 | void 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. */ |
| 14 | void FAST_FUNC xopen_xwrite_close(const char* file, const char* str) | 14 | void 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 | ||
| 38 | len_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 | ||
| 39 | void FAST_FUNC xconnect(int s, const struct sockaddr *s_addr, socklen_t addrlen) | 52 | void 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 | */ | ||
| 56 | unsigned FAST_FUNC bb_lookup_port(const char *port, const char *protocol, unsigned default_port) | 70 | unsigned 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 | } |
| 211 | void 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. |
| 213 | off_t FAST_FUNC xlseek(int fd, off_t offset, int whence) | 217 | off_t FAST_FUNC xlseek(int fd, off_t offset, int whence) |
diff --git a/loginutils/adduser.c b/loginutils/adduser.c index d4b50130c..17b5088ec 100644 --- a/loginutils/adduser.c +++ b/loginutils/adduser.c | |||
| @@ -145,7 +145,7 @@ int adduser_main(int argc UNUSED_PARAM, char **argv) | |||
| 145 | /*99999,*/ /* sp->sp_max */ | 145 | /*99999,*/ /* sp->sp_max */ |
| 146 | /*7*/ /* sp->sp_warn */ | 146 | /*7*/ /* sp->sp_warn */ |
| 147 | ); | 147 | ); |
| 148 | xwrite(fd, s, strlen(s)); | 148 | xwrite_str(fd, s); |
| 149 | close(fd); | 149 | close(fd); |
| 150 | } | 150 | } |
| 151 | #endif | 151 | #endif |
diff --git a/loginutils/getty.c b/loginutils/getty.c index ba5b0d6c8..467316fb8 100644 --- a/loginutils/getty.c +++ b/loginutils/getty.c | |||
| @@ -713,6 +713,7 @@ int getty_main(int argc UNUSED_PARAM, char **argv) | |||
| 713 | /* Write the modem init string and DON'T flush the buffers */ | 713 | /* Write the modem init string and DON'T flush the buffers */ |
| 714 | if (options.flags & F_INITSTRING) { | 714 | if (options.flags & F_INITSTRING) { |
| 715 | debug("writing init string\n"); | 715 | debug("writing init string\n"); |
| 716 | /* todo: use xwrite_str? */ | ||
| 716 | full_write(STDOUT_FILENO, options.initstring, strlen(options.initstring)); | 717 | full_write(STDOUT_FILENO, options.initstring, strlen(options.initstring)); |
| 717 | } | 718 | } |
| 718 | 719 | ||
diff --git a/modutils/modutils-24.c b/modutils/modutils-24.c index 451975ab9..169fe54ae 100644 --- a/modutils/modutils-24.c +++ b/modutils/modutils-24.c | |||
| @@ -3513,7 +3513,7 @@ static void set_tainted(int fd, const char *m_name, | |||
| 3513 | buf[sizeof(buf)-1] = '\0'; | 3513 | buf[sizeof(buf)-1] = '\0'; |
| 3514 | oldval = strtoul(buf, NULL, 10); | 3514 | oldval = strtoul(buf, NULL, 10); |
| 3515 | sprintf(buf, "%d\n", oldval | taint); | 3515 | sprintf(buf, "%d\n", oldval | taint); |
| 3516 | write(fd, buf, strlen(buf)); | 3516 | xwrite_str(fd, buf); |
| 3517 | } | 3517 | } |
| 3518 | } | 3518 | } |
| 3519 | 3519 | ||
diff --git a/networking/ftpd.c b/networking/ftpd.c index 91cbc17f4..6289edf0c 100644 --- a/networking/ftpd.c +++ b/networking/ftpd.c | |||
| @@ -107,14 +107,6 @@ struct globals { | |||
| 107 | #define G (*(struct globals*)&bb_common_bufsiz1) | 107 | #define G (*(struct globals*)&bb_common_bufsiz1) |
| 108 | #define INIT_G() do { } while (0) | 108 | #define INIT_G() do { } while (0) |
| 109 | 109 | ||
| 110 | |||
| 111 | // libbb candidate? | ||
| 112 | static void | ||
| 113 | xwrite_str(int fd, const char *str) | ||
| 114 | { | ||
| 115 | xwrite(fd, str, strlen(str)); | ||
| 116 | } | ||
| 117 | |||
| 118 | static char * | 110 | static char * |
| 119 | replace_text(const char *str, const char from, const char *to) | 111 | replace_text(const char *str, const char from, const char *to) |
| 120 | { | 112 | { |
| @@ -918,20 +910,6 @@ handle_stou(void) | |||
| 918 | } | 910 | } |
| 919 | #endif /* ENABLE_FEATURE_FTP_WRITE */ | 911 | #endif /* ENABLE_FEATURE_FTP_WRITE */ |
| 920 | 912 | ||
| 921 | /* TODO: libbb candidate (tftp has another copy) */ | ||
| 922 | static len_and_sockaddr *get_sock_lsa(int s) | ||
| 923 | { | ||
| 924 | len_and_sockaddr *lsa; | ||
| 925 | socklen_t len = 0; | ||
| 926 | |||
| 927 | if (getsockname(s, NULL, &len) != 0) | ||
| 928 | return NULL; | ||
| 929 | lsa = xzalloc(LSA_LEN_SIZE + len); | ||
| 930 | lsa->len = len; | ||
| 931 | getsockname(s, &lsa->u.sa, &lsa->len); | ||
| 932 | return lsa; | ||
| 933 | } | ||
| 934 | |||
| 935 | int ftpd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 913 | int ftpd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
| 936 | int ftpd_main(int argc UNUSED_PARAM, char **argv) | 914 | int ftpd_main(int argc UNUSED_PARAM, char **argv) |
| 937 | { | 915 | { |
diff --git a/networking/tftp.c b/networking/tftp.c index 799dd9903..fa0851615 100644 --- a/networking/tftp.c +++ b/networking/tftp.c | |||
| @@ -622,21 +622,6 @@ int tftp_main(int argc UNUSED_PARAM, char **argv) | |||
| 622 | #endif /* ENABLE_TFTP */ | 622 | #endif /* ENABLE_TFTP */ |
| 623 | 623 | ||
| 624 | #if ENABLE_TFTPD | 624 | #if ENABLE_TFTPD |
| 625 | |||
| 626 | /* TODO: libbb candidate? */ | ||
| 627 | static len_and_sockaddr *get_sock_lsa(int s) | ||
| 628 | { | ||
| 629 | len_and_sockaddr *lsa; | ||
| 630 | socklen_t len = 0; | ||
| 631 | |||
| 632 | if (getsockname(s, NULL, &len) != 0) | ||
| 633 | return NULL; | ||
| 634 | lsa = xzalloc(LSA_LEN_SIZE + len); | ||
| 635 | lsa->len = len; | ||
| 636 | getsockname(s, &lsa->u.sa, &lsa->len); | ||
| 637 | return lsa; | ||
| 638 | } | ||
| 639 | |||
| 640 | int tftpd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 625 | int tftpd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
| 641 | int tftpd_main(int argc UNUSED_PARAM, char **argv) | 626 | int tftpd_main(int argc UNUSED_PARAM, char **argv) |
| 642 | { | 627 | { |
diff --git a/procps/sysctl.c b/procps/sysctl.c index d59e2690a..862cd1756 100644 --- a/procps/sysctl.c +++ b/procps/sysctl.c | |||
| @@ -21,11 +21,6 @@ static int sysctl_display_all(const char *path); | |||
| 21 | static int sysctl_handle_preload_file(const char *filename); | 21 | static int sysctl_handle_preload_file(const char *filename); |
| 22 | static void sysctl_dots_to_slashes(char *name); | 22 | static void sysctl_dots_to_slashes(char *name); |
| 23 | 23 | ||
| 24 | static void dwrite_str(int fd, const char *buf) | ||
| 25 | { | ||
| 26 | write(fd, buf, strlen(buf)); | ||
| 27 | } | ||
| 28 | |||
| 29 | enum { | 24 | enum { |
| 30 | FLAG_SHOW_KEYS = 1 << 0, | 25 | FLAG_SHOW_KEYS = 1 << 0, |
| 31 | FLAG_SHOW_KEY_ERRORS = 1 << 1, | 26 | FLAG_SHOW_KEY_ERRORS = 1 << 1, |
| @@ -147,7 +142,7 @@ static int sysctl_act_on_setting(char *setting) | |||
| 147 | } | 142 | } |
| 148 | 143 | ||
| 149 | if (option_mask32 & FLAG_WRITE) { | 144 | if (option_mask32 & FLAG_WRITE) { |
| 150 | dwrite_str(fd, value); | 145 | xwrite_str(fd, value); |
| 151 | close(fd); | 146 | close(fd); |
| 152 | if (option_mask32 & FLAG_SHOW_KEYS) | 147 | if (option_mask32 & FLAG_SHOW_KEYS) |
| 153 | printf("%s = ", outname); | 148 | printf("%s = ", outname); |
diff --git a/shell/msh.c b/shell/msh.c index 0cb81fee7..5f8c90ef6 100644 --- a/shell/msh.c +++ b/shell/msh.c | |||
| @@ -743,7 +743,7 @@ static void print_tree(struct op *head) | |||
| 743 | static void prs(const char *s) | 743 | static void prs(const char *s) |
| 744 | { | 744 | { |
| 745 | if (*s) | 745 | if (*s) |
| 746 | write(STDERR_FILENO, s, strlen(s)); | 746 | xwrite_str(STDERR_FILENO, s); |
| 747 | } | 747 | } |
| 748 | 748 | ||
| 749 | static void prn(unsigned u) | 749 | static void prn(unsigned u) |
| @@ -3600,7 +3600,7 @@ static int doset(struct op *t UNUSED_PARAM, char **args) | |||
| 3600 | cp = args[1]; | 3600 | cp = args[1]; |
| 3601 | if (cp == NULL) { | 3601 | if (cp == NULL) { |
| 3602 | for (vp = vlist; vp; vp = vp->next) | 3602 | for (vp = vlist; vp; vp = vp->next) |
| 3603 | varput(vp->name, 1); | 3603 | varput(vp->name, STDOUT_FILENO); |
| 3604 | return 0; | 3604 | return 0; |
| 3605 | } | 3605 | } |
| 3606 | if (*cp == '-') { | 3606 | if (*cp == '-') { |
| @@ -3639,8 +3639,8 @@ static int doset(struct op *t UNUSED_PARAM, char **args) | |||
| 3639 | static void varput(char *s, int out) | 3639 | static void varput(char *s, int out) |
| 3640 | { | 3640 | { |
| 3641 | if (isalnum(*s) || *s == '_') { | 3641 | if (isalnum(*s) || *s == '_') { |
| 3642 | write(out, s, strlen(s)); | 3642 | xwrite_str(out, s); |
| 3643 | write(out, "\n", 1); | 3643 | xwrite(out, "\n", 1); |
| 3644 | } | 3644 | } |
| 3645 | } | 3645 | } |
| 3646 | 3646 | ||
