Skip to content

Commit ee9a2b4

Browse files
committed
Use stat stat()+S_ISDIR() instead of dirent->d_type
Reading readdir(3) is looks like dirent->d_type's DT_DIR is not supported on all systems. Relates to issue #12
1 parent da7d710 commit ee9a2b4

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

find-themes.c

+13-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#define _POSIX_C_SOURCE 200809L
2-
#define _DEFAULT_SOURCE
32
#include <assert.h>
43
#include <dirent.h>
54
#include <stdint.h>
65
#include <stdio.h>
76
#include <stdlib.h>
87
#include <string.h>
8+
#include <strings.h>
99
#include <sys/stat.h>
1010
#include <unistd.h>
1111
#include "tweaks.h"
@@ -23,6 +23,15 @@ grow_vector_by_one_theme(struct themes *themes)
2323
return theme;
2424
}
2525

26+
static bool
27+
isdir(const char *path, const char *dirname)
28+
{
29+
char buf[4096];
30+
snprintf(buf, sizeof(buf), "%s/%s", path, dirname);
31+
struct stat st;
32+
return (!stat(buf, &st) && S_ISDIR(st.st_mode));
33+
}
34+
2635
/**
2736
* add_theme_if_icon_theme - add theme iff it is a proper icon theme
2837
* @themes: vector
@@ -42,7 +51,7 @@ add_theme_if_icon_theme(struct themes *themes, const char *path)
4251
return;
4352
}
4453
while ((entry = readdir(dp))) {
45-
if (entry->d_type != DT_DIR || entry->d_name[0] == '.') {
54+
if (entry->d_name[0] == '.' || !isdir(path, entry->d_name)) {
4655
continue;
4756
}
4857

@@ -66,7 +75,7 @@ add_theme_if_icon_theme(struct themes *themes, const char *path)
6675
* This could be "scalable", "22x22", or whatever...
6776
*/
6877
while ((sub_entry = readdir(sub_dp))) {
69-
if (sub_entry->d_type != DT_DIR || sub_entry->d_name[0] == '.') {
78+
if (sub_entry->d_name[0] == '.' || !isdir(buf, sub_entry->d_name)) {
7079
continue;
7180
}
7281
if (!strcmp(sub_entry->d_name, "cursors")) {
@@ -113,7 +122,7 @@ process_dir(struct themes *themes, const char *path, const char *filename)
113122
return;
114123
}
115124
while ((entry = readdir(dp))) {
116-
if (entry->d_type == DT_DIR && entry->d_name[0] != '.') {
125+
if (entry->d_name[0] != '.' && isdir(path, entry->d_name)) {
117126
char buf[4096];
118127
snprintf(buf, sizeof(buf), "%s/%s/%s", path, entry->d_name, filename);
119128
/* filter 'hicolor' as it is not a complete icon set */

0 commit comments

Comments
 (0)