… | |
… | |
80 | # include <signal.h> |
80 | # include <signal.h> |
81 | # include <dirent.h> |
81 | # include <dirent.h> |
82 | |
82 | |
83 | /* POSIX_SOURCE is useless on bsd's, and XOPEN_SOURCE is unreliable there, too */ |
83 | /* POSIX_SOURCE is useless on bsd's, and XOPEN_SOURCE is unreliable there, too */ |
84 | # if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) |
84 | # if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) |
|
|
85 | # define _DIRENT_HAVE_D_TYPE /* sigh */ |
85 | # define D_INO(de) (de)->d_fileno |
86 | # define D_INO(de) (de)->d_fileno |
86 | # define _DIRENT_HAVE_D_TYPE /* sigh */ |
87 | # define D_NAMLEN(de) (de)->d_namlen |
87 | # elif defined(__linux) || defined(d_ino) || _XOPEN_SOURCE >= 600 |
88 | # elif defined(__linux) || defined(d_ino) || _XOPEN_SOURCE >= 600 |
88 | # define D_INO(de) (de)->d_ino |
89 | # define D_INO(de) (de)->d_ino |
89 | # endif |
90 | # endif |
|
|
91 | |
|
|
92 | #ifdef _D_EXACT_NAMLEN |
|
|
93 | # undef D_NAMLEN |
|
|
94 | # define D_NAMLEN(de) _D_EXACT_NAMLEN (de) |
|
|
95 | #endif |
90 | |
96 | |
91 | # ifdef _DIRENT_HAVE_D_TYPE |
97 | # ifdef _DIRENT_HAVE_D_TYPE |
92 | # define D_TYPE(de) (de)->d_type |
98 | # define D_TYPE(de) (de)->d_type |
93 | # endif |
99 | # endif |
94 | |
100 | |
… | |
… | |
114 | #endif |
120 | #endif |
115 | |
121 | |
116 | #ifndef D_TYPE |
122 | #ifndef D_TYPE |
117 | # define D_TYPE(de) 0 |
123 | # define D_TYPE(de) 0 |
118 | #endif |
124 | #endif |
119 | |
|
|
120 | #ifndef D_INO |
125 | #ifndef D_INO |
121 | # define D_INO(de) 0 |
126 | # define D_INO(de) 0 |
|
|
127 | #endif |
|
|
128 | #ifndef D_NAMLEN |
|
|
129 | # define D_NAMLEN(de) strlen ((de)->d_name) |
122 | #endif |
130 | #endif |
123 | |
131 | |
124 | /* number of seconds after which an idle threads exit */ |
132 | /* number of seconds after which an idle threads exit */ |
125 | #define IDLE_TIMEOUT 10 |
133 | #define IDLE_TIMEOUT 10 |
126 | |
134 | |
… | |
… | |
1095 | name = entp->d_name; |
1103 | name = entp->d_name; |
1096 | |
1104 | |
1097 | /* skip . and .. entries */ |
1105 | /* skip . and .. entries */ |
1098 | if (name [0] != '.' || (name [1] && (name [1] != '.' || name [2]))) |
1106 | if (name [0] != '.' || (name [1] && (name [1] != '.' || name [2]))) |
1099 | { |
1107 | { |
1100 | int len = strlen (name) + 1; |
1108 | int len = D_NAMLEN (entp) + 1; |
1101 | |
1109 | |
1102 | while (expect_false (namesoffs + len > namesalloc)) |
1110 | while (expect_false (namesoffs + len > namesalloc)) |
1103 | { |
1111 | { |
1104 | namesalloc *= 2; |
1112 | namesalloc *= 2; |
1105 | X_LOCK (wrklock); |
1113 | X_LOCK (wrklock); |
… | |
… | |
1144 | case DT_FIFO: ent->type = EIO_DT_FIFO; break; |
1152 | case DT_FIFO: ent->type = EIO_DT_FIFO; break; |
1145 | #endif |
1153 | #endif |
1146 | #ifdef DT_CHR |
1154 | #ifdef DT_CHR |
1147 | case DT_CHR: ent->type = EIO_DT_CHR; break; |
1155 | case DT_CHR: ent->type = EIO_DT_CHR; break; |
1148 | #endif |
1156 | #endif |
|
|
1157 | #ifdef DT_MPC |
|
|
1158 | case DT_MPC: ent->type = EIO_DT_MPC; break; |
|
|
1159 | #endif |
1149 | #ifdef DT_DIR |
1160 | #ifdef DT_DIR |
1150 | case DT_DIR: ent->type = EIO_DT_DIR; break; |
1161 | case DT_DIR: ent->type = EIO_DT_DIR; break; |
|
|
1162 | #endif |
|
|
1163 | #ifdef DT_NAM |
|
|
1164 | case DT_NAM: ent->type = EIO_DT_NAM; break; |
1151 | #endif |
1165 | #endif |
1152 | #ifdef DT_BLK |
1166 | #ifdef DT_BLK |
1153 | case DT_BLK: ent->type = EIO_DT_BLK; break; |
1167 | case DT_BLK: ent->type = EIO_DT_BLK; break; |
1154 | #endif |
1168 | #endif |
|
|
1169 | #ifdef DT_MPB |
|
|
1170 | case DT_MPB: ent->type = EIO_DT_MPB; break; |
|
|
1171 | #endif |
1155 | #ifdef DT_REG |
1172 | #ifdef DT_REG |
1156 | case DT_REG: ent->type = EIO_DT_REG; break; |
1173 | case DT_REG: ent->type = EIO_DT_REG; break; |
|
|
1174 | #endif |
|
|
1175 | #ifdef DT_NWK |
|
|
1176 | case DT_NWK: ent->type = EIO_DT_NWK; break; |
|
|
1177 | #endif |
|
|
1178 | #ifdef DT_CMP |
|
|
1179 | case DT_CMP: ent->type = EIO_DT_CMP; break; |
1157 | #endif |
1180 | #endif |
1158 | #ifdef DT_LNK |
1181 | #ifdef DT_LNK |
1159 | case DT_LNK: ent->type = EIO_DT_LNK; break; |
1182 | case DT_LNK: ent->type = EIO_DT_LNK; break; |
1160 | #endif |
1183 | #endif |
1161 | #ifdef DT_SOCK |
1184 | #ifdef DT_SOCK |
1162 | case DT_SOCK: ent->type = EIO_DT_SOCK; break; |
1185 | case DT_SOCK: ent->type = EIO_DT_SOCK; break; |
1163 | #endif |
1186 | #endif |
|
|
1187 | #ifdef DT_DOOR |
|
|
1188 | case DT_DOOR: ent->type = EIO_DT_DOOR; break; |
|
|
1189 | #endif |
1164 | #ifdef DT_WHT |
1190 | #ifdef DT_WHT |
1165 | case DT_WHT: ent->type = EIO_DT_WHT; break; |
1191 | case DT_WHT: ent->type = EIO_DT_WHT; break; |
1166 | #endif |
1192 | #endif |
1167 | } |
1193 | } |
1168 | |
1194 | |
… | |
… | |
1173 | if (ent->type == EIO_DT_UNKNOWN) |
1199 | if (ent->type == EIO_DT_UNKNOWN) |
1174 | { |
1200 | { |
1175 | if (*name == '.') /* leading dots are likely directories, and, in any case, rare */ |
1201 | if (*name == '.') /* leading dots are likely directories, and, in any case, rare */ |
1176 | ent->score = 98; |
1202 | ent->score = 98; |
1177 | else if (!strchr (name, '.')) /* absense of dots indicate likely dirs */ |
1203 | else if (!strchr (name, '.')) /* absense of dots indicate likely dirs */ |
1178 | ent->score = len <= 4 ? 5 : len <= 7 ? 4 : 1; /* shorter == more likely dir, but avoid too many classes */ |
1204 | ent->score = len <= 2 ? len + 60 : len <= 4 ? 50 : len <= 7 ? 40 : 10; /* shorter == more likely dir, but avoid too many classes */ |
1179 | } |
1205 | } |
1180 | else if (ent->type == DT_DIR) |
1206 | else if (ent->type == EIO_DT_DIR) |
1181 | ent->score = 100; |
1207 | ent->score = 100; |
1182 | } |
1208 | } |
1183 | } |
1209 | } |
1184 | |
1210 | |
1185 | namesoffs += len; |
1211 | namesoffs += len; |