1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * Copyright (c) 1998-2001 Sendmail, Inc. and its suppliers. 3*7c478bd9Sstevel@tonic-gate * All rights reserved. 4*7c478bd9Sstevel@tonic-gate * Copyright (c) 1983, 1995-1997 Eric P. Allman. All rights reserved. 5*7c478bd9Sstevel@tonic-gate * Copyright (c) 1988, 1993 6*7c478bd9Sstevel@tonic-gate * The Regents of the University of California. All rights reserved. 7*7c478bd9Sstevel@tonic-gate * 8*7c478bd9Sstevel@tonic-gate * By using this file, you agree to the terms and conditions set 9*7c478bd9Sstevel@tonic-gate * forth in the LICENSE file which can be found at the top level of 10*7c478bd9Sstevel@tonic-gate * the sendmail distribution. 11*7c478bd9Sstevel@tonic-gate * 12*7c478bd9Sstevel@tonic-gate * 13*7c478bd9Sstevel@tonic-gate * $Id: bitops.h,v 1.2 2001/09/22 22:05:42 ca Exp $ 14*7c478bd9Sstevel@tonic-gate */ 15*7c478bd9Sstevel@tonic-gate 16*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 17*7c478bd9Sstevel@tonic-gate 18*7c478bd9Sstevel@tonic-gate #ifndef SM_BITOPS_H 19*7c478bd9Sstevel@tonic-gate # define SM_BITOPS_H 20*7c478bd9Sstevel@tonic-gate 21*7c478bd9Sstevel@tonic-gate /* 22*7c478bd9Sstevel@tonic-gate ** Data structure for bit maps. 23*7c478bd9Sstevel@tonic-gate ** 24*7c478bd9Sstevel@tonic-gate ** Each bit in this map can be referenced by an ascii character. 25*7c478bd9Sstevel@tonic-gate ** This is 256 possible bits, or 32 8-bit bytes. 26*7c478bd9Sstevel@tonic-gate */ 27*7c478bd9Sstevel@tonic-gate 28*7c478bd9Sstevel@tonic-gate # define BITMAPBITS 256 /* number of bits in a bit map */ 29*7c478bd9Sstevel@tonic-gate # define BYTEBITS 8 /* number of bits in a byte */ 30*7c478bd9Sstevel@tonic-gate # define BITMAPBYTES (BITMAPBITS / BYTEBITS) /* number of bytes in bit map */ 31*7c478bd9Sstevel@tonic-gate # define BITMAPMAX ((BITMAPBYTES / sizeof (int)) - 1) 32*7c478bd9Sstevel@tonic-gate 33*7c478bd9Sstevel@tonic-gate /* internal macros */ 34*7c478bd9Sstevel@tonic-gate 35*7c478bd9Sstevel@tonic-gate /* make sure this index never leaves the allowed range: 0 to BITMAPMAX */ 36*7c478bd9Sstevel@tonic-gate # define _BITWORD(bit) (((unsigned char)(bit) / (BYTEBITS * sizeof (int))) & BITMAPMAX) 37*7c478bd9Sstevel@tonic-gate # define _BITBIT(bit) ((unsigned int)1 << ((unsigned char)(bit) % (BYTEBITS * sizeof (int)))) 38*7c478bd9Sstevel@tonic-gate 39*7c478bd9Sstevel@tonic-gate typedef unsigned int BITMAP256[BITMAPBYTES / sizeof (int)]; 40*7c478bd9Sstevel@tonic-gate 41*7c478bd9Sstevel@tonic-gate /* properly case and truncate bit */ 42*7c478bd9Sstevel@tonic-gate # define bitidx(bit) ((unsigned int) (bit) & 0xff) 43*7c478bd9Sstevel@tonic-gate 44*7c478bd9Sstevel@tonic-gate /* test bit number N */ 45*7c478bd9Sstevel@tonic-gate # define bitnset(bit, map) ((map)[_BITWORD(bit)] & _BITBIT(bit)) 46*7c478bd9Sstevel@tonic-gate 47*7c478bd9Sstevel@tonic-gate /* set bit number N */ 48*7c478bd9Sstevel@tonic-gate # define setbitn(bit, map) (map)[_BITWORD(bit)] |= _BITBIT(bit) 49*7c478bd9Sstevel@tonic-gate 50*7c478bd9Sstevel@tonic-gate /* clear bit number N */ 51*7c478bd9Sstevel@tonic-gate # define clrbitn(bit, map) (map)[_BITWORD(bit)] &= ~_BITBIT(bit) 52*7c478bd9Sstevel@tonic-gate 53*7c478bd9Sstevel@tonic-gate /* clear an entire bit map */ 54*7c478bd9Sstevel@tonic-gate # define clrbitmap(map) memset((char *) map, '\0', BITMAPBYTES) 55*7c478bd9Sstevel@tonic-gate 56*7c478bd9Sstevel@tonic-gate /* bit hacking */ 57*7c478bd9Sstevel@tonic-gate # define bitset(bit, word) (((word) & (bit)) != 0) 58*7c478bd9Sstevel@tonic-gate 59*7c478bd9Sstevel@tonic-gate #endif /* ! SM_BITOPS_H */ 60