diff options
author | Thomas Haller <thaller@redhat.com> | 2022-03-15 13:17:02 (GMT) |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2022-03-16 23:09:45 (GMT) |
commit | 14a9ebcf6d3bfa7d4415e07b7c2af23b79314cb3 (patch) | |
tree | 1da079277e9ae97f3ad47a770de30cbcd56c39ef /include | |
parent | 2e0d7f85d2aeed9181a276079b5a28cc1c8e90ac (diff) | |
download | libnl-14a9ebcf6d3bfa7d4415e07b7c2af23b79314cb3.zip libnl-14a9ebcf6d3bfa7d4415e07b7c2af23b79314cb3.tar.gz libnl-14a9ebcf6d3bfa7d4415e07b7c2af23b79314cb3.tar.bz2 |
utils: add internal _nl_memdup() helper
Diffstat (limited to 'include')
-rw-r--r-- | include/netlink-private/utils.h | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/include/netlink-private/utils.h b/include/netlink-private/utils.h index 4aec021..8fb12af 100644 --- a/include/netlink-private/utils.h +++ b/include/netlink-private/utils.h @@ -280,4 +280,24 @@ _nl_close(int fd) return r; } +static inline void * +_nl_memdup(const void *ptr, size_t len) +{ + void *p; + + if (len == 0) { + /* malloc() leaves it implementation defined whether to return NULL. + * Callers rely on returning NULL if len is zero. */ + return NULL; + } + + p = malloc(len); + if (!p) + return NULL; + memcpy(p, ptr, len); + return p; +} + +#define _nl_memdup_ptr(ptr) ((__typeof__(ptr)) _nl_memdup((ptr), sizeof(*(ptr)))) + #endif |