My dmenu build
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

40 lines
742 B

  1. /* See LICENSE file for copyright and license details. */
  2. #include <dirent.h>
  3. #include <limits.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <string.h>
  7. #include <unistd.h>
  8. #include <sys/stat.h>
  9. static void lsx(const char *dir);
  10. int
  11. main(int argc, char *argv[]) {
  12. int i;
  13. if(argc < 2)
  14. lsx(".");
  15. else for(i = 1; i < argc; i++)
  16. lsx(argv[i]);
  17. return EXIT_SUCCESS;
  18. }
  19. void
  20. lsx(const char *dir) {
  21. char buf[PATH_MAX];
  22. struct dirent *d;
  23. struct stat st;
  24. DIR *dp;
  25. if(!(dp = opendir(dir))) {
  26. perror(dir);
  27. return;
  28. }
  29. while((d = readdir(dp)))
  30. if(snprintf(buf, sizeof buf, "%s/%s", dir, d->d_name) < (ssize_t)sizeof buf
  31. && !stat(buf, &st) && S_ISREG(st.st_mode) && access(buf, X_OK) == 0)
  32. puts(d->d_name);
  33. closedir(dp);
  34. }