filehelper.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 *_filename);
  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 *_directory);
  37. void dir_list_free(struct dir_list *);
  38. bool file_exists(const char *_filename);
  39. #endif // _FILEHELPER_H_