commit 6840ee8
sewn
·
2026-11-10 11:56:07 +0000 UTC
parent ffc8033
ignore dotfiles
1 files changed,
+9,
-3
M
wawa.c
M
wawa.c
+9,
-3
1@@ -412,6 +412,12 @@ static const struct wl_registry_listener registry_listener = {
2 .global_remove = noop, /* layer_surface_handle_closed */
3 };
4
5+int
6+ignore(const struct dirent *ent)
7+{
8+ return ent->d_name[0] != '.';
9+}
10+
11 int
12 main(int argc, char *argv[])
13 {
14@@ -454,9 +460,9 @@ file:
15 srand((intptr_t)path | (unsigned int)time(NULL));
16 scan:
17 if (chdir(path) < 0) die("chdir:"); // slower & easier than strncpy PATH_MAX
18- if ((dirn = scandir(".", &namelist, NULL, alphasort)) < 0) die("scandir:");
19- if (dirn < 3) die("no images");
20- name = namelist[2 + rand() % (dirn - 2)];
21+ if ((dirn = scandir(".", &namelist, &ignore, alphasort)) < 0) die("scandir:");
22+ if (dirn < 1) die("no images");
23+ name = namelist[rand() % dirn];
24 while (dirn--) if (namelist[dirn] != name) free(namelist[dirn]);
25 free(namelist);
26 mode = basename((path = name->d_name));