18232165peter/* Licensed to the Apache Software Foundation (ASF) under one or more
28232165peter * contributor license agreements.  See the NOTICE file distributed with
38232165peter * this work for additional information regarding copyright ownership.
48232165peter * The ASF licenses this file to You under the Apache License, Version 2.0
58232165peter * (the "License"); you may not use this file except in compliance with
68232165peter * the License.  You may obtain a copy of the License at
78232165peter *
88232165peter *     http://www.apache.org/licenses/LICENSE-2.0
98232165peter *
108232165peter * Unless required by applicable law or agreed to in writing, software
118232165peter * distributed under the License is distributed on an "AS IS" BASIS,
128232165peter * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
138232165peter * See the License for the specific language governing permissions and
148232165peter * limitations under the License.
158232165peter */
168232165peter
178232165peter#ifndef APR_GENERAL_H
188232165peter#define APR_GENERAL_H
198232165peter
208232165peter/**
218232165peter * @file apr_general.h
228232165peter * This is collection of oddballs that didn't fit anywhere else,
238232165peter * and might move to more appropriate headers with the release
248232165peter * of APR 1.0.
258232165peter * @brief APR Miscellaneous library routines
268232165peter */
278232165peter
288232165peter#include "apr.h"
298232165peter#include "apr_pools.h"
308232165peter#include "apr_errno.h"
318232165peter
328232165peter#if APR_HAVE_SIGNAL_H
338232165peter#include <signal.h>
348232165peter#endif
358232165peter
368232165peter#ifdef __cplusplus
378232165peterextern "C" {
388232165peter#endif /* __cplusplus */
398232165peter
408232165peter/**
418232165peter * @defgroup apr_general Miscellaneous library routines
428232165peter * @ingroup APR
438232165peter * This is collection of oddballs that didn't fit anywhere else,
448232165peter * and might move to more appropriate headers with the release
458232165peter * of APR 1.0.
468232165peter * @{
478232165peter */
488232165peter
498232165peter/** FALSE */
508232165peter#ifndef FALSE
518232165peter#define FALSE 0
528232165peter#endif
538232165peter/** TRUE */
548232165peter#ifndef TRUE
558232165peter#define TRUE (!FALSE)
568232165peter#endif
578232165peter
588232165peter/** a space */
598232165peter#define APR_ASCII_BLANK  '\040'
608232165peter/** a carrige return */
618232165peter#define APR_ASCII_CR     '\015'
628232165peter/** a line feed */
638232165peter#define APR_ASCII_LF     '\012'
648232165peter/** a tab */
658232165peter#define APR_ASCII_TAB    '\011'
668232165peter
678232165peter/** signal numbers typedef */
688232165petertypedef int               apr_signum_t;
698232165peter
708232165peter/**
718232165peter * Finding offsets of elements within structures.
728232165peter * Taken from the X code... they've sweated portability of this stuff
738232165peter * so we don't have to.  Sigh...
748232165peter * @param p_type pointer type name
758232165peter * @param field  data field within the structure pointed to
768232165peter * @return offset
778232165peter */
788232165peter
79ed0c2f8peter#if defined(CRAY) || (defined(__arm) && !(defined(LINUX) || defined(__FreeBSD__)))
808232165peter#ifdef __STDC__
818232165peter#define APR_OFFSET(p_type,field) _Offsetof(p_type,field)
828232165peter#else
838232165peter#ifdef CRAY2
848232165peter#define APR_OFFSET(p_type,field) \
858232165peter        (sizeof(int)*((unsigned int)&(((p_type)NULL)->field)))
868232165peter
878232165peter#else /* !CRAY2 */
888232165peter
898232165peter#define APR_OFFSET(p_type,field) ((unsigned int)&(((p_type)NULL)->field))
908232165peter
918232165peter#endif /* !CRAY2 */
928232165peter#endif /* __STDC__ */
938232165peter#else /* ! (CRAY || __arm) */
948232165peter
958232165peter#define APR_OFFSET(p_type,field) \
968232165peter        ((long) (((char *) (&(((p_type)NULL)->field))) - ((char *) NULL)))
978232165peter
988232165peter#endif /* !CRAY */
998232165peter
1008232165peter/**
1018232165peter * Finding offsets of elements within structures.
1028232165peter * @param s_type structure type name
1038232165peter * @param field  data field within the structure
1048232165peter * @return offset
1058232165peter */
1068232165peter#if defined(offsetof) && !defined(__cplusplus)
1078232165peter#define APR_OFFSETOF(s_type,field) offsetof(s_type,field)
1088232165peter#else
1098232165peter#define APR_OFFSETOF(s_type,field) APR_OFFSET(s_type*,field)
1108232165peter#endif
1118232165peter
1128232165peter#ifndef DOXYGEN
1138232165peter
1148232165peter/* A couple of prototypes for functions in case some platform doesn't
1158232165peter * have it
1168232165peter */
1178232165peter#if (!APR_HAVE_STRCASECMP) && (APR_HAVE_STRICMP)
1188232165peter#define strcasecmp(s1, s2) stricmp(s1, s2)
1198232165peter#elif (!APR_HAVE_STRCASECMP)
1208232165peterint strcasecmp(const char *a, const char *b);
1218232165peter#endif
1228232165peter
1238232165peter#if (!APR_HAVE_STRNCASECMP) && (APR_HAVE_STRNICMP)
1248232165peter#define strncasecmp(s1, s2, n) strnicmp(s1, s2, n)
1258232165peter#elif (!APR_HAVE_STRNCASECMP)
1268232165peterint strncasecmp(const char *a, const char *b, size_t n);
1278232165peter#endif
1288232165peter
1298232165peter#endif
1308232165peter
1318232165peter/**
1328232165peter * Alignment macros
1338232165peter */
1348232165peter
1358232165peter/* APR_ALIGN() is only to be used to align on a power of 2 boundary */
1368232165peter#define APR_ALIGN(size, boundary) \
1378232165peter    (((size) + ((boundary) - 1)) & ~((boundary) - 1))
1388232165peter
1398232165peter/** Default alignment */
1408232165peter#define APR_ALIGN_DEFAULT(size) APR_ALIGN(size, 8)
1418232165peter
1428232165peter
1438232165peter/**
1448232165peter * String and memory functions
1458232165peter */
1468232165peter
1478232165peter/* APR_STRINGIFY is defined here, and also in apr_release.h, so wrap it */
1488232165peter#ifndef APR_STRINGIFY
1498232165peter/** Properly quote a value as a string in the C preprocessor */
1508232165peter#define APR_STRINGIFY(n) APR_STRINGIFY_HELPER(n)
1518232165peter/** Helper macro for APR_STRINGIFY */
1528232165peter#define APR_STRINGIFY_HELPER(n) #n
1538232165peter#endif
1548232165peter
1558232165peter#if (!APR_HAVE_MEMMOVE)
1568232165peter#define memmove(a,b,c) bcopy(b,a,c)
1578232165peter#endif
1588232165peter
1598232165peter#if (!APR_HAVE_MEMCHR)
1608232165petervoid *memchr(const void *s, int c, size_t n);
1618232165peter#endif
1628232165peter
1638232165peter/** @} */
1648232165peter
1658232165peter/**
1668232165peter * @defgroup apr_library Library initialization and termination
1678232165peter * @{
1688232165peter */
1698232165peter
1708232165peter/**
1718232165peter * Setup any APR internal data structures.  This MUST be the first function
1728232165peter * called for any APR library. It is safe to call apr_initialize several
173c88884apeter * times as long as apr_terminate() is called the same number of times.
174c88884apeter * @remark See apr_app_initialize() if this is an application, rather than
1758232165peter * a library consumer of apr.
1768232165peter */
1778232165peterAPR_DECLARE(apr_status_t) apr_initialize(void);
1788232165peter
1798232165peter/**
1808232165peter * Set up an application with normalized argc, argv (and optionally env) in
1818232165peter * order to deal with platform-specific oddities, such as Win32 services,
1828232165peter * code pages and signals.  This must be the first function called for any
1838232165peter * APR program.
1848232165peter * @param argc Pointer to the argc that may be corrected
1858232165peter * @param argv Pointer to the argv that may be corrected
1868232165peter * @param env Pointer to the env that may be corrected, may be NULL
187c88884apeter * @remark See apr_initialize() if this is a library consumer of apr.
188c88884apeter * Otherwise, this call is identical to apr_initialize(), and must be closed
189c88884apeter * with a call to apr_terminate() at the end of program execution.
1908232165peter */
1918232165peterAPR_DECLARE(apr_status_t) apr_app_initialize(int *argc,
1928232165peter                                             char const * const * *argv,
1938232165peter                                             char const * const * *env);
1948232165peter
1958232165peter/**
1968232165peter * Tear down any APR internal data structures which aren't torn down
1978232165peter * automatically. apr_terminate must be called once for every call to
1988232165peter * apr_initialize() or apr_app_initialize().
1998232165peter * @remark An APR program must call this function at termination once it
2008232165peter *         has stopped using APR services.  The APR developers suggest using
201c88884apeter *         @c atexit(apr_terminate) to ensure this is called.  When using APR
202c88884apeter *         from a language other than C that has problems with the calling
203c88884apeter *         convention, use apr_terminate2() instead.
204c88884apeter * @see apr_terminate2
2058232165peter */
2068232165peterAPR_DECLARE_NONSTD(void) apr_terminate(void);
2078232165peter
2088232165peter/**
2098232165peter * Tear down any APR internal data structures which aren't torn down
210c88884apeter * automatically, same as apr_terminate()
211c88884apeter * @remark An APR program must call either the apr_terminate() or apr_terminate2
2128232165peter *         function once it it has finished using APR services.  The APR
213c88884apeter *         developers suggest using @c atexit(apr_terminate) to ensure this is done.
2148232165peter *         apr_terminate2 exists to allow non-c language apps to tear down apr,
215c88884apeter *         while apr_terminate() is recommended from c language applications.
2168232165peter */
2178232165peterAPR_DECLARE(void) apr_terminate2(void);
2188232165peter
2198232165peter/** @} */
2208232165peter
2218232165peter/**
2228232165peter * @defgroup apr_random Random Functions
2238232165peter * @{
2248232165peter */
2258232165peter
2268232165peter#if APR_HAS_RANDOM || defined(DOXYGEN)
2278232165peter
2288232165peter/* TODO: I'm not sure this is the best place to put this prototype...*/
2298232165peter/**
2308232165peter * Generate random bytes.
2318232165peter * @param buf Buffer to fill with random bytes
2328232165peter * @param length Length of buffer in bytes
2338232165peter */
2348232165peterAPR_DECLARE(apr_status_t) apr_generate_random_bytes(unsigned char * buf,
2358232165peter                                                    apr_size_t length);
2368232165peter
2378232165peter#endif
2388232165peter/** @} */
2398232165peter
2408232165peter#ifdef __cplusplus
2418232165peter}
2428232165peter#endif
2438232165peter
2448232165peter#endif  /* ! APR_GENERAL_H */
245