1 /* $NetBSD: util.h,v 1.1.1.2 2008/05/18 14:29:52 aymeric Exp $ */
5 * The Regents of the University of California. All rights reserved.
6 * Copyright (c) 1994, 1995, 1996
7 * Keith Bostic. All rights reserved.
9 * See the LICENSE file for redistribution information.
11 * Id: util.h,v 10.5 1996/03/16 14:42:47 bostic Exp (Berkeley) Date: 1996/03/16 14:42:47
14 /* Macros to init/set/clear/test flags. */
15 #define FL_INIT(l, f) (l) = (f) /* Specific flags location. */
16 #define FL_SET(l, f) ((l) |= (f))
17 #define FL_CLR(l, f) ((l) &= ~(f))
18 #define FL_ISSET(l, f) ((l) & (f))
20 #define LF_INIT(f) FL_INIT(flags, f) /* Local variable flags. */
21 #define LF_SET(f) FL_SET(flags, f)
22 #define LF_CLR(f) FL_CLR(flags, f)
23 #define LF_ISSET(f) FL_ISSET(flags, f)
25 #define F_INIT(p, f) FL_INIT((p)->flags, f) /* Structure element flags. */
26 #define F_SET(p, f) FL_SET((p)->flags, f)
27 #define F_CLR(p, f) FL_CLR((p)->flags, f)
28 #define F_ISSET(p, f) FL_ISSET((p)->flags, f)
30 /* Offset to next column of stop size, e.g. tab offsets. */
31 #define COL_OFF(c, stop) ((stop) - ((c) % (stop)))
33 /* Busy message types. */
34 typedef enum { B_NONE
, B_OFF
, B_READ
, B_RECOVER
, B_SEARCH
, B_WRITE
} bmsg_t
;
37 * Number handling defines and protoypes.
39 * NNFITS: test for addition of two negative numbers under a limit
40 * NPFITS: test for addition of two positive numbers under a limit
41 * NADD_SLONG: test for addition of two signed longs
42 * NADD_USLONG: test for addition of two unsigned longs
44 enum nresult
{ NUM_ERR
, NUM_OK
, NUM_OVER
, NUM_UNDER
};
45 #define NNFITS(min, cur, add) \
46 (((long)(min)) - (cur) <= (add))
47 #define NPFITS(max, cur, add) \
48 (((unsigned long)(max)) - (cur) >= (add))
49 #define NADD_SLONG(sp, v1, v2) \
52 NNFITS(LONG_MIN, (v1), (v2))) ? NUM_UNDER : NUM_OK : \
55 NPFITS(LONG_MAX, (unsigned long)(v1), (unsigned long)(v2)) ? \
58 #define NADD_USLONG(sp, v1, v2) \
59 (NPFITS(ULONG_MAX, (v1), (v2)) ? NUM_OK : NUM_OVER)