Replace deprecated readdir_r by readdir
This reverts262555d5
,7fb53873
anda0b859b2
This commit is contained in:
parent
99a7d9aa35
commit
ff37cdb2be
4 changed files with 18 additions and 31 deletions
|
@ -191,29 +191,27 @@ i2c_list_ports(void)
|
||||||
size_t szRes = 1;
|
size_t szRes = 1;
|
||||||
|
|
||||||
res[0] = NULL;
|
res[0] = NULL;
|
||||||
DIR *dir;
|
DIR *pdDir;
|
||||||
if ((dir = opendir("/dev")) == NULL) {
|
if ((pdDir = opendir("/dev")) == NULL) {
|
||||||
perror("opendir error: /dev");
|
perror("opendir error: /dev");
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
struct dirent entry;
|
struct dirent *pdDirEnt;
|
||||||
struct dirent *result;
|
while ((pdDirEnt = readdir(pdDir)) != NULL) {
|
||||||
|
|
||||||
while ((readdir_r(dir, &entry, &result) == 0) && (result != NULL)) {
|
|
||||||
const char **p = i2c_ports_device_radix;
|
const char **p = i2c_ports_device_radix;
|
||||||
while (*p) {
|
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 *));
|
char **res2 = realloc(res, (szRes + 1) * sizeof(char *));
|
||||||
if (!res2) {
|
if (!res2) {
|
||||||
perror("malloc");
|
perror("malloc");
|
||||||
goto oom;
|
goto oom;
|
||||||
}
|
}
|
||||||
res = res2;
|
res = res2;
|
||||||
if (!(res[szRes - 1] = malloc(6 + strlen(entry.d_name)))) {
|
if (!(res[szRes - 1] = malloc(6 + strlen(pdDirEnt->d_name)))) {
|
||||||
perror("malloc");
|
perror("malloc");
|
||||||
goto oom;
|
goto oom;
|
||||||
}
|
}
|
||||||
sprintf(res[szRes - 1], "/dev/%s", entry.d_name);
|
sprintf(res[szRes - 1], "/dev/%s", pdDirEnt->d_name);
|
||||||
|
|
||||||
szRes++;
|
szRes++;
|
||||||
res[szRes - 1] = NULL;
|
res[szRes - 1] = NULL;
|
||||||
|
@ -222,7 +220,7 @@ i2c_list_ports(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
oom:
|
oom:
|
||||||
closedir(dir);
|
closedir(pdDir);
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
|
@ -283,10 +283,7 @@ spi_list_ports(void)
|
||||||
|
|
||||||
DIR *pdDir = opendir("/dev");
|
DIR *pdDir = opendir("/dev");
|
||||||
struct dirent *pdDirEnt;
|
struct dirent *pdDirEnt;
|
||||||
struct dirent entry;
|
while ((pdDirEnt = readdir(pdDir)) != NULL) {
|
||||||
struct dirent *result;
|
|
||||||
while ((readdir_r(pdDir, &entry, &result) == 0) && (result != NULL)) {
|
|
||||||
pdDirEnt = &entry;
|
|
||||||
#if !defined(__APPLE__)
|
#if !defined(__APPLE__)
|
||||||
if (!isdigit(pdDirEnt->d_name[strlen(pdDirEnt->d_name) - 1]))
|
if (!isdigit(pdDirEnt->d_name[strlen(pdDirEnt->d_name) - 1]))
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -394,32 +394,31 @@ uart_list_ports(void)
|
||||||
size_t szRes = 1;
|
size_t szRes = 1;
|
||||||
|
|
||||||
res[0] = NULL;
|
res[0] = NULL;
|
||||||
DIR *dir;
|
DIR *pdDir;
|
||||||
if ((dir = opendir("/dev")) == NULL) {
|
if ((pdDir = opendir("/dev")) == NULL) {
|
||||||
perror("opendir error: /dev");
|
perror("opendir error: /dev");
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
struct dirent entry;
|
struct dirent *pdDirEnt;
|
||||||
struct dirent *result;
|
while ((pdDirEnt = readdir(pdDir)) != NULL) {
|
||||||
while ((readdir_r(dir, &entry, &result) == 0) && (result != NULL)) {
|
|
||||||
#if !defined(__APPLE__)
|
#if !defined(__APPLE__)
|
||||||
if (!isdigit(entry.d_name[strlen(entry.d_name) - 1]))
|
if (!isdigit(pdDirEnt->d_name[strlen(pdDirEnt->d_name) - 1]))
|
||||||
continue;
|
continue;
|
||||||
#endif
|
#endif
|
||||||
const char **p = serial_ports_device_radix;
|
const char **p = serial_ports_device_radix;
|
||||||
while (*p) {
|
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 *));
|
char **res2 = realloc(res, (szRes + 1) * sizeof(char *));
|
||||||
if (!res2) {
|
if (!res2) {
|
||||||
perror("malloc");
|
perror("malloc");
|
||||||
goto oom;
|
goto oom;
|
||||||
}
|
}
|
||||||
res = res2;
|
res = res2;
|
||||||
if (!(res[szRes - 1] = malloc(6 + strlen(entry.d_name)))) {
|
if (!(res[szRes - 1] = malloc(6 + strlen(pdDirEnt->d_name)))) {
|
||||||
perror("malloc");
|
perror("malloc");
|
||||||
goto oom;
|
goto oom;
|
||||||
}
|
}
|
||||||
sprintf(res[szRes - 1], "/dev/%s", entry.d_name);
|
sprintf(res[szRes - 1], "/dev/%s", pdDirEnt->d_name);
|
||||||
|
|
||||||
szRes++;
|
szRes++;
|
||||||
res[szRes - 1] = NULL;
|
res[szRes - 1] = NULL;
|
||||||
|
@ -428,7 +427,7 @@ uart_list_ports(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
oom:
|
oom:
|
||||||
closedir(dir);
|
closedir(pdDir);
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "Unable to open directory: %s", dirname);
|
||||||
} else {
|
} else {
|
||||||
struct dirent *de;
|
struct dirent *de;
|
||||||
#ifdef WIN32
|
|
||||||
while ((de = readdir(d)) != NULL) {
|
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
|
// FIXME add a way to sort devices
|
||||||
if (de->d_name[0] != '.') {
|
if (de->d_name[0] != '.') {
|
||||||
const size_t filename_len = strlen(de->d_name);
|
const size_t filename_len = strlen(de->d_name);
|
||||||
|
|
Loading…
Reference in a new issue