My slstatus configuration
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.
 
 
 
 

32 lines
553 B

  1. /* See LICENSE file for copyright and license details. */
  2. #include <errno.h>
  3. #include <dirent.h>
  4. #include <stdio.h>
  5. #include <string.h>
  6. #include "../util.h"
  7. const char *
  8. num_files(const char *dir)
  9. {
  10. struct dirent *dp;
  11. DIR *fd;
  12. int num = 0;
  13. if (!(fd = opendir(dir))) {
  14. fprintf(stderr, "opendir '%s': %s\n", dir, strerror(errno));
  15. return NULL;
  16. }
  17. while ((dp = readdir(fd))) {
  18. if (!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, "..")) {
  19. continue; /* skip self and parent */
  20. }
  21. num++;
  22. }
  23. closedir(fd);
  24. return bprintf("%d", num);
  25. }