Open files in binary mode on systems that have O_BINARY
[libtar.git] / compat / compat.h
blob70ac2f435f12d28b93a370a0588723564fe7387b
1 /* prototypes for borrowed "compatibility" code */
3 #include <config.h>
5 #include <sys/types.h>
6 #include <sys/stat.h>
8 #include <stdarg.h>
9 #include <stddef.h>
11 #ifdef HAVE_LIBGEN_H
12 # include <libgen.h>
13 #endif
16 #if defined(NEED_BASENAME) && !defined(HAVE_BASENAME)
18 # ifdef basename
19 # undef basename /* fix glibc brokenness */
20 # endif
22 char *openbsd_basename(const char *);
23 # define basename openbsd_basename
25 #endif /* NEED_BASENAME && ! HAVE_BASENAME */
28 #if defined(NEED_DIRNAME) && !defined(HAVE_DIRNAME)
30 char *openbsd_dirname(const char *);
31 # define dirname openbsd_dirname
33 #endif /* NEED_DIRNAME && ! HAVE_DIRNAME */
36 #ifdef NEED_FNMATCH
37 # ifndef HAVE_FNMATCH
39 # define FNM_NOMATCH 1 /* Match failed. */
41 # define FNM_NOESCAPE 0x01 /* Disable backslash escaping. */
42 # define FNM_PATHNAME 0x02 /* Slash must be matched by slash. */
43 # define FNM_PERIOD 0x04 /* Period must be matched by period. */
45 # define FNM_LEADING_DIR 0x08 /* Ignore /<tail> after Imatch. */
46 # define FNM_CASEFOLD 0x10 /* Case insensitive search. */
47 # define FNM_IGNORECASE FNM_CASEFOLD
48 # define FNM_FILE_NAME FNM_PATHNAME
50 int openbsd_fnmatch(const char *, const char *, int);
51 # define fnmatch openbsd_fnmatch
53 # else /* HAVE_FNMATCH */
55 # ifdef HAVE_FNMATCH_H
56 # include <fnmatch.h>
57 # endif
59 # endif /* ! HAVE_FNMATCH */
60 #endif /* NEED_FNMATCH */
63 #ifdef NEED_GETHOSTBYNAME_R
65 # include <netdb.h>
67 # if GETHOSTBYNAME_R_NUM_ARGS != 6
69 int compat_gethostbyname_r(const char *, struct hostent *,
70 char *, size_t, struct hostent **, int *);
72 # define gethostbyname_r compat_gethostbyname_r
74 # endif /* GETHOSTBYNAME_R_NUM_ARGS != 6 */
76 #endif /* NEED_GETHOSTBYNAME_R */
79 #if defined(NEED_GETHOSTNAME) && !defined(HAVE_GETHOSTNAME)
81 int gethostname(char *, size_t);
83 #endif /* NEED_GETHOSTNAME && ! HAVE_GETHOSTNAME */
86 #ifdef NEED_GETSERVBYNAME_R
88 # include <netdb.h>
90 # if GETSERVBYNAME_R_NUM_ARGS != 6
92 int compat_getservbyname_r(const char *, const char *, struct servent *,
93 char *, size_t, struct servent **);
95 # define getservbyname_r compat_getservbyname_r
97 # endif /* GETSERVBYNAME_R_NUM_ARGS != 6 */
99 #endif /* NEED_GETSERVBYNAME_R */
103 #ifdef NEED_GLOB
104 # ifndef HAVE_GLOB
106 typedef struct {
107 int gl_pathc; /* Count of total paths so far. */
108 int gl_matchc; /* Count of paths matching pattern. */
109 int gl_offs; /* Reserved at beginning of gl_pathv. */
110 int gl_flags; /* Copy of flags parameter to glob. */
111 char **gl_pathv; /* List of paths matching pattern. */
112 /* Copy of errfunc parameter to glob. */
113 int (*gl_errfunc)(const char *, int);
116 * Alternate filesystem access methods for glob; replacement
117 * versions of closedir(3), readdir(3), opendir(3), stat(2)
118 * and lstat(2).
120 void (*gl_closedir)(void *);
121 struct dirent *(*gl_readdir)(void *);
122 void *(*gl_opendir)(const char *);
123 int (*gl_lstat)(const char *, struct stat *);
124 int (*gl_stat)(const char *, struct stat *);
125 } glob_t;
127 /* Flags */
128 # define GLOB_APPEND 0x0001 /* Append to output from previous call. */
129 # define GLOB_DOOFFS 0x0002 /* Use gl_offs. */
130 # define GLOB_ERR 0x0004 /* Return on error. */
131 # define GLOB_MARK 0x0008 /* Append / to matching directories. */
132 # define GLOB_NOCHECK 0x0010 /* Return pattern itself if nothing matches. */
133 # define GLOB_NOSORT 0x0020 /* Don't sort. */
135 # define GLOB_ALTDIRFUNC 0x0040 /* Use alternately specified directory funcs. */
136 # define GLOB_BRACE 0x0080 /* Expand braces ala csh. */
137 # define GLOB_MAGCHAR 0x0100 /* Pattern had globbing characters. */
138 # define GLOB_NOMAGIC 0x0200 /* GLOB_NOCHECK without magic chars (csh). */
139 # define GLOB_QUOTE 0x0400 /* Quote special chars with \. */
140 # define GLOB_TILDE 0x0800 /* Expand tilde names from the passwd file. */
141 # define GLOB_NOESCAPE 0x1000 /* Disable backslash escaping. */
143 /* Error values returned by glob(3) */
144 # define GLOB_NOSPACE (-1) /* Malloc call failed. */
145 # define GLOB_ABORTED (-2) /* Unignored error. */
146 # define GLOB_NOMATCH (-3) /* No match and GLOB_NOCHECK not set. */
147 # define GLOB_NOSYS (-4) /* Function not supported. */
148 # define GLOB_ABEND GLOB_ABORTED
150 int openbsd_glob(const char *, int, int (*)(const char *, int), glob_t *);
151 void openbsd_globfree(glob_t *);
152 # define glob openbsd_glob
153 # define globfree openbsd_globfree
155 # else /* HAVE_GLOB */
157 # ifdef HAVE_GLOB_H
158 # include <glob.h>
159 # endif
161 # endif /* ! HAVE_GLOB */
162 #endif /* NEED_GLOB */
165 #if defined(NEED_INET_ATON) && !defined(HAVE_INET_ATON)
167 int inet_aton(const char *, struct in_addr *);
169 #endif /* NEED_INET_ATON && ! HAVE_INET_ATON */
172 #ifdef NEED_MAKEDEV
174 # ifdef MAJOR_IN_MKDEV
175 # include <sys/mkdev.h>
176 # else
177 # ifdef MAJOR_IN_SYSMACROS
178 # include <sys/sysmacros.h>
179 # endif
180 # endif
183 ** On most systems makedev() has two args.
184 ** Some weird systems, like QNX6, have makedev() functions that expect
185 ** an extra first argument for "node", which can be 0 for a local
186 ** machine.
189 # ifdef MAKEDEV_THREE_ARGS
190 # define compat_makedev(maj, min) makedev(0, maj, min)
191 # else
192 # define compat_makedev makedev
193 # endif
195 #endif /* NEED_MAKEDEV */
198 #if defined(NEED_SNPRINTF) && !defined(HAVE_SNPRINTF)
200 int mutt_snprintf(char *, size_t, const char *, ...);
201 int mutt_vsnprintf(char *, size_t, const char *, va_list);
202 #define snprintf mutt_snprintf
203 #define vsnprintf mutt_vsnprintf
205 #endif /* NEED_SNPRINTF && ! HAVE_SNPRINTF */
208 #if defined(NEED_STRLCAT) && !defined(HAVE_STRLCAT)
210 size_t strlcat(char *, const char *, size_t);
212 #endif /* NEED_STRLCAT && ! HAVE_STRLCAT */
215 #if defined(NEED_STRLCPY) && !defined(HAVE_STRLCPY)
217 size_t strlcpy(char *, const char *, size_t);
219 #endif /* NEED_STRLCPY && ! HAVE_STRLCPY */
222 #if defined(NEED_STRDUP) && !defined(HAVE_STRDUP)
224 char *openbsd_strdup(const char *);
225 # define strdup openbsd_strdup
227 #endif /* NEED_STRDUP && ! HAVE_STRDUP */
230 #if defined(NEED_STRMODE) && !defined(HAVE_STRMODE)
232 void strmode(register mode_t, register char *);
234 #endif /* NEED_STRMODE && ! HAVE_STRMODE */
237 #if defined(NEED_STRRSTR) && !defined(HAVE_STRRSTR)
239 char *strrstr(char *, char *);
241 #endif /* NEED_STRRSTR && ! HAVE_STRRSTR */
244 #ifdef NEED_STRSEP
246 # ifdef HAVE_STRSEP
247 # define _LINUX_SOURCE_COMPAT /* needed on AIX 4.3.3 */
248 # else
250 char *strsep(register char **, register const char *);
252 # endif
254 #endif /* NEED_STRSEP */