file_utils: add exists_dir_at()

parent ae9215cf
...@@ -539,3 +539,15 @@ int timens_offset_write(clockid_t clk_id, int64_t s_offset, int64_t ns_offset) ...@@ -539,3 +539,15 @@ int timens_offset_write(clockid_t clk_id, int64_t s_offset, int64_t ns_offset)
return 0; return 0;
} }
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);
}
...@@ -73,5 +73,6 @@ __hidden extern int lxc_open_dirfd(const char *dir); ...@@ -73,5 +73,6 @@ __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 int timens_offset_write(clockid_t clk_id, int64_t s_offset, int64_t ns_offset); __hidden extern int timens_offset_write(clockid_t clk_id, int64_t s_offset, int64_t ns_offset);
__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