lib/path: add ul_path_is_accessible()
This function allow to check that path_cxt is usable. Note that ul_new_path() does not open the path. Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
parent
bf1d0a4ea0
commit
655d736da3
|
@ -42,6 +42,7 @@ int ul_path_set_enoent_redirect(struct path_cxt *pc, int (*func)(struct path_cxt
|
||||||
int ul_path_get_dirfd(struct path_cxt *pc);
|
int ul_path_get_dirfd(struct path_cxt *pc);
|
||||||
void ul_path_close_dirfd(struct path_cxt *pc);
|
void ul_path_close_dirfd(struct path_cxt *pc);
|
||||||
int ul_path_isopen_dirfd(struct path_cxt *pc);
|
int ul_path_isopen_dirfd(struct path_cxt *pc);
|
||||||
|
int ul_path_is_accessible(struct path_cxt *pc);
|
||||||
|
|
||||||
char *ul_path_get_abspath(struct path_cxt *pc, char *buf, size_t bufsz, const char *path, ...)
|
char *ul_path_get_abspath(struct path_cxt *pc, char *buf, size_t bufsz, const char *path, ...)
|
||||||
__attribute__ ((__format__ (__printf__, 4, 5)));
|
__attribute__ ((__format__ (__printf__, 4, 5)));
|
||||||
|
|
14
lib/path.c
14
lib/path.c
|
@ -195,6 +195,20 @@ static const char *get_absdir(struct path_cxt *pc)
|
||||||
return pc->path_buffer;
|
return pc->path_buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ul_path_is_accessible(struct path_cxt *pc)
|
||||||
|
{
|
||||||
|
const char *path;
|
||||||
|
assert(pc);
|
||||||
|
|
||||||
|
if (pc->dir_fd >= 0)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
path = get_absdir(pc);
|
||||||
|
if (!path)
|
||||||
|
return 0;
|
||||||
|
return access(path, F_OK) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
int ul_path_get_dirfd(struct path_cxt *pc)
|
int ul_path_get_dirfd(struct path_cxt *pc)
|
||||||
{
|
{
|
||||||
assert(pc);
|
assert(pc);
|
||||||
|
|
Loading…
Reference in New Issue