Mirror of :pserver:cvs@cvs.fefe.de:/cvs libowfat https://www.fefe.de/libowfat/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

array.h 1.7 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /* this header file comes from libowfat, http://www.fefe.de/libowfat/ */
  2. #ifndef ARRAY_H
  3. #define ARRAY_H
  4. #include <stddef.h>
  5. #include <libowfat/compiler.h>
  6. #include <libowfat/uint64.h>
  7. #ifdef __cplusplus
  8. extern "C" {
  9. #endif
  10. typedef struct {
  11. char* p;
  12. int64 allocated; /* in bytes */
  13. uint64 initialized; /* in bytes */
  14. /* p and allocated nonzero: array is allocated */
  15. /* p and allocated zero: array is unallocated */
  16. /* p zero and allocated < 0: array is failed */
  17. size_t headroom; /* the actual pointer for free() and realloc() is p-headroom */
  18. } array;
  19. void* array_allocate(array* x,uint64 membersize,int64 pos) noexcept;
  20. void* array_get(const array* const x,uint64 membersize,int64 pos) noexcept;
  21. void* array_start(const array* const x) noexcept;
  22. att_pure
  23. int64 array_length(const array* const x,uint64 membersize) noexcept;
  24. att_pure
  25. int64 array_bytes(const array* const x) noexcept;
  26. void array_truncate(array* x,uint64 membersize,int64 len) noexcept;
  27. void array_trunc(array* x) noexcept;
  28. void array_reset(array* x) noexcept;
  29. void array_fail(array* x) noexcept;
  30. int array_equal(const array* const x,const array* const y) noexcept;
  31. void array_cat(array* to,const array* const from) noexcept;
  32. void array_catb(array* to,const char* from,uint64 len) noexcept;
  33. void array_cats(array* to,const char* from) noexcept;
  34. void array_cats0(array* to,const char* from) noexcept;
  35. void array_cat0(array* to) noexcept;
  36. void array_cate(array* to,const array* const from,int64 pos,int64 stop) noexcept;
  37. void array_shift(array* x,uint64 membersize,uint64 members) noexcept;
  38. void array_chop(array* x,uint64 membersize,uint64 members) noexcept;
  39. #define array_failed(x) (array_bytes(x)==-1)
  40. #define array_unallocated(x) (array_bytes(x)==0)
  41. #ifdef __cplusplus
  42. }
  43. #endif
  44. #endif