Replace deprecated readdir_r by readdir

This reverts 262555d5, 7fb53873 and a0b859b2
This commit is contained in:
Philippe Teuwen 2017-02-17 12:10:30 +01:00
parent 99a7d9aa35
commit ff37cdb2be
4 changed files with 18 additions and 31 deletions

View file

@ -191,29 +191,27 @@ i2c_list_ports(void)
size_t szRes = 1;
res[0] = NULL;
DIR *dir;
if ((dir = opendir("/dev")) == NULL) {
DIR *pdDir;
if ((pdDir = opendir("/dev")) == NULL) {
perror("opendir error: /dev");
return res;
}
struct dirent entry;
struct dirent *result;
while ((readdir_r(dir, &entry, &result) == 0) && (result != NULL)) {
struct dirent *pdDirEnt;
while ((pdDirEnt = readdir(pdDir)) != NULL) {
const char **p = i2c_ports_device_radix;
while (*p) {
if (!strncmp(entry.d_name, *p, strlen(*p))) {
if (!strncmp(pdDirEnt->d_name, *p, strlen(*p))) {
char **res2 = realloc(res, (szRes + 1) * sizeof(char *));
if (!res2) {
perror("malloc");
goto oom;
}
res = res2;
if (!(res[szRes - 1] = malloc(6 + strlen(entry.d_name)))) {
if (!(res[szRes - 1] = malloc(6 + strlen(pdDirEnt->d_name)))) {
perror("malloc");
goto oom;
}
sprintf(res[szRes - 1], "/dev/%s", entry.d_name);
sprintf(res[szRes - 1], "/dev/%s", pdDirEnt->d_name);
szRes++;
res[szRes - 1] = NULL;
@ -222,7 +220,7 @@ i2c_list_ports(void)
}
}
oom:
closedir(dir);
closedir(pdDir);
return res;
}

View file

@ -283,10 +283,7 @@ spi_list_ports(void)
DIR *pdDir = opendir("/dev");
struct dirent *pdDirEnt;
struct dirent entry;
struct dirent *result;
while ((readdir_r(pdDir, &entry, &result) == 0) && (result != NULL)) {
pdDirEnt = &entry;
while ((pdDirEnt = readdir(pdDir)) != NULL) {
#if !defined(__APPLE__)
if (!isdigit(pdDirEnt->d_name[strlen(pdDirEnt->d_name) - 1]))
continue;

View file

@ -394,32 +394,31 @@ uart_list_ports(void)
size_t szRes = 1;
res[0] = NULL;
DIR *dir;
if ((dir = opendir("/dev")) == NULL) {
DIR *pdDir;
if ((pdDir = opendir("/dev")) == NULL) {
perror("opendir error: /dev");
return res;
}
struct dirent entry;
struct dirent *result;
while ((readdir_r(dir, &entry, &result) == 0) && (result != NULL)) {
struct dirent *pdDirEnt;
while ((pdDirEnt = readdir(pdDir)) != NULL) {
#if !defined(__APPLE__)
if (!isdigit(entry.d_name[strlen(entry.d_name) - 1]))
if (!isdigit(pdDirEnt->d_name[strlen(pdDirEnt->d_name) - 1]))
continue;
#endif
const char **p = serial_ports_device_radix;
while (*p) {
if (!strncmp(entry.d_name, *p, strlen(*p))) {
if (!strncmp(pdDirEnt->d_name, *p, strlen(*p))) {
char **res2 = realloc(res, (szRes + 1) * sizeof(char *));
if (!res2) {
perror("malloc");
goto oom;
}
res = res2;
if (!(res[szRes - 1] = malloc(6 + strlen(entry.d_name)))) {
if (!(res[szRes - 1] = malloc(6 + strlen(pdDirEnt->d_name)))) {
perror("malloc");
goto oom;
}
sprintf(res[szRes - 1], "/dev/%s", entry.d_name);
sprintf(res[szRes - 1], "/dev/%s", pdDirEnt->d_name);
szRes++;
res[szRes - 1] = NULL;
@ -428,7 +427,7 @@ uart_list_ports(void)
}
}
oom:
closedir(dir);
closedir(pdDir);
return res;
}

View file

@ -265,14 +265,7 @@ conf_devices_load(const char *dirname, nfc_context *context)
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "Unable to open directory: %s", dirname);
} else {
struct dirent *de;
#ifdef WIN32
while ((de = readdir(d)) != NULL) {
#else
struct dirent entry;
struct dirent *result;
while ((readdir_r(d, &entry, &result) == 0) && (result != NULL)) {
de = &entry;
#endif
// FIXME add a way to sort devices
if (de->d_name[0] != '.') {
const size_t filename_len = strlen(de->d_name);