chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
login: fix pos-array allocation
[elogind.git]
/
src
/
shared
/
util.h
diff --git
a/src/shared/util.h
b/src/shared/util.h
index 9913fcefaeba3ff6a4bfd16aaf0cec0cd2fa5828..78b1444739227d6e27db1930e03b5aba8edba89f 100644
(file)
--- a/
src/shared/util.h
+++ b/
src/shared/util.h
@@
-723,6
+723,15
@@
void* greedy_realloc0(void **p, size_t *allocated, size_t need);
#define GREEDY_REALLOC0(array, allocated, need) \
greedy_realloc0((void**) &(array), &(allocated), sizeof((array)[0]) * (need))
#define GREEDY_REALLOC0(array, allocated, need) \
greedy_realloc0((void**) &(array), &(allocated), sizeof((array)[0]) * (need))
+#define GREEDY_REALLOC0_T(array, count, need) \
+ ({ \
+ size_t _size = (count) * sizeof((array)[0]); \
+ void *_ptr = GREEDY_REALLOC0((array), _size, (need)); \
+ if (_ptr) \
+ (count) = _size / sizeof((array)[0]); \
+ _ptr; \
+ })
+
static inline void _reset_errno_(int *saved_errno) {
errno = *saved_errno;
}
static inline void _reset_errno_(int *saved_errno) {
errno = *saved_errno;
}