aos_buf.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #ifndef LIBAOS_BUF_H
  2. #define LIBAOS_BUF_H
  3. #include "aos_define.h"
  4. #include "aos_list.h"
  5. AOS_CPP_START
  6. typedef struct {
  7. aos_list_t node;
  8. uint8_t *pos;
  9. uint8_t *last;
  10. uint8_t *start;
  11. uint8_t *end;
  12. } aos_buf_t;
  13. typedef struct {
  14. aos_list_t node;
  15. int64_t file_pos;
  16. int64_t file_last;
  17. apr_file_t *file;
  18. uint32_t owner:1;
  19. } aos_file_buf_t;
  20. aos_buf_t *aos_create_buf(aos_pool_t *p, int size);
  21. #define aos_buf_size(b) (b->last - b->pos)
  22. aos_file_buf_t *aos_create_file_buf(aos_pool_t *p);
  23. aos_buf_t *aos_buf_pack(aos_pool_t *p, const void *data, int size);
  24. int64_t aos_buf_list_len(aos_list_t *list);
  25. char *aos_buf_list_content(aos_pool_t *p, aos_list_t *list);
  26. void aos_buf_append_string(aos_pool_t *p, aos_buf_t *b, const char *str, int len);
  27. /**
  28. * @param fb file_pos, file_last equal file_size.
  29. * @return AOSE_OK success, other failure.
  30. */
  31. int aos_open_file_for_read(aos_pool_t *p, const char *path, aos_file_buf_t *fb);
  32. int aos_open_file_for_all_read(aos_pool_t *p, const char *path, aos_file_buf_t *fb);
  33. int aos_open_file_for_range_read(aos_pool_t *p, const char *path,
  34. int64_t file_pos, int64_t file_last,
  35. aos_file_buf_t *fb);
  36. /**
  37. * create the file if not there, truncate if file exists.
  38. * @param fb not check file_pos, file_last.
  39. * @return AOSE_OK success, other failure.
  40. */
  41. int aos_open_file_for_write(aos_pool_t *p, const char *path, aos_file_buf_t *fb);
  42. AOS_CPP_END
  43. #endif