summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBert Vermeulen <bert@biot.com>2012-01-19 17:12:02 +0100
committerBert Vermeulen <bert@biot.com>2012-01-19 17:12:02 +0100
commiteb2bbd668758f00afccda9a04690e84b56cc99b1 (patch)
tree360c87bf92301eb23a4f02c99ffc584fef220064
parent1d552cd37d050b346adccdcd61e1ee695d5a6d52 (diff)
downloadlibsigrokdecode-eb2bbd668758f00afccda9a04690e84b56cc99b1.tar.gz
libsigrokdecode-eb2bbd668758f00afccda9a04690e84b56cc99b1.zip
srd: fix decoder loading, and back to using glib dirent wrappers
-rw-r--r--decoder.c22
1 files changed, 9 insertions, 13 deletions
diff --git a/decoder.c b/decoder.c
index 7dd1e96..6651642 100644
--- a/decoder.c
+++ b/decoder.c
@@ -21,7 +21,7 @@
#include "config.h"
#include "sigrokdecode.h" /* First, so we avoid a _POSIX_C_SOURCE warning. */
#include "sigrokdecode-internal.h"
-#include <dirent.h>
+#include <glib.h>
/* The list of protocol decoders. */
GSList *pd_list = NULL;
@@ -262,24 +262,20 @@ int srd_unload_decoder(struct srd_decoder *dec)
int srd_load_all_decoders(void)
{
- DIR *dir;
- struct dirent *dp;
+ GDir *dir;
+ GError *error;
+ struct srd_decoder *dec;
int ret;
+ const gchar *direntry;
char *decodername;
- struct srd_decoder *dec;
- if (!(dir = opendir(DECODERS_DIR))) {
- Py_Finalize(); /* Returns void. */
+ if (!(dir = g_dir_open(DECODERS_DIR, 0, &error))) {
return SRD_ERR_DECODERS_DIR;
}
- while ((dp = readdir(dir)) != NULL) {
- /* Ignore filenames which don't end with ".py". */
- if (!g_str_has_suffix(dp->d_name, ".py"))
- continue;
-
+ while ((direntry = g_dir_read_name(dir)) != NULL) {
/* The decoder name is the PD directory name (e.g. "i2c"). */
- decodername = g_strndup(dp->d_name, strlen(dp->d_name) - 3);
+ decodername = g_strdup(direntry);
/* TODO: Error handling. Use g_try_malloc(). */
if (!(dec = malloc(sizeof(struct srd_decoder)))) {
@@ -294,7 +290,7 @@ int srd_load_all_decoders(void)
pd_list = g_slist_append(pd_list, dec);
}
}
- closedir(dir);
+ g_dir_close(dir);
return SRD_OK;
}