My slstatus configuration
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

num_files.c 526 B

1234567891011121314151617181920212223242526272829303132
  1. /* See LICENSE file for copyright and license details. */
  2. #include <dirent.h>
  3. #include <errno.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;
  13. if (!(fd = opendir(dir))) {
  14. warn("opendir '%s':", dir);
  15. return NULL;
  16. }
  17. num = 0;
  18. while ((dp = readdir(fd))) {
  19. if (!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, "..")) {
  20. continue; /* skip self and parent */
  21. }
  22. num++;
  23. }
  24. closedir(fd);
  25. return bprintf("%d", num);
  26. }