int ul_path_set_enoent_redirect(struct path_cxt *pc, int (*func)(struct path_cxt *, const char *, int *));
int ul_path_get_dirfd(struct path_cxt *pc);
+char *ul_path_get_abspath(struct path_cxt *pc, char *buf, size_t bufsz, const char *path, ...)
+ __attribute__ ((__format__ (__printf__, 4, 5)));
+
int ul_path_access(struct path_cxt *pc, int mode, const char *path);
int ul_path_accessf(struct path_cxt *pc, int mode, const char *path, ...)
__attribute__ ((__format__ (__printf__, 3, 4)));
return pc->path_buffer;
}
-
int ul_path_get_dirfd(struct path_cxt *pc)
{
assert(pc);
return pc->path_buffer;
}
+char *ul_path_get_abspath(struct path_cxt *pc, char *buf, size_t bufsz, const char *path, ...)
+{
+ if (path) {
+ int rc;
+ va_list ap;
+ const char *tail = NULL;
+
+ va_start(ap, path);
+ tail = ul_path_mkpath(pc, path, ap);
+ va_end(ap);
+
+ rc = snprintf(buf, bufsz, "%s/%s/%s",
+ pc->prefix ? pc->prefix : "",
+ pc->dir_path,
+ tail);
+
+ if ((size_t)rc >= bufsz) {
+ errno = ENAMETOOLONG;
+ return NULL;
+ }
+ } else {
+ const char *tmp = get_absdir(pc);
+
+ if (!tmp)
+ return NULL;
+ strncpy(buf, tmp, bufsz);
+ buf[bufsz - 1] = '\0';
+ }
+
+ return buf;
+}
+
+
int ul_path_access(struct path_cxt *pc, int mode, const char *path)
{
int dir, rc;