btrfs-progs: move test_isdir() to utils.c
authorSatoru Takeuchi <takeuchi_satoru@jp.fujitsu.com>
Fri, 1 Aug 2014 02:58:00 +0000 (11:58 +0900)
committerDavid Sterba <dsterba@suse.cz>
Fri, 22 Aug 2014 13:07:04 +0000 (15:07 +0200)
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 <takeuchi_satoru@jp.fujitsu.com>
Cc: David Sterba <dsterba@suse.cz>
Cc: Mike Fleetwood <mike.fleetwood@googlemail.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
cmds-subvolume.c
utils.c
utils.h

index 29ded12..0d4a52e 100644 (file)
@@ -41,25 +41,6 @@ static const char * const subvolume_cmd_group_usage[] = {
        NULL
 };
 
-/*
- * 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
- */
-static int test_isdir(char *path)
-{
-       struct stat     st;
-       int             res;
-
-       res = stat(path, &st);
-       if(res < 0 )
-               return -1;
-
-       return S_ISDIR(st.st_mode);
-}
-
 static const char * const cmd_subvol_create_usage[] = {
        "btrfs subvolume create [-i <qgroupid>] [<dest>/]<name>",
        "Create a subvolume",
diff --git a/utils.c b/utils.c
index d2397e8..6c09366 100644 (file)
--- 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);
+}
diff --git a/utils.h b/utils.h
index e3d80c1..fd25126 100644 (file)
--- a/utils.h
+++ b/utils.h
@@ -117,6 +117,7 @@ int test_uuid_unique(char *fs_uuid);
 
 int test_minimum_size(const char *file, u32 leafsize);
 int test_issubvolname(const char *name);
+int test_isdir(const char *path);
 
 /*
  * Btrfs minimum size calculation is complicated, it should include at least: