summaryrefslogtreecommitdiff
path: root/libwindow-settings/mate-wm-manager.c
diff options
context:
space:
mode:
authorrbuj <[email protected]>2020-11-25 16:42:07 +0100
committerVictor Kareh <[email protected]>2020-12-11 10:40:04 -0500
commitde6b879a003afaa1201cc6f0c1cfa278d754fa87 (patch)
tree1c7e8d5e99341c36b3ed116327defaf4c6feb6eb /libwindow-settings/mate-wm-manager.c
parent69c70e1d2279f835901a144acc87a50147bcf927 (diff)
downloadmate-control-center-de6b879a003afaa1201cc6f0c1cfa278d754fa87.tar.bz2
mate-control-center-de6b879a003afaa1201cc6f0c1cfa278d754fa87.tar.xz
mate-wm-manager: do not use dirent.h
Diffstat (limited to 'libwindow-settings/mate-wm-manager.c')
-rw-r--r--libwindow-settings/mate-wm-manager.c46
1 files changed, 30 insertions, 16 deletions
diff --git a/libwindow-settings/mate-wm-manager.c b/libwindow-settings/mate-wm-manager.c
index ce622b04..096f9009 100644
--- a/libwindow-settings/mate-wm-manager.c
+++ b/libwindow-settings/mate-wm-manager.c
@@ -32,9 +32,6 @@
#include <glib/gi18n.h>
#include <gdk/gdk.h>
#include <gdk/gdkx.h>
-
-#include <sys/types.h>
-#include <dirent.h>
#include <string.h>
typedef struct {
@@ -73,29 +70,46 @@ wm_free (AvailableWindowManager *wm)
static GList *
list_desktop_files_in_dir (const gchar *directory)
{
- DIR *dir;
- struct dirent *child;
- GList *result = NULL;
- gchar *suffix;
-
- if ((dir = opendir (directory)) == NULL)
+ GDir *dir;
+ GList *result = NULL;
+ const gchar *suffix;
+ const gchar *name;
+ const char* const ext = ".desktop";
+ size_t ext_len;
+ GError *error = NULL;
+
+ dir = g_dir_open (directory, 0, &error);
+
+ if (error) {
+ g_debug ("Could not read the folder content: %s",
+ error->message);
+ g_error_free (error);
return NULL;
+ }
- while ((child = readdir (dir)) != NULL) {
+ ext_len = strlen (ext);
+
+ while ((name = g_dir_read_name (dir)) != NULL) {
/* Ignore files without .desktop suffix, and ignore
* .desktop files with no prefix
*/
- suffix = child->d_name + strlen (child->d_name) - 8;
- /* strlen(".desktop") == 8 */
+ size_t name_len;
+
+ name_len = strlen (name);
- if (suffix <= child->d_name ||
- strcmp (suffix, ".desktop") != 0)
+ if (name_len <= ext_len)
+ continue;
+
+ suffix = name + name_len - ext_len;
+
+ if (strcmp (suffix, ext) != 0)
continue;
result = g_list_prepend (result,
- g_build_filename (directory, child->d_name, NULL));
+ g_build_filename (directory, name, NULL));
}
- closedir (dir);
+
+ g_dir_close (dir);
return result;
}