apr_general.inc 6.9 KB

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