1
1
#define _POSIX_C_SOURCE 200809L
2
- #define _DEFAULT_SOURCE
3
2
#include <assert.h>
4
3
#include <dirent.h>
5
4
#include <stdint.h>
6
5
#include <stdio.h>
7
6
#include <stdlib.h>
8
7
#include <string.h>
8
+ #include <strings.h>
9
9
#include <sys/stat.h>
10
10
#include <unistd.h>
11
11
#include "tweaks.h"
@@ -23,6 +23,15 @@ grow_vector_by_one_theme(struct themes *themes)
23
23
return theme ;
24
24
}
25
25
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
+
26
35
/**
27
36
* add_theme_if_icon_theme - add theme iff it is a proper icon theme
28
37
* @themes: vector
@@ -42,7 +51,7 @@ add_theme_if_icon_theme(struct themes *themes, const char *path)
42
51
return ;
43
52
}
44
53
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 ) ) {
46
55
continue ;
47
56
}
48
57
@@ -66,7 +75,7 @@ add_theme_if_icon_theme(struct themes *themes, const char *path)
66
75
* This could be "scalable", "22x22", or whatever...
67
76
*/
68
77
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 ) ) {
70
79
continue ;
71
80
}
72
81
if (!strcmp (sub_entry -> d_name , "cursors" )) {
@@ -113,7 +122,7 @@ process_dir(struct themes *themes, const char *path, const char *filename)
113
122
return ;
114
123
}
115
124
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 ) ) {
117
126
char buf [4096 ];
118
127
snprintf (buf , sizeof (buf ), "%s/%s/%s" , path , entry -> d_name , filename );
119
128
/* filter 'hicolor' as it is not a complete icon set */
0 commit comments