buffer.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 __BUFFER_H__
  17. #define __BUFFER_H__
  18. #include <sys/queue.h>
  19. #include <stdint.h>
  20. struct buffer {
  21. TAILQ_ENTRY(buffer) entries;
  22. size_t size;
  23. char data[1];
  24. };
  25. struct buffer_list {
  26. TAILQ_HEAD(buffer_list_head, buffer) buffers;
  27. size_t size;
  28. };
  29. struct buffer *buffer_new(const char *_data);
  30. struct buffer *buffer_bin_new(const void *, size_t);
  31. struct buffer *buffer_empty_new(size_t);
  32. ssize_t buffer_write(struct buffer *, int);
  33. char *buffer_list_concat_string(struct buffer_list *);
  34. char *buffer_list_concat(struct buffer_list *);
  35. struct buffer_list *buffer_list_new(void);
  36. void buffer_list_free(struct buffer_list *);
  37. void buffer_list_add(struct buffer_list *, const void *,
  38. size_t);
  39. void buffer_list_add_string(struct buffer_list *,
  40. const char *);
  41. void buffer_list_add_stringn(struct buffer_list *,
  42. const char *, size_t);
  43. void buffer_list_add_buffer(struct buffer_list *,
  44. struct buffer *);
  45. void buffer_list_add_list(struct buffer_list *,
  46. struct buffer_list *);
  47. struct buffer *buffer_list_rem_head(struct buffer_list *);
  48. struct buffer *buffer_list_rem_tail(struct buffer_list *);
  49. struct buffer *buffer_list_rem(struct buffer_list *, struct buffer *);
  50. struct buffer_list *buffer_list_gzip(struct buffer_list *,
  51. const char *_filename, uint32_t _mtime);
  52. #endif // __BUFFER_H__