]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
fd-util: add ASSERT_FD() that is similar to ASSERT_PTR() but for fds
authorLennart Poettering <lennart@poettering.net>
Thu, 20 Apr 2023 08:10:35 +0000 (10:10 +0200)
committerLennart Poettering <lennart@poettering.net>
Mon, 24 Apr 2023 18:51:51 +0000 (20:51 +0200)
src/basic/fd-util.h

index 655ad2928475173d04b138a3ecf42dff1ccc8571..2f59e334c5c12051405b3bfa94ef3ac2fbe80aa7 100644 (file)
@@ -121,3 +121,11 @@ static inline char *format_proc_fd_path(char buf[static PROC_FD_PATH_MAX], int f
         format_proc_fd_path((char[PROC_FD_PATH_MAX]) {}, (fd))
 
 const char *accmode_to_string(int flags);
+
+/* Like ASSERT_PTR, but for fds */
+#define ASSERT_FD(fd)                           \
+        ({                                      \
+                int _fd_ = (fd);                \
+                assert(_fd_ >= 0);              \
+                _fd_;                           \
+        })