projects
/
platform
/
upstream
/
systemd.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
4348c84
)
alloc-util: add alloca() counterparts for memdup() and memdup_suffix0()
author
Lennart Poettering
<lennart@poettering.net>
Mon, 15 Oct 2018 10:05:54 +0000
(12:05 +0200)
committer
Lennart Poettering
<lennart@poettering.net>
Mon, 15 Oct 2018 17:35:00 +0000
(19:35 +0200)
src/basic/alloc-util.h
patch
|
blob
|
history
diff --git
a/src/basic/alloc-util.h
b/src/basic/alloc-util.h
index
ebe4288
..
2a6deb1
100644
(file)
--- a/
src/basic/alloc-util.h
+++ b/
src/basic/alloc-util.h
@@
-46,6
+46,21
@@
static inline void *mfree(void *memory) {
void* memdup(const void *p, size_t l) _alloc_(2);
void* memdup_suffix0(const void *p, size_t l) _alloc_(2);
+#define memdupa(p, l) \
+ ({ \
+ void *_q_; \
+ _q_ = alloca(l); \
+ memcpy(_q_, p, l); \
+ })
+
+#define memdupa_suffix0(p, l) \
+ ({ \
+ void *_q_; \
+ _q_ = alloca(l + 1); \
+ ((uint8_t*) _q_)[l] = 0; \
+ memcpy(_q_, p, l); \
+ })
+
static inline void freep(void *p) {
free(*(void**) p);
}