+ char **r = NULL;
+ int size = 0, alloc = 0;
+ DIR *dir;
+ struct dirent *d;
+
+ NEED_ROOT (NULL);
+ ABS_PATH (path, NULL);
+
+ CHROOT_IN;
+ dir = opendir (path);
+ CHROOT_OUT;
+
+ if (!dir) {
+ reply_with_perror ("opendir: %s", path);
+ return NULL;
+ }
+
+ while ((d = readdir (dir)) != NULL) {
+ if (strcmp (d->d_name, ".") == 0 || strcmp (d->d_name, "..") == 0)
+ continue;
+
+ if (add_string (&r, &size, &alloc, d->d_name) == -1) {
+ closedir (dir);
+ return NULL;
+ }
+ }
+
+ if (add_string (&r, &size, &alloc, NULL) == -1) {
+ closedir (dir);
+ return NULL;
+ }
+
+ if (closedir (dir) == -1) {
+ reply_with_perror ("closedir: %s", path);
+ free_strings (r);
+ return NULL;
+ }
+
+ sort_strings (r, size-1);
+ return r;