summaryrefslogtreecommitdiff
path: root/tests/mm_file_traverser.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/mm_file_traverser.c')
-rwxr-xr-xtests/mm_file_traverser.c122
1 files changed, 122 insertions, 0 deletions
diff --git a/tests/mm_file_traverser.c b/tests/mm_file_traverser.c
new file mode 100755
index 0000000..994f91f
--- /dev/null
+++ b/tests/mm_file_traverser.c
@@ -0,0 +1,122 @@
+/*
+ * libmm-fileinfo
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Haejeong Kim <backto.kim@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <dirent.h>
+#include <limits.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <glib.h>
+
+#include "mm_file_traverse.h"
+
+static GList *g_directories = NULL;
+
+int mmfile_get_file_names (char *root_dir, MMFunc cbfunc, void* user_data)
+{
+ struct stat statbuf;
+ struct dirent *dirp;
+ DIR *dp;
+
+ char pdirname[MMFILE_PATH_MAX+1];
+
+ memset (pdirname, 0x00, MMFILE_PATH_MAX+1);
+
+ if ( lstat (root_dir, &statbuf) < 0 )
+ {
+ printf ("lstat error\n");
+ return MMFILE_FAIL;
+ }
+
+ if ( S_ISDIR (statbuf.st_mode) == 0 )
+ {
+ printf ("it is not directory\n");
+ return MMFILE_FAIL;
+ }
+
+ g_directories = g_list_append(g_directories, strdup (root_dir));
+
+
+ int i = 0;
+ gpointer element_data = NULL;
+ while ( (element_data = g_list_nth_data (g_directories, i)) != NULL )
+ {
+ if (strlen ((char*) element_data) > 0 && strlen ((char*) element_data) <= MMFILE_PATH_MAX)
+ {
+ strcpy (pdirname, (char*) element_data);
+
+ if ( (dp = opendir (pdirname)) != NULL )
+ {
+ while ( (dirp = readdir (dp)) != NULL )
+ {
+ char cdirname[MMFILE_PATH_MAX+1];
+
+ if ( strcmp (dirp->d_name, ".") == 0 ||
+ strcmp (dirp->d_name, "..") == 0 )
+ {
+ continue;
+ }
+
+ memset (cdirname, 0x00, MMFILE_PATH_MAX+1);
+ strcpy (cdirname, pdirname);
+ strcat (cdirname, "/");
+ strcat (cdirname, dirp->d_name);
+
+ if ( lstat (cdirname, &statbuf) < 0 )
+ {
+ printf ("lstat error\n");
+ closedir (dp);
+ return MMFILE_FAIL;
+ }
+
+ if ( S_ISDIR (statbuf.st_mode) )
+ {
+ printf ("directory: %s\n", cdirname);
+ g_directories = g_list_append(g_directories, strdup (cdirname));
+ }
+ else
+ {
+ printf ("file: %s\n", cdirname);
+ if ( cbfunc != NULL )
+ {
+ cbfunc (cdirname, user_data, true);
+ }
+ }
+
+ }
+
+ closedir (dp);
+ }
+ }
+
+ i++;
+ }
+
+ g_list_free (g_directories);
+
+ return MMFILE_SUCCESS;
+
+
+}
+