You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@celix.apache.org by pn...@apache.org on 2017/01/16 11:29:43 UTC
celix git commit: CELIX-392: Using readdir instead of the now
deprecated readdir_r
Repository: celix
Updated Branches:
refs/heads/develop 14c863583 -> 15935d7fb
CELIX-392: Using readdir instead of the now deprecated readdir_r
Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/15935d7f
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/15935d7f
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/15935d7f
Branch: refs/heads/develop
Commit: 15935d7fbb59636c84c239e4990c084fee464af4
Parents: 14c8635
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Mon Jan 16 12:27:20 2017 +0100
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Mon Jan 16 12:29:28 2017 +0100
----------------------------------------------------------------------
deployment_admin/private/src/deployment_admin.c | 30 ++++++-------
framework/private/src/bundle_archive.c | 41 +++++++++---------
framework/private/src/bundle_cache.c | 45 +++++++++++---------
3 files changed, 59 insertions(+), 57 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/15935d7f/deployment_admin/private/src/deployment_admin.c
----------------------------------------------------------------------
diff --git a/deployment_admin/private/src/deployment_admin.c b/deployment_admin/private/src/deployment_admin.c
index 6c8c505..17e78db 100644
--- a/deployment_admin/private/src/deployment_admin.c
+++ b/deployment_admin/private/src/deployment_admin.c
@@ -505,15 +505,16 @@ static celix_status_t deploymentAdmin_deleteTree(char * directory) {
status = CELIX_FILE_IO_EXCEPTION;
} else {
- struct dirent dp;
- struct dirent *result = NULL;
- int rc = readdir_r(dir, &dp, &result);
- while (rc == 0 && result != NULL) {
- if ((strcmp((dp.d_name), ".") != 0) && (strcmp((dp.d_name), "..") != 0)) {
+ struct dirent* dent = NULL;
+
+ errno = 0;
+ dent = readdir(dir);
+ while (errno == 0 && dent != NULL) {
+ if ((strcmp((dent->d_name), ".") != 0) && (strcmp((dent->d_name), "..") != 0)) {
char subdir[512];
- snprintf(subdir, sizeof(subdir), "%s/%s", directory, dp.d_name);
+ snprintf(subdir, sizeof(subdir), "%s/%s", directory, dent->d_name);
- if (dp.d_type == DT_DIR) {
+ if (dent->d_type == DT_DIR) {
status = deploymentAdmin_deleteTree(subdir);
} else {
if (remove(subdir) != 0) {
@@ -522,20 +523,17 @@ static celix_status_t deploymentAdmin_deleteTree(char * directory) {
}
}
}
- rc = readdir_r(dir, &dp, &result);
- }
- if (rc != 0) {
- status = CELIX_FILE_IO_EXCEPTION;
+ errno = 0;
+ dent = readdir(dir);
}
- if (closedir(dir) != 0) {
+ if (errno != 0) {
status = CELIX_FILE_IO_EXCEPTION;
- }
- if (status == CELIX_SUCCESS) {
- if (rmdir(directory) != 0) {
+ } else if (closedir(dir) != 0) {
+ status = CELIX_FILE_IO_EXCEPTION;
+ } else if (rmdir(directory) != 0) {
status = CELIX_FILE_IO_EXCEPTION;
- }
}
}
http://git-wip-us.apache.org/repos/asf/celix/blob/15935d7f/framework/private/src/bundle_archive.c
----------------------------------------------------------------------
diff --git a/framework/private/src/bundle_archive.c b/framework/private/src/bundle_archive.c
index 3d0513d..266d970 100644
--- a/framework/private/src/bundle_archive.c
+++ b/framework/private/src/bundle_archive.c
@@ -202,23 +202,23 @@ celix_status_t bundleArchive_recreate(const char * archiveRoot, bundle_archive_p
long highestId = -1;
char *location = NULL;
- struct dirent dent;
- struct dirent *result = NULL;
+ struct dirent *dent = NULL;
struct stat st;
- int rc;
- rc = readdir_r(archive->archiveRootDir, &dent, &result);
- while (rc == 0 && result != NULL) {
+ errno = 0;
+ dent = readdir(archive->archiveRootDir);
+ while (errno == 0 && dent != NULL) {
char subdir[512];
- snprintf(subdir, 512, "%s/%s", archiveRoot, dent.d_name);
+ snprintf(subdir, 512, "%s/%s", archiveRoot, dent->d_name);
int rv = stat(subdir, &st);
- if (rv == 0 && S_ISDIR(st.st_mode) && (strncmp(dent.d_name, "version", 7) == 0)) {
- sscanf(dent.d_name, "version%*d.%ld", &idx);
+ if (rv == 0 && S_ISDIR(st.st_mode) && (strncmp(dent->d_name, "version", 7) == 0)) {
+ sscanf(dent->d_name, "version%*d.%ld", &idx);
if (idx > highestId) {
highestId = idx;
}
}
- rc = readdir_r(archive->archiveRootDir, &dent, &result);
+ errno = 0;
+ dent = readdir(archive->archiveRootDir);
}
status = CELIX_DO_IF(status, bundleArchive_getRevisionLocation(archive, 0, &location));
@@ -751,15 +751,14 @@ static celix_status_t bundleArchive_deleteTree(bundle_archive_pt archive, const
status = CELIX_FILE_IO_EXCEPTION;
} else {
- struct dirent dp;
- struct dirent *result = NULL;
- int rc = 0;
+ struct dirent* dent = NULL;
- rc = readdir_r(dir, &dp, &result);
- while (rc == 0 && result != NULL) {
- if ((strcmp((dp.d_name), ".") != 0) && (strcmp((dp.d_name), "..") != 0)) {
+ errno = 0;
+ dent = readdir(dir);
+ while (errno == 0 && dent != NULL) {
+ if ((strcmp((dent->d_name), ".") != 0) && (strcmp((dent->d_name), "..") != 0)) {
char subdir[512];
- snprintf(subdir, 512, "%s/%s", directory, dp.d_name);
+ snprintf(subdir, 512, "%s/%s", directory, dent->d_name);
struct stat st;
if (stat(subdir, &st) == 0) {
@@ -773,13 +772,15 @@ static celix_status_t bundleArchive_deleteTree(bundle_archive_pt archive, const
}
}
}
- rc = readdir_r(dir, &dp, &result);
+ errno = 0;
+ dent = readdir(dir);
}
- if (closedir(dir) != 0) {
+ if (errno != 0) {
+ status = CELIX_FILE_IO_EXCEPTION;
+ } else if (closedir(dir) != 0) {
status = CELIX_FILE_IO_EXCEPTION;
- }
- if (status == CELIX_SUCCESS) {
+ } else if (status == CELIX_SUCCESS) {
if (rmdir(directory) != 0) {
status = CELIX_FILE_IO_EXCEPTION;
}
http://git-wip-us.apache.org/repos/asf/celix/blob/15935d7f/framework/private/src/bundle_cache.c
----------------------------------------------------------------------
diff --git a/framework/private/src/bundle_cache.c b/framework/private/src/bundle_cache.c
index 1572bc0..39875b5 100644
--- a/framework/private/src/bundle_cache.c
+++ b/framework/private/src/bundle_cache.c
@@ -95,22 +95,21 @@ celix_status_t bundleCache_getArchives(bundle_cache_pt cache, array_list_pt *arc
array_list_pt list = NULL;
arrayList_create(&list);
- struct dirent dp;
- struct dirent *result = NULL;
- int rc = 0;
+ struct dirent* dent = NULL;
- rc = readdir_r(dir, &dp, &result);
- while (rc == 0 && result != NULL) {
+ errno = 0;
+ dent = readdir(dir);
+ while (errno == 0 && dent != NULL) {
char archiveRoot[512];
- snprintf(archiveRoot, sizeof(archiveRoot), "%s/%s", cache->cacheDir, dp.d_name);
+ snprintf(archiveRoot, sizeof(archiveRoot), "%s/%s", cache->cacheDir, dent->d_name);
if (stat (archiveRoot, &st) == 0) {
if (S_ISDIR (st.st_mode)
- && (strcmp((dp.d_name), ".") != 0)
- && (strcmp((dp.d_name), "..") != 0)
- && (strncmp(dp.d_name, "bundle", 6) == 0)
- && (strcmp(dp.d_name, "bundle0") != 0)) {
+ && (strcmp((dent->d_name), ".") != 0)
+ && (strcmp((dent->d_name), "..") != 0)
+ && (strncmp(dent->d_name, "bundle", 6) == 0)
+ && (strcmp(dent->d_name, "bundle0") != 0)) {
bundle_archive_pt archive = NULL;
status = bundleArchive_recreate(archiveRoot, &archive);
@@ -120,10 +119,11 @@ celix_status_t bundleCache_getArchives(bundle_cache_pt cache, array_list_pt *arc
}
}
- rc = readdir_r(dir, &dp, &result);
+ errno = 0;
+ dent = readdir(dir);
}
- if (rc != 0) {
+ if (errno != 0) {
fw_log(logger, OSGI_FRAMEWORK_LOG_ERROR, "Error reading dir");
status = CELIX_FILE_IO_EXCEPTION;
} else {
@@ -172,18 +172,17 @@ static celix_status_t bundleCache_deleteTree(bundle_cache_pt cache, char * direc
celix_status_t status = CELIX_SUCCESS;
struct stat st;
+ errno = 0;
dir = opendir(directory);
if (dir == NULL) {
status = CELIX_FILE_IO_EXCEPTION;
} else {
- struct dirent dp;
- struct dirent *result = NULL;
- int rc = 0;
- rc = readdir_r(dir, &dp, &result);
- while (rc == 0 && result != NULL) {
- if ((strcmp((dp.d_name), ".") != 0) && (strcmp((dp.d_name), "..") != 0)) {
+ struct dirent* dent = NULL;
+ dent = readdir(dir);
+ while (errno == 0 && dent != NULL) {
+ if ((strcmp((dent->d_name), ".") != 0) && (strcmp((dent->d_name), "..") != 0)) {
char subdir[512];
- snprintf(subdir, sizeof(subdir), "%s/%s", directory, dp.d_name);
+ snprintf(subdir, sizeof(subdir), "%s/%s", directory, dent->d_name);
if (stat(subdir, &st) == 0) {
if (S_ISDIR (st.st_mode)) {
@@ -196,10 +195,14 @@ static celix_status_t bundleCache_deleteTree(bundle_cache_pt cache, char * direc
}
}
}
- rc = readdir_r(dir, &dp, &result);
+ errno = 0;
+ dent = readdir(dir);
}
- if (closedir(dir) != 0) {
+ if (errno != 0) {
+ status = CELIX_FILE_IO_EXCEPTION;
+ }
+ else if (closedir(dir) != 0) {
status = CELIX_FILE_IO_EXCEPTION;
}
if (status == CELIX_SUCCESS) {