kmalloc: Avoid code duplication.
[dragonfly.git] / contrib / tnftp / tnftp.h
blob85619efd3da4328131cab3ac2fc193fd57e0f4f4
1 /* $NetBSD: tnftp.h,v 1.36 2014/10/31 07:22:03 lukem Exp $ */
3 #define FTP_PRODUCT PACKAGE_NAME
4 #define FTP_VERSION PACKAGE_VERSION
6 #include "tnftp_config.h"
8 #include <assert.h>
9 #include <stdio.h>
10 #include <ctype.h>
11 #include <errno.h>
13 #if defined(HAVE_SYS_TYPES_H)
14 # include <sys/types.h>
15 #endif
16 #if defined(STDC_HEADERS)
17 # include <stdarg.h>
18 # include <stdlib.h>
19 # include <string.h>
20 #endif
21 #if defined(HAVE_LIBGEN_H)
22 # include <libgen.h>
23 #endif
24 #if defined(HAVE_UNISTD_H)
25 # include <unistd.h>
26 #endif
27 #if defined(HAVE_POLL_H)
28 # include <poll.h>
29 #elif defined(HAVE_SYS_POLL_H)
30 # include <sys/poll.h>
31 #endif
32 #if defined(HAVE_SYS_SOCKET_H)
33 # include <sys/socket.h>
34 #endif
35 #if defined(HAVE_NETINET_IN_H)
36 # include <netinet/in.h>
37 #endif
38 #if defined(HAVE_NETINET_IN_SYSTM_H)
39 # include <netinet/in_systm.h>
40 #endif
41 #if defined(HAVE_NETINET_IP_H)
42 # include <netinet/ip.h>
43 #endif
44 #if defined(HAVE_NETINET_TCP_H)
45 # include <netinet/tcp.h>
46 #endif
47 #if defined(HAVE_NETDB_H)
48 # if HAVE_DECL_AI_NUMERICHOST
49 # include <netdb.h>
50 # else /* !HAVE_DECL_AI_NUMERICHOST */
51 # define getaddrinfo non_rfc2553_getaddrinfo
52 # include <netdb.h>
53 # undef getaddrinfo
54 # endif /* !HAVE_DECL_AI_NUMERICHOST */
55 #endif
56 #if defined(HAVE_ARPA_INET_H)
57 # include <arpa/inet.h>
58 #endif
59 #if defined(HAVE_DIRENT_H)
60 # include <dirent.h>
61 #else
62 # define dirent direct
63 # if defined(HAVE_SYS_NDIR_H)
64 # include <sys/ndir.h>
65 # endif
66 # if defined(HAVE_SYS_DIR_H)
67 # include <sys/dir.h>
68 # endif
69 # if defined(HAVE_NDIR_H)
70 # include <ndir.h>
71 # endif
72 #endif
73 #if defined(HAVE_SYS_UIO_H)
74 # include <sys/uio.h>
75 #endif
77 #if defined(HAVE_SYS_IOCTL_H)
78 # include <sys/ioctl.h>
79 #endif
80 #if defined(HAVE_SYS_PARAM_H)
81 # include <sys/param.h>
82 #endif
83 #if defined(HAVE_SYS_STAT_H)
84 # include <sys/stat.h>
85 #endif
86 #if defined(HAVE_SYS_SYSLIMITS_H)
87 # include <sys/syslimits.h>
88 #endif
89 #if defined(HAVE_SYS_WAIT_H)
90 # include <sys/wait.h>
91 #endif
93 #if defined(HAVE_ARPA_FTP_H)
94 # include <arpa/ftp.h>
95 #endif
97 #if defined(HAVE_FCNTL_H)
98 # include <fcntl.h>
99 #endif
100 #if defined(HAVE_LIMITS_H)
101 # include <limits.h>
102 #endif
103 #if defined(HAVE_LOCALE_H)
104 # include <locale.h>
105 #endif
106 #if defined(HAVE_PWD_H)
107 # include <pwd.h>
108 #endif
109 #if defined(HAVE_SETJMP_H)
110 # include <setjmp.h>
111 #endif
112 #if defined(HAVE_SIGNAL_H)
113 # include <signal.h>
114 #endif
115 #if defined(HAVE_STDDEF_H)
116 # include <stddef.h>
117 #endif
118 #if defined(HAVE_TERMIOS_H)
119 # include <termios.h>
120 #endif
122 #if defined(HAVE_POLL)
123 /* we use poll */
124 #elif defined(HAVE_SELECT)
125 /* we use select */
126 #else /* !defined(HAVE_POLL) && !defined(HAVE_SELECT) */
127 # error "no poll() or select() found"
128 #endif
129 #if !defined(POLLIN)
130 # define POLLIN 0x0001
131 #endif
132 #if !defined(POLLOUT)
133 # define POLLOUT 0x0004
134 #endif
135 #if !defined(POLLRDNORM)
136 # define POLLRDNORM 0x0040
137 #endif
138 #if !defined(POLLWRNORM)
139 # define POLLWRNORM POLLOUT
140 #endif
141 #if !defined(POLLRDBAND)
142 # define POLLRDBAND 0x0080
143 #endif
144 #if !defined(INFTIM)
145 # define INFTIM -1
146 #endif
147 #if !defined(HAVE_STRUCT_POLLFD)
148 struct pollfd {
149 int fd;
150 short events;
151 short revents;
153 #endif
155 #if defined(TIME_WITH_SYS_TIME)
156 # include <sys/time.h>
157 # include <time.h>
158 #else
159 # if defined(HAVE_SYS_TIME_H)
160 # include <sys/time.h>
161 # else
162 # include <time.h>
163 # endif
164 #endif
166 #if defined(HAVE_ERR_H)
167 # include <err.h>
168 #endif
170 #if defined(USE_GLOB_H) /* not set by configure; used by other build systems */
171 # include <glob.h>
172 #else
173 # include "ftpglob.h"
174 #endif
176 #if defined(HAVE_PATHS_H)
177 # include <paths.h>
178 #endif
179 #if !defined(_PATH_BSHELL)
180 # define _PATH_BSHELL "/bin/sh"
181 #endif
182 #if !defined(_PATH_TMP)
183 # define _PATH_TMP "/tmp/"
184 #endif
186 typedef struct _stringlist {
187 char **sl_str;
188 size_t sl_max;
189 size_t sl_cur;
190 } StringList;
192 StringList *sl_init(void);
193 int sl_add(StringList *, char *);
194 void sl_free(StringList *, int);
195 char *sl_find(StringList *, char *);
197 #if defined(HAVE_TERMCAP_H)
198 # include <termcap.h>
199 #else
200 int tgetent(char *, const char *);
201 char *tgetstr(const char *, char **);
202 int tgetflag(const char *);
203 int tgetnum(const char *);
204 char *tgoto(const char *, int, int);
205 void tputs(const char *, int, int (*)(int));
206 #endif /* !HAVE_TERMCAP_H */
208 #if defined(HAVE_VIS_H) && defined(HAVE_STRVIS) && defined(HAVE_STRUNVIS)
209 # include <vis.h>
210 #else
211 # include "ftpvis.h"
212 #endif
214 #if !defined(HAVE_IN_PORT_T)
215 typedef unsigned short in_port_t;
216 #endif
218 #if !defined(HAVE_SA_FAMILY_T)
219 typedef unsigned short sa_family_t;
220 #endif
222 #if !defined(HAVE_SOCKLEN_T)
223 typedef unsigned int socklen_t;
224 #endif
226 #if defined(USE_INET6)
227 # define INET6
228 #endif
230 #if !HAVE_DECL_AI_NUMERICHOST
232 /* RFC 2553 */
233 #undef EAI_ADDRFAMILY
234 #define EAI_ADDRFAMILY 1 /* address family for hostname not supported */
235 #undef EAI_AGAIN
236 #define EAI_AGAIN 2 /* temporary failure in name resolution */
237 #undef EAI_BADFLAGS
238 #define EAI_BADFLAGS 3 /* invalid value for ai_flags */
239 #undef EAI_FAIL
240 #define EAI_FAIL 4 /* non-recoverable failure in name resolution */
241 #undef EAI_FAMILY
242 #define EAI_FAMILY 5 /* ai_family not supported */
243 #undef EAI_MEMORY
244 #define EAI_MEMORY 6 /* memory allocation failure */
245 #undef EAI_NODATA
246 #define EAI_NODATA 7 /* no address associated with hostname */
247 #undef EAI_NONAME
248 #define EAI_NONAME 8 /* hostname nor servname provided, or not known */
249 #undef EAI_SERVICE
250 #define EAI_SERVICE 9 /* servname not supported for ai_socktype */
251 #undef EAI_SOCKTYPE
252 #define EAI_SOCKTYPE 10 /* ai_socktype not supported */
253 #undef EAI_SYSTEM
254 #define EAI_SYSTEM 11 /* system error returned in errno */
256 /* KAME extensions? */
257 #undef EAI_BADHINTS
258 #define EAI_BADHINTS 12
259 #undef EAI_PROTOCOL
260 #define EAI_PROTOCOL 13
261 #undef EAI_MAX
262 #define EAI_MAX 14
264 /* RFC 2553 */
265 #undef NI_MAXHOST
266 #define NI_MAXHOST 1025
267 #undef NI_MAXSERV
268 #define NI_MAXSERV 32
270 #undef NI_NOFQDN
271 #define NI_NOFQDN 0x00000001
272 #undef NI_NUMERICHOST
273 #define NI_NUMERICHOST 0x00000002
274 #undef NI_NAMEREQD
275 #define NI_NAMEREQD 0x00000004
276 #undef NI_NUMERICSERV
277 #define NI_NUMERICSERV 0x00000008
278 #undef NI_DGRAM
279 #define NI_DGRAM 0x00000010
281 /* RFC 2553 */
282 #undef AI_PASSIVE
283 #define AI_PASSIVE 0x00000001 /* get address to use bind() */
284 #undef AI_CANONNAME
285 #define AI_CANONNAME 0x00000002 /* fill ai_canonname */
287 /* KAME extensions ? */
288 #undef AI_NUMERICHOST
289 #define AI_NUMERICHOST 0x00000004 /* prevent name resolution */
290 #undef AI_MASK
291 #define AI_MASK (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST)
293 /* RFC 2553 */
294 #undef AI_ALL
295 #define AI_ALL 0x00000100 /* IPv6 and IPv4-mapped (with AI_V4MAPPED) */
296 #undef AI_V4MAPPED_CFG
297 #define AI_V4MAPPED_CFG 0x00000200 /* accept IPv4-mapped if kernel supports */
298 #undef AI_ADDRCONFIG
299 #define AI_ADDRCONFIG 0x00000400 /* only if any address is assigned */
300 #undef AI_V4MAPPED
301 #define AI_V4MAPPED 0x00000800 /* accept IPv4-mapped IPv6 address */
303 #endif /* !HAVE_DECL_AI_NUMERICHOST */
306 #if !HAVE_DECL_AI_NUMERICHOST && !defined(HAVE_STRUCT_ADDRINFO) \
307 && !defined(USE_SOCKS)
309 struct addrinfo {
310 int ai_flags; /* AI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST */
311 int ai_family; /* PF_xxx */
312 int ai_socktype; /* SOCK_xxx */
313 int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */
314 socklen_t ai_addrlen; /* length of ai_addr */
315 char *ai_canonname; /* canonical name for hostname */
316 struct sockaddr *ai_addr; /* binary address */
317 struct addrinfo *ai_next; /* next structure in linked list */
320 int getaddrinfo(const char *, const char *,
321 const struct addrinfo *, struct addrinfo **);
322 int getnameinfo(const struct sockaddr *, socklen_t,
323 char *, size_t, char *, size_t, int);
324 void freeaddrinfo(struct addrinfo *);
325 const char *gai_strerror(int);
327 #endif /* !HAVE_DECL_AI_NUMERICHOST && !defined(HAVE_STRUCT_ADDRINFO) \
328 && !defined(USE_SOCKS) */
330 #if !defined(HAVE_STRUCT_DIRENT_D_NAMLEN)
331 # define DIRENT_MISSING_D_NAMLEN
332 #endif
334 #if !HAVE_DECL_H_ERRNO
335 extern int h_errno;
336 #endif
337 #define HAVE_H_ERRNO 1 /* XXX: an assumption for now... */
339 #if !HAVE_DECL_FCLOSE
340 int fclose(FILE *);
341 #endif
343 #if !HAVE_DECL_GETPASS
344 char *getpass(const char *);
345 #endif
347 #if !HAVE_DECL_OPTARG
348 extern char *optarg;
349 #endif
351 #if !HAVE_DECL_OPTIND
352 extern int optind;
353 #endif
355 #if !HAVE_DECL_PCLOSE
356 int pclose(FILE *);
357 #endif
359 #if !HAVE_DECL_DIRNAME
360 char *dirname(char *);
361 #endif
363 #if !defined(HAVE_ERR)
364 void err(int, const char *, ...);
365 void errx(int, const char *, ...);
366 void warn(const char *, ...);
367 void warnx(const char *, ...);
368 #endif
370 #if !defined(HAVE_FGETLN)
371 char *fgetln(FILE *, size_t *);
372 #endif
374 #if !defined(HAVE_FSEEKO)
375 int fseeko(FILE *, off_t, int);
376 #endif
378 #if !defined(HAVE_INET_NTOP)
379 const char *inet_ntop(int, const void *, char *, socklen_t);
380 #endif
382 #if !defined(HAVE_INET_PTON)
383 int inet_pton(int, const char *, void *);
384 #endif
386 #if !defined(HAVE_MKSTEMP)
387 int mkstemp(char *);
388 #endif
390 #if !defined(HAVE_SETPROGNAME)
391 const char *getprogname(void);
392 void setprogname(const char *);
393 #endif
395 #if !defined(HAVE_SNPRINTF)
396 int snprintf(char *, size_t, const char *, ...);
397 #endif
399 #if !defined(HAVE_STRDUP)
400 char *strdup(const char *);
401 #endif
403 #if !defined(HAVE_STRERROR)
404 char *strerror(int);
405 #endif
407 #if !defined(HAVE_STRPTIME) || !HAVE_DECL_STRPTIME
408 char *strptime(const char *, const char *, struct tm *);
409 #endif
411 #if defined(HAVE_PRINTF_LONG_LONG) && defined(HAVE_LONG_LONG_INT)
412 # if !defined(HAVE_STRTOLL)
413 long long strtoll(const char *, char **, int);
414 # endif
415 # if !defined(LLONG_MIN)
416 # define LLONG_MIN (-0x7fffffffffffffffLL-1)
417 # endif
418 # if !defined(LLONG_MAX)
419 # define LLONG_MAX (0x7fffffffffffffffLL)
420 # endif
421 #else /* !(defined(HAVE_PRINTF_LONG_LONG) && defined(HAVE_LONG_LONG_INT)) */
422 # define NO_LONG_LONG 1
423 #endif /* !(defined(HAVE_PRINTF_LONG_LONG) && defined(HAVE_LONG_LONG_INT)) */
425 #if !defined(HAVE_TIMEGM)
426 time_t timegm(struct tm *);
427 #endif
429 #if !defined(HAVE_STRLCAT)
430 size_t strlcat(char *, const char *, size_t);
431 #endif
433 #if !defined(HAVE_STRLCPY)
434 size_t strlcpy(char *, const char *, size_t);
435 #endif
437 #if !defined(HAVE_STRSEP)
438 char *strsep(char **stringp, const char *delim);
439 #endif
441 #if !defined(HAVE_UTIMES)
442 int utimes(const char *, const struct timeval *);
443 #endif
445 #if !defined(HAVE_MEMMOVE)
446 # define memmove(a,b,c) bcopy((b),(a),(c))
447 /* XXX: add others #defines for borken systems? */
448 #endif
450 #if defined(HAVE_GETPASSPHRASE)
451 # define getpass getpassphrase
452 #endif
454 #if !defined(MIN)
455 # define MIN(a, b) ((a) < (b) ? (a) : (b))
456 #endif
457 #if !defined(MAX)
458 # define MAX(a, b) ((a) < (b) ? (b) : (a))
459 #endif
461 #if !defined(timersub)
462 # define timersub(tvp, uvp, vvp) \
463 do { \
464 (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \
465 (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \
466 if ((vvp)->tv_usec < 0) { \
467 (vvp)->tv_sec--; \
468 (vvp)->tv_usec += 1000000; \
470 } while (0)
471 #endif
473 #if !defined(S_ISLNK)
474 # define S_ISLNK(m) ((m & S_IFMT) == S_IFLNK)
475 #endif
477 #define EPOCH_YEAR 1970
478 #define SECSPERHOUR 3600
479 #define SECSPERDAY 86400
480 #define TM_YEAR_BASE 1900
482 #if defined(USE_SOCKS) /* (Dante) SOCKS5 */
483 #define connect Rconnect
484 #define bind Rbind
485 #define getsockname Rgetsockname
486 #define getpeername Rgetpeername
487 #define accept Raccept
488 #define rresvport Rrresvport
489 #define bindresvport Rbindresvport
490 #define gethostbyname Rgethostbyname
491 #define gethostbyname2 Rgethostbyname2
492 #define sendto Rsendto
493 #define recvfrom Rrecvfrom
494 #define recvfrom Rrecvfrom
495 #define write Rwrite
496 #define writev Rwritev
497 #define send Rsend
498 #define sendmsg Rsendmsg
499 #define read Rread
500 #define readv Rreadv
501 #define recv Rrecv
502 #define recvmsg Rrecvmsg
503 #define getaddrinfo Rgetaddrinfo
504 #define getipnodebyname Rgetipnodebyname
505 #endif /* defined(USE_SOCKS) */
509 * Compatibility for stuff in NetBSD <sys/cdefs.h>
511 #undef __dead
512 #define __dead
514 #ifdef __UNCONST
515 #undef __UNCONST
516 #endif
517 #define __UNCONST(a) ((void *)(unsigned long)(const void *)(a))