summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2017-01-03 17:13:47 +0100
committerJosé Bollo <jose.bollo@iot.bzh>2017-01-03 17:13:47 +0100
commit91f3e6ecdada77d57c8d92a955776fd8fe6d402e (patch)
treeab423644494eec359783b3dd370ed6111dfc9f4d
parent295f6a51457153c04be00754836094fb116756de (diff)
Removes uses of readdir_r
Since glibc 2.24, readdir_r is deprecated. Change-Id: Id0e186e67b7e60bd537a8ba85ede446be0c5095e Signed-off-by: José Bollo <jose.bollo@iot.bzh>
-rw-r--r--src/afb-api-so.c28
-rw-r--r--src/locale-root.c20
2 files changed, 26 insertions, 22 deletions
diff --git a/src/afb-api-so.c b/src/afb-api-so.c
index 5fa3e44b..554df39a 100644
--- a/src/afb-api-so.c
+++ b/src/afb-api-so.c
@@ -22,6 +22,7 @@
#include <assert.h>
#include <string.h>
#include <dirent.h>
+#include <errno.h>
#include <dlfcn.h>
#include <unistd.h>
#include <limits.h>
@@ -350,7 +351,7 @@ error:
static int adddirs(char path[PATH_MAX], size_t end)
{
DIR *dir;
- struct dirent ent, *result;
+ struct dirent *dent;
size_t len;
/* open the DIR now */
@@ -365,29 +366,34 @@ static int adddirs(char path[PATH_MAX], size_t end)
if (end)
path[end++] = '/';
for (;;) {
- readdir_r(dir, &ent, &result);
- if (result == NULL)
+ errno = 0;
+ dent = readdir(dir);
+ if (dent == NULL) {
+ if (errno != 0)
+ ERROR("read error while scanning directory %.*s: %m", (int)(end - 1), path);
break;
+ }
- len = strlen(ent.d_name);
+ len = strlen(dent->d_name);
if (len + end >= PATH_MAX) {
- ERROR("path too long while scanning bindings for %s", ent.d_name);
+ ERROR("path too long while scanning bindings for %s", dent->d_name);
continue;
}
- memcpy(&path[end], ent.d_name, len+1);
- if (ent.d_type == DT_DIR) {
+ if (dent->d_type == DT_DIR) {
/* case of directories */
- if (ent.d_name[0] == '.') {
+ if (dent->d_name[0] == '.') {
if (len == 1)
continue;
- if (ent.d_name[1] == '.' && len == 2)
+ if (dent->d_name[1] == '.' && len == 2)
continue;
}
+ memcpy(&path[end], dent->d_name, len+1);
adddirs(path, end+len);;
- } else if (ent.d_type == DT_REG) {
+ } else if (dent->d_type == DT_REG) {
/* case of files */
- if (!strstr(ent.d_name, ".so"))
+ if (memcmp(&dent->d_name[len - 3], ".so", 4))
continue;
+ memcpy(&path[end], dent->d_name, len+1);
if (afb_api_so_add_binding(path) < 0)
return -1;
}
diff --git a/src/locale-root.c b/src/locale-root.c
index ead820b4..ee88f3f5 100644
--- a/src/locale-root.c
+++ b/src/locale-root.c
@@ -214,7 +214,7 @@ static int init_container(struct locale_container *container, int dirfd)
{
int rc, sfd;
DIR *dir;
- struct dirent dent, *e;
+ struct dirent *dent;
struct stat st;
size_t i, j;
struct locale_folder *f;
@@ -239,23 +239,21 @@ static int init_container(struct locale_container *container, int dirfd)
/* enumerate the entries */
for(;;) {
/* next entry */
- rc = readdir_r(dir, &dent, &e);
- if (rc < 0) {
- /* error */
- closedir(dir);
- return rc;
- }
- if (e == NULL) {
+ errno = 0;
+ dent = readdir(dir);
+ if (dent == NULL) {
/* end of entries */
closedir(dir);
+ if (errno != 0)
+ return -1;
break;
}
- if (dent.d_type == DT_DIR || (dent.d_type == DT_UNKNOWN && fstatat(sfd, dent.d_name, &st, 0) == 0 && S_ISDIR(st.st_mode))) {
+ if (dent->d_type == DT_DIR || (dent->d_type == DT_UNKNOWN && fstatat(sfd, dent->d_name, &st, 0) == 0 && S_ISDIR(st.st_mode))) {
/* directory aka folder */
- if (dent.d_name[0] == '.' && (dent.d_name[1] == 0 || (dent.d_name[1] == '.' && dent.d_name[2] == 0))) {
+ if (dent->d_name[0] == '.' && (dent->d_name[1] == 0 || (dent->d_name[1] == '.' && dent->d_name[2] == 0))) {
/* nothing to do for special directories, basic detection, improves if needed */
} else {
- rc = add_folder(container, dent.d_name);
+ rc = add_folder(container, dent->d_name);
if (rc < 0) {
closedir(dir);
return rc;