summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog8
-rw-r--r--plugins/pychrysa/pychrysa.c30
-rw-r--r--src/common/xdg.c16
3 files changed, 43 insertions, 11 deletions
diff --git a/ChangeLog b/ChangeLog
index d11ea68..e11a601 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+17-07-28 Cyrille Bagard <nocbos@gmail.com>
+
+ * plugins/pychrysa/pychrysa.c:
+ Replace the deprecated readdir_r() function by readdir() calls.
+
+ * src/common/xdg.c:
+ Set and check errno when using readdir().
+
17-07-27 Cyrille Bagard <nocbos@gmail.com>
* plugins/pychrysa/arch/instruction.c:
diff --git a/plugins/pychrysa/pychrysa.c b/plugins/pychrysa/pychrysa.c
index f09c234..f959671 100644
--- a/plugins/pychrysa/pychrysa.c
+++ b/plugins/pychrysa/pychrysa.c
@@ -24,6 +24,7 @@
#include "pychrysa.h"
+#include <errno.h>
#include <pygobject.h>
#include <stdio.h>
#include <stdbool.h>
@@ -485,9 +486,7 @@ static bool load_python_plugins(GPluginModule *plugin, GObject *ref)
char *save; /* Sauvegarde pour ré-entrance */
char *path; /* Chemin à fouiller */
DIR *dir; /* Répertoire à parcourir */
- struct dirent entry; /* Elément trouvé */
- struct dirent *next; /* Prochain élément fourni */
- int ret; /* Bilan d'un appel système */
+ struct dirent *entry; /* Elément trouvé */
char *modname; /* Nom du module pour Python */
char *filename; /* Chemin d'accès reconstruit */
GPluginModule *pyplugin; /* Lien vers un grffon Python */
@@ -511,20 +510,31 @@ static bool load_python_plugins(GPluginModule *plugin, GObject *ref)
_("Looking for Python plugins in '%s'..."),
path);
- for (ret = readdir_r(dir, &entry, &next);
- ret == 0 && next != NULL;
- ret = readdir_r(dir, &entry, &next))
+ while (1)
{
- if (entry.d_type != DT_DIR) continue;
- if (entry.d_name[0] == '.') continue;
+ errno = 0;
- modname = strdup(entry.d_name);
+ entry = readdir(dir);
+
+ if (entry == NULL)
+ {
+ if (errno != 0)
+ perror("readdir");
+
+ break;
+
+ }
+
+ if (entry->d_type != DT_DIR) continue;
+ if (entry->d_name[0] == '.') continue;
+
+ modname = strdup(entry->d_name);
modname = stradd(modname, ".");
modname = stradd(modname, "__init__");
filename = strdup(path);
filename = stradd(filename, G_DIR_SEPARATOR_S);
- filename = stradd(filename, entry.d_name);
+ filename = stradd(filename, entry->d_name);
pyplugin = g_python_plugin_new(modname, filename, ref);
diff --git a/src/common/xdg.c b/src/common/xdg.c
index 5430743..8b7ff5d 100644
--- a/src/common/xdg.c
+++ b/src/common/xdg.c
@@ -25,6 +25,7 @@
#include <dirent.h>
+#include <errno.h>
#include <glib.h>
#include <malloc.h>
#include <stdlib.h>
@@ -60,8 +61,21 @@ char *get_xdg_config_dir(const char *suffix)
directory = opendir(env);
if (directory == NULL) goto default_cfg_dir;
- for (entry = readdir(directory); entry != NULL && result == NULL; entry = readdir(directory))
+ while (1)
{
+ errno = 0;
+
+ entry = readdir(directory);
+
+ if (entry == NULL)
+ {
+ if (errno != 0)
+ perror("readdir");
+
+ break;
+
+ }
+
if (strcmp(entry->d_name, ".") == 0) continue;
if (strcmp(entry->d_name, "..") == 0) continue;