|
|
1.1 ! root 1: /* (-lgl ! 2: * COHERENT Driver Kit Version 1.1.0 ! 3: * Copyright (c) 1982, 1990 by Mark Williams Company. ! 4: * All rights reserved. May not be copied without permission. ! 5: -lgl) */ ! 6: /* ! 7: * Coherent. Some useful functions. ! 8: */ ! 9: ! 10: #ifndef FUN_H ! 11: #define FUN_H FUN_H ! 12: ! 13: /* ! 14: * Number of elements in a structure. ! 15: */ ! 16: #define nel(a) (sizeof(a)/sizeof((a)[0])) ! 17: ! 18: /* ! 19: * Character pointer to integer. ! 20: */ ! 21: #define cpi(p) ((char *)(p) - (char *)0) ! 22: ! 23: /* ! 24: * Round a number upwards to be a multiple of another. ! 25: */ ! 26: #define roundu(n1, n2) (((n1)+(n2)-1)/n2*n2) ! 27: ! 28: /* ! 29: * Offset in bytes of `m' in the structure `s'. ! 30: */ ! 31: #define offset(s, m) ((int) &(((struct s *) 0)->m)) ! 32: ! 33: /* ! 34: * Add an unsigned number without overflow. ! 35: */ ! 36: #define addu(v, n) { \ ! 37: unsigned x; \ ! 38: \ ! 39: x = v + (n); \ ! 40: v = x>=v ? x : MAXU; \ ! 41: } ! 42: ! 43: /* ! 44: * Subtract an unsigned number without overflow. ! 45: */ ! 46: #define subu(v, n) { \ ! 47: unsigned x; \ ! 48: \ ! 49: x = v - (n); \ ! 50: v = x<=v ? x : 0; \ ! 51: }; ! 52: ! 53: #endif
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.