My slstatus configuration
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 

30 řádky
498 B

  1. #include <dirent.h>
  2. #include <err.h>
  3. #include <stdio.h>
  4. #include <string.h>
  5. #include "util.h"
  6. const char *
  7. num_files(const char *dir)
  8. {
  9. struct dirent *dp;
  10. DIR *fd;
  11. int num = 0;
  12. if ((fd = opendir(dir)) == NULL) {
  13. warn("Failed to get number of files in directory %s", dir);
  14. return NULL;
  15. }
  16. while ((dp = readdir(fd)) != NULL) {
  17. if (!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, ".."))
  18. continue; /* skip self and parent */
  19. num++;
  20. }
  21. closedir(fd);
  22. return bprintf("%d", num);
  23. }