dirent.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <sys/cdefs.h>
  8. #include <sys/types.h>
  9. __BEGIN_DECLS
  10. enum {
  11. DT_UNKNOWN = 0,
  12. #define DT_UNKNOWN DT_UNKNOWN
  13. DT_FIFO = 1,
  14. #define DT_FIFO DT_FIFO
  15. DT_CHR = 2,
  16. #define DT_CHR DT_CHR
  17. DT_DIR = 4,
  18. #define DT_DIR DT_DIR
  19. DT_BLK = 6,
  20. #define DT_BLK DT_BLK
  21. DT_REG = 8,
  22. #define DT_REG DT_REG
  23. DT_LNK = 10,
  24. #define DT_LNK DT_LNK
  25. DT_SOCK = 12,
  26. #define DT_SOCK DT_SOCK
  27. DT_WHT = 14
  28. #define DT_WHT DT_WHT
  29. };
  30. struct dirent {
  31. ino_t d_ino;
  32. off_t d_off;
  33. unsigned short d_reclen;
  34. unsigned char d_type;
  35. char d_name[256];
  36. };
  37. struct __DIR {
  38. int fd;
  39. struct dirent cur_ent;
  40. char* buffer;
  41. size_t buffer_size;
  42. char* nextptr;
  43. };
  44. typedef struct __DIR DIR;
  45. DIR* opendir(const char* name);
  46. int closedir(DIR*);
  47. void rewinddir(DIR*);
  48. struct dirent* readdir(DIR*);
  49. int readdir_r(DIR*, struct dirent*, struct dirent**);
  50. int dirfd(DIR*);
  51. int scandir(const char* dirp, struct dirent*** namelist,
  52. int (*filter)(const struct dirent*),
  53. int (*compar)(const struct dirent**, const struct dirent**));
  54. __END_DECLS