From 3cd8556c542721f41b63d1978d75ce8891f27908 Mon Sep 17 00:00:00 2001 From: TingPing Date: Wed, 4 Jun 2014 13:56:33 -0400 Subject: Use GDir instead of dirent --- src/common/util.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/common/util.c b/src/common/util.c index 2dc0034b..167f8b81 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -34,13 +34,11 @@ #include #include #include -#include "../dirent/dirent-win32.h" #else #include #include #include #include -#include #endif #include "../../config.h" @@ -934,27 +932,26 @@ break_while: void for_files (char *dirname, char *mask, void callback (char *file)) { - DIR *dir; - struct dirent *ent; + GDir *dir; + const gchar *entry_name; char *buf; - dir = opendir (dirname); + dir = g_dir_open (dirname, 0, NULL); if (dir) { - while ((ent = readdir (dir))) + while ((entry_name = g_dir_read_name (dir))) { - if (strcmp (ent->d_name, ".") && strcmp (ent->d_name, "..")) + if (strcmp (entry_name, ".") && strcmp (entry_name, "..")) { - if (match (mask, ent->d_name)) + if (match (mask, entry_name)) { - buf = malloc (strlen (dirname) + strlen (ent->d_name) + 2); - sprintf (buf, "%s" G_DIR_SEPARATOR_S "%s", dirname, ent->d_name); + buf = g_build_filename (dirname, entry_name, NULL); callback (buf); - free (buf); + g_free (buf); } } } - closedir (dir); + g_dir_close (dir); } } -- cgit 1.4.1