Replace 'readdir_r' with 'readdir'
authorInkyun Kil <inkyun.kil@samsung.com>
Thu, 15 Dec 2016 04:30:03 +0000 (13:30 +0900)
committerSangyoon Jang <s89.jang@samsung.com>
Fri, 23 Dec 2016 08:26:47 +0000 (17:26 +0900)
'readdir_r' is deprecated since version 2.24 glibc.
By upgrading TOOLCHAIN for platform, it should be replaced by 'readdir'

Change-Id: I711318a6b12a237bc8c9ee9edc981c67e86dd331
Signed-off-by: Inkyun Kil <inkyun.kil@samsung.com>
src/delta.c
src/install_preload_pkg.c
src/pkg_cleardata.c
src/pkg_getsize.c

index fbc5968a16d5060c2d75e0d12b900ae62fbb5b28..ddc84555c649c05baa2474f39b75312d7e8035b3 100644 (file)
@@ -50,15 +50,13 @@ static void __free_g_list(GList *list)
 static GList *__list_directory(const char *dir_name, const char *tpk_path, GList *list)
 {
        DIR *dir = NULL;
-       struct dirent file_info;
-       struct dirent *result;
+       struct dirent *file_info = NULL;
        int flag = 0;
        char path[PATH_MAX] = {0, };
        char rel_path_old_tpk_file[PATH_MAX] = {0, };
        char *file_path = NULL;
        char buf[BUF_SIZE] = {0};
        const char *d_name = NULL;
-       int ret = 0;
        int path_length;
 
        dir = opendir(dir_name);
@@ -68,15 +66,9 @@ static GList *__list_directory(const char *dir_name, const char *tpk_path, GList
                exit(EXIT_FAILURE);
        }
 
-       while (1) {
-               ret = readdir_r(dir, &file_info, &result);
-               if (ret != 0 || result == NULL) {
-                       flag++;
-                       break;
-               }
-
-               d_name = file_info.d_name;
-               if (!(file_info.d_type & DT_DIR)) {
+       while ((file_info = readdir(dir)) != NULL) {
+               d_name = file_info->d_name;
+               if (!(file_info->d_type & DT_DIR)) {
                        snprintf(rel_path_old_tpk_file, PATH_MAX, "%s/%s", dir_name, d_name);
                        strncpy(path, rel_path_old_tpk_file + strlen(tpk_path),
                                        strlen(rel_path_old_tpk_file));
@@ -86,7 +78,7 @@ static GList *__list_directory(const char *dir_name, const char *tpk_path, GList
                        memset(rel_path_old_tpk_file, 0, PATH_MAX);
                }
 
-               if (file_info.d_type & DT_DIR) {
+               if (file_info->d_type & DT_DIR) {
                        if (strcmp(d_name, "..") != 0 && strcmp(d_name, ".") != 0) {
                                path_length = snprintf(path, PATH_MAX, "%s/%s", dir_name, d_name);
                                if (path_length >= PATH_MAX) {
index bd8ddb05a5fc691c20c661b6d4ee0c5c60c0613c..4ed08f9ef4d9a877d8cb4841f8a38cbdd75c9b8c 100644 (file)
@@ -58,7 +58,7 @@ static int _install_preload_pkg(const char *backend, const char *directory,
                bool readonly)
 {
        DIR *dir;
-       struct dirent file_info, *result;
+       struct dirent *file_info = NULL;
        int ret;
        char file_path[BUFSZE];
        char err_buf[BUFSZE];
@@ -77,14 +77,12 @@ static int _install_preload_pkg(const char *backend, const char *directory,
 
        _D("Loading pkg files from %s", directory);
 
-       for (ret = readdir_r(dir, &file_info, &result);
-                       ret == 0 && result != NULL;
-                       ret = readdir_r(dir, &file_info, &result)) {
-               if (file_info.d_name[0] == '.')
+       while ((file_info = readdir(dir)) != NULL) {
+               if (file_info->d_name[0] == '.')
                        continue;
 
                snprintf(file_path, sizeof(file_path), "%s/%s", directory,
-                       file_info.d_name);
+                       file_info->d_name);
                _D("pkg file %s", file_path);
 
                pid_t pid = fork();
index ebeb8c3ab8b49fb2f94388ed2daced45663d9e54..0c4abb095e3b715ede9f2ff6f2ff67b0d8e779c2 100644 (file)
@@ -63,7 +63,7 @@ static int __clear_dir(const char *dirname)
        int ret = 0;
        DIR *dp = NULL;
        char buf[1024] = {0, };
-       struct dirent ep, *result;
+       struct dirent *ep = NULL;
        char *abs_filename = NULL;
        struct stat stFileInfo;
 
@@ -87,17 +87,15 @@ static int __clear_dir(const char *dirname)
                goto err;
        }
 
-       for (ret = readdir_r(dp, &ep, &result);
-               ret == 0 && result != NULL;
-               ret = readdir_r(dp, &ep, &result)) {
+       while ((ep = readdir(dp)) != NULL) {
                snprintf(abs_filename, PATH_MAX - 1, "%s/%s", dirname,
-                       ep.d_name);
+                       ep->d_name);
                if (lstat(abs_filename, &stFileInfo) < 0)
                        perror(abs_filename);
 
                if (S_ISDIR(stFileInfo.st_mode)) {
-                       if (strcmp(ep.d_name, ".") &&
-                               strcmp(ep.d_name, "..")) {
+                       if (strcmp(ep->d_name, ".") &&
+                               strcmp(ep->d_name, "..")) {
                                ret = __clear_dir(abs_filename);
                                if (ret != 0)
                                        LOGE("Couldn't remove the directory. "
index 8e4dfa4075fc87c367d58fdf09d4ac3b7fd0cff8..5ef76a30ccbeb0a127644b543e3fca8622b8b205 100644 (file)
@@ -83,7 +83,7 @@ static long long __calculate_directory_size(int dfd, bool include_itself)
        int subfd;
        int ret;
        DIR *dir;
-       struct dirent dent, *result;
+       struct dirent *dent = NULL;
        const char *file_info;
        char buf[1024] = {0, };
 
@@ -104,10 +104,8 @@ static long long __calculate_directory_size(int dfd, bool include_itself)
                return -1;
        }
 
-       for (ret = readdir_r(dir, &dent, &result);
-               ret == 0 && result != NULL;
-               ret = readdir_r(dir, &dent, &result)) {
-               file_info = dent.d_name;
+       while ((dent = readdir(dir)) != NULL) {
+               file_info = dent->d_name;
                if (file_info[0] == '.') {
                        if (file_info[1] == '\0')
                                continue;
@@ -115,7 +113,7 @@ static long long __calculate_directory_size(int dfd, bool include_itself)
                                continue;
                }
 
-               if (dent.d_type == DT_DIR) {
+               if (dent->d_type == DT_DIR) {
                        subfd = openat(dfd, file_info, O_RDONLY | O_DIRECTORY);
                        if (subfd < 0) {
                                LOGE("openat() failed, file_info:%s, errno: %d(%s)",
@@ -269,7 +267,7 @@ static int __calculate_pkg_size_info(STORAGE_TYPE type, const char *pkgid,
        int subfd = -1;
        struct stat st;
        int ret;
-       struct dirent ent, *result;
+       struct dirent *dent = NULL;
        long long size = 0;
 
        if (type == STORAGE_TYPE_INTERNAL_GLOBAL_PATH) {
@@ -312,18 +310,15 @@ static int __calculate_pkg_size_info(STORAGE_TYPE type, const char *pkgid,
                goto error;
        }
        *app_size += __stat_size(&st);
-       for (ret = readdir_r(dir, &ent, &result);
-                       ret == 0 && result != NULL;
-                       ret = readdir_r(dir, &ent, &result)) {
-               const char *name = ent.d_name;
+       while ((dent = readdir(dir)) != NULL) {
+               const char *name = dent->d_name;
                if (name[0] == '.') {
-                       if (name[1] == '\0')
-                               continue;
+                       if (name[1] == '\0') continue;
                        if ((name[1] == '.') && (name[2] == '\0'))
                                continue;
                }
 
-               if (ent.d_type != DT_DIR)
+               if (dent->d_type != DT_DIR)
                        continue;
 
                subfd = openat(dfd, name, O_RDONLY | O_DIRECTORY);