buffer.h 2.1 KB

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