summaryrefslogtreecommitdiff
path: root/include/ntfs-3g/support.h (plain)
blob: 6af4761e22b2e03d36f0b376c9b47746240678c3
1/*
2 * support.h - Useful definitions and macros. Originated from the Linux-NTFS project.
3 *
4 * Copyright (c) 2000-2004 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 NTFS-3G
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#ifdef HAVE_CONFIG_H
26#include "config.h"
27#endif
28
29#ifdef HAVE_STDDEF_H
30#include <stddef.h>
31#endif
32
33/*
34 * Our mailing list. Use this define to prevent typos in email address.
35 */
36#define NTFS_DEV_LIST "ntfs-3g-devel@lists.sf.net"
37
38/*
39 * Generic macro to convert pointers to values for comparison purposes.
40 */
41#ifndef p2n
42#define p2n(p) ((ptrdiff_t)((ptrdiff_t*)(p)))
43#endif
44
45/*
46 * The classic min and max macros.
47 */
48#ifndef min
49#define min(a,b) ((a) <= (b) ? (a) : (b))
50#endif
51
52#ifndef max
53#define max(a,b) ((a) >= (b) ? (a) : (b))
54#endif
55
56/*
57 * Useful macro for determining the offset of a struct member.
58 */
59#ifndef offsetof
60#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
61#endif
62
63/*
64 * Simple bit operation macros. NOTE: These are NOT atomic.
65 */
66#define test_bit(bit, var) ((var) & (1 << (bit)))
67#define set_bit(bit, var) (var) |= 1 << (bit)
68#define clear_bit(bit, var) (var) &= ~(1 << (bit))
69
70#define test_and_set_bit(bit, var) \
71({ \
72 const BOOL old_state = test_bit(bit, var); \
73 set_bit(bit, var); \
74 old_state; \
75})
76
77#define test_and_clear_bit(bit, var) \
78({ \
79 const BOOL old_state = test_bit(bit, var); \
80 clear_bit(bit, var); \
81 old_state; \
82})
83
84#endif /* defined _NTFS_SUPPORT_H */
85
86