apr_general.inc 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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. {$ifndef DOXYGEN}
  83. { A couple of prototypes for functions in case some platform doesn't
  84. * have it
  85. }
  86. {#if (!APR_HAVE_STRCASECMP) && (APR_HAVE_STRICMP)
  87. #define strcasecmp(s1, s2) stricmp(s1, s2)
  88. #elif (!APR_HAVE_STRCASECMP)
  89. int strcasecmp(const char *a, const char *b);
  90. #endif
  91. #if (!APR_HAVE_STRNCASECMP) && (APR_HAVE_STRNICMP)
  92. #define strncasecmp(s1, s2, n) strnicmp(s1, s2, n)
  93. #elif (!APR_HAVE_STRNCASECMP)
  94. int strncasecmp(const char *a, const char *b, size_t n);
  95. #endif}
  96. {$endif}
  97. {
  98. * Alignment macros
  99. }
  100. { APR_ALIGN() is only to be used to align on a power of 2 boundary }
  101. {#define APR_ALIGN(size, boundary) \
  102. (((size) + ((boundary) - 1)) & ~((boundary) - 1))}
  103. { Default alignment }
  104. //#define APR_ALIGN_DEFAULT(size) APR_ALIGN(size, 8)
  105. {
  106. * String and memory functions
  107. }
  108. { APR_STRINGIFY is defined here, and also in apr_release.h, so wrap it }
  109. {$ifndef APR_STRINGIFY}
  110. { Properly quote a value as a string in the C preprocessor }
  111. //#define APR_STRINGIFY(n) APR_STRINGIFY_HELPER(n)
  112. { Helper macro for APR_STRINGIFY }
  113. {#define APR_STRINGIFY_HELPER(n) #n}
  114. {$endif}
  115. {#if (!APR_HAVE_MEMMOVE)
  116. #define memmove(a,b,c) bcopy(b,a,c)
  117. #endif
  118. #if (!APR_HAVE_MEMCHR)
  119. void *memchr(const void *s, int c, size_t n);
  120. #endif}
  121. {
  122. * @defgroup apr_library Library initialization and termination
  123. }
  124. {
  125. * Setup any APR internal data structures. This MUST be the first function
  126. * called for any APR library.
  127. * @remark See apr_app_initialize if this is an application, rather than
  128. * a library consumer of apr.
  129. }
  130. function apr_initialize: apr_status_t;
  131. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  132. external LibAPR name LibNamePrefix + 'apr_initialize' + LibSuff0;
  133. {
  134. * Set up an application with normalized argc, argv (and optionally env) in
  135. * order to deal with platform-specific oddities, such as Win32 services,
  136. * code pages and signals. This must be the first function called for any
  137. * APR program.
  138. * @param argc Pointer to the argc that may be corrected
  139. * @param argv Pointer to the argv that may be corrected
  140. * @param env Pointer to the env that may be corrected, may be NULL
  141. * @remark See apr_initialize if this is a library consumer of apr.
  142. * Otherwise, this call is identical to apr_initialize, and must be closed
  143. * with a call to apr_terminate at the end of program execution.
  144. }
  145. function apr_app_initialize(argc: PInteger; argv, env: PPChar): apr_status_t;
  146. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  147. external LibAPR name LibNamePrefix + 'apr_app_initialize' + LibSuff12;
  148. {
  149. * Tear down any APR internal data structures which aren't torn down
  150. * automatically.
  151. * @remark An APR program must call this function at termination once it
  152. * has stopped using APR services. The APR developers suggest using
  153. * atexit to ensure this is called. When using APR from a language
  154. * other than C that has problems with the calling convention, use
  155. * apr_terminate2() instead.
  156. }
  157. procedure apr_terminate;
  158. cdecl; external LibAPR name 'apr_terminate';
  159. {
  160. * Tear down any APR internal data structures which aren't torn down
  161. * automatically, same as apr_terminate
  162. * @remark An APR program must call either the apr_terminate or apr_terminate2
  163. * function once it it has finished using APR services. The APR
  164. * developers suggest using atexit(apr_terminate) to ensure this is done.
  165. * apr_terminate2 exists to allow non-c language apps to tear down apr,
  166. * while apr_terminate is recommended from c language applications.
  167. }
  168. procedure apr_terminate2;
  169. cdecl; external LibAPR name LibNamePrefix + 'apr_terminate2' + LibSuff0;
  170. {
  171. * @defgroup apr_random Random Functions
  172. }
  173. {$if defined(APR_HAS_RANDOM) or defined(DOXYGEN)}
  174. { TODO: I'm not sure this is the best place to put this prototype...}
  175. {
  176. * Generate random bytes.
  177. * @param buf Buffer to fill with random bytes
  178. * @param length Length of buffer in bytes (becomes apr_size_t in APR 1.0)
  179. }
  180. function apr_generate_random_bytes(buf: PChar; length: Integer): apr_status_t;
  181. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  182. external LibAPR name LibNamePrefix + 'apr_generate_random_bytes' + LibSuff8;
  183. {$endif}