My dmenu build
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

39 lines
713 B

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