1251875Speter/* Licensed to the Apache Software Foundation (ASF) under one or more 2251875Speter * contributor license agreements. See the NOTICE file distributed with 3251875Speter * this work for additional information regarding copyright ownership. 4251875Speter * The ASF licenses this file to You under the Apache License, Version 2.0 5251875Speter * (the "License"); you may not use this file except in compliance with 6251875Speter * the License. You may obtain a copy of the License at 7251875Speter * 8251875Speter * http://www.apache.org/licenses/LICENSE-2.0 9251875Speter * 10251875Speter * Unless required by applicable law or agreed to in writing, software 11251875Speter * distributed under the License is distributed on an "AS IS" BASIS, 12251875Speter * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13251875Speter * See the License for the specific language governing permissions and 14251875Speter * limitations under the License. 15251875Speter */ 16251875Speter 17251875Speter#ifndef APR_GENERAL_H 18251875Speter#define APR_GENERAL_H 19251875Speter 20251875Speter/** 21251875Speter * @file apr_general.h 22251875Speter * This is collection of oddballs that didn't fit anywhere else, 23251875Speter * and might move to more appropriate headers with the release 24251875Speter * of APR 1.0. 25251875Speter * @brief APR Miscellaneous library routines 26251875Speter */ 27251875Speter 28251875Speter#include "apr.h" 29251875Speter#include "apr_pools.h" 30251875Speter#include "apr_errno.h" 31251875Speter 32251875Speter#if APR_HAVE_SIGNAL_H 33251875Speter#include <signal.h> 34251875Speter#endif 35251875Speter 36251875Speter#ifdef __cplusplus 37251875Speterextern "C" { 38251875Speter#endif /* __cplusplus */ 39251875Speter 40251875Speter/** 41251875Speter * @defgroup apr_general Miscellaneous library routines 42251875Speter * @ingroup APR 43251875Speter * This is collection of oddballs that didn't fit anywhere else, 44251875Speter * and might move to more appropriate headers with the release 45251875Speter * of APR 1.0. 46251875Speter * @{ 47251875Speter */ 48251875Speter 49251875Speter/** FALSE */ 50251875Speter#ifndef FALSE 51251875Speter#define FALSE 0 52251875Speter#endif 53251875Speter/** TRUE */ 54251875Speter#ifndef TRUE 55251875Speter#define TRUE (!FALSE) 56251875Speter#endif 57251875Speter 58251875Speter/** a space */ 59251875Speter#define APR_ASCII_BLANK '\040' 60251875Speter/** a carrige return */ 61251875Speter#define APR_ASCII_CR '\015' 62251875Speter/** a line feed */ 63251875Speter#define APR_ASCII_LF '\012' 64251875Speter/** a tab */ 65251875Speter#define APR_ASCII_TAB '\011' 66251875Speter 67251875Speter/** signal numbers typedef */ 68251875Spetertypedef int apr_signum_t; 69251875Speter 70251875Speter/** 71251875Speter * Finding offsets of elements within structures. 72251875Speter * Taken from the X code... they've sweated portability of this stuff 73251875Speter * so we don't have to. Sigh... 74251875Speter * @param p_type pointer type name 75251875Speter * @param field data field within the structure pointed to 76251875Speter * @return offset 77251875Speter */ 78251875Speter 79253734Speter#if defined(CRAY) || (defined(__arm) && !(defined(LINUX) || defined(__FreeBSD__))) 80251875Speter#ifdef __STDC__ 81251875Speter#define APR_OFFSET(p_type,field) _Offsetof(p_type,field) 82251875Speter#else 83251875Speter#ifdef CRAY2 84251875Speter#define APR_OFFSET(p_type,field) \ 85251875Speter (sizeof(int)*((unsigned int)&(((p_type)NULL)->field))) 86251875Speter 87251875Speter#else /* !CRAY2 */ 88251875Speter 89251875Speter#define APR_OFFSET(p_type,field) ((unsigned int)&(((p_type)NULL)->field)) 90251875Speter 91251875Speter#endif /* !CRAY2 */ 92251875Speter#endif /* __STDC__ */ 93251875Speter#else /* ! (CRAY || __arm) */ 94251875Speter 95251875Speter#define APR_OFFSET(p_type,field) \ 96251875Speter ((long) (((char *) (&(((p_type)NULL)->field))) - ((char *) NULL))) 97251875Speter 98251875Speter#endif /* !CRAY */ 99251875Speter 100251875Speter/** 101251875Speter * Finding offsets of elements within structures. 102251875Speter * @param s_type structure type name 103251875Speter * @param field data field within the structure 104251875Speter * @return offset 105251875Speter */ 106251875Speter#if defined(offsetof) && !defined(__cplusplus) 107251875Speter#define APR_OFFSETOF(s_type,field) offsetof(s_type,field) 108251875Speter#else 109251875Speter#define APR_OFFSETOF(s_type,field) APR_OFFSET(s_type*,field) 110251875Speter#endif 111251875Speter 112251875Speter#ifndef DOXYGEN 113251875Speter 114251875Speter/* A couple of prototypes for functions in case some platform doesn't 115251875Speter * have it 116251875Speter */ 117251875Speter#if (!APR_HAVE_STRCASECMP) && (APR_HAVE_STRICMP) 118251875Speter#define strcasecmp(s1, s2) stricmp(s1, s2) 119251875Speter#elif (!APR_HAVE_STRCASECMP) 120251875Speterint strcasecmp(const char *a, const char *b); 121251875Speter#endif 122251875Speter 123251875Speter#if (!APR_HAVE_STRNCASECMP) && (APR_HAVE_STRNICMP) 124251875Speter#define strncasecmp(s1, s2, n) strnicmp(s1, s2, n) 125251875Speter#elif (!APR_HAVE_STRNCASECMP) 126251875Speterint strncasecmp(const char *a, const char *b, size_t n); 127251875Speter#endif 128251875Speter 129251875Speter#endif 130251875Speter 131251875Speter/** 132251875Speter * Alignment macros 133251875Speter */ 134251875Speter 135251875Speter/* APR_ALIGN() is only to be used to align on a power of 2 boundary */ 136251875Speter#define APR_ALIGN(size, boundary) \ 137251875Speter (((size) + ((boundary) - 1)) & ~((boundary) - 1)) 138251875Speter 139251875Speter/** Default alignment */ 140251875Speter#define APR_ALIGN_DEFAULT(size) APR_ALIGN(size, 8) 141251875Speter 142251875Speter 143251875Speter/** 144251875Speter * String and memory functions 145251875Speter */ 146251875Speter 147251875Speter/* APR_STRINGIFY is defined here, and also in apr_release.h, so wrap it */ 148251875Speter#ifndef APR_STRINGIFY 149251875Speter/** Properly quote a value as a string in the C preprocessor */ 150251875Speter#define APR_STRINGIFY(n) APR_STRINGIFY_HELPER(n) 151251875Speter/** Helper macro for APR_STRINGIFY */ 152251875Speter#define APR_STRINGIFY_HELPER(n) #n 153251875Speter#endif 154251875Speter 155251875Speter#if (!APR_HAVE_MEMMOVE) 156251875Speter#define memmove(a,b,c) bcopy(b,a,c) 157251875Speter#endif 158251875Speter 159251875Speter#if (!APR_HAVE_MEMCHR) 160251875Spetervoid *memchr(const void *s, int c, size_t n); 161251875Speter#endif 162251875Speter 163251875Speter/** @} */ 164251875Speter 165251875Speter/** 166251875Speter * @defgroup apr_library Library initialization and termination 167251875Speter * @{ 168251875Speter */ 169251875Speter 170251875Speter/** 171251875Speter * Setup any APR internal data structures. This MUST be the first function 172251875Speter * called for any APR library. It is safe to call apr_initialize several 173362181Sdim * times as long as apr_terminate() is called the same number of times. 174362181Sdim * @remark See apr_app_initialize() if this is an application, rather than 175251875Speter * a library consumer of apr. 176251875Speter */ 177251875SpeterAPR_DECLARE(apr_status_t) apr_initialize(void); 178251875Speter 179251875Speter/** 180251875Speter * Set up an application with normalized argc, argv (and optionally env) in 181251875Speter * order to deal with platform-specific oddities, such as Win32 services, 182251875Speter * code pages and signals. This must be the first function called for any 183251875Speter * APR program. 184251875Speter * @param argc Pointer to the argc that may be corrected 185251875Speter * @param argv Pointer to the argv that may be corrected 186251875Speter * @param env Pointer to the env that may be corrected, may be NULL 187362181Sdim * @remark See apr_initialize() if this is a library consumer of apr. 188362181Sdim * Otherwise, this call is identical to apr_initialize(), and must be closed 189362181Sdim * with a call to apr_terminate() at the end of program execution. 190251875Speter */ 191251875SpeterAPR_DECLARE(apr_status_t) apr_app_initialize(int *argc, 192251875Speter char const * const * *argv, 193251875Speter char const * const * *env); 194251875Speter 195251875Speter/** 196251875Speter * Tear down any APR internal data structures which aren't torn down 197251875Speter * automatically. apr_terminate must be called once for every call to 198251875Speter * apr_initialize() or apr_app_initialize(). 199251875Speter * @remark An APR program must call this function at termination once it 200251875Speter * has stopped using APR services. The APR developers suggest using 201362181Sdim * @c atexit(apr_terminate) to ensure this is called. When using APR 202362181Sdim * from a language other than C that has problems with the calling 203362181Sdim * convention, use apr_terminate2() instead. 204362181Sdim * @see apr_terminate2 205251875Speter */ 206251875SpeterAPR_DECLARE_NONSTD(void) apr_terminate(void); 207251875Speter 208251875Speter/** 209251875Speter * Tear down any APR internal data structures which aren't torn down 210362181Sdim * automatically, same as apr_terminate() 211362181Sdim * @remark An APR program must call either the apr_terminate() or apr_terminate2 212251875Speter * function once it it has finished using APR services. The APR 213362181Sdim * developers suggest using @c atexit(apr_terminate) to ensure this is done. 214251875Speter * apr_terminate2 exists to allow non-c language apps to tear down apr, 215362181Sdim * while apr_terminate() is recommended from c language applications. 216251875Speter */ 217251875SpeterAPR_DECLARE(void) apr_terminate2(void); 218251875Speter 219251875Speter/** @} */ 220251875Speter 221251875Speter/** 222251875Speter * @defgroup apr_random Random Functions 223251875Speter * @{ 224251875Speter */ 225251875Speter 226251875Speter#if APR_HAS_RANDOM || defined(DOXYGEN) 227251875Speter 228251875Speter/* TODO: I'm not sure this is the best place to put this prototype...*/ 229251875Speter/** 230251875Speter * Generate random bytes. 231251875Speter * @param buf Buffer to fill with random bytes 232251875Speter * @param length Length of buffer in bytes 233251875Speter */ 234251875SpeterAPR_DECLARE(apr_status_t) apr_generate_random_bytes(unsigned char * buf, 235251875Speter apr_size_t length); 236251875Speter 237251875Speter#endif 238251875Speter/** @} */ 239251875Speter 240251875Speter#ifdef __cplusplus 241251875Speter} 242251875Speter#endif 243251875Speter 244251875Speter#endif /* ! APR_GENERAL_H */ 245