http://linux-ntfs.sourceforge.net/snapshots/ntfsprogs-200307311516.tar.bz2
[ntfsprogs.git] / include / support.h
1 /*
2  * support.h - Useful definitions and macros. Part of the Linux-NTFS project.
3  *
4  * Copyright (c) 2000-2002 Anton Altaparmakov
5  *
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.
10  *
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.
15  *
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
20  */
21
22 #ifndef _NTFS_SUPPORT_H
23 #define _NTFS_SUPPORT_H
24
25 #include <stddef.h>
26
27 /*
28  * Generic macro to convert pointers to values for comparison purposes.
29  */
30 #ifndef p2n
31 #define p2n(p)          ((ptrdiff_t)((ptrdiff_t*)(p)))
32 #endif
33
34 /*
35  * The classical min and max macros.
36  */
37 #ifndef min
38 #define min(a,b)        ((a) <= (b) ? (a) : (b))
39 #endif
40
41 #ifndef max
42 #define max(a,b)        ((a) >= (b) ? (a) : (b))
43 #endif
44
45 /*
46  * Simple bit operation macros. NOTE: These are NOT atomic.
47  */
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))
51
52 #define test_and_set_bit(bit, var)                      \
53 ({                                                      \
54         const BOOL old_state = test_bit(bit, var);      \
55         set_bit(bit, var);                              \
56         old_state;                                      \
57 })
58
59 #define test_and_clear_bit(bit, var)                    \
60 ({                                                      \
61         const BOOL old_state = test_bit(bit, var);      \
62         clear_bit(bit, var);                            \
63         old_state;                                      \
64 })
65
66 #endif /* defined _NTFS_SUPPORT_H */
67