1 /* $XTermId: sys.h,v 1.23 2021/01/13 22:13:24 tom Exp $ */
2 
3 /*
4 Copyright 2010-2013,2021 by Thomas E. Dickey
5 Copyright (c) 2001 by Juliusz Chroboczek
6 
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software and associated documentation files (the "Software"), to deal
9 in the Software without restriction, including without limitation the rights
10 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 copies of the Software, and to permit persons to whom the Software is
12 furnished to do so, subject to the following conditions:
13 
14 The above copyright notice and this permission notice shall be included in
15 all copies or substantial portions of the Software.
16 
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
20 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 THE SOFTWARE.
24 */
25 
26 #ifndef LUIT_SYS_H
27 #define LUIT_SYS_H 1
28 
29 #if defined(__GNUC__) && defined(_FORTIFY_SOURCE)
30 #define USE_IGNORE_RC
31 extern int ignore_unused;
32 #define IGNORE_RC(func) ignore_unused = (int) func
33 #else
34 #define IGNORE_RC(func) (void) func
35 #endif /* gcc workarounds */
36 
37 #define IO_CanRead   1
38 #define IO_CanWrite  2
39 #define IO_Closed    4
40 
41 #define TypeCalloc(type)    (type *) calloc((size_t) 1, sizeof(type))
42 #define TypeCallocN(type,n) (type *) calloc((size_t) (n), sizeof(type))
43 
44 #define SizeOf(v)        (sizeof(v) / sizeof(v[0]))
45 
46 int waitForOutput(int fd);
47 int waitForInput(int fd1, int fd2);
48 int setWindowSize(int sfd, int dfd);
49 int installHandler(int signum, void (*handler) (int));
50 int copyTermios(int sfd, int dfd);
51 int restoreTermios(int sfd);
52 int setRawTermios(int sfd);
53 char *my_basename(char *path);
54 int allocatePty(int *pty_return, char **line_return);
55 int openTty(char *line);
56 int droppriv(void);
57 char *strmalloc(const char *value);
58 
59 #ifdef HAVE_STRCASECMP
60 #define StrCaseCmp(a,b) strcasecmp(a,b)
61 #else
62 int my_strcasecmp(const char *a, const char *b);
63 #define StrCaseCmp(a,b) my_strcasecmp(a,b)
64 #endif
65 
66 #ifdef NO_LEAKS
67 void luit_leaks(void);
68 void charset_leaks(void);
69 void fontenc_leaks(void);
70 void iso2022_leaks(void);
71 void luitconv_leaks(void);
72 void ExitProgram(int code) GCC_NORETURN;
73 #else
74 #define ExitProgram(code) exit(code)
75 #endif
76 
77 #define ExitSuccess() ExitProgram(EXIT_SUCCESS)
78 #define ExitFailure() ExitProgram(EXIT_FAILURE)
79 
80 #endif /* LUIT_SYS_H */
81