+/* Allocate dirent as recommended by READDIR(3), NOTES on readdir_r */
+static
+struct dirent *alloc_dirent(const char *path)
+{
+ size_t len;
+ long name_max;
+ struct dirent *entry;
+
+ name_max = pathconf(path, _PC_NAME_MAX);
+ if (name_max == -1) {
+ name_max = PATH_MAX;
+ }
+ len = offsetof(struct dirent, d_name) + name_max + 1;
+ entry = zmalloc(len);
+ return entry;
+}
+