4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Haejeong Kim <backto.kim@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
29 #include "mm_file_traverse.h"
31 int mmfile_get_file_names(char *root_dir, MMFunc cbfunc, void *user_data)
35 GArray *dir_array = NULL;
37 char pdirname[MMFILE_PATH_MAX + 1] = {0, };
38 char *current_path = NULL;
39 char *start_path = NULL;
40 char *tmp_path = NULL;
42 if (!g_file_test(root_dir, G_FILE_TEST_IS_DIR)) {
43 printf("it is not directory\n");
47 dir_array = g_array_new(false, false, sizeof(char*));
48 if (dir_array == NULL) {
49 printf("g_array_new failed");
53 start_path = g_strdup(root_dir);
54 if (start_path != NULL)
55 g_array_append_val(dir_array, start_path);
57 while (dir_array->len != 0) {
58 current_path = g_array_index(dir_array , char*, 0);
59 g_array_remove_index(dir_array, 0);
61 dir = g_dir_open(current_path, 0, &error);
62 if (dir != NULL && error == NULL) {
63 while ((name = g_dir_read_name(dir))) {
64 memset(pdirname, 0, sizeof(pdirname));
65 snprintf(pdirname, sizeof(pdirname), "%s/%s", current_path, name);
67 if (g_file_test(pdirname, G_FILE_TEST_IS_DIR)) {
68 tmp_path = g_strdup(pdirname);
69 g_array_append_val(dir_array, tmp_path);
70 } else if (g_file_test(pdirname, G_FILE_TEST_IS_REGULAR)) {
72 cbfunc(pdirname, user_data, true);
76 printf("g_dir_open failed");
82 SAFE_FREE(current_path);
86 g_array_free(dir_array, FALSE);
88 return MMFILE_SUCCESS;