From: Christian Brauner Date: Thu, 11 Feb 2021 13:40:17 +0000 (+0100) Subject: string_utils: add fdstr() X-Git-Tag: lxc-5.0.0~291^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=74f4638877607afc7d9320f99c8b3fe23e59c382;p=thirdparty%2Flxc.git string_utils: add fdstr() Signed-off-by: Christian Brauner --- 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 */