apr_general.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. /* Licensed to the Apache Software Foundation (ASF) under one or more
  2. * contributor license agreements. See the NOTICE file distributed with
  3. * this work for additional information regarding copyright ownership.
  4. * The ASF licenses this file to You under the Apache License, Version 2.0
  5. * (the "License"); you may not use this file except in compliance with
  6. * the License. You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef APR_GENERAL_H
  17. #define APR_GENERAL_H
  18. /**
  19. * @file apr_general.h
  20. * This is collection of oddballs that didn't fit anywhere else,
  21. * and might move to more appropriate headers with the release
  22. * of APR 1.0.
  23. * @brief APR Miscellaneous library routines
  24. */
  25. #include "apr.h"
  26. #include "apr_pools.h"
  27. #include "apr_errno.h"
  28. #if APR_HAVE_SIGNAL_H
  29. #include <signal.h>
  30. #endif
  31. #ifdef __cplusplus
  32. extern "C" {
  33. #endif /* __cplusplus */
  34. /**
  35. * @defgroup apr_general Miscellaneous library routines
  36. * @ingroup APR
  37. * This is collection of oddballs that didn't fit anywhere else,
  38. * and might move to more appropriate headers with the release
  39. * of APR 1.0.
  40. * @{
  41. */
  42. /** FALSE */
  43. #ifndef FALSE
  44. #define FALSE 0
  45. #endif
  46. /** TRUE */
  47. #ifndef TRUE
  48. #define TRUE (!FALSE)
  49. #endif
  50. /** a space */
  51. #define APR_ASCII_BLANK '\040'
  52. /** a carrige return */
  53. #define APR_ASCII_CR '\015'
  54. /** a line feed */
  55. #define APR_ASCII_LF '\012'
  56. /** a tab */
  57. #define APR_ASCII_TAB '\011'
  58. /** signal numbers typedef */
  59. typedef int apr_signum_t;
  60. /**
  61. * Finding offsets of elements within structures.
  62. * Taken from the X code... they've sweated portability of this stuff
  63. * so we don't have to. Sigh...
  64. * @param p_type pointer type name
  65. * @param field data field within the structure pointed to
  66. * @return offset
  67. */
  68. #if defined(CRAY) || (defined(__arm) && !(defined(LINUX) || defined(__FreeBSD__)))
  69. #ifdef __STDC__
  70. #define APR_OFFSET(p_type,field) _Offsetof(p_type,field)
  71. #else
  72. #ifdef CRAY2
  73. #define APR_OFFSET(p_type,field) \
  74. (sizeof(int)*((unsigned int)&(((p_type)NULL)->field)))
  75. #else /* !CRAY2 */
  76. #define APR_OFFSET(p_type,field) ((unsigned int)&(((p_type)NULL)->field))
  77. #endif /* !CRAY2 */
  78. #endif /* __STDC__ */
  79. #else /* ! (CRAY || __arm) */
  80. #define APR_OFFSET(p_type,field) \
  81. ((long) (((char *) (&(((p_type)NULL)->field))) - ((char *) NULL)))
  82. #endif /* !CRAY */
  83. /**
  84. * Finding offsets of elements within structures.
  85. * @param s_type structure type name
  86. * @param field data field within the structure
  87. * @return offset
  88. */
  89. #if defined(offsetof) && !defined(__cplusplus)
  90. #define APR_OFFSETOF(s_type,field) offsetof(s_type,field)
  91. #else
  92. #define APR_OFFSETOF(s_type,field) APR_OFFSET(s_type*,field)
  93. #endif
  94. #ifndef DOXYGEN
  95. /* A couple of prototypes for functions in case some platform doesn't
  96. * have it
  97. */
  98. #if (!APR_HAVE_STRCASECMP) && (APR_HAVE_STRICMP)
  99. #define strcasecmp(s1, s2) stricmp(s1, s2)
  100. #elif (!APR_HAVE_STRCASECMP)
  101. int strcasecmp(const char *a, const char *b);
  102. #endif
  103. #if (!APR_HAVE_STRNCASECMP) && (APR_HAVE_STRNICMP)
  104. #define strncasecmp(s1, s2, n) strnicmp(s1, s2, n)
  105. #elif (!APR_HAVE_STRNCASECMP)
  106. int strncasecmp(const char *a, const char *b, size_t n);
  107. #endif
  108. #endif
  109. /**
  110. * Alignment macros
  111. */
  112. /* APR_ALIGN() is only to be used to align on a power of 2 boundary */
  113. #define APR_ALIGN(size, boundary) \
  114. (((size) + ((boundary) - 1)) & ~((boundary) - 1))
  115. /** Default alignment */
  116. #define APR_ALIGN_DEFAULT(size) APR_ALIGN(size, 8)
  117. /**
  118. * String and memory functions
  119. */
  120. /* APR_STRINGIFY is defined here, and also in apr_release.h, so wrap it */
  121. #ifndef APR_STRINGIFY
  122. /** Properly quote a value as a string in the C preprocessor */
  123. #define APR_STRINGIFY(n) APR_STRINGIFY_HELPER(n)
  124. /** Helper macro for APR_STRINGIFY */
  125. #define APR_STRINGIFY_HELPER(n) #n
  126. #endif
  127. #if (!APR_HAVE_MEMMOVE)
  128. #define memmove(a,b,c) bcopy(b,a,c)
  129. #endif
  130. #if (!APR_HAVE_MEMCHR)
  131. void *memchr(const void *s, int c, size_t n);
  132. #endif
  133. /** @} */
  134. /**
  135. * @defgroup apr_library Library initialization and termination
  136. * @{
  137. */
  138. /**
  139. * Setup any APR internal data structures. This MUST be the first function
  140. * called for any APR library. It is safe to call apr_initialize several
  141. * times as long as apr_terminate() is called the same number of times.
  142. * @remark See apr_app_initialize() if this is an application, rather than
  143. * a library consumer of apr.
  144. */
  145. APR_DECLARE(apr_status_t) apr_initialize(void);
  146. /**
  147. * Set up an application with normalized argc, argv (and optionally env) in
  148. * order to deal with platform-specific oddities, such as Win32 services,
  149. * code pages and signals. This must be the first function called for any
  150. * APR program.
  151. * @param argc Pointer to the argc that may be corrected
  152. * @param argv Pointer to the argv that may be corrected
  153. * @param env Pointer to the env that may be corrected, may be NULL
  154. * @remark See apr_initialize() if this is a library consumer of apr.
  155. * Otherwise, this call is identical to apr_initialize(), and must be closed
  156. * with a call to apr_terminate() at the end of program execution.
  157. */
  158. APR_DECLARE(apr_status_t) apr_app_initialize(int *argc,
  159. char const * const * *argv,
  160. char const * const * *env);
  161. /**
  162. * Tear down any APR internal data structures which aren't torn down
  163. * automatically. apr_terminate must be called once for every call to
  164. * apr_initialize() or apr_app_initialize().
  165. * @remark An APR program must call this function at termination once it
  166. * has stopped using APR services. The APR developers suggest using
  167. * @c atexit(apr_terminate) to ensure this is called. When using APR
  168. * from a language other than C that has problems with the calling
  169. * convention, use apr_terminate2() instead.
  170. * @see apr_terminate2
  171. */
  172. APR_DECLARE_NONSTD(void) apr_terminate(void);
  173. /**
  174. * Tear down any APR internal data structures which aren't torn down
  175. * automatically, same as apr_terminate()
  176. * @remark An APR program must call either the apr_terminate() or apr_terminate2
  177. * function once it it has finished using APR services. The APR
  178. * developers suggest using @c atexit(apr_terminate) to ensure this is done.
  179. * apr_terminate2 exists to allow non-c language apps to tear down apr,
  180. * while apr_terminate() is recommended from c language applications.
  181. */
  182. APR_DECLARE(void) apr_terminate2(void);
  183. /** @} */
  184. /**
  185. * @defgroup apr_random Random Functions
  186. * @{
  187. */
  188. #if APR_HAS_RANDOM || defined(DOXYGEN)
  189. /* TODO: I'm not sure this is the best place to put this prototype...*/
  190. /**
  191. * Generate random bytes.
  192. * @param buf Buffer to fill with random bytes
  193. * @param length Length of buffer in bytes
  194. */
  195. APR_DECLARE(apr_status_t) apr_generate_random_bytes(unsigned char * buf,
  196. apr_size_t length);
  197. #endif
  198. /** @} */
  199. #ifdef __cplusplus
  200. }
  201. #endif
  202. #endif /* ! APR_GENERAL_H */