chunk.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. Copyright (c) 2013 Martin Sustrik All rights reserved.
  3. Permission is hereby granted, free of charge, to any person obtaining a copy
  4. of this software and associated documentation files (the "Software"),
  5. to deal in the Software without restriction, including without limitation
  6. the rights to use, copy, modify, merge, publish, distribute, sublicense,
  7. and/or sell copies of the Software, and to permit persons to whom
  8. the Software is furnished to do so, subject to the following conditions:
  9. The above copyright notice and this permission notice shall be included
  10. in all copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  14. THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  16. FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  17. IN THE SOFTWARE.
  18. */
  19. #ifndef NN_CHUNK_INCLUDED
  20. #define NN_CHUNK_INCLUDED
  21. #include <stddef.h>
  22. #include <stdint.h>
  23. /* Allocates the chunk using the allocation mechanism specified by 'type'. */
  24. int nn_chunk_alloc (size_t size, int type, void **result);
  25. /* Resizes a chunk previously allocated with nn_chunk_alloc. */
  26. int nn_chunk_realloc (size_t size, void **chunk);
  27. /* Releases a reference to the chunk and once the reference count had dropped
  28. to zero, deallocates the chunk. */
  29. void nn_chunk_free (void *p);
  30. /* Increases the reference count of the chunk by 'n'. */
  31. void nn_chunk_addref (void *p, uint32_t n);
  32. /* Returns size of the chunk buffer. */
  33. size_t nn_chunk_size (void *p);
  34. /* Trims n bytes from the beginning of the chunk. Returns pointer to the new
  35. chunk. */
  36. void *nn_chunk_trim (void *p, size_t n);
  37. #endif