fileaccess.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #ifndef BACKEND_FILEACCESS_H_
  2. #define BACKEND_FILEACCESS_H_
  3. #include "list.h"
  4. #include <stdarg.h>
  5. #include <fcntl.h>
  6. #include <stdio.h>
  7. #include <dirent.h>
  8. struct fileaccess {
  9. int fd;
  10. FILE *stream;
  11. };
  12. void file_close(struct fileaccess *fa);
  13. struct fileaccess * file_open(int flags, const char *path_fmt, ...);
  14. struct fileaccess * sysfs_file_open(int flags, const char *path_fmt, ...);
  15. struct fileaccess * procfs_file_open(int flags, const char *path_fmt, ...);
  16. int file_read_buf(struct fileaccess *fa, char *buf, size_t size);
  17. int file_read_string(struct fileaccess *fa, char *buf, size_t size);
  18. int file_read_int(struct fileaccess *fa, int *value, int base);
  19. int file_write_int(struct fileaccess *fa, int value, int base);
  20. int file_read_bool(struct fileaccess *fa, int *value);
  21. int file_write_bool(struct fileaccess *fa, int value);
  22. struct text_line {
  23. char *text;
  24. struct list_head list;
  25. };
  26. int file_read_text_lines(struct fileaccess *fa, struct list_head *lines_list,
  27. int strip_whitespace);
  28. void text_line_free(struct text_line *tl);
  29. void text_lines_free(struct list_head *lines_list);
  30. struct dir_entry {
  31. char *name;
  32. unsigned int type; /* DT_... */
  33. struct list_head list;
  34. };
  35. int list_directory(struct list_head *dir_entries, const char *path_fmt, ...);
  36. int list_sysfs_directory(struct list_head *dir_entries, const char *path_fmt, ...);
  37. int list_procfs_directory(struct list_head *dir_entries, const char *path_fmt, ...);
  38. void dir_entry_free(struct dir_entry *dir_entry);
  39. void dir_entries_free(struct list_head *dir_entries);
  40. #endif /* BACKEND_FILEACCESS_H_ */