lib/replace/replace.h

説明を見る。
00001 /* 
00002    Unix SMB/CIFS implementation.
00003 
00004    macros to go along with the lib/replace/ portability layer code
00005 
00006    Copyright (C) Andrew Tridgell 2005
00007    Copyright (C) Jelmer Vernooij 2006
00008 
00009      ** NOTE! The following LGPL license applies to the replace
00010      ** library. This does NOT imply that all of Samba is released
00011      ** under the LGPL
00012    
00013    This library is free software; you can redistribute it and/or
00014    modify it under the terms of the GNU Lesser General Public
00015    License as published by the Free Software Foundation; either
00016    version 2 of the License, or (at your option) any later version.
00017 
00018    This library is distributed in the hope that it will be useful,
00019    but WITHOUT ANY WARRANTY; without even the implied warranty of
00020    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00021    Lesser General Public License for more details.
00022 
00023    You should have received a copy of the GNU Lesser General Public
00024    License along with this library; if not, write to the Free Software
00025    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00026 */
00027 
00028 #ifndef _LIBREPLACE_REPLACE_H
00029 #define _LIBREPLACE_REPLACE_H
00030 
00031 #ifndef NO_CONFIG_H
00032 #include "config.h"
00033 #endif
00034 
00035 #ifdef HAVE_STANDARDS_H
00036 #include <standards.h>
00037 #endif
00038 
00039 #include <stdio.h>
00040 #include <stdlib.h>
00041 #include <stdarg.h>
00042 #include <errno.h>
00043 
00044 #if defined(_MSC_VER) || defined(__MINGW32__)
00045 #include "win32_replace.h"
00046 #endif
00047 
00048 #ifdef __COMPAR_FN_T
00049 #define QSORT_CAST (__compar_fn_t)
00050 #endif
00051 
00052 #ifndef QSORT_CAST
00053 #define QSORT_CAST (int (*)(const void *, const void *))
00054 #endif
00055 
00056 #ifdef HAVE_STDINT_H
00057 #include <stdint.h>
00058 /* force off HAVE_INTTYPES_H so that roken doesn't try to include both,
00059    which causes a warning storm on irix */
00060 #undef HAVE_INTTYPES_H
00061 #elif HAVE_INTTYPES_H
00062 #include <inttypes.h>
00063 #endif
00064 
00065 #ifdef HAVE_STRING_H
00066 #include <string.h>
00067 #endif
00068 
00069 #ifdef HAVE_STRINGS_H
00070 #include <strings.h>
00071 #endif
00072 
00073 #ifdef HAVE_SYS_TYPES_H
00074 #include <sys/types.h>
00075 #endif
00076 
00077 #if STDC_HEADERS
00078 #include <stdlib.h>
00079 #include <stddef.h>
00080 #endif
00081 
00082 #if !defined(HAVE_VOLATILE)
00083 #define volatile
00084 #endif
00085 
00086 /**
00087   this is a warning hack. The idea is to use this everywhere that we
00088   get the "discarding const" warning from gcc. That doesn't actually
00089   fix the problem of course, but it means that when we do get to
00090   cleaning them up we can do it by searching the code for
00091   discard_const.
00092 
00093   It also means that other error types aren't as swamped by the noise
00094   of hundreds of const warnings, so we are more likely to notice when
00095   we get new errors.
00096 
00097   Please only add more uses of this macro when you find it
00098   _really_ hard to fix const warnings. Our aim is to eventually use
00099   this function in only a very few places.
00100 
00101   Also, please call this via the discard_const_p() macro interface, as that
00102   makes the return type safe.
00103 */
00104 #define discard_const(ptr) ((void *)((intptr_t)(ptr)))
00105 
00106 /** Type-safe version of discard_const */
00107 #define discard_const_p(type, ptr) ((type *)discard_const(ptr))
00108 
00109 #ifndef HAVE_STRERROR
00110 extern char *sys_errlist[];
00111 #define strerror(i) sys_errlist[i]
00112 #endif
00113 
00114 #ifndef HAVE_ERRNO_DECL
00115 extern int errno;
00116 #endif
00117 
00118 #ifndef HAVE_STRDUP
00119 #define strdup rep_strdup
00120 char *rep_strdup(const char *s);
00121 #endif
00122 
00123 #ifndef HAVE_MEMMOVE
00124 #define memmove rep_memmove
00125 void *rep_memmove(void *dest,const void *src,int size);
00126 #endif
00127 
00128 #if !defined(HAVE_MKTIME) || !defined(HAVE_TIMEGM)
00129 #include "system/time.h"
00130 #endif
00131 
00132 #ifndef HAVE_MKTIME
00133 #define mktime rep_mktime
00134 time_t rep_mktime(struct tm *t);
00135 #endif
00136 
00137 #ifndef HAVE_TIMEGM
00138 struct tm;
00139 #define timegm rep_timegm
00140 time_t rep_timegm(struct tm *tm);
00141 #endif
00142 
00143 #ifndef HAVE_STRLCPY
00144 #define strlcpy rep_strlcpy
00145 size_t rep_strlcpy(char *d, const char *s, size_t bufsize);
00146 #endif
00147 
00148 #ifndef HAVE_STRLCAT
00149 #define strlcat rep_strlcat
00150 size_t rep_strlcat(char *d, const char *s, size_t bufsize);
00151 #endif
00152 
00153 #if (defined(BROKEN_STRNDUP) || !defined(HAVE_STRNDUP))
00154 #undef HAVE_STRNDUP
00155 #define strndup rep_strndup
00156 char *rep_strndup(const char *s, size_t n);
00157 #endif
00158 
00159 #if (defined(BROKEN_STRNLEN) || !defined(HAVE_STRNLEN))
00160 #undef HAVE_STRNLEN
00161 #define strnlen rep_strnlen
00162 size_t rep_strnlen(const char *s, size_t n);
00163 #endif
00164 
00165 #ifndef HAVE_SETENV
00166 #define setenv rep_setenv
00167 int rep_setenv(const char *name, const char *value, int overwrite);
00168 #else
00169 #ifndef HAVE_SETENV_DECL
00170 int setenv(const char *name, const char *value, int overwrite);
00171 #endif
00172 #endif
00173 
00174 #ifndef HAVE_UNSETENV
00175 #define unsetenv rep_unsetenv
00176 int rep_unsetenv(const char *name); 
00177 #endif
00178 
00179 #ifndef HAVE_SETEUID
00180 #define seteuid rep_seteuid
00181 int rep_seteuid(uid_t);
00182 #endif
00183 
00184 #ifndef HAVE_SETEGID
00185 #define setegid rep_setegid
00186 int rep_setegid(gid_t);
00187 #endif
00188 
00189 #ifndef HAVE_SETLINEBUF
00190 #define setlinebuf rep_setlinebuf
00191 void rep_setlinebuf(FILE *);
00192 #endif
00193 
00194 #ifndef HAVE_STRCASESTR
00195 #define strcasestr rep_strcasestr
00196 char *rep_strcasestr(const char *haystack, const char *needle);
00197 #endif
00198 
00199 #ifndef HAVE_STRTOK_R
00200 #define strtok_r rep_strtok_r 
00201 char *rep_strtok_r(char *s, const char *delim, char **save_ptr);
00202 #endif
00203 
00204 #ifndef HAVE_STRTOLL
00205 #define strtoll rep_strtoll
00206 long long int rep_strtoll(const char *str, char **endptr, int base);
00207 #endif
00208 
00209 #ifndef HAVE_STRTOULL
00210 #define strtoull rep_strtoull
00211 unsigned long long int rep_strtoull(const char *str, char **endptr, int base);
00212 #endif
00213 
00214 #ifndef HAVE_FTRUNCATE
00215 #define ftruncate rep_ftruncate
00216 int rep_ftruncate(int,off_t);
00217 #endif
00218 
00219 #ifndef HAVE_INITGROUPS
00220 #define initgroups rep_initgroups
00221 int rep_initgroups(char *name, gid_t id);
00222 #endif
00223 
00224 #if !defined(HAVE_BZERO) && defined(HAVE_MEMSET)
00225 #define bzero(a,b) memset((a),'\0',(b))
00226 #endif
00227 
00228 #ifndef HAVE_DLERROR
00229 #define dlerror rep_dlerror
00230 char *rep_dlerror(void);
00231 #endif
00232 
00233 #ifndef HAVE_DLOPEN
00234 #define dlopen rep_dlopen
00235 void *rep_dlopen(const char *name, int flags);
00236 #endif
00237 
00238 #ifndef HAVE_DLSYM
00239 #define dlsym rep_dlsym
00240 void *rep_dlsym(void *handle, const char *symbol);
00241 #endif
00242 
00243 #ifndef HAVE_DLCLOSE
00244 #define dlclose rep_dlclose
00245 int rep_dlclose(void *handle);
00246 #endif
00247 
00248 #ifndef HAVE_SOCKETPAIR
00249 #define socketpair rep_socketpair
00250 int rep_socketpair(int d, int type, int protocol, int sv[2]);
00251 #endif
00252 
00253 #ifndef PRINTF_ATTRIBUTE
00254 #if (__GNUC__ >= 3) && (__GNUC_MINOR__ >= 1 )
00255 /** Use gcc attribute to check printf fns.  a1 is the 1-based index of
00256  * the parameter containing the format, and a2 the index of the first
00257  * argument. Note that some gcc 2.x versions don't handle this
00258  * properly **/
00259 #define PRINTF_ATTRIBUTE(a1, a2) __attribute__ ((format (__printf__, a1, a2)))
00260 #else
00261 #define PRINTF_ATTRIBUTE(a1, a2)
00262 #endif
00263 #endif
00264 
00265 #ifndef HAVE_VASPRINTF
00266 #define vasprintf rep_vasprintf
00267 int rep_vasprintf(char **ptr, const char *format, va_list ap) PRINTF_ATTRIBUTE(2,0);
00268 #endif
00269 
00270 #if !defined(HAVE_SNPRINTF) || !defined(HAVE_C99_VSNPRINTF)
00271 #define snprintf rep_snprintf
00272 int rep_snprintf(char *,size_t ,const char *, ...) PRINTF_ATTRIBUTE(3,4);
00273 #endif
00274 
00275 #if !defined(HAVE_VSNPRINTF) || !defined(HAVE_C99_VSNPRINTF)
00276 #define vsnprintf rep_vsnprintf
00277 int rep_vsnprintf(char *,size_t ,const char *, va_list ap) PRINTF_ATTRIBUTE(3,0);
00278 #endif
00279 
00280 #ifndef HAVE_ASPRINTF
00281 #define asprintf rep_asprintf
00282 int rep_asprintf(char **,const char *, ...) PRINTF_ATTRIBUTE(2,3);
00283 #endif
00284 
00285 #ifndef HAVE_VSYSLOG
00286 #ifdef HAVE_SYSLOG
00287 #define vsyslog rep_vsyslog
00288 void rep_vsyslog (int facility_priority, const char *format, va_list arglist) PRINTF_ATTRIBUTE(2,0);
00289 #endif
00290 #endif
00291 
00292 /* we used to use these fns, but now we have good replacements
00293    for snprintf and vsnprintf */
00294 #define slprintf snprintf
00295 
00296 
00297 #ifndef HAVE_VA_COPY
00298 #undef va_copy
00299 #ifdef HAVE___VA_COPY
00300 #define va_copy(dest, src) __va_copy(dest, src)
00301 #else
00302 #define va_copy(dest, src) (dest) = (src)
00303 #endif
00304 #endif
00305 
00306 #ifndef HAVE_VOLATILE
00307 #define volatile
00308 #endif
00309 
00310 #ifndef HAVE_COMPARISON_FN_T
00311 typedef int (*comparison_fn_t)(const void *, const void *);
00312 #endif
00313 
00314 #ifdef REPLACE_STRPTIME
00315 #define strptime rep_strptime
00316 struct tm;
00317 char *rep_strptime(const char *buf, const char *format, struct tm *tm);
00318 #endif
00319 
00320 /* Load header file for dynamic linking stuff */
00321 #ifdef HAVE_DLFCN_H
00322 #include <dlfcn.h>
00323 #endif
00324 
00325 #ifndef RTLD_LAZY
00326 #define RTLD_LAZY 0
00327 #endif
00328 
00329 #ifndef HAVE_SECURE_MKSTEMP
00330 #define mkstemp(path) rep_mkstemp(path)
00331 int rep_mkstemp(char *temp);
00332 #endif
00333 
00334 #ifndef HAVE_MKDTEMP
00335 #define mkdtemp rep_mkdtemp
00336 char *rep_mkdtemp(char *template);
00337 #endif
00338 
00339 #ifdef HAVE_LIMITS_H
00340 #include <limits.h>
00341 #endif
00342 
00343 /* The extra casts work around common compiler bugs.  */
00344 #define _TYPE_SIGNED(t) (! ((t) 0 < (t) -1))
00345 /* The outer cast is needed to work around a bug in Cray C 5.0.3.0.
00346    It is necessary at least when t == time_t.  */
00347 #define _TYPE_MINIMUM(t) ((t) (_TYPE_SIGNED (t) \
00348                               ? ~ (t) 0 << (sizeof (t) * CHAR_BIT - 1) : (t) 0))
00349 #define _TYPE_MAXIMUM(t) ((t) (~ (t) 0 - _TYPE_MINIMUM (t)))
00350 
00351 #ifndef HOST_NAME_MAX
00352 #define HOST_NAME_MAX 64
00353 #endif
00354 
00355 #ifndef UINT16_MAX
00356 #define UINT16_MAX 65535
00357 #endif
00358 
00359 #ifndef UINT32_MAX
00360 #define UINT32_MAX (4294967295U)
00361 #endif
00362 
00363 #ifndef UINT64_MAX
00364 #define UINT64_MAX ((uint64_t)-1)
00365 #endif
00366 
00367 #ifndef CHAR_BIT
00368 #define CHAR_BIT 8
00369 #endif
00370 
00371 #ifndef INT32_MAX
00372 #define INT32_MAX _TYPE_MAXIMUM(int32_t)
00373 #endif
00374 
00375 #ifdef HAVE_STDBOOL_H
00376 #include <stdbool.h>
00377 #endif
00378 
00379 #if !defined(HAVE_BOOL)
00380 #ifdef HAVE__Bool
00381 #define bool _Bool
00382 #else
00383 typedef int bool;
00384 #endif
00385 #endif
00386 
00387 /*
00388  * to prevent <rpcsvc/yp_prot.h> from doing a redefine of 'bool'
00389  *
00390  * IRIX, HPUX, MacOS 10 and Solaris need BOOL_DEFINED
00391  * Tru64 needs _BOOL_EXISTS
00392  * AIX needs _BOOL,_TRUE,_FALSE
00393  */
00394 #ifndef BOOL_DEFINED
00395 #define BOOL_DEFINED
00396 #endif
00397 #ifndef _BOOL_EXISTS
00398 #define _BOOL_EXISTS
00399 #endif
00400 #ifndef _BOOL
00401 #define _BOOL
00402 #endif
00403 
00404 #ifndef __bool_true_false_are_defined
00405 #define __bool_true_false_are_defined
00406 #endif
00407 
00408 #ifndef true
00409 #define true (1)
00410 #endif
00411 #ifndef false
00412 #define false (0)
00413 #endif
00414 
00415 #ifndef _TRUE
00416 #define _TRUE true
00417 #endif
00418 #ifndef _FALSE
00419 #define _FALSE false
00420 #endif
00421 
00422 #ifndef HAVE_FUNCTION_MACRO
00423 #ifdef HAVE_func_MACRO
00424 #define __FUNCTION__ __func__
00425 #else
00426 #define __FUNCTION__ ("")
00427 #endif
00428 #endif
00429 
00430 #ifdef HAVE_SYS_PARAM_H
00431 #include <sys/param.h>
00432 #endif
00433 
00434 #ifndef MIN
00435 #define MIN(a,b) ((a)<(b)?(a):(b))
00436 #endif
00437 
00438 #ifndef MAX
00439 #define MAX(a,b) ((a)>(b)?(a):(b))
00440 #endif
00441 
00442 #ifndef __STRING
00443 #define __STRING(x)    #x
00444 #endif
00445 
00446 #ifndef _STRINGSTRING
00447 #define __STRINGSTRING(x) __STRING(x)
00448 #endif
00449 
00450 #ifndef __LINESTR__
00451 #define __LINESTR__ __STRINGSTRING(__LINE__)
00452 #endif
00453 
00454 #ifndef __location__
00455 #define __location__ __FILE__ ":" __LINESTR__
00456 #endif
00457 
00458 /** 
00459  * zero a structure 
00460  */
00461 #define ZERO_STRUCT(x) memset((char *)&(x), 0, sizeof(x))
00462 
00463 /** 
00464  * zero a structure given a pointer to the structure 
00465  */
00466 #define ZERO_STRUCTP(x) do { if ((x) != NULL) memset((char *)(x), 0, sizeof(*(x))); } while(0)
00467 
00468 /** 
00469  * zero a structure given a pointer to the structure - no zero check 
00470  */
00471 #define ZERO_STRUCTPN(x) memset((char *)(x), 0, sizeof(*(x)))
00472 
00473 /* zero an array - note that sizeof(array) must work - ie. it must not be a
00474    pointer */
00475 #define ZERO_ARRAY(x) memset((char *)(x), 0, sizeof(x))
00476 
00477 /**
00478  * work out how many elements there are in a static array 
00479  */
00480 #define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
00481 
00482 /** 
00483  * pointer difference macro 
00484  */
00485 #define PTR_DIFF(p1,p2) ((ptrdiff_t)(((const char *)(p1)) - (const char *)(p2)))
00486 
00487 #if MMAP_BLACKLIST
00488 #undef HAVE_MMAP
00489 #endif
00490 
00491 #endif /* _LIBREPLACE_REPLACE_H */

Sambaに対してSat Aug 29 21:22:58 2009に生成されました。  doxygen 1.4.7