X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fshared%2Futil.h;h=8ddd1a5daf600f49a9e94249a2735e514a2b90ed;hp=0f8c39335334f8cf458b00def6207bef59fdb5e9;hb=9489490a693ec5d1e3b49eecedb0ca5511568665;hpb=849958d1ba3533c953fad46d4d41c0ec6e48316d diff --git a/src/shared/util.h b/src/shared/util.h index 0f8c39335..8ddd1a5da 100644 --- a/src/shared/util.h +++ b/src/shared/util.h @@ -666,14 +666,21 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(FILE*, endmntent); #define _cleanup_close_pair_ _cleanup_(close_pairp) _malloc_ _alloc_(1, 2) static inline void *malloc_multiply(size_t a, size_t b) { - if (_unlikely_(b == 0 || a > ((size_t) -1) / b)) + if (_unlikely_(b != 0 && a > ((size_t) -1) / b)) return NULL; return malloc(a * b); } +_alloc_(2, 3) static inline void *realloc_multiply(void *p, size_t a, size_t b) { + if (_unlikely_(b != 0 && a > ((size_t) -1) / b)) + return NULL; + + return realloc(p, a * b); +} + _alloc_(2, 3) static inline void *memdup_multiply(const void *p, size_t a, size_t b) { - if (_unlikely_(b == 0 || a > ((size_t) -1) / b)) + if (_unlikely_(b != 0 && a > ((size_t) -1) / b)) return NULL; return memdup(p, a * b); @@ -946,3 +953,8 @@ int update_reboot_param_file(const char *param); int umount_recursive(const char *target, int flags); int bind_remount_recursive(const char *prefix, bool ro); + +int fflush_and_check(FILE *f); + +char *tempfn_xxxxxx(const char *p); +char *tempfn_random(const char *p);