From: Bert Vermeulen Date: Thu, 19 Jan 2012 16:12:02 +0000 (+0100) Subject: srd: fix decoder loading, and back to using glib dirent wrappers X-Git-Tag: libsigrokdecode-0.1.0~120 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=eb2bbd668758f00afccda9a04690e84b56cc99b1;p=libsigrokdecode.git srd: fix decoder loading, and back to using glib dirent wrappers --- 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 +#include /* 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; }