Skip to content

Commit

Permalink
string_utils: add fdstr()
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
  • Loading branch information
Christian Brauner committed Feb 26, 2021
1 parent aabafa6 commit 00c5cdf
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/lxc/string_utils.h
Expand Up @@ -159,4 +159,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 */

0 comments on commit 00c5cdf

Please sign in to comment.