From: Jiyong Min Date: Mon, 13 Mar 2017 06:15:41 +0000 (+0900) Subject: Replace readdir_r to readdir to fix build error X-Git-Tag: accepted/tizen/unified/20170313.120247 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Ftags%2Faccepted%2Ftizen%2Funified%2F20170313.120247;p=platform%2Fcore%2Fmultimedia%2Flibmm-fileinfo.git Replace readdir_r to readdir to fix build error [Problem] After update tool chain to GCC6, 'readdir_r is deprecated' build error happen 'readdir_r' is deprecated because of below reasons. * On systems where NAME_MAX is undefined, calling readdir_r() may be unsafe because the interface does not allow the caller to specify the length of the buffer used for the returned directory entry. * On some systems, readdir_r() can't read directory entries with very long names. When the glibc implementation encounters such a name, readdir_r() fails with the error ENAMETOOLONG after the final directory entry has been read. On some other systems, readdir_r() may return a success status, but the returned d_name field may not be null terminated or may be truncated. Change-Id: Iaeabf4b09ab77dfedbc161c725c27a39ec4325c2 Signed-off-by: jiyong.min --- diff --git a/tests/mm_file_traverser.c b/tests/mm_file_traverser.c index eef3f1b..1006120 100755 --- a/tests/mm_file_traverser.c +++ b/tests/mm_file_traverser.c @@ -32,12 +32,12 @@ #include "mm_file_traverse.h" static GList *g_directories = NULL; +static GMutex g_fileinfo_mutex; int mmfile_get_file_names(char *root_dir, MMFunc cbfunc, void *user_data) { struct stat statbuf; - struct dirent dirp; - struct dirent *result = NULL; + struct dirent *dirp; DIR *dp; char pdirname[MMFILE_PATH_MAX + 1]; @@ -54,6 +54,9 @@ int mmfile_get_file_names(char *root_dir, MMFunc cbfunc, void *user_data) return MMFILE_FAIL; } + /* "readdir" is thread-unsafty, so mutex lock is necessary for thread-safety*/ + g_mutex_lock(&g_fileinfo_mutex); + g_directories = g_list_append(g_directories, strdup(root_dir)); @@ -64,22 +67,24 @@ int mmfile_get_file_names(char *root_dir, MMFunc cbfunc, void *user_data) strncpy(pdirname, (char *) element_data, strlen((char *) element_data)); if ((dp = opendir(pdirname)) != NULL) { - while (!readdir_r(dp, &dirp, &result)) { + while ((dirp = readdir(dp)) != NULL) { char cdirname[MMFILE_PATH_MAX + 1]; - if (strcmp(dirp.d_name, ".") == 0 || - strcmp(dirp.d_name, "..") == 0) { + if (strcmp(dirp->d_name, ".") == 0 || + strcmp(dirp->d_name, "..") == 0) { continue; } memset(cdirname, 0x00, MMFILE_PATH_MAX + 1); strncpy(cdirname, pdirname, strlen(pdirname)); strncat(cdirname, "/", 1); - strncat(cdirname, dirp.d_name, strlen(dirp.d_name)); + strncat(cdirname, dirp->d_name, strlen(dirp->d_name)); if (lstat(cdirname, &statbuf) < 0) { printf("lstat error\n"); + free(dirp); closedir(dp); + g_mutex_unlock(&g_fileinfo_mutex); return MMFILE_FAIL; } @@ -92,7 +97,7 @@ int mmfile_get_file_names(char *root_dir, MMFunc cbfunc, void *user_data) cbfunc(cdirname, user_data, true); } } - + free(dirp); } closedir(dp); @@ -104,6 +109,8 @@ int mmfile_get_file_names(char *root_dir, MMFunc cbfunc, void *user_data) g_list_free(g_directories); + g_mutex_unlock(&g_fileinfo_mutex); + return MMFILE_SUCCESS;