file_utils: add exists_dir_at()

parent 3e2ec670
...@@ -512,3 +512,15 @@ FILE *fdopen_cached(int fd, const char *mode, void **caller_freed_buffer) ...@@ -512,3 +512,15 @@ FILE *fdopen_cached(int fd, const char *mode, void **caller_freed_buffer)
#endif #endif
return f; return f;
} }
bool exists_dir_at(int dir_fd, const char *path)
{
struct stat sb;
int ret;
ret = fstatat(dir_fd, path, &sb, 0);
if (ret < 0)
return false;
return S_ISDIR(sb.st_mode);
}
...@@ -72,5 +72,6 @@ __hidden extern int fd_to_fd(int from, int to); ...@@ -72,5 +72,6 @@ __hidden extern int fd_to_fd(int from, int to);
__hidden extern int lxc_open_dirfd(const char *dir); __hidden extern int lxc_open_dirfd(const char *dir);
__hidden extern FILE *fdopen_cached(int fd, const char *mode, void **caller_freed_buffer); __hidden extern FILE *fdopen_cached(int fd, const char *mode, void **caller_freed_buffer);
__hidden extern FILE *fopen_cached(const char *path, const char *mode, void **caller_freed_buffer); __hidden extern FILE *fopen_cached(const char *path, const char *mode, void **caller_freed_buffer);
__hidden extern bool exists_dir_at(int dir_fd, const char *path);
#endif /* __LXC_FILE_UTILS_H */ #endif /* __LXC_FILE_UTILS_H */
...@@ -569,15 +569,7 @@ gid_t get_ns_gid(gid_t orig) ...@@ -569,15 +569,7 @@ gid_t get_ns_gid(gid_t orig)
bool dir_exists(const char *path) bool dir_exists(const char *path)
{ {
struct stat sb; return exists_dir_at(-1, path);
int ret;
ret = stat(path, &sb);
if (ret < 0)
/* Could be something other than eexist, just say "no". */
return false;
return S_ISDIR(sb.st_mode);
} }
/* Note we don't use SHA-1 here as we don't want to depend on HAVE_GNUTLS. /* Note we don't use SHA-1 here as we don't want to depend on HAVE_GNUTLS.
......
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