2 * support.h - Useful definitions and macros. Part of the Linux-NTFS project.
4 * Copyright (c) 2000-2002 Anton Altaparmakov
6 * This program/include file is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as published
8 * by the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program/include file is distributed in the hope that it will be
12 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program (in the main directory of the Linux-NTFS
18 * distribution in the file COPYING); if not, write to the Free Software
19 * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #ifndef _NTFS_SUPPORT_H
23 #define _NTFS_SUPPORT_H
28 * Generic macro to convert pointers to values for comparison purposes.
31 #define p2n(p) ((ptrdiff_t)((ptrdiff_t*)(p)))
35 * The classical min and max macros.
38 #define min(a,b) ((a) <= (b) ? (a) : (b))
42 #define max(a,b) ((a) >= (b) ? (a) : (b))
46 * Simple bit operation macros. NOTE: These are NOT atomic.
48 #define test_bit(bit, var) ((var) & (1 << (bit)))
49 #define set_bit(bit, var) (var) |= 1 << (bit)
50 #define clear_bit(bit, var) (var) &= ~(1 << (bit))
52 #define test_and_set_bit(bit, var) \
54 const BOOL old_state = test_bit(bit, var); \
59 #define test_and_clear_bit(bit, var) \
61 const BOOL old_state = test_bit(bit, var); \
62 clear_bit(bit, var); \
66 #endif /* defined _NTFS_SUPPORT_H */