char *xstrdup(const char *s) FAST_FUNC RETURNS_MALLOC;
char *xstrndup(const char *s, int n) FAST_FUNC RETURNS_MALLOC;
+void *xmemdup(const void *s, int n) FAST_FUNC RETURNS_MALLOC;
void overlapping_strcpy(char *dst, const char *src) FAST_FUNC;
char *safe_strncpy(char *dst, const char *src, size_t size) FAST_FUNC;
char *strncpy_IFNAMSIZ(char *dst, const char *src) FAST_FUNC;
break;
if (flags & PSSCAN_ARGVN) {
sp->argv_len = n;
- sp->argv0 = xmalloc(n + 1);
- memcpy(sp->argv0, buf, n + 1);
+ sp->argv0 = xmemdup(buf, n + 1);
/* sp->argv0[n] = '\0'; - buf has it */
} else {
sp->argv_len = 0;
return memcpy(t, s, n);
}
+void* FAST_FUNC xmemdup(const void *s, int n)
+{
+ return memcpy(xmalloc(n), s, n);
+}
+
// Die if we can't open a file and return a FILE* to it.
// Notice we haven't got xfread(), This is for use with fscanf() and friends.
FILE* FAST_FUNC xfopen(const char *path, const char *mode)
break;
}
/* add_entry */
- llist_add_to(&zlist, memcpy(xmalloc(sizeof(ut)), &ut, sizeof(ut)));
+ llist_add_to(&zlist, xmemdup(&ut, sizeof(ut)));
break;
case USER_PROCESS: {
int show;
show_entry(&ut, state, boot_time);
}
/* add_entry */
- llist_add_to(&zlist, memcpy(xmalloc(sizeof(ut)), &ut, sizeof(ut)));
+ llist_add_to(&zlist, xmemdup(&ut, sizeof(ut)));
break;
}
}
#define outudp ((struct udphdr *)(outip + 1))
-/* libbb candidate? tftp uses this idiom too */
-static len_and_sockaddr* dup_sockaddr(const len_and_sockaddr *lsa)
-{
- len_and_sockaddr *new_lsa = xzalloc(LSA_LEN_SIZE + lsa->len);
- memcpy(new_lsa, lsa, LSA_LEN_SIZE + lsa->len);
- return new_lsa;
-}
-
-
static int
wait_for_reply(len_and_sockaddr *from_lsa, struct sockaddr *to, unsigned *timestamp_us, int *left_ms)
{
printf(" from %s", source);
printf(", %d hops max, %d byte packets\n", max_ttl, packlen);
- from_lsa = dup_sockaddr(dest_lsa);
+ from_lsa = xmemdup(dest_lsa, LSA_LEN_SIZE + dest_lsa->len);
lastaddr = xzalloc(dest_lsa->len);
to = xzalloc(dest_lsa->len);
seq = 0;
uint8_t *opt = d6_find_option(option, option_end, code);
if (!opt)
return opt;
- return memcpy(xmalloc(opt[3] + 4), opt, opt[3] + 4);
+ return xmemdup(opt, opt[3] + 4);
}
static void *d6_store_blob(void *dst, const void *src, unsigned len)
* Our solution: ONLY bare $(trap) or `trap` is special.
*/
/* Save trap handler strings for trap builtin to print */
- trap_ptr = memcpy(xmalloc(sizeof(trap)), trap, sizeof(trap));
+ trap_ptr = xmemdup(trap, sizeof(trap));
/* Fall through into clearing traps */
}
clear_traps();
if (G.parser) {
parse_next_rule();
if (G.rule_vec) { /* mdev -s */
- rule = memcpy(xmalloc(sizeof(G.cur_rule)), &G.cur_rule, sizeof(G.cur_rule));
+ rule = xmemdup(&G.cur_rule, sizeof(G.cur_rule));
G.rule_vec = xrealloc_vector(G.rule_vec, 4, G.rule_idx);
G.rule_vec[G.rule_idx++] = rule;
dbg3("> G.rule_vec[G.rule_idx:%d]=%p", G.rule_idx, G.rule_vec[G.rule_idx]);