has.cc 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
  2. *
  3. * Data Differential YATL (i.e. libtest) library
  4. *
  5. * Copyright (C) 2012 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. #include <config.h>
  37. #include <libtest/common.h>
  38. #include <cstdlib>
  39. #include <unistd.h>
  40. namespace libtest {
  41. bool has_libmemcached(void)
  42. {
  43. if (HAVE_LIBMEMCACHED)
  44. {
  45. return true;
  46. }
  47. return false;
  48. }
  49. bool has_libdrizzle(void)
  50. {
  51. if (HAVE_LIBDRIZZLE)
  52. {
  53. return true;
  54. }
  55. return false;
  56. }
  57. bool has_postgres_support(void)
  58. {
  59. if (getenv("POSTGES_IS_RUNNING_AND_SETUP"))
  60. {
  61. if (HAVE_LIBPQ)
  62. {
  63. return true;
  64. }
  65. }
  66. return false;
  67. }
  68. bool has_gearmand()
  69. {
  70. if (HAVE_GEARMAND_BINARY)
  71. {
  72. std::stringstream arg_buffer;
  73. if (getenv("PWD") and strcmp(MEMCACHED_BINARY, "gearmand/gearmand") == 0)
  74. {
  75. arg_buffer << getenv("PWD");
  76. arg_buffer << "/";
  77. }
  78. arg_buffer << GEARMAND_BINARY;
  79. if (access(arg_buffer.str().c_str(), X_OK) == 0)
  80. {
  81. return true;
  82. }
  83. }
  84. return false;
  85. }
  86. bool has_drizzled()
  87. {
  88. if (HAVE_DRIZZLED_BINARY)
  89. {
  90. if (access(DRIZZLED_BINARY, X_OK) == 0)
  91. {
  92. return true;
  93. }
  94. }
  95. return false;
  96. }
  97. bool has_mysqld()
  98. {
  99. #if defined(HAVE_MYSQL_BUILD) && HAVE_MYSQL_BUILD
  100. if (HAVE_MYSQL_BUILD)
  101. {
  102. if (access(HAVE_MYSQL, X_OK) == 0)
  103. {
  104. return true;
  105. }
  106. }
  107. #endif
  108. return false;
  109. }
  110. bool has_memcached()
  111. {
  112. if (HAVE_MEMCACHED_BINARY)
  113. {
  114. std::stringstream arg_buffer;
  115. if (getenv("PWD") and strcmp(MEMCACHED_BINARY, "memcached/memcached") == 0)
  116. {
  117. arg_buffer << getenv("PWD");
  118. arg_buffer << "/";
  119. }
  120. arg_buffer << MEMCACHED_BINARY;
  121. if (access(arg_buffer.str().c_str(), X_OK) == 0)
  122. {
  123. return true;
  124. }
  125. }
  126. return false;
  127. }
  128. bool has_memcached_sasl()
  129. {
  130. #if defined(HAVE_MEMCACHED_SASL_BINARY) && HAVE_MEMCACHED_SASL_BINARY
  131. if (HAVE_MEMCACHED_SASL_BINARY)
  132. {
  133. if (access(MEMCACHED_SASL_BINARY, X_OK) == 0)
  134. {
  135. return true;
  136. }
  137. }
  138. #endif
  139. return false;
  140. }
  141. } // namespace libtest