X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fbasic%2Futil.h;h=af5a4fc9e607fd86d4650661abaae33cb79b56bb;hb=c733f9b08d9eadc5e671185112567ada81116bdf;hp=1fe660b62098494511c9db898c26c8f646330485;hpb=c6edc23d5f8a483e93a891bf7eb76b5f4caf2fb4;p=elogind.git diff --git a/src/basic/util.h b/src/basic/util.h index 1fe660b62..af5a4fc9e 100644 --- a/src/basic/util.h +++ b/src/basic/util.h @@ -111,6 +111,16 @@ static inline void qsort_safe(void *base, size_t nmemb, size_t size, comparison_ qsort(base, nmemb, size, compar); } +/** + * Normal memcpy requires src to be nonnull. We do nothing if n is 0. + */ +static inline void memcpy_safe(void *dst, const void *src, size_t n) { + if (n == 0) + return; + assert(src); + memcpy(dst, src, n); +} + #if 0 /// UNNEEDED by elogind int on_ac_power(void); #endif // 0 @@ -129,7 +139,6 @@ static inline void _reset_errno_(int *saved_errno) { #define PROTECT_ERRNO _cleanup_(_reset_errno_) __attribute__((unused)) int _saved_errno_ = errno -#if 0 /// UNNEEDED by elogind static inline int negative_errno(void) { /* This helper should be used to shut up gcc if you know 'errno' is * negative. Instead of "return -errno;", use "return negative_errno();" @@ -138,7 +147,6 @@ static inline int negative_errno(void) { assert_return(errno > 0, -EINVAL); return -errno; } -#endif // 0 static inline unsigned u64log2(uint64_t n) { #if __SIZEOF_LONG_LONG__ == 8 @@ -189,7 +197,7 @@ int namespace_enter(int pidns_fd, int mntns_fd, int netns_fd, int userns_fd, int uint64_t physical_memory(void); #if 0 /// UNNEEDED by elogind -int update_reboot_param_file(const char *param); #endif // 0 +int update_reboot_parameter_and_warn(const char *param); int version(void);