r8420: slowly getting my way through some more heimdal portability fixes
[jelmer/samba4-debian.git] / source / 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    
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 2 of the License, or
11    (at your option) any later version.
12    
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17    
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 #ifndef _replace_h
24 #define _replace_h
25
26 #ifdef __COMPAR_FN_T
27 #define QSORT_CAST (__compar_fn_t)
28 #endif
29
30 #ifndef QSORT_CAST
31 #define QSORT_CAST (int (*)(const void *, const void *))
32 #endif
33
34 #ifndef HAVE_STRDUP
35 char *strdup(const char *s);
36 #endif
37
38 #ifndef HAVE_MEMMOVE
39 void *memmove(void *dest,const void *src,int size);
40 #endif
41
42 #ifndef HAVE_MKTIME
43 time_t mktime(struct tm *t);
44 #endif
45
46 #ifndef HAVE_STRLCPY
47 size_t strlcpy(char *d, const char *s, size_t bufsize);
48 #endif
49
50 #ifndef HAVE_STRLCAT
51 size_t strlcat(char *d, const char *s, size_t bufsize);
52 #endif
53
54 #ifndef HAVE_STRNDUP
55 char *strndup(const char *s, size_t n);
56 #endif
57
58 #ifndef HAVE_STRNLEN
59 size_t strnlen(const char *s, size_t n);
60 #endif
61
62 #ifndef HAVE_STRTOUL
63 unsigned long strtoul(const char *nptr, char **endptr, int base);
64 #endif
65
66 #ifndef HAVE_SETENV
67 int setenv(const char *name, const char *value, int overwrite); 
68 #endif
69
70 #ifndef HAVE_VASPRINTF_DECL
71 int vasprintf(char **ptr, const char *format, va_list ap);
72 #endif
73
74 #if !defined(HAVE_BZERO) && defined(HAVE_MEMSET)
75 #define bzero(a,b) memset((a),'\0',(b))
76 #endif
77
78 #ifndef PRINTF_ATTRIBUTE
79 #if !defined(NO_PRINTF_ATTRIBUTE) && (__GNUC__ >= 3)
80 /** Use gcc attribute to check printf fns.  a1 is the 1-based index of
81  * the parameter containing the format, and a2 the index of the first
82  * argument. Note that some gcc 2.x versions don't handle this
83  * properly **/
84 #define PRINTF_ATTRIBUTE(a1, a2) __attribute__ ((format (__printf__, a1, a2)))
85 #else
86 #define PRINTF_ATTRIBUTE(a1, a2)
87 #endif
88 #endif
89
90 /* add varargs prototypes with printf checking */
91 #ifndef HAVE_SNPRINTF_DECL
92 int snprintf(char *,size_t ,const char *, ...) PRINTF_ATTRIBUTE(3,4);
93 #endif
94 #ifndef HAVE_ASPRINTF_DECL
95 int asprintf(char **,const char *, ...) PRINTF_ATTRIBUTE(2,3);
96 #endif
97
98
99 /* we used to use these fns, but now we have good replacements
100    for snprintf and vsnprintf */
101 #define slprintf snprintf
102
103
104 #ifdef HAVE_VA_COPY
105 #define VA_COPY(dest, src) va_copy(dest, src)
106 #elif defined(HAVE___VA_COPY)
107 #define VA_COPY(dest, src) __va_copy(dest, src)
108 #else
109 #define VA_COPY(dest, src) (dest) = (src)
110 #endif
111
112 #if defined(HAVE_VOLATILE)
113 #define VOLATILE volatile
114 #else
115 #define VOLATILE
116 #endif
117
118 #ifndef HAVE_COMPARISON_FN_T
119 typedef int (*comparison_fn_t)(const void *, const void *);
120 #endif
121
122 #endif