Skip to content

Commit

Permalink
file_utils: move dup_cloexec() to header
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 971c1e7 commit 8f53570
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
14 changes: 0 additions & 14 deletions src/lxc/file_utils.c
Expand Up @@ -564,20 +564,6 @@ int fd_cloexec(int fd, bool cloexec)
return 0;
}

static inline int dup_cloexec(int fd)
{
__do_close int fd_dup = -EBADF;

fd_dup = dup(fd);
if (fd_dup < 0)
return -errno;

if (fd_cloexec(fd_dup, true))
return -errno;

return move_fd(fd_dup);
}

FILE *fdopen_at(int dfd, const char *path, const char *mode,
unsigned int o_flags, unsigned int resolve_flags)
{
Expand Down
14 changes: 14 additions & 0 deletions src/lxc/file_utils.h
Expand Up @@ -104,4 +104,18 @@ __hidden extern ssize_t lxc_read_try_buf_at(int dfd, const char *path,
*/
__hidden extern bool same_file_lax(int fda, int fdb);

static inline int dup_cloexec(int fd)
{
__do_close int fd_dup = -EBADF;

fd_dup = dup(fd);
if (fd_dup < 0)
return -errno;

if (fd_cloexec(fd_dup, true))
return -errno;

return move_fd(fd_dup);
}

#endif /* __LXC_FILE_UTILS_H */

0 comments on commit 8f53570

Please sign in to comment.