commit - 0a33395dcffe4fea2971eecec30c3fceb2c8cce2
commit + 5cbe17635e5b5884548a53bd3c09b401dbd15e51
blob - ccb515253662f4140e300944221476f898be23e9
blob + 3f17a51e34489942a6dae397473b4c45c8382015
--- fs.c
+++ fs.c
static void die(void) __attribute__((__noreturn__));
static void send_file(uint32_t, FILE *);
static void handle_get(struct imsg*, size_t);
+static int select_non_dot(const struct dirent *);
+static int select_non_dotdot(const struct dirent *);
static void handle_get_file(struct imsg*, size_t);
static void handle_quit(struct imsg*, size_t);
static void handle_bookmark_page(struct imsg*, size_t);
return m->mime;
return NULL;
+}
+
+static int
+select_non_dot(const struct dirent *d)
+{
+ return strcmp(d->d_name, ".");
+}
+
+static int
+select_non_dotdot(const struct dirent *d)
+{
+ return strcmp(d->d_name, ".") && strcmp(d->d_name, "..");
}
static inline void
{
struct dirent **names;
struct evbuffer *ev;
+ int (*selector)(const struct dirent *) = select_non_dot;
int i, len;
+ if (!strcmp(path, "/"))
+ selector = select_non_dotdot;
+
if ((ev = evbuffer_new()) == NULL ||
- (len = scandir(path, &names, NULL, alphasort)) == -1) {
+ (len = scandir(path, &names, selector, alphasort)) == -1) {
evbuffer_free(ev);
send_hdr(peerid, 40, "failure reading the directory");
return;