runit

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

gen_allocdefs.h (1212B)


      1 /* Public domain. */
      2 
      3 #ifndef GEN_ALLOC_DEFS_H
      4 #define GEN_ALLOC_DEFS_H
      5 
      6 #define GEN_ALLOC_ready(ta,type,field,len,a,i,n,x,base,ta_ready) \
      7 int ta_ready(register ta *x,register unsigned int n) \
      8 { register unsigned int i; \
      9   if (x->field) { \
     10     i = x->a; \
     11     if (n > i) { \
     12       x->a = base + n + (n >> 3); \
     13       if (alloc_re(&x->field,i * sizeof(type),x->a * sizeof(type))) return 1; \
     14       x->a = i; return 0; } \
     15     return 1; } \
     16   x->len = 0; \
     17   return !!(x->field = (type *) alloc((x->a = n) * sizeof(type))); }
     18 
     19 #define GEN_ALLOC_readyplus(ta,type,field,len,a,i,n,x,base,ta_rplus) \
     20 int ta_rplus(register ta *x,register unsigned int n) \
     21 { register unsigned int i; \
     22   if (x->field) { \
     23     i = x->a; n += x->len; \
     24     if (n > i) { \
     25       x->a = base + n + (n >> 3); \
     26       if (alloc_re(&x->field,i * sizeof(type),x->a * sizeof(type))) return 1; \
     27       x->a = i; return 0; } \
     28     return 1; } \
     29   x->len = 0; \
     30   return !!(x->field = (type *) alloc((x->a = n) * sizeof(type))); }
     31 
     32 #define GEN_ALLOC_append(ta,type,field,len,a,i,n,x,base,ta_rplus,ta_append) \
     33 int ta_append(register ta *x,register const type *i) \
     34 { if (!ta_rplus(x,1)) return 0; x->field[x->len++] = *i; return 1; }
     35 
     36 #endif