Skip to content
Snippets Groups Projects
Commit 1c0bfd24 authored by Colin Walters's avatar Colin Walters
Browse files

dirfd: Add glnx_ensure_dir()

Another one where we have a lot of inlines in ostree at least. Not the same as
`glnx_shutil_mkdir_p_at()` since in these cases we don't want automatic
intermediate dirs, and it's cheaper to just call `mkdirat()` and handle `EEXIST`
rather than do a `stat()` first.
parent 268ae488
No related branches found
No related tags found
No related merge requests found
......@@ -83,6 +83,34 @@ char *glnx_fdrel_abspath (int dfd,
void glnx_gen_temp_name (gchar *tmpl);
/**
* glnx_ensure_dir:
* @dfd: directory fd
* @path: Directory path
* @mode: Mode
* @error: Return location for a #GError, or %NULL
*
* Wrapper around mkdirat() which ignores adds #GError support, ensures that
* it retries on %EINTR, and also ignores `EEXIST`.
*
* See also `glnx_shutil_mkdir_p_at()` for recursive handling.
*
* Returns: %TRUE on success, %FALSE otherwise
*/
static inline gboolean
glnx_ensure_dir (int dfd,
const char *path,
mode_t mode,
GError **error)
{
if (TEMP_FAILURE_RETRY (mkdirat (dfd, path, mode)) != 0)
{
if (G_UNLIKELY (errno != EEXIST))
return glnx_throw_errno_prefix (error, "mkdirat(%s)", path);
}
return TRUE;
}
gboolean glnx_mkdtempat (int dfd,
gchar *tmpl,
int mode,
......
......@@ -185,6 +185,8 @@ mkdir_p_at_internal (int dfd,
*
* Similar to g_mkdir_with_parents(), except operates relative to the
* directory fd @dfd.
*
* See also glnx_ensure_dir() for a non-recursive version.
*/
gboolean
glnx_shutil_mkdir_p_at (int dfd,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment