filehelper.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * Copyright (c) 2018 Markus Hennecke <markus-hennecke@markus-hennecke.de>
  3. *
  4. * Permission to use, copy, modify, and distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #ifndef __FILEHELPER_H__
  17. #define __FILEHELPER_H__
  18. #include <sys/queue.h>
  19. #include <sys/stat.h>
  20. #include <sys/types.h>
  21. #include <stdbool.h>
  22. struct dir_entry {
  23. TAILQ_ENTRY(dir_entry) entries;
  24. struct stat sb;
  25. u_int8_t type;
  26. char *filename;
  27. };
  28. struct dir_list {
  29. TAILQ_HEAD(, dir_entry) entries;
  30. time_t newest;
  31. char *path;
  32. };
  33. struct dir_entry *dir_entry_new(const char *);
  34. void dir_entry_free(struct dir_entry *);
  35. bool dir_entry_exists(const char *, struct dir_list *);
  36. struct dir_list *get_dir_entries(const char *);
  37. struct dir_list *get_dir_entries_fd(int);
  38. struct dir_list *get_dir_entries_at(int, const char *);
  39. void dir_list_free(struct dir_list *);
  40. bool file_exists(const char *_filename);
  41. bool dir_exists(const char *_dirname);
  42. bool dir_exists_at(int, const char *_dirname);
  43. #endif // __FILEHELPER_H__