]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
string_utils: add proc_self_fd()
authorChristian Brauner <christian.brauner@ubuntu.com>
Thu, 11 Feb 2021 13:39:58 +0000 (14:39 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Thu, 11 Feb 2021 13:44:52 +0000 (14:44 +0100)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/string_utils.h

index dd086cee70e69140f4c70be0433ff823063838e9..c98429c092a3a24995be0db065ba5a2569857a06 100644 (file)
@@ -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 */