libotutil: new function ot_openat_ignore_enoent

Refactor some common code

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
Giuseppe Scrivano committed 2016-03-15 09:48:47 +01:00
1 parent 89514dd8ba
commit a98133072d
4 files changed
+42 -61

No files matched your search

+25
View File
@@ -205,3 +205,28 @@ ot_ensure_unlinked_at (int dfd,
}
return TRUE;
}
gboolean
ot_openat_ignore_enoent (int dfd,
const char *path,
int *out_fd,
GError **error)
{
gboolean ret = FALSE;
int target_fd = -1;
target_fd = openat (dfd, path, O_CLOEXEC | O_RDONLY);
if (target_fd < 0)
{
if (errno != ENOENT)
{
glnx_set_error_from_errno (error);
goto out;
}
}
ret = TRUE;
*out_fd = target_fd;
out:
return ret;
}
+5
View File
@@ -61,4 +61,9 @@ gboolean ot_ensure_unlinked_at (int dfd,
const char *path,
GError **error);
gboolean ot_openat_ignore_enoent (int dfd,
const char *path,
int *out_fd,
GError **error);
G_END_DECLS