replace: Move memalign() from lib/util/system.c to libreplace.
[gd/samba-autobuild/.git] / lib / replace / replace.h
1 /*
2    Unix SMB/CIFS implementation.
3
4    macros to go along with the lib/replace/ portability layer code
5
6    Copyright (C) Andrew Tridgell 2005
7    Copyright (C) Jelmer Vernooij 2006-2008
8    Copyright (C) Jeremy Allison 2007.
9
10      ** NOTE! The following LGPL license applies to the replace
11      ** library. This does NOT imply that all of Samba is released
12      ** under the LGPL
13
14    This library is free software; you can redistribute it and/or
15    modify it under the terms of the GNU Lesser General Public
16    License as published by the Free Software Foundation; either
17    version 3 of the License, or (at your option) any later version.
18
19    This library is distributed in the hope that it will be useful,
20    but WITHOUT ANY WARRANTY; without even the implied warranty of
21    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
22    Lesser General Public License for more details.
23
24    You should have received a copy of the GNU Lesser General Public
25    License along with this library; if not, see <http://www.gnu.org/licenses/>.
26 */
27
28 #ifndef _LIBREPLACE_REPLACE_H
29 #define _LIBREPLACE_REPLACE_H
30
31 #ifndef NO_CONFIG_H
32 #include "config.h"
33 #endif
34
35 #ifdef HAVE_STANDARDS_H
36 #include <standards.h>
37 #endif
38
39 #include <stdio.h>
40 #include <stdlib.h>
41 #include <stdarg.h>
42 #include <errno.h>
43
44 #if defined(_MSC_VER) || defined(__MINGW32__)
45 #include "win32_replace.h"
46 #endif
47
48
49 #ifdef HAVE_STDINT_H
50 #include <stdint.h>
51 /* force off HAVE_INTTYPES_H so that roken doesn't try to include both,
52    which causes a warning storm on irix */
53 #undef HAVE_INTTYPES_H
54 #elif HAVE_INTTYPES_H
55 #define __STDC_FORMAT_MACROS
56 #include <inttypes.h>
57 #endif
58
59 #ifdef HAVE_MALLOC_H
60 #include <malloc.h>
61 #endif
62
63 #ifndef __PRI64_PREFIX
64 # if __WORDSIZE == 64
65 #  define __PRI64_PREFIX        "l"
66 # else
67 #  define __PRI64_PREFIX        "ll"
68 # endif
69 #endif
70
71 /* Decimal notation.  */
72 #ifndef PRId8
73 # define PRId8          "d"
74 #endif
75 #ifndef PRId16
76 # define PRId16         "d"
77 #endif
78 #ifndef PRId32
79 # define PRId32         "d"
80 #endif
81 #ifndef PRId64
82 # define PRId64         __PRI64_PREFIX "d"
83 #endif
84
85 #ifndef PRIi8
86 # define PRIi8          "i"
87 #endif
88 #ifndef PRIi16
89 # define PRIi16         "i"
90 #endif
91 #ifndef PRIi32
92 # define PRIi32         "i"
93 #endif
94 #ifndef PRIi64
95 # define PRIi64         __PRI64_PREFIX "i"
96 #endif
97
98 #ifndef PRIu8
99 # define PRIu8          "u"
100 #endif
101 #ifndef PRIu16
102 # define PRIu16         "u"
103 #endif
104 #ifndef PRIu32
105 # define PRIu32         "u"
106 #endif
107 #ifndef PRIu64
108 # define PRIu64         __PRI64_PREFIX "u"
109 #endif
110
111 #ifdef HAVE_BSD_STRING_H
112 #include <bsd/string.h>
113 #endif
114
115 #ifdef HAVE_STRING_H
116 #include <string.h>
117 #endif
118
119 #ifdef HAVE_STRINGS_H
120 #include <strings.h>
121 #endif
122
123 #ifdef HAVE_SYS_TYPES_H
124 #include <sys/types.h>
125 #endif
126
127 #if STDC_HEADERS
128 #include <stdlib.h>
129 #include <stddef.h>
130 #endif
131
132 #ifdef HAVE_LINUX_TYPES_H
133 /*
134  * This is needed as some broken header files require this to be included early
135  */
136 #include <linux/types.h>
137 #endif
138
139 #ifndef HAVE_STRERROR
140 extern char *sys_errlist[];
141 #define strerror(i) sys_errlist[i]
142 #endif
143
144 #ifndef HAVE_ERRNO_DECL
145 extern int errno;
146 #endif
147
148 #ifndef HAVE_STRDUP
149 #define strdup rep_strdup
150 char *rep_strdup(const char *s);
151 #endif
152
153 #ifndef HAVE_MEMMOVE
154 #define memmove rep_memmove
155 void *rep_memmove(void *dest,const void *src,int size);
156 #endif
157
158 #ifndef HAVE_MEMMEM
159 #define memmem rep_memmem
160 void *rep_memmem(const void *haystack, size_t haystacklen,
161                  const void *needle, size_t needlelen);
162 #endif
163
164 #ifndef HAVE_MEMALIGN
165 #define memalign rep_memalign
166 void *rep_memalign(size_t boundary, size_t size);
167 #endif
168
169 #ifndef HAVE_MKTIME
170 #define mktime rep_mktime
171 /* prototype is in "system/time.h" */
172 #endif
173
174 #ifndef HAVE_TIMEGM
175 #define timegm rep_timegm
176 /* prototype is in "system/time.h" */
177 #endif
178
179 #ifndef HAVE_UTIME
180 #define utime rep_utime
181 /* prototype is in "system/time.h" */
182 #endif
183
184 #ifndef HAVE_UTIMES
185 #define utimes rep_utimes
186 /* prototype is in "system/time.h" */
187 #endif
188
189 #ifndef HAVE_STRLCPY
190 #define strlcpy rep_strlcpy
191 size_t rep_strlcpy(char *d, const char *s, size_t bufsize);
192 #endif
193
194 #ifndef HAVE_STRLCAT
195 #define strlcat rep_strlcat
196 size_t rep_strlcat(char *d, const char *s, size_t bufsize);
197 #endif
198
199 #if (defined(BROKEN_STRNDUP) || !defined(HAVE_STRNDUP))
200 #undef HAVE_STRNDUP
201 #define strndup rep_strndup
202 char *rep_strndup(const char *s, size_t n);
203 #endif
204
205 #if (defined(BROKEN_STRNLEN) || !defined(HAVE_STRNLEN))
206 #undef HAVE_STRNLEN
207 #define strnlen rep_strnlen
208 size_t rep_strnlen(const char *s, size_t n);
209 #endif
210
211 #if !HAVE_DECL_ENVIRON
212 #ifdef __APPLE__
213 #include <crt_externs.h>
214 #define environ (*_NSGetEnviron())
215 #else
216 extern char **environ;
217 #endif
218 #endif
219
220 #ifndef HAVE_SETENV
221 #define setenv rep_setenv
222 int rep_setenv(const char *name, const char *value, int overwrite);
223 #else
224 #ifndef HAVE_SETENV_DECL
225 int setenv(const char *name, const char *value, int overwrite);
226 #endif
227 #endif
228
229 #ifndef HAVE_UNSETENV
230 #define unsetenv rep_unsetenv
231 int rep_unsetenv(const char *name);
232 #endif
233
234 #ifndef HAVE_SETEUID
235 #define seteuid rep_seteuid
236 int rep_seteuid(uid_t);
237 #endif
238
239 #ifndef HAVE_SETEGID
240 #define setegid rep_setegid
241 int rep_setegid(gid_t);
242 #endif
243
244 #if (defined(USE_SETRESUID) && !defined(HAVE_SETRESUID_DECL))
245 /* stupid glibc */
246 int setresuid(uid_t ruid, uid_t euid, uid_t suid);
247 #endif
248 #if (defined(USE_SETRESUID) && !defined(HAVE_SETRESGID_DECL))
249 int setresgid(gid_t rgid, gid_t egid, gid_t sgid);
250 #endif
251
252 #ifndef HAVE_CHOWN
253 #define chown rep_chown
254 int rep_chown(const char *path, uid_t uid, gid_t gid);
255 #endif
256
257 #ifndef HAVE_CHROOT
258 #define chroot rep_chroot
259 int rep_chroot(const char *dirname);
260 #endif
261
262 #ifndef HAVE_LINK
263 #define link rep_link
264 int rep_link(const char *oldpath, const char *newpath);
265 #endif
266
267 #ifndef HAVE_READLINK
268 #define readlink rep_readlink
269 ssize_t rep_readlink(const char *path, char *buf, size_t bufsize);
270 #endif
271
272 #ifndef HAVE_SYMLINK
273 #define symlink rep_symlink
274 int rep_symlink(const char *oldpath, const char *newpath);
275 #endif
276
277 #ifndef HAVE_REALPATH
278 #define realpath rep_realpath
279 char *rep_realpath(const char *path, char *resolved_path);
280 #endif
281
282 #ifndef HAVE_LCHOWN
283 #define lchown rep_lchown
284 int rep_lchown(const char *fname,uid_t uid,gid_t gid);
285 #endif
286
287 #ifdef HAVE_UNIX_H
288 #include <unix.h>
289 #endif
290
291 #ifndef HAVE_SETLINEBUF
292 #define setlinebuf rep_setlinebuf
293 void rep_setlinebuf(FILE *);
294 #endif
295
296 #ifndef HAVE_STRCASESTR
297 #define strcasestr rep_strcasestr
298 char *rep_strcasestr(const char *haystack, const char *needle);
299 #endif
300
301 #ifndef HAVE_STRTOK_R
302 #define strtok_r rep_strtok_r
303 char *rep_strtok_r(char *s, const char *delim, char **save_ptr);
304 #endif
305
306
307
308 #ifndef HAVE_STRTOLL
309 #define strtoll rep_strtoll
310 long long int rep_strtoll(const char *str, char **endptr, int base);
311 #else
312 #ifdef HAVE_BSD_STRTOLL
313 #define strtoll rep_strtoll
314 long long int rep_strtoll(const char *str, char **endptr, int base);
315 #endif
316 #endif
317
318 #ifndef HAVE_STRTOULL
319 #define strtoull rep_strtoull
320 unsigned long long int rep_strtoull(const char *str, char **endptr, int base);
321 #else
322 #ifdef HAVE_BSD_STRTOLL /* yes, it's not HAVE_BSD_STRTOULL */
323 #define strtoull rep_strtoull
324 unsigned long long int rep_strtoull(const char *str, char **endptr, int base);
325 #endif
326 #endif
327
328 #ifndef HAVE_FTRUNCATE
329 #define ftruncate rep_ftruncate
330 int rep_ftruncate(int,off_t);
331 #endif
332
333 #ifndef HAVE_INITGROUPS
334 #define initgroups rep_initgroups
335 int rep_initgroups(char *name, gid_t id);
336 #endif
337
338 #if !defined(HAVE_BZERO) && defined(HAVE_MEMSET)
339 #define bzero(a,b) memset((a),'\0',(b))
340 #endif
341
342 #ifndef HAVE_DLERROR
343 #define dlerror rep_dlerror
344 char *rep_dlerror(void);
345 #endif
346
347 #ifndef HAVE_DLOPEN
348 #define dlopen rep_dlopen
349 #ifdef DLOPEN_TAKES_UNSIGNED_FLAGS
350 void *rep_dlopen(const char *name, unsigned int flags);
351 #else
352 void *rep_dlopen(const char *name, int flags);
353 #endif
354 #endif
355
356 #ifndef HAVE_DLSYM
357 #define dlsym rep_dlsym
358 void *rep_dlsym(void *handle, const char *symbol);
359 #endif
360
361 #ifndef HAVE_DLCLOSE
362 #define dlclose rep_dlclose
363 int rep_dlclose(void *handle);
364 #endif
365
366 #ifndef HAVE_SOCKETPAIR
367 #define socketpair rep_socketpair
368 /* prototype is in system/network.h */
369 #endif
370
371 #ifndef HAVE_VDPRINTF
372 #define vdprintf rep_vdprintf
373 int rep_vdprintf(int fd, const char *format, va_list ap);
374 #endif
375
376 #ifndef HAVE_DPRINTF
377 #define dprintf rep_dprintf
378 int rep_dprintf(int fd, const char *format, ...);
379 #endif
380
381 #ifndef PRINTF_ATTRIBUTE
382 #if (__GNUC__ >= 3) && (__GNUC_MINOR__ >= 1 )
383 /** Use gcc attribute to check printf fns.  a1 is the 1-based index of
384  * the parameter containing the format, and a2 the index of the first
385  * argument. Note that some gcc 2.x versions don't handle this
386  * properly **/
387 #define PRINTF_ATTRIBUTE(a1, a2) __attribute__ ((format (__printf__, a1, a2)))
388 #else
389 #define PRINTF_ATTRIBUTE(a1, a2)
390 #endif
391 #endif
392
393 #ifndef _DEPRECATED_
394 #if (__GNUC__ >= 3) && (__GNUC_MINOR__ >= 1 )
395 #define _DEPRECATED_ __attribute__ ((deprecated))
396 #else
397 #define _DEPRECATED_
398 #endif
399 #endif
400
401 #ifndef HAVE_VASPRINTF
402 #define vasprintf rep_vasprintf
403 int rep_vasprintf(char **ptr, const char *format, va_list ap) PRINTF_ATTRIBUTE(2,0);
404 #endif
405
406 #if !defined(HAVE_SNPRINTF) || !defined(HAVE_C99_VSNPRINTF)
407 #define snprintf rep_snprintf
408 int rep_snprintf(char *,size_t ,const char *, ...) PRINTF_ATTRIBUTE(3,4);
409 #endif
410
411 #if !defined(HAVE_VSNPRINTF) || !defined(HAVE_C99_VSNPRINTF)
412 #define vsnprintf rep_vsnprintf
413 int rep_vsnprintf(char *,size_t ,const char *, va_list ap) PRINTF_ATTRIBUTE(3,0);
414 #endif
415
416 #ifndef HAVE_ASPRINTF
417 #define asprintf rep_asprintf
418 int rep_asprintf(char **,const char *, ...) PRINTF_ATTRIBUTE(2,3);
419 #endif
420
421 #ifndef HAVE_VSYSLOG
422 #ifdef HAVE_SYSLOG
423 #define vsyslog rep_vsyslog
424 void rep_vsyslog (int facility_priority, const char *format, va_list arglist) PRINTF_ATTRIBUTE(2,0);
425 #endif
426 #endif
427
428 /* we used to use these fns, but now we have good replacements
429    for snprintf and vsnprintf */
430 #define slprintf snprintf
431
432
433 #ifndef HAVE_VA_COPY
434 #undef va_copy
435 #ifdef HAVE___VA_COPY
436 #define va_copy(dest, src) __va_copy(dest, src)
437 #else
438 #define va_copy(dest, src) (dest) = (src)
439 #endif
440 #endif
441
442 #ifndef HAVE_VOLATILE
443 #define volatile
444 #endif
445
446 #ifndef HAVE_COMPARISON_FN_T
447 typedef int (*comparison_fn_t)(const void *, const void *);
448 #endif
449
450 #ifdef REPLACE_STRPTIME
451 #define strptime rep_strptime
452 struct tm;
453 char *rep_strptime(const char *buf, const char *format, struct tm *tm);
454 #endif
455
456 #ifndef HAVE_DUP2
457 #define dup2 rep_dup2
458 int rep_dup2(int oldfd, int newfd);
459 #endif
460
461 /* Load header file for dynamic linking stuff */
462 #ifdef HAVE_DLFCN_H
463 #include <dlfcn.h>
464 #endif
465
466 #ifndef RTLD_LAZY
467 #define RTLD_LAZY 0
468 #endif
469 #ifndef RTLD_NOW
470 #define RTLD_NOW 0
471 #endif
472 #ifndef RTLD_GLOBAL
473 #define RTLD_GLOBAL 0
474 #endif
475
476 #ifndef HAVE_SECURE_MKSTEMP
477 #define mkstemp(path) rep_mkstemp(path)
478 int rep_mkstemp(char *temp);
479 #endif
480
481 #ifndef HAVE_MKDTEMP
482 #define mkdtemp rep_mkdtemp
483 char *rep_mkdtemp(char *template);
484 #endif
485
486 #ifndef HAVE_PREAD
487 #define pread rep_pread
488 ssize_t rep_pread(int __fd, void *__buf, size_t __nbytes, off_t __offset);
489 #define LIBREPLACE_PREAD_REPLACED 1
490 #else
491 #define LIBREPLACE_PREAD_NOT_REPLACED 1
492 #endif
493
494 #ifndef HAVE_PWRITE
495 #define pwrite rep_pwrite
496 ssize_t rep_pwrite(int __fd, const void *__buf, size_t __nbytes, off_t __offset);
497 #define LIBREPLACE_PWRITE_REPLACED 1
498 #else
499 #define LIBREPLACE_PWRITE_NOT_REPLACED 1
500 #endif
501
502 #if !defined(HAVE_INET_NTOA) || defined(REPLACE_INET_NTOA)
503 #define inet_ntoa rep_inet_ntoa
504 /* prototype is in "system/network.h" */
505 #endif
506
507 #ifndef HAVE_INET_PTON
508 #define inet_pton rep_inet_pton
509 /* prototype is in "system/network.h" */
510 #endif
511
512 #ifndef HAVE_INET_NTOP
513 #define inet_ntop rep_inet_ntop
514 /* prototype is in "system/network.h" */
515 #endif
516
517 #ifndef HAVE_INET_ATON
518 #define inet_aton rep_inet_aton
519 /* prototype is in "system/network.h" */
520 #endif
521
522 #ifndef HAVE_CONNECT
523 #define connect rep_connect
524 /* prototype is in "system/network.h" */
525 #endif
526
527 #ifndef HAVE_GETHOSTBYNAME
528 #define gethostbyname rep_gethostbyname
529 /* prototype is in "system/network.h" */
530 #endif
531
532 #ifndef HAVE_GETIFADDRS
533 #define getifaddrs rep_getifaddrs
534 /* prototype is in "system/network.h" */
535 #endif
536
537 #ifndef HAVE_FREEIFADDRS
538 #define freeifaddrs rep_freeifaddrs
539 /* prototype is in "system/network.h" */
540 #endif
541
542 #ifndef HAVE_GET_CURRENT_DIR_NAME
543 #define get_current_dir_name rep_get_current_dir_name
544 char *rep_get_current_dir_name(void);
545 #endif
546
547 #if !defined(HAVE_STRERROR_R) || !defined(STRERROR_R_PROTO_COMPATIBLE)
548 #undef strerror_r
549 #define strerror_r rep_strerror_r
550 int rep_strerror_r(int errnum, char *buf, size_t buflen);
551 #endif
552
553 #if !defined(HAVE_CLOCK_GETTIME)
554 #define clock_gettime rep_clock_gettime
555 #endif
556
557 #ifdef HAVE_LIMITS_H
558 #include <limits.h>
559 #endif
560
561 #ifdef HAVE_SYS_PARAM_H
562 #include <sys/param.h>
563 #endif
564
565 /* The extra casts work around common compiler bugs.  */
566 #define _TYPE_SIGNED(t) (! ((t) 0 < (t) -1))
567 /* The outer cast is needed to work around a bug in Cray C 5.0.3.0.
568    It is necessary at least when t == time_t.  */
569 #define _TYPE_MINIMUM(t) ((t) (_TYPE_SIGNED (t) \
570                               ? ~ (t) 0 << (sizeof (t) * CHAR_BIT - 1) : (t) 0))
571 #define _TYPE_MAXIMUM(t) ((t) (~ (t) 0 - _TYPE_MINIMUM (t)))
572
573 #ifndef UINT16_MAX
574 #define UINT16_MAX 65535
575 #endif
576
577 #ifndef UINT32_MAX
578 #define UINT32_MAX (4294967295U)
579 #endif
580
581 #ifndef UINT64_MAX
582 #define UINT64_MAX ((uint64_t)-1)
583 #endif
584
585 #ifndef CHAR_BIT
586 #define CHAR_BIT 8
587 #endif
588
589 #ifndef INT32_MAX
590 #define INT32_MAX _TYPE_MAXIMUM(int32_t)
591 #endif
592
593 #ifdef HAVE_STDBOOL_H
594 #include <stdbool.h>
595 #endif
596
597 #if !defined(HAVE_BOOL)
598 #ifdef HAVE__Bool
599 #define bool _Bool
600 #else
601 typedef int bool;
602 #endif
603 #endif
604
605 #if !defined(HAVE_INTPTR_T)
606 typedef long long intptr_t ;
607 #endif
608
609 #if !defined(HAVE_UINTPTR_T)
610 typedef unsigned long long uintptr_t ;
611 #endif
612
613 #if !defined(HAVE_PTRDIFF_T)
614 typedef unsigned long long ptrdiff_t ;
615 #endif
616
617 /*
618  * to prevent <rpcsvc/yp_prot.h> from doing a redefine of 'bool'
619  *
620  * IRIX, HPUX, MacOS 10 and Solaris need BOOL_DEFINED
621  * Tru64 needs _BOOL_EXISTS
622  * AIX needs _BOOL,_TRUE,_FALSE
623  */
624 #ifndef BOOL_DEFINED
625 #define BOOL_DEFINED
626 #endif
627 #ifndef _BOOL_EXISTS
628 #define _BOOL_EXISTS
629 #endif
630 #ifndef _BOOL
631 #define _BOOL
632 #endif
633
634 #ifndef __bool_true_false_are_defined
635 #define __bool_true_false_are_defined
636 #endif
637
638 #ifndef true
639 #define true (1)
640 #endif
641 #ifndef false
642 #define false (0)
643 #endif
644
645 #ifndef _TRUE
646 #define _TRUE true
647 #endif
648 #ifndef _FALSE
649 #define _FALSE false
650 #endif
651
652 #ifndef HAVE_FUNCTION_MACRO
653 #ifdef HAVE_func_MACRO
654 #define __FUNCTION__ __func__
655 #else
656 #define __FUNCTION__ ("")
657 #endif
658 #endif
659
660
661 #ifndef MIN
662 #define MIN(a,b) ((a)<(b)?(a):(b))
663 #endif
664
665 #ifndef MAX
666 #define MAX(a,b) ((a)>(b)?(a):(b))
667 #endif
668
669 #if !defined(HAVE_VOLATILE)
670 #define volatile
671 #endif
672
673 /**
674   this is a warning hack. The idea is to use this everywhere that we
675   get the "discarding const" warning from gcc. That doesn't actually
676   fix the problem of course, but it means that when we do get to
677   cleaning them up we can do it by searching the code for
678   discard_const.
679
680   It also means that other error types aren't as swamped by the noise
681   of hundreds of const warnings, so we are more likely to notice when
682   we get new errors.
683
684   Please only add more uses of this macro when you find it
685   _really_ hard to fix const warnings. Our aim is to eventually use
686   this function in only a very few places.
687
688   Also, please call this via the discard_const_p() macro interface, as that
689   makes the return type safe.
690 */
691 #define discard_const(ptr) ((void *)((uintptr_t)(ptr)))
692
693 /** Type-safe version of discard_const */
694 #define discard_const_p(type, ptr) ((type *)discard_const(ptr))
695
696 #ifndef __STRING
697 #define __STRING(x)    #x
698 #endif
699
700 #ifndef __STRINGSTRING
701 #define __STRINGSTRING(x) __STRING(x)
702 #endif
703
704 #ifndef __LINESTR__
705 #define __LINESTR__ __STRINGSTRING(__LINE__)
706 #endif
707
708 #ifndef __location__
709 #define __location__ __FILE__ ":" __LINESTR__
710 #endif
711
712 /** 
713  * zero a structure 
714  */
715 #define ZERO_STRUCT(x) memset((char *)&(x), 0, sizeof(x))
716
717 /** 
718  * zero a structure given a pointer to the structure 
719  */
720 #define ZERO_STRUCTP(x) do { if ((x) != NULL) memset((char *)(x), 0, sizeof(*(x))); } while(0)
721
722 /** 
723  * zero a structure given a pointer to the structure - no zero check 
724  */
725 #define ZERO_STRUCTPN(x) memset((char *)(x), 0, sizeof(*(x)))
726
727 /* zero an array - note that sizeof(array) must work - ie. it must not be a
728    pointer */
729 #define ZERO_ARRAY(x) memset((char *)(x), 0, sizeof(x))
730
731 /**
732  * work out how many elements there are in a static array 
733  */
734 #define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
735
736 /** 
737  * pointer difference macro 
738  */
739 #define PTR_DIFF(p1,p2) ((ptrdiff_t)(((const char *)(p1)) - (const char *)(p2)))
740
741 #if MMAP_BLACKLIST
742 #undef HAVE_MMAP
743 #endif
744
745 #ifdef __COMPAR_FN_T
746 #define QSORT_CAST (__compar_fn_t)
747 #endif
748
749 #ifndef QSORT_CAST
750 #define QSORT_CAST (int (*)(const void *, const void *))
751 #endif
752
753 #ifndef PATH_MAX
754 #define PATH_MAX 1024
755 #endif
756
757 #ifndef MAX_DNS_NAME_LENGTH
758 #define MAX_DNS_NAME_LENGTH 256 /* Actually 255 but +1 for terminating null. */
759 #endif
760
761 #ifndef HAVE_CRYPT
762 char *ufc_crypt(const char *key, const char *salt);
763 #define crypt ufc_crypt
764 #else
765 #ifdef HAVE_CRYPT_H
766 #include <crypt.h>
767 #endif
768 #endif
769
770 /* these macros gain us a few percent of speed on gcc */
771 #if (__GNUC__ >= 3)
772 /* the strange !! is to ensure that __builtin_expect() takes either 0 or 1
773    as its first argument */
774 #ifndef likely
775 #define likely(x)   __builtin_expect(!!(x), 1)
776 #endif
777 #ifndef unlikely
778 #define unlikely(x) __builtin_expect(!!(x), 0)
779 #endif
780 #else
781 #ifndef likely
782 #define likely(x) (x)
783 #endif
784 #ifndef unlikely
785 #define unlikely(x) (x)
786 #endif
787 #endif
788
789 #ifndef HAVE_FDATASYNC
790 #define fdatasync(fd) fsync(fd)
791 #elif !defined(HAVE_DECL_FDATASYNC)
792 int fdatasync(int );
793 #endif
794
795 /* these are used to mark symbols as local to a shared lib, or
796  * publicly available via the shared lib API */
797 #ifndef _PUBLIC_
798 #ifdef HAVE_VISIBILITY_ATTR
799 #define _PUBLIC_ __attribute__((visibility("default")))
800 #else
801 #define _PUBLIC_
802 #endif
803 #endif
804
805 #ifndef _PRIVATE_
806 #ifdef HAVE_VISIBILITY_ATTR
807 #  define _PRIVATE_ __attribute__((visibility("hidden")))
808 #else
809 #  define _PRIVATE_
810 #endif
811 #endif
812
813 #ifndef HAVE_POLL
814 #define poll rep_poll
815 /* prototype is in "system/network.h" */
816 #endif
817
818 #if !defined(getpass)
819 #ifdef REPLACE_GETPASS
820 #if defined(REPLACE_GETPASS_BY_GETPASSPHRASE)
821 #define getpass(prompt) getpassphrase(prompt)
822 #else
823 #define getpass(prompt) rep_getpass(prompt)
824 char *rep_getpass(const char *prompt);
825 #endif
826 #endif
827 #endif
828
829 #endif /* _LIBREPLACE_REPLACE_H */