tmux  3.2a
About: tmux is a terminal multiplexer that lets you switch easily between several programs in one terminal.
  Fossies Dox: tmux-3.2a.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

compat.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
3  *
4  * Permission to use, copy, modify, and distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
13  * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
14  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16 
17 #ifndef COMPAT_H
18 #define COMPAT_H
19 
20 #include <sys/types.h>
21 #include <sys/ioctl.h>
22 #include <sys/uio.h>
23 
24 #include <fnmatch.h>
25 #include <limits.h>
26 #include <stdio.h>
27 #include <termios.h>
28 #include <wchar.h>
29 
30 #ifdef HAVE_EVENT2_EVENT_H
31 #include <event2/event.h>
32 #include <event2/event_compat.h>
33 #include <event2/event_struct.h>
34 #include <event2/buffer.h>
35 #include <event2/buffer_compat.h>
36 #include <event2/bufferevent.h>
37 #include <event2/bufferevent_struct.h>
38 #include <event2/bufferevent_compat.h>
39 #else
40 #include <event.h>
41 #endif
42 
43 #ifdef HAVE_MALLOC_TRIM
44 #include <malloc.h>
45 #endif
46 
47 #ifdef HAVE_UTF8PROC
48 #include <utf8proc.h>
49 #endif
50 
51 #ifndef __GNUC__
52 #define __attribute__(a)
53 #endif
54 
55 #ifdef BROKEN___DEAD
56 #undef __dead
57 #endif
58 
59 #ifndef __unused
60 #define __unused __attribute__ ((__unused__))
61 #endif
62 #ifndef __dead
63 #define __dead __attribute__ ((__noreturn__))
64 #endif
65 #ifndef __packed
66 #define __packed __attribute__ ((__packed__))
67 #endif
68 #ifndef __weak
69 #define __weak __attribute__ ((__weak__))
70 #endif
71 
72 #ifndef ECHOPRT
73 #define ECHOPRT 0
74 #endif
75 
76 #ifndef ACCESSPERMS
77 #define ACCESSPERMS (S_IRWXU|S_IRWXG|S_IRWXO)
78 #endif
79 
80 #if !defined(FIONREAD) && defined(__sun)
81 #include <sys/filio.h>
82 #endif
83 
84 #ifdef HAVE_ERR_H
85 #include <err.h>
86 #else
87 void err(int, const char *, ...);
88 void errx(int, const char *, ...);
89 void warn(const char *, ...);
90 void warnx(const char *, ...);
91 #endif
92 
93 #ifdef HAVE_PATHS_H
94 #include <paths.h>
95 #endif
96 
97 #ifndef _PATH_BSHELL
98 #define _PATH_BSHELL "/bin/sh"
99 #endif
100 
101 #ifndef _PATH_TMP
102 #define _PATH_TMP "/tmp/"
103 #endif
104 
105 #ifndef _PATH_DEVNULL
106 #define _PATH_DEVNULL "/dev/null"
107 #endif
108 
109 #ifndef _PATH_TTY
110 #define _PATH_TTY "/dev/tty"
111 #endif
112 
113 #ifndef _PATH_DEV
114 #define _PATH_DEV "/dev/"
115 #endif
116 
117 #ifndef _PATH_DEFPATH
118 #define _PATH_DEFPATH "/usr/bin:/bin"
119 #endif
120 
121 #ifndef _PATH_VI
122 #define _PATH_VI "/usr/bin/vi"
123 #endif
124 
125 #ifndef __OpenBSD__
126 #define pledge(s, p) (0)
127 #endif
128 
129 #ifndef IMAXBEL
130 #define IMAXBEL 0
131 #endif
132 
133 #ifdef HAVE_STDINT_H
134 #include <stdint.h>
135 #else
136 #include <inttypes.h>
137 #endif
138 
139 #ifdef HAVE_QUEUE_H
140 #include <sys/queue.h>
141 #else
142 #include "compat/queue.h"
143 #endif
144 
145 #ifdef HAVE_TREE_H
146 #include <sys/tree.h>
147 #else
148 #include "compat/tree.h"
149 #endif
150 
151 #ifdef HAVE_BITSTRING_H
152 #include <bitstring.h>
153 #else
154 #include "compat/bitstring.h"
155 #endif
156 
157 #ifdef HAVE_LIBUTIL_H
158 #include <libutil.h>
159 #endif
160 
161 #ifdef HAVE_PTY_H
162 #include <pty.h>
163 #endif
164 
165 #ifdef HAVE_UTIL_H
166 #include <util.h>
167 #endif
168 
169 #ifdef HAVE_VIS
170 #include <vis.h>
171 #else
172 #include "compat/vis.h"
173 #endif
174 
175 #ifdef HAVE_IMSG
176 #include <imsg.h>
177 #else
178 #include "compat/imsg.h"
179 #endif
180 
181 #ifdef BROKEN_CMSG_FIRSTHDR
182 #undef CMSG_FIRSTHDR
183 #define CMSG_FIRSTHDR(mhdr) \
184  ((mhdr)->msg_controllen >= sizeof(struct cmsghdr) ? \
185  (struct cmsghdr *)(mhdr)->msg_control : \
186  (struct cmsghdr *)NULL)
187 #endif
188 
189 #ifndef CMSG_ALIGN
190 #ifdef _CMSG_DATA_ALIGN
191 #define CMSG_ALIGN _CMSG_DATA_ALIGN
192 #else
193 #define CMSG_ALIGN(len) (((len) + sizeof(long) - 1) & ~(sizeof(long) - 1))
194 #endif
195 #endif
196 
197 #ifndef CMSG_SPACE
198 #define CMSG_SPACE(len) (CMSG_ALIGN(sizeof(struct cmsghdr)) + CMSG_ALIGN(len))
199 #endif
200 
201 #ifndef CMSG_LEN
202 #define CMSG_LEN(len) (CMSG_ALIGN(sizeof(struct cmsghdr)) + (len))
203 #endif
204 
205 #ifndef O_DIRECTORY
206 #define O_DIRECTORY 0
207 #endif
208 
209 #ifndef FNM_CASEFOLD
210 #ifdef FNM_IGNORECASE
211 #define FNM_CASEFOLD FNM_IGNORECASE
212 #else
213 #define FNM_CASEFOLD 0
214 #endif
215 #endif
216 
217 #ifndef INFTIM
218 #define INFTIM -1
219 #endif
220 
221 #ifndef WAIT_ANY
222 #define WAIT_ANY -1
223 #endif
224 
225 #ifndef SUN_LEN
226 #define SUN_LEN(sun) (sizeof (sun)->sun_path)
227 #endif
228 
229 #ifndef timercmp
230 #define timercmp(tvp, uvp, cmp) \
231  (((tvp)->tv_sec == (uvp)->tv_sec) ? \
232  ((tvp)->tv_usec cmp (uvp)->tv_usec) : \
233  ((tvp)->tv_sec cmp (uvp)->tv_sec))
234 #endif
235 
236 #ifndef timeradd
237 #define timeradd(tvp, uvp, vvp) \
238  do { \
239  (vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec; \
240  (vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec; \
241  if ((vvp)->tv_usec >= 1000000) { \
242  (vvp)->tv_sec++; \
243  (vvp)->tv_usec -= 1000000; \
244  } \
245  } while (0)
246 #endif
247 
248 #ifndef timersub
249 #define timersub(tvp, uvp, vvp) \
250  do { \
251  (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \
252  (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \
253  if ((vvp)->tv_usec < 0) { \
254  (vvp)->tv_sec--; \
255  (vvp)->tv_usec += 1000000; \
256  } \
257  } while (0)
258 #endif
259 
260 #ifndef TTY_NAME_MAX
261 #define TTY_NAME_MAX 32
262 #endif
263 
264 #ifndef HOST_NAME_MAX
265 #define HOST_NAME_MAX 255
266 #endif
267 
268 #ifndef CLOCK_REALTIME
269 #define CLOCK_REALTIME 0
270 #endif
271 #ifndef CLOCK_MONOTONIC
272 #define CLOCK_MONOTONIC CLOCK_REALTIME
273 #endif
274 
275 #ifndef HAVE_FLOCK
276 #define LOCK_SH 0
277 #define LOCK_EX 0
278 #define LOCK_NB 0
279 #define flock(fd, op) (0)
280 #endif
281 
282 #ifndef HAVE_EXPLICIT_BZERO
283 /* explicit_bzero.c */
284 void explicit_bzero(void *, size_t);
285 #endif
286 
287 #ifndef HAVE_GETDTABLECOUNT
288 /* getdtablecount.c */
289 int getdtablecount(void);
290 #endif
291 
292 #ifndef HAVE_CLOSEFROM
293 /* closefrom.c */
294 void closefrom(int);
295 #endif
296 
297 #ifndef HAVE_STRCASESTR
298 /* strcasestr.c */
299 char *strcasestr(const char *, const char *);
300 #endif
301 
302 #ifndef HAVE_STRSEP
303 /* strsep.c */
304 char *strsep(char **, const char *);
305 #endif
306 
307 #ifndef HAVE_STRTONUM
308 /* strtonum.c */
309 long long strtonum(const char *, long long, long long, const char **);
310 #endif
311 
312 #ifndef HAVE_STRLCPY
313 /* strlcpy.c */
314 size_t strlcpy(char *, const char *, size_t);
315 #endif
316 
317 #ifndef HAVE_STRLCAT
318 /* strlcat.c */
319 size_t strlcat(char *, const char *, size_t);
320 #endif
321 
322 #ifndef HAVE_STRNLEN
323 /* strnlen.c */
324 size_t strnlen(const char *, size_t);
325 #endif
326 
327 #ifndef HAVE_STRNDUP
328 /* strndup.c */
329 char *strndup(const char *, size_t);
330 #endif
331 
332 #ifndef HAVE_MEMMEM
333 /* memmem.c */
334 void *memmem(const void *, size_t, const void *, size_t);
335 #endif
336 
337 #ifndef HAVE_DAEMON
338 /* daemon.c */
339 int daemon(int, int);
340 #endif
341 
342 #ifndef HAVE_GETPROGNAME
343 /* getprogname.c */
344 const char *getprogname(void);
345 #endif
346 
347 #ifndef HAVE_SETPROCTITLE
348 /* setproctitle.c */
349 void setproctitle(const char *, ...);
350 #endif
351 
352 #ifndef HAVE_CLOCK_GETTIME
353 /* clock_gettime.c */
354 int clock_gettime(int, struct timespec *);
355 #endif
356 
357 #ifndef HAVE_B64_NTOP
358 /* base64.c */
359 #undef b64_ntop
360 #undef b64_pton
361 int b64_ntop(const char *, size_t, char *, size_t);
362 int b64_pton(const char *, u_char *, size_t);
363 #endif
364 
365 #ifndef HAVE_FDFORKPTY
366 /* fdforkpty.c */
367 int getptmfd(void);
368 pid_t fdforkpty(int, int *, char *, struct termios *,
369  struct winsize *);
370 #endif
371 
372 #ifndef HAVE_FORKPTY
373 /* forkpty.c */
374 pid_t forkpty(int *, char *, struct termios *, struct winsize *);
375 #endif
376 
377 #ifndef HAVE_ASPRINTF
378 /* asprintf.c */
379 int asprintf(char **, const char *, ...);
380 int vasprintf(char **, const char *, va_list);
381 #endif
382 
383 #ifndef HAVE_FGETLN
384 /* fgetln.c */
385 char *fgetln(FILE *, size_t *);
386 #endif
387 
388 #ifndef HAVE_GETLINE
389 /* getline.c */
390 ssize_t getline(char **, size_t *, FILE *);
391 #endif
392 
393 #ifndef HAVE_SETENV
394 /* setenv.c */
395 int setenv(const char *, const char *, int);
396 int unsetenv(const char *);
397 #endif
398 
399 #ifndef HAVE_CFMAKERAW
400 /* cfmakeraw.c */
401 void cfmakeraw(struct termios *);
402 #endif
403 
404 #ifndef HAVE_FREEZERO
405 /* freezero.c */
406 void freezero(void *, size_t);
407 #endif
408 
409 #ifndef HAVE_REALLOCARRAY
410 /* reallocarray.c */
411 void *reallocarray(void *, size_t, size_t);
412 #endif
413 
414 #ifndef HAVE_RECALLOCARRAY
415 /* recallocarray.c */
416 void *recallocarray(void *, size_t, size_t, size_t);
417 #endif
418 
419 #ifdef HAVE_UTF8PROC
420 /* utf8proc.c */
421 int utf8proc_wcwidth(wchar_t);
422 int utf8proc_mbtowc(wchar_t *, const char *, size_t);
423 int utf8proc_wctomb(char *, wchar_t);
424 #endif
425 
426 #ifdef NEED_FUZZING
427 /* tmux.c */
428 #define main __weak main
429 #endif
430 
431 /* getopt.c */
432 extern int BSDopterr;
433 extern int BSDoptind;
434 extern int BSDoptopt;
435 extern int BSDoptreset;
436 extern char *BSDoptarg;
437 int BSDgetopt(int, char *const *, const char *);
438 #define getopt(ac, av, o) BSDgetopt(ac, av, o)
439 #define opterr BSDopterr
440 #define optind BSDoptind
441 #define optopt BSDoptopt
442 #define optreset BSDoptreset
443 #define optarg BSDoptarg
444 
445 #endif /* COMPAT_H */
int b64_ntop(const char *, size_t, char *, size_t)
char * strcasestr(const char *, const char *)
void * recallocarray(void *, size_t, size_t, size_t)
int BSDoptopt
void warn(const char *,...)
const char * getprogname(void)
char * BSDoptarg
int vasprintf(char **, const char *, va_list)
char * strsep(char **, const char *)
char * fgetln(FILE *, size_t *)
int clock_gettime(int, struct timespec *)
int setenv(const char *, const char *, int)
int unsetenv(const char *)
void freezero(void *, size_t)
pid_t forkpty(int *, char *, struct termios *, struct winsize *)
int BSDoptreset
size_t strlcat(char *, const char *, size_t)
size_t strlcpy(char *, const char *, size_t)
int BSDoptind
ssize_t getline(char **, size_t *, FILE *)
void closefrom(int)
pid_t fdforkpty(int, int *, char *, struct termios *, struct winsize *)
void errx(int, const char *,...)
int BSDopterr
long long strtonum(const char *, long long, long long, const char **)
void setproctitle(const char *,...)
int BSDgetopt(int, char *const *, const char *)
int b64_pton(const char *, u_char *, size_t)
int daemon(int, int)
int getptmfd(void)
void warnx(const char *,...)
void * reallocarray(void *, size_t, size_t)
void explicit_bzero(void *, size_t)
void cfmakeraw(struct termios *)
int getdtablecount(void)
size_t strnlen(const char *, size_t)
char * strndup(const char *, size_t)
int asprintf(char **, const char *,...)
void * memmem(const void *, size_t, const void *, size_t)
void err(int, const char *,...)