rlenferink closed pull request #22: migrated readdir_r (deprecated) to readdir.
URL: https://github.com/apache/celix/pull/22
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/deployment_admin/private/src/deployment_admin.c
b/deployment_admin/private/src/deployment_admin.c
index 6c8c505e..f7c1edd4 100644
--- a/deployment_admin/private/src/deployment_admin.c
+++ b/deployment_admin/private/src/deployment_admin.c
@@ -505,15 +505,15 @@ 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 *dp;
+ errno = 0;
+ dp = readdir(dir);
+ while (dp != NULL) {
+ if ((strcmp((dp->d_name), ".") != 0) &&
(strcmp((dp->d_name), "..") != 0)) {
char subdir[512];
- snprintf(subdir, sizeof(subdir), "%s/%s",
directory, dp.d_name);
+ snprintf(subdir, sizeof(subdir), "%s/%s",
directory, dp->d_name);
- if (dp.d_type == DT_DIR) {
+ if (dp->d_type == DT_DIR) {
status =
deploymentAdmin_deleteTree(subdir);
} else {
if (remove(subdir) != 0) {
@@ -522,10 +522,11 @@ static celix_status_t deploymentAdmin_deleteTree(char *
directory) {
}
}
}
- rc = readdir_r(dir, &dp, &result);
+ errno = 0;
+ dp = readdir(dir);
}
- if (rc != 0) {
+ if (errno != 0) {
status = CELIX_FILE_IO_EXCEPTION;
}
diff --git a/framework/private/src/bundle_archive.c
b/framework/private/src/bundle_archive.c
index 3d0513db..6f128d30 100644
--- a/framework/private/src/bundle_archive.c
+++ b/framework/private/src/bundle_archive.c
@@ -202,23 +202,21 @@ 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;
struct stat st;
- int rc;
- rc = readdir_r(archive->archiveRootDir, &dent,
&result);
- while (rc == 0 && result != NULL) {
+ dent = readdir(archive->archiveRootDir);
+ while (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);
+ dent = readdir(archive->archiveRootDir);
}
status = CELIX_DO_IF(status,
bundleArchive_getRevisionLocation(archive, 0, &location));
@@ -751,15 +749,13 @@ 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 *dp;
- rc = readdir_r(dir, &dp, &result);
- while (rc == 0 && result != NULL) {
- if ((strcmp((dp.d_name), ".") != 0) &&
(strcmp((dp.d_name), "..") != 0)) {
+ dp = readdir(dir);
+ while (dp != NULL) {
+ if ((strcmp((dp->d_name), ".") != 0) &&
(strcmp((dp->d_name), "..") != 0)) {
char subdir[512];
- snprintf(subdir, 512, "%s/%s", directory,
dp.d_name);
+ snprintf(subdir, 512, "%s/%s", directory,
dp->d_name);
struct stat st;
if (stat(subdir, &st) == 0) {
@@ -773,7 +769,7 @@ static celix_status_t
bundleArchive_deleteTree(bundle_archive_pt archive, const
}
}
}
- rc = readdir_r(dir, &dp, &result);
+ dp = readdir(dir);
}
if (closedir(dir) != 0) {
diff --git a/framework/private/src/bundle_cache.c
b/framework/private/src/bundle_cache.c
index 1572bc0b..d08cf5df 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 *dp;
- rc = readdir_r(dir, &dp, &result);
- while (rc == 0 && result != NULL) {
+ errno = 0;
+ dp = readdir(dir);
+ while (dp != NULL) {
char archiveRoot[512];
- snprintf(archiveRoot, sizeof(archiveRoot), "%s/%s",
cache->cacheDir, dp.d_name);
+ snprintf(archiveRoot, sizeof(archiveRoot), "%s/%s",
cache->cacheDir, dp->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((dp->d_name), ".")
!= 0)
+ && (strcmp((dp->d_name), "..")
!= 0)
+ && (strncmp(dp->d_name,
"bundle", 6) == 0)
+ && (strcmp(dp->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;
+ dp = readdir(dir);
}
- if (rc != 0) {
+ if (errno != 0) {
fw_log(logger, OSGI_FRAMEWORK_LOG_ERROR, "Error reading
dir");
status = CELIX_FILE_IO_EXCEPTION;
} else {
@@ -176,14 +176,12 @@ static celix_status_t
bundleCache_deleteTree(bundle_cache_pt cache, char * direc
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 *dp;
+ dp = readdir(dir);
+ while (dp != NULL) {
+ if ((strcmp((dp->d_name), ".") != 0) &&
(strcmp((dp->d_name), "..") != 0)) {
char subdir[512];
- snprintf(subdir, sizeof(subdir), "%s/%s",
directory, dp.d_name);
+ snprintf(subdir, sizeof(subdir), "%s/%s",
directory, dp->d_name);
if (stat(subdir, &st) == 0) {
if (S_ISDIR (st.st_mode)) {
@@ -196,7 +194,7 @@ static celix_status_t
bundleCache_deleteTree(bundle_cache_pt cache, char * direc
}
}
}
- rc = readdir_r(dir, &dp, &result);
+ dp = readdir(dir);
}
if (closedir(dir) != 0) {
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services