From c2d83207bf964e6c0624ce870a01ac1b13ab165b Mon Sep 17 00:00:00 2001 From: Satoru Takeuchi Date: Fri, 1 Aug 2014 11:58:00 +0900 Subject: btrfs-progs: move test_isdir() to utils.c Since test_isdir() is a utility function, it's better to move it to utils.c. In addition, "const char *" is more appropriate type as its "path" argument because this argument is not changed in this function. Signed-off-by: Satoru Takeuchi Cc: David Sterba Cc: Mike Fleetwood Signed-off-by: David Sterba --- utils.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'utils.c') diff --git a/utils.c b/utils.c index d2397e85..6c093666 100644 --- a/utils.c +++ b/utils.c @@ -2417,3 +2417,22 @@ int test_issubvolname(const char *name) return name[0] != '\0' && !strchr(name, '/') && strcmp(name, ".") && strcmp(name, ".."); } + +/* + * test if path is a directory + * this function return + * 0-> path exists but it is not a directory + * 1-> path exists and it is a directory + * -1 -> path is unaccessible + */ +int test_isdir(const char *path) +{ + struct stat st; + int ret; + + ret = stat(path, &st); + if(ret < 0 ) + return -1; + + return S_ISDIR(st.st_mode); +} -- cgit v1.2.3