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.
 
 
 
 
 
 

44 lines
819 B

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