diff --git a/libnfc/buses/i2c.c b/libnfc/buses/i2c.c index a37372d..dc1ad1f 100644 --- a/libnfc/buses/i2c.c +++ b/libnfc/buses/i2c.c @@ -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; } diff --git a/libnfc/buses/spi.c b/libnfc/buses/spi.c index b81c92b..3d29fd3 100644 --- a/libnfc/buses/spi.c +++ b/libnfc/buses/spi.c @@ -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; diff --git a/libnfc/buses/uart.c b/libnfc/buses/uart.c index b9b6121..61ad87d 100644 --- a/libnfc/buses/uart.c +++ b/libnfc/buses/uart.c @@ -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; } diff --git a/libnfc/conf.c b/libnfc/conf.c index 981e272..590ca6e 100644 --- a/libnfc/conf.c +++ b/libnfc/conf.c @@ -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);