Whamcloud - gitweb
replace tag with rtag to better deal with added/removed files
[fs/lustre-release.git] / lnet / include / libcfs / portals_lib.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  Copyright (C) 2001 Cluster File Systems, Inc. <braam@clusterfs.com>
5  *
6  *   This file is part of Lustre, http://www.lustre.org.
7  *
8  *   Lustre is free software; you can redistribute it and/or
9  *   modify it under the terms of version 2 of the GNU General Public
10  *   License as published by the Free Software Foundation.
11  *
12  *   Lustre is distributed in the hope that it will be useful,
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *   GNU General Public License for more details.
16  *
17  *   You should have received a copy of the GNU General Public License
18  *   along with Lustre; if not, write to the Free Software
19  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  *
21  * Basic library routines. 
22  *
23  */
24
25 #ifndef __LIBCFS_PORTALS_LIB_H__
26 #define __LIBCFS_PORTALS_LIB_H__
27
28 #if defined(__linux__)
29 #include <libcfs/linux/portals_lib.h>
30 #elif defined(__APPLE__)
31 #include <libcfs/darwin/portals_lib.h>
32 #else
33 #error Unsupported Operating System
34 #endif
35
36 #undef MIN
37 #define MIN(a,b) (((a)<(b)) ? (a): (b))
38 #undef MAX
39 #define MAX(a,b) (((a)>(b)) ? (a): (b))
40 #define MKSTR(ptr) ((ptr))? (ptr) : ""
41
42 static inline int size_round4 (int val)
43 {
44         return (val + 3) & (~0x3);
45 }
46
47 static inline int size_round (int val)
48 {
49         return (val + 7) & (~0x7);
50 }
51
52 static inline int size_round16(int val)
53 {
54         return (val + 0xf) & (~0xf);
55 }
56
57 static inline int size_round32(int val)
58 {
59         return (val + 0x1f) & (~0x1f);
60 }
61
62 static inline int size_round0(int val)
63 {
64         if (!val)
65                 return 0;
66         return (val + 1 + 7) & (~0x7);
67 }
68
69 static inline size_t round_strlen(char *fset)
70 {
71         return size_round(strlen(fset) + 1);
72 }
73
74 #define LOGL(var,len,ptr)                                       \
75 do {                                                            \
76         if (var)                                                \
77                 memcpy((char *)ptr, (const char *)var, len);    \
78         ptr += size_round(len);                                 \
79 } while (0)
80
81 #define LOGU(var,len,ptr)                                       \
82 do {                                                            \
83         if (var)                                                \
84                 memcpy((char *)var, (const char *)ptr, len);    \
85         ptr += size_round(len);                                 \
86 } while (0)
87
88 #define LOGL0(var,len,ptr)                              \
89 do {                                                    \
90         if (!len)                                       \
91                 break;                                  \
92         memcpy((char *)ptr, (const char *)var, len);    \
93         *((char *)(ptr) + len) = 0;                     \
94         ptr += size_round(len + 1);                     \
95 } while (0)
96
97 #endif /* _PORTALS_LIB_H */