chiark / gitweb /
shared: move assert_return_errno() from libudev
authorTom Gundersen <teg@jklm.no>
Fri, 10 Apr 2015 18:39:43 +0000 (20:39 +0200)
committerSven Eden <yamakuzure@gmx.net>
Tue, 14 Mar 2017 07:01:57 +0000 (08:01 +0100)
This should not be used for any new code, as we don't set errno in new code,
but there are several legacy users, so let's keep it in shared.

src/shared/macro.h

index 7f89951..7ae1ed8 100644 (file)
@@ -256,6 +256,15 @@ static inline unsigned long ALIGN_POWER2(unsigned long u) {
                 }                                                       \
         } while (false)
 
+#define assert_return_errno(expr, r, err)                               \
+        do {                                                            \
+                if (_unlikely_(!(expr))) {                              \
+                        log_assert_failed_return(#expr, __FILE__, __LINE__, __PRETTY_FUNCTION__); \
+                        errno = err;                                    \
+                        return (r);                                     \
+                }                                                       \
+        } while (false)
+
 #define PTR_TO_INT(p) ((int) ((intptr_t) (p)))
 #define INT_TO_PTR(u) ((void *) ((intptr_t) (u)))
 #define PTR_TO_UINT(p) ((unsigned int) ((uintptr_t) (p)))