From: Lucas De Marchi Date: Fri, 2 Dec 2011 19:21:18 +0000 (-0200) Subject: Add memdup() helper X-Git-Tag: v1~120 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e22c85f357d4ae9258383213d68a731cabd3a210;p=thirdparty%2Fkmod.git Add memdup() helper --- diff --git a/libkmod/libkmod-private.h b/libkmod/libkmod-private.h index c589a22d..f2797b42 100644 --- a/libkmod/libkmod-private.h +++ b/libkmod/libkmod-private.h @@ -80,5 +80,6 @@ char *getline_wrapped(FILE *fp, unsigned int *linenum) __attribute__((nonnull(1) char *underscores(struct kmod_ctx *ctx, char *s) __attribute__((nonnull(1, 2))); #define streq(a, b) (strcmp((a), (b)) == 0) bool startswith(const char *s, const char *prefix) __attribute__((nonnull(1, 2))); +void *memdup(const void *p, size_t n) __attribute__((nonnull(1)); #endif diff --git a/libkmod/libkmod-util.c b/libkmod/libkmod-util.c index 556dfcd1..b6e3cfc5 100644 --- a/libkmod/libkmod-util.c +++ b/libkmod/libkmod-util.c @@ -133,3 +133,13 @@ bool startswith(const char *s, const char *prefix) { return memcmp(s, prefix, pl) == 0; } + +inline void *memdup(const void *p, size_t n) +{ + void *r = malloc(n); + + if (r == NULL) + return NULL; + + return memcpy(r, p, n); +}