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.
 
 
 
 
 
 

42 rivejä
776 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 <unistd.h>
  7. #include <sys/stat.h>
  8. static void lsx(const char *dir);
  9. static int status = EXIT_SUCCESS;
  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 status;
  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. status = EXIT_FAILURE;
  27. perror(dir);
  28. return;
  29. }
  30. while((d = readdir(dp)))
  31. if(snprintf(buf, sizeof buf, "%s/%s", dir, d->d_name) < (int)sizeof buf
  32. && stat(buf, &st) == 0 && S_ISREG(st.st_mode) && access(buf, X_OK) == 0)
  33. puts(d->d_name);
  34. closedir(dp);
  35. }