From 74f4638877607afc7d9320f99c8b3fe23e59c382 Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Thu, 11 Feb 2021 14:40:17 +0100 Subject: [PATCH] string_utils: add fdstr() Signed-off-by: Christian Brauner --- src/lxc/string_utils.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/lxc/string_utils.h b/src/lxc/string_utils.h index c98429c09..f12879254 100644 --- a/src/lxc/string_utils.h +++ b/src/lxc/string_utils.h @@ -161,4 +161,15 @@ static inline const char *proc_self_fd(int fd) return buf; } +static inline const char *fdstr(int fd) +{ + static const char *fdstr_invalid = "-EBADF"; + static char buf[INTTYPE_TO_STRLEN(int)]; + + if (strnprintf(buf, sizeof(buf), "%d", fd) < 0) + return fdstr_invalid; + + return buf; +} + #endif /* __LXC_STRING_UTILS_H */ -- 2.47.2