cmake
[m6w6/libmemcached] / libtest / has.cc
1 /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
2 *
3 * Data Differential YATL (i.e. libtest) library
4 *
5 * Copyright (C) 2012-2013 Data Differential, http://datadifferential.com/
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are
9 * met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 *
14 * * Redistributions in binary form must reproduce the above
15 * copyright notice, this list of conditions and the following disclaimer
16 * in the documentation and/or other materials provided with the
17 * distribution.
18 *
19 * * The names of its contributors may not be used to endorse or
20 * promote products derived from this software without specific prior
21 * written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 *
35 */
36
37 #include "libtest/yatlcon.h"
38 #include <libtest/common.h>
39
40 #include <cstdio>
41 #include <cstdlib>
42 #include <unistd.h>
43
44 namespace libtest {
45
46 bool has_libmemcached_sasl(void)
47 {
48 return false;
49 }
50
51 bool has_libmemcached(void)
52 {
53 #if defined(HAVE_LIBMEMCACHED) && HAVE_LIBMEMCACHED
54 if (HAVE_LIBMEMCACHED)
55 {
56 return true;
57 }
58 #endif
59
60 return false;
61 }
62
63 bool has_libdrizzle(void)
64 {
65 #if defined(HAVE_LIBDRIZZLE) && HAVE_LIBDRIZZLE
66 if (HAVE_LIBDRIZZLE)
67 {
68 return true;
69 }
70 #endif
71
72 return false;
73 }
74
75 bool has_postgres_support(void)
76 {
77 char *getenv_ptr;
78 if (bool((getenv_ptr= getenv("POSTGRES_IS_RUNNING_AND_SETUP"))))
79 {
80 (void)(getenv_ptr);
81 #if defined(HAVE_LIBPQ) && HAVE_LIBPQ
82 if (HAVE_LIBPQ)
83 {
84 return true;
85 }
86 #endif
87 }
88
89 return false;
90 }
91
92
93 bool has_gearmand()
94 {
95 #if defined(GEARMAND_BINARY) && defined(HAVE_GEARMAND_BINARY) && HAVE_GEARMAND_BINARY
96 if (HAVE_GEARMAND_BINARY)
97 {
98 std::stringstream arg_buffer;
99
100 char *getenv_ptr;
101 if (bool((getenv_ptr= getenv("PWD"))) and
102 ((strcmp(GEARMAND_BINARY, "./gearmand/gearmand") == 0) or (strcmp(GEARMAND_BINARY, "gearmand/gearmand") == 0)))
103 {
104 arg_buffer << getenv_ptr;
105 arg_buffer << "/";
106 }
107 arg_buffer << GEARMAND_BINARY;
108
109 if (access(arg_buffer.str().c_str(), X_OK) == 0)
110 {
111 return true;
112 }
113 }
114 #endif
115
116 return false;
117 }
118
119 bool has_drizzled()
120 {
121 #if defined(DRIZZLED_BINARY) && defined(HAVE_DRIZZLED_BINARY) && HAVE_DRIZZLED_BINARY
122 if (HAVE_DRIZZLED_BINARY)
123 {
124 if (access(DRIZZLED_BINARY, X_OK) == 0)
125 {
126 return true;
127 }
128 }
129 #endif
130
131 return false;
132 }
133
134 bool has_mysqld()
135 {
136 #if defined(MYSQLD_BINARY) && defined(HAVE_MYSQLD_BUILD) && HAVE_MYSQLD_BUILD
137 if (HAVE_MYSQLD_BUILD)
138 {
139 if (access(MYSQLD_BINARY, X_OK) == 0)
140 {
141 return true;
142 }
143 }
144 #endif
145
146 return false;
147 }
148
149 static char memcached_binary_path[FILENAME_MAX];
150
151 static void initialize_memcached_binary_path()
152 {
153 memcached_binary_path[0]= 0;
154
155 #if defined(MEMCACHED_BINARY) && defined(HAVE_MEMCACHED_BINARY) && HAVE_MEMCACHED_BINARY
156 if (HAVE_MEMCACHED_BINARY)
157 {
158 std::stringstream arg_buffer;
159
160 char *getenv_ptr;
161 if (bool((getenv_ptr= getenv("PWD"))) and strcmp(MEMCACHED_BINARY, "memcached/memcached") == 0)
162 {
163 arg_buffer << getenv_ptr;
164 arg_buffer << "/";
165 }
166 arg_buffer << MEMCACHED_BINARY;
167
168 if (access(arg_buffer.str().c_str(), X_OK) == 0)
169 {
170 strncpy(memcached_binary_path, arg_buffer.str().c_str(), FILENAME_MAX-1);
171 }
172 }
173 #endif
174 }
175
176 static pthread_once_t memcached_binary_once= PTHREAD_ONCE_INIT;
177 static void initialize_memcached_binary(void)
178 {
179 int ret;
180 if ((ret= pthread_once(&memcached_binary_once, initialize_memcached_binary_path)) != 0)
181 {
182 FATAL(strerror(ret));
183 }
184 }
185
186 bool has_memcached()
187 {
188 initialize_memcached_binary();
189
190 if (memcached_binary_path[0] and (strlen(memcached_binary_path) > 0))
191 {
192 return true;
193 }
194
195 return false;
196 }
197
198 const char* memcached_binary()
199 {
200 initialize_memcached_binary();
201
202 if (memcached_binary_path[0])
203 {
204 return memcached_binary_path;
205 }
206
207 return NULL;
208 }
209
210 const char *gearmand_binary()
211 {
212 #if defined(GEARMAND_BINARY)
213 return GEARMAND_BINARY;
214 #else
215 return NULL;
216 #endif
217 }
218
219 const char *drizzled_binary()
220 {
221 #if defined(DRIZZLED_BINARY)
222 return DRIZZLED_BINARY;
223 #else
224 return NULL;
225 #endif
226 }
227
228 } // namespace libtest