fspr_general.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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 fspr_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 "fspr.h"
  26. #include "fspr_pools.h"
  27. #include "fspr_errno.h"
  28. #if !defined(NSIG) && !defined(_ANSI_SOURCE) && defined(_DARWIN_C_SOURCE)
  29. #define NSIG __DARWIN_NSIG
  30. #endif
  31. #if APR_HAVE_SIGNAL_H
  32. #include <signal.h>
  33. #endif
  34. #ifdef __cplusplus
  35. extern "C" {
  36. #endif /* __cplusplus */
  37. /**
  38. * @defgroup fspr_general Miscellaneous library routines
  39. * @ingroup APR
  40. * This is collection of oddballs that didn't fit anywhere else,
  41. * and might move to more appropriate headers with the release
  42. * of APR 1.0.
  43. * @{
  44. */
  45. /** FALSE */
  46. #ifndef FALSE
  47. #define FALSE 0
  48. #endif
  49. /** TRUE */
  50. #ifndef TRUE
  51. #define TRUE (!FALSE)
  52. #endif
  53. /** a space */
  54. #define APR_ASCII_BLANK '\040'
  55. /** a carrige return */
  56. #define APR_ASCII_CR '\015'
  57. /** a line feed */
  58. #define APR_ASCII_LF '\012'
  59. /** a tab */
  60. #define APR_ASCII_TAB '\011'
  61. /** signal numbers typedef */
  62. typedef int fspr_signum_t;
  63. /**
  64. * Finding offsets of elements within structures.
  65. * Taken from the X code... they've sweated portability of this stuff
  66. * so we don't have to. Sigh...
  67. * @param p_type pointer type name
  68. * @param field data field within the structure pointed to
  69. * @return offset
  70. */
  71. #if defined(CRAY) || (defined(__arm) && !(defined(LINUX) || defined(__FreeBSD__)))
  72. #ifdef __STDC__
  73. #define APR_OFFSET(p_type,field) _Offsetof(p_type,field)
  74. #else
  75. #ifdef CRAY2
  76. #define APR_OFFSET(p_type,field) \
  77. (sizeof(int)*((unsigned int)&(((p_type)NULL)->field)))
  78. #else /* !CRAY2 */
  79. #define APR_OFFSET(p_type,field) ((unsigned int)&(((p_type)NULL)->field))
  80. #endif /* !CRAY2 */
  81. #endif /* __STDC__ */
  82. #else /* ! (CRAY || __arm) */
  83. #define APR_OFFSET(p_type,field) \
  84. ((long) (((char *) (&(((p_type)NULL)->field))) - ((char *) NULL)))
  85. #endif /* !CRAY */
  86. /**
  87. * Finding offsets of elements within structures.
  88. * @param s_type structure type name
  89. * @param field data field within the structure
  90. * @return offset
  91. */
  92. #if defined(offsetof) && !defined(__cplusplus)
  93. #define APR_OFFSETOF(s_type,field) offsetof(s_type,field)
  94. #else
  95. #define APR_OFFSETOF(s_type,field) APR_OFFSET(s_type*,field)
  96. #endif
  97. #ifndef DOXYGEN
  98. /* A couple of prototypes for functions in case some platform doesn't
  99. * have it
  100. */
  101. #if (!APR_HAVE_STRCASECMP) && (APR_HAVE_STRICMP)
  102. #define strcasecmp(s1, s2) stricmp(s1, s2)
  103. #elif (!APR_HAVE_STRCASECMP)
  104. int strcasecmp(const char *a, const char *b);
  105. #endif
  106. #if (!APR_HAVE_STRNCASECMP) && (APR_HAVE_STRNICMP)
  107. #define strncasecmp(s1, s2, n) strnicmp(s1, s2, n)
  108. #elif (!APR_HAVE_STRNCASECMP)
  109. int strncasecmp(const char *a, const char *b, size_t n);
  110. #endif
  111. #endif
  112. /**
  113. * Alignment macros
  114. */
  115. /* APR_ALIGN() is only to be used to align on a power of 2 boundary */
  116. #define APR_ALIGN(size, boundary) \
  117. (((size) + ((boundary) - 1)) & ~((boundary) - 1))
  118. /** Default alignment */
  119. #define APR_ALIGN_DEFAULT(size) APR_ALIGN(size, 8)
  120. /**
  121. * String and memory functions
  122. */
  123. /* APR_STRINGIFY is defined here, and also in fspr_release.h, so wrap it */
  124. #ifndef APR_STRINGIFY
  125. /** Properly quote a value as a string in the C preprocessor */
  126. #define APR_STRINGIFY(n) APR_STRINGIFY_HELPER(n)
  127. /** Helper macro for APR_STRINGIFY */
  128. #define APR_STRINGIFY_HELPER(n) #n
  129. #endif
  130. #if (!APR_HAVE_MEMMOVE)
  131. #define memmove(a,b,c) bcopy(b,a,c)
  132. #endif
  133. #if (!APR_HAVE_MEMCHR)
  134. void *memchr(const void *s, int c, size_t n);
  135. #endif
  136. /** @} */
  137. /**
  138. * @defgroup fspr_library Library initialization and termination
  139. * @{
  140. */
  141. /**
  142. * Setup any APR internal data structures. This MUST be the first function
  143. * called for any APR library.
  144. * @remark See fspr_app_initialize if this is an application, rather than
  145. * a library consumer of apr.
  146. */
  147. APR_DECLARE(fspr_status_t) fspr_initialize(void);
  148. /**
  149. * Set up an application with normalized argc, argv (and optionally env) in
  150. * order to deal with platform-specific oddities, such as Win32 services,
  151. * code pages and signals. This must be the first function called for any
  152. * APR program.
  153. * @param argc Pointer to the argc that may be corrected
  154. * @param argv Pointer to the argv that may be corrected
  155. * @param env Pointer to the env that may be corrected, may be NULL
  156. * @remark See fspr_initialize if this is a library consumer of apr.
  157. * Otherwise, this call is identical to fspr_initialize, and must be closed
  158. * with a call to fspr_terminate at the end of program execution.
  159. */
  160. APR_DECLARE(fspr_status_t) fspr_app_initialize(int *argc,
  161. char const * const * *argv,
  162. char const * const * *env);
  163. /**
  164. * Tear down any APR internal data structures which aren't torn down
  165. * automatically.
  166. * @remark An APR program must call this function at termination once it
  167. * has stopped using APR services. The APR developers suggest using
  168. * atexit to ensure this is called. When using APR from a language
  169. * other than C that has problems with the calling convention, use
  170. * fspr_terminate2() instead.
  171. */
  172. APR_DECLARE_NONSTD(void) fspr_terminate(void);
  173. /**
  174. * Tear down any APR internal data structures which aren't torn down
  175. * automatically, same as fspr_terminate
  176. * @remark An APR program must call either the fspr_terminate or fspr_terminate2
  177. * function once it it has finished using APR services. The APR
  178. * developers suggest using atexit(fspr_terminate) to ensure this is done.
  179. * fspr_terminate2 exists to allow non-c language apps to tear down apr,
  180. * while fspr_terminate is recommended from c language applications.
  181. */
  182. APR_DECLARE(void) fspr_terminate2(void);
  183. /** @} */
  184. /**
  185. * @defgroup fspr_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(fspr_status_t) fspr_generate_random_bytes(unsigned char * buf,
  196. fspr_size_t length);
  197. #endif
  198. /** @} */
  199. #ifdef __cplusplus
  200. }
  201. #endif
  202. #endif /* ! APR_GENERAL_H */