diff options
author | Ron Yorston <rmy@frippery.org> | 2015-07-19 23:05:20 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2015-07-19 23:05:20 +0200 |
commit | d840c5d139cfa50fbe4f6f67c178b0edf0c690c8 (patch) | |
tree | e75010ca3ce7769f53a6170ebe940f37c6a94dc1 /networking | |
parent | 78cfa00154dca18a1326d2064121bf65cd081781 (diff) | |
download | busybox-w32-d840c5d139cfa50fbe4f6f67c178b0edf0c690c8.tar.gz busybox-w32-d840c5d139cfa50fbe4f6f67c178b0edf0c690c8.tar.bz2 busybox-w32-d840c5d139cfa50fbe4f6f67c178b0edf0c690c8.zip |
libbb: add a function to make a copy of a region of memory
Introduce a library routine to package the idiom:
p = xmalloc(b, n);
memcpy(p, b, n);
and use it where possible. The example in traceroute used xzalloc
but it didn't need to.
function old new delta
xmemdup - 32 +32
last_main 834 826 -8
make_device 2321 2311 -10
common_traceroute_main 3698 3685 -13
readtoken1 3182 3168 -14
procps_scan 1222 1206 -16
forkchild 655 638 -17
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/6 up/down: 32/-78) Total: -46 bytes
Signed-off-by: Ron Yorston <rmy@frippery.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'networking')
-rw-r--r-- | networking/traceroute.c | 11 | ||||
-rw-r--r-- | networking/udhcp/d6_dhcpc.c | 2 |
2 files changed, 2 insertions, 11 deletions
diff --git a/networking/traceroute.c b/networking/traceroute.c index 97a7a19e0..12ba614e8 100644 --- a/networking/traceroute.c +++ b/networking/traceroute.c | |||
@@ -387,15 +387,6 @@ struct globals { | |||
387 | #define outudp ((struct udphdr *)(outip + 1)) | 387 | #define outudp ((struct udphdr *)(outip + 1)) |
388 | 388 | ||
389 | 389 | ||
390 | /* libbb candidate? tftp uses this idiom too */ | ||
391 | static len_and_sockaddr* dup_sockaddr(const len_and_sockaddr *lsa) | ||
392 | { | ||
393 | len_and_sockaddr *new_lsa = xzalloc(LSA_LEN_SIZE + lsa->len); | ||
394 | memcpy(new_lsa, lsa, LSA_LEN_SIZE + lsa->len); | ||
395 | return new_lsa; | ||
396 | } | ||
397 | |||
398 | |||
399 | static int | 390 | static int |
400 | wait_for_reply(len_and_sockaddr *from_lsa, struct sockaddr *to, unsigned *timestamp_us, int *left_ms) | 391 | wait_for_reply(len_and_sockaddr *from_lsa, struct sockaddr *to, unsigned *timestamp_us, int *left_ms) |
401 | { | 392 | { |
@@ -1074,7 +1065,7 @@ common_traceroute_main(int op, char **argv) | |||
1074 | printf(" from %s", source); | 1065 | printf(" from %s", source); |
1075 | printf(", %d hops max, %d byte packets\n", max_ttl, packlen); | 1066 | printf(", %d hops max, %d byte packets\n", max_ttl, packlen); |
1076 | 1067 | ||
1077 | from_lsa = dup_sockaddr(dest_lsa); | 1068 | from_lsa = xmemdup(dest_lsa, LSA_LEN_SIZE + dest_lsa->len); |
1078 | lastaddr = xzalloc(dest_lsa->len); | 1069 | lastaddr = xzalloc(dest_lsa->len); |
1079 | to = xzalloc(dest_lsa->len); | 1070 | to = xzalloc(dest_lsa->len); |
1080 | seq = 0; | 1071 | seq = 0; |
diff --git a/networking/udhcp/d6_dhcpc.c b/networking/udhcp/d6_dhcpc.c index 044f04673..4e9b705b9 100644 --- a/networking/udhcp/d6_dhcpc.c +++ b/networking/udhcp/d6_dhcpc.c | |||
@@ -118,7 +118,7 @@ static void *d6_copy_option(uint8_t *option, uint8_t *option_end, unsigned code) | |||
118 | uint8_t *opt = d6_find_option(option, option_end, code); | 118 | uint8_t *opt = d6_find_option(option, option_end, code); |
119 | if (!opt) | 119 | if (!opt) |
120 | return opt; | 120 | return opt; |
121 | return memcpy(xmalloc(opt[3] + 4), opt, opt[3] + 4); | 121 | return xmemdup(opt, opt[3] + 4); |
122 | } | 122 | } |
123 | 123 | ||
124 | static void *d6_store_blob(void *dst, const void *src, unsigned len) | 124 | static void *d6_store_blob(void *dst, const void *src, unsigned len) |