summaryrefslogtreecommitdiff
path: root/src/basic/fd-util.h
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2023-04-20 10:10:35 +0200
committerLennart Poettering <lennart@poettering.net>2023-04-24 20:51:51 +0200
commit6f81bcef2558835dc2265f932d4b22a8b9424db2 (patch)
tree03acbb7bac6c20282b73cf5790605d1797374459 /src/basic/fd-util.h
parent13d9669980cf3ec19e036d1d99e6b5b60f0695a7 (diff)
downloadsystemd-6f81bcef2558835dc2265f932d4b22a8b9424db2.tar.gz
fd-util: add ASSERT_FD() that is similar to ASSERT_PTR() but for fds
Diffstat (limited to 'src/basic/fd-util.h')
-rw-r--r--src/basic/fd-util.h8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/basic/fd-util.h b/src/basic/fd-util.h
index 655ad29284..2f59e334c5 100644
--- a/src/basic/fd-util.h
+++ b/src/basic/fd-util.h
@@ -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_; \
+ })