Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / include / compat.h
1 /*
2  * Ceph - scalable distributed file system
3  *
4  * Copyright (C) 2011 Stanislav Sedov <stas@FreeBSD.org>
5  *
6  * This is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License version 2.1, as published by the Free Software
9  * Foundation.  See file COPYING.
10  */
11
12 #ifndef CEPH_COMPAT_H
13 #define CEPH_COMPAT_H
14
15 #include "acconfig.h"
16
17 #if defined(__linux__)
18 #define PROCPREFIX
19 #endif
20
21 #if defined(__FreeBSD__)
22
23 // FreeBSD supports Linux procfs with its compatibility module
24 // And all compatibility stuff is standard mounted on this 
25 #define PROCPREFIX "/compat/linux"
26
27 /* Make sure that ENODATA is defined in the correct way */
28 #ifndef ENODATA
29 #define ENODATA ENOATTR
30 #else
31 #if (ENODATA == 9919)
32 // #warning ENODATA already defined to be 9919, redefining to fix
33 // Silencing this warning because it fires at all files where compat.h
34 // is included after boost files.
35 //
36 // This value stems from the definition in the boost library
37 // And when this case occurs it is due to the fact that boost files
38 // are included before this file. Redefinition might not help in this
39 // case since already parsed code has evaluated to the wrong value.
40 // This would warrrant for d definition that would actually be evaluated
41 // at the location of usage and report a possible confict.
42 // This is left up to a future improvement
43 #elif (ENODATA != 87)
44 #warning ENODATA already defined to a value different from 87 (ENOATRR), refining to fix
45 #endif
46 #undef ENODATA
47 #define ENODATA ENOATTR
48 #endif
49 #ifndef MSG_MORE
50 #define MSG_MORE 0
51 #endif
52
53 #ifndef O_DSYNC
54 #define O_DSYNC O_SYNC
55 #endif
56
57 // Fix clock accuracy
58 #if !defined(CLOCK_MONOTONIC_COARSE)
59 #if defined(CLOCK_MONOTONIC_FAST)
60 #define CLOCK_MONOTONIC_COARSE CLOCK_MONOTONIC_FAST
61 #else
62 #define CLOCK_MONOTONIC_COARSE CLOCK_MONOTONIC
63 #endif
64 #endif
65 #if !defined(CLOCK_REALTIME_COARSE)
66 #if defined(CLOCK_REALTIME_FAST)
67 #define CLOCK_REALTIME_COARSE CLOCK_REALTIME_FAST
68 #else
69 #define CLOCK_REALTIME_COARSE CLOCK_REALTIME
70 #endif
71 #endif
72
73 /* And include the extra required include file */
74 #include <pthread_np.h>
75
76 #endif /* !__FreeBSD__ */
77
78 #if defined(__APPLE__) || defined(__FreeBSD__)
79 /* get PATH_MAX */
80 #include <limits.h>
81
82 #ifndef EREMOTEIO
83 #define EREMOTEIO 121
84 #endif
85
86 #ifndef HOST_NAME_MAX
87 #ifdef MAXHOSTNAMELEN 
88 #define HOST_NAME_MAX MAXHOSTNAMELEN 
89 #else
90 #define HOST_NAME_MAX 255
91 #endif
92 #endif
93
94 #endif /* __APPLE__ */
95
96 /* O_LARGEFILE is not defined/required on OSX/FreeBSD */
97 #ifndef O_LARGEFILE
98 #define O_LARGEFILE 0
99 #endif
100
101 /* Could be relevant for other platforms */
102 #ifndef ERESTART
103 #define ERESTART EINTR
104 #endif
105
106 #ifndef TEMP_FAILURE_RETRY
107 #define TEMP_FAILURE_RETRY(expression) ({     \
108   __typeof(expression) __result;              \
109   do {                                        \
110     __result = (expression);                  \
111   } while (__result == -1 && errno == EINTR); \
112   __result; })
113 #endif
114
115 #ifdef __cplusplus
116 # define VOID_TEMP_FAILURE_RETRY(expression) \
117    static_cast<void>(TEMP_FAILURE_RETRY(expression))
118 #else
119 # define VOID_TEMP_FAILURE_RETRY(expression) \
120    do { (void)TEMP_FAILURE_RETRY(expression); } while (0)
121 #endif
122
123 #if defined(__FreeBSD__) || defined(__APPLE__)
124 #define lseek64(fd, offset, whence) lseek(fd, offset, whence)
125 #endif
126
127 #if defined(__sun) || defined(_AIX)
128 #define LOG_AUTHPRIV    (10<<3)
129 #define LOG_FTP         (11<<3)
130 #define __STRING(x)     "x"
131 #define IFTODT(mode)   (((mode) & 0170000) >> 12)
132 #endif
133
134 #if defined(_AIX)
135 #define MSG_DONTWAIT MSG_NONBLOCK
136 #endif
137
138 #if defined(HAVE_PTHREAD_SETNAME_NP)
139   #if defined(__APPLE__)
140     #define ceph_pthread_setname(thread, name) ({ \
141       int __result = 0;                         \
142       if (thread == pthread_self())             \
143         __result = pthread_setname_np(name);    \
144       __result; })
145   #else
146     #define ceph_pthread_setname pthread_setname_np
147   #endif
148 #elif defined(HAVE_PTHREAD_SET_NAME_NP)
149   /* Fix a small name diff */
150   #define ceph_pthread_setname pthread_set_name_np
151 #else
152   /* compiler warning free success noop */
153   #define ceph_pthread_setname(thread, name) ({ \
154     int __i = 0;                              \
155     __i; })
156 #endif
157
158 #if defined(HAVE_PTHREAD_GETNAME_NP)
159   #define ceph_pthread_getname pthread_getname_np
160 #else
161   /* compiler warning free success noop */
162   #define ceph_pthread_getname(thread, name, len) ({ \
163     if (name != NULL)                              \
164       *name = '\0';                                \
165     0; })
166 #endif
167
168 #endif /* !CEPH_COMPAT_H */