Commit 401464d2 authored by Cyrill Gorcunov's avatar Cyrill Gorcunov

Add close_safe helper

Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@gmail.com>
parent aff6918b
......@@ -148,6 +148,7 @@ void printk_vma(struct vma_area *vma_area);
int reopen_fd_as(int new_fd, int old_fd);
int parse_maps(pid_t pid, struct list_head *vma_list);
int close_safe(int *fd);
#define __xalloc(op, size, ...) \
({ \
......
......@@ -226,6 +226,20 @@ err_cont:
goto err;
}
int close_safe(int *fd)
{
int ret = 0;
if (*fd > -1) {
ret = close(*fd);
if (!ret)
*fd = -1;
else
pr_perror("Unable to close fd: %d\n", *fd);
}
return ret;
}
int reopen_fd_as(int new_fd, int old_fd)
{
if (old_fd != new_fd) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment