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.
 
 
 
 

31 lines
748 B

  1. #ifdef __dietlibc__
  2. #include <sys/cdefs.h>
  3. #else
  4. #define __likely(x) x
  5. #define __unlikely(x) x
  6. #endif
  7. #include "safemult.h"
  8. #include "array.h"
  9. #if 0
  10. static array x;
  11. t *p;
  12. int64 pos;
  13. p = array_get(&x,sizeof(t),pos);
  14. array_get is similar to array_allocate, but it does not allocate any
  15. extra bytes, and it does not initialize any extra bytes. It
  16. returns 0 if x is unallocated, for example, or if fewer than
  17. (pos+1)*sizeof(t) bytes are initialized.
  18. #endif
  19. void* array_get(array* x,uint64 membersize,int64 pos) {
  20. uint64 wanted;
  21. if (__unlikely(pos+1<1)) return 0;
  22. if (__unlikely(umult64(membersize,pos,&wanted))) return 0;
  23. if (__unlikely(wanted > x->allocated)) return 0;
  24. return x->p+pos*membersize;
  25. }