From: Christian Brauner Date: Thu, 11 Feb 2021 13:39:58 +0000 (+0100) Subject: string_utils: add proc_self_fd() X-Git-Tag: lxc-5.0.0~291^2~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4b7686ea7b660d89bf4290f64ca4331a8ddf74e3;p=thirdparty%2Flxc.git string_utils: add proc_self_fd() Signed-off-by: Christian Brauner --- diff --git a/src/lxc/string_utils.h b/src/lxc/string_utils.h index dd086cee7..c98429c09 100644 --- a/src/lxc/string_utils.h +++ b/src/lxc/string_utils.h @@ -149,4 +149,16 @@ static inline bool strequal(const char *str, const char *eq) __ret_strnprintf; \ }) +static inline const char *proc_self_fd(int fd) +{ + static const char *invalid_fd_path = "/proc/self/fd/-EBADF"; + static char buf[LXC_PROC_SELF_FD_LEN] = "/proc/self/fd/"; + + if (strnprintf(buf + STRLITERALLEN("/proc/self/fd/"), + INTTYPE_TO_STRLEN(int), "%d", fd) < 0) + return invalid_fd_path; + + return buf; +} + #endif /* __LXC_STRING_UTILS_H */