]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
Add memdup() helper
authorLucas De Marchi <lucas.demarchi@profusion.mobi>
Fri, 2 Dec 2011 19:21:18 +0000 (17:21 -0200)
committerLucas De Marchi <lucas.demarchi@profusion.mobi>
Sat, 3 Dec 2011 06:07:15 +0000 (04:07 -0200)
libkmod/libkmod-private.h
libkmod/libkmod-util.c

index c589a22ddd671b115b32519c0b7a493efaecc1c9..f2797b42942ecdf3c536ea93c72b675608fb3257 100644 (file)
@@ -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
index 556dfcd125fb64b270e727c96d9de8e75f279c23..b6e3cfc53aa0a59a986e29a5eda9a59672a4e6a1 100644 (file)
@@ -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);
+}