xref: /netbsd-src/usr.bin/resize/resize.h (revision 74010a1af9185cd8e5682a8a47538dd9723ca8cf)
1 /*	$NetBSD: resize.h,v 1.3 2023/04/20 22:23:53 gutteridge Exp $	*/
2 
3 /*-
4  * Copyright (c) 2021 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Christos Zoulas.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #include <time.h>
33 #include <termios.h>
34 #include <pwd.h>
35 #include <string.h>
36 #include <stdlib.h>
37 #include <unistd.h>
38 #include <fcntl.h>
39 #include <errno.h>
40 #include <fcntl.h>
41 #include <util.h>
42 #include <signal.h>
43 #include <libgen.h>
44 #include <sys/ioctl.h>
45 
46 #define DFT_TERMTYPE "vt100"
47 
48 #define USE_TERMINFO
49 #define USE_STRUCT_WINSIZE
50 #define USE_TERMIOS
51 
52 #define GCC_NORETURN __dead
53 #define GCC_UNUSED __unused
54 
55 #define IGNORE_RC(a) (void)(a)
56 #define ENVP_ARG , char **envp
57 
58 #define TTYSIZE_STRUCT struct winsize
59 #define TTYSIZE_ROWS(ws) (ws).ws_row
60 #define TTYSIZE_COLS(ws) (ws).ws_col
61 #define SET_TTYSIZE(fd, ws) ioctl((fd), TIOCSWINSZ, &(ws))
62 
63 #define x_basename(a) estrdup(basename(a))
64 #define x_strdup(a) estrdup(a)
65 #define x_getenv(a) getenv(a)
66 #define x_getlogin(u, p) __nothing
67 #define x_strindex(s, c) strstr((s), (c))
68 
69 static int
x_getpwuid(uid_t uid,struct passwd * pw)70 x_getpwuid(uid_t uid, struct passwd *pw)
71 {
72 	struct passwd *p = getpwuid(uid);
73 	if (p == NULL) {
74 		memset(pw, 0, sizeof(*pw));
75 		return 1;
76 	}
77 	*pw = *p;
78 	return 0;
79 }
80 
81 #define setup_winsize(ws, row, col, xpixel, ypixel) \
82     (void)((ws).ws_row = row, \
83 	(ws).ws_col = col, \
84 	(ws).ws_xpixel = xpixel, \
85 	(ws).ws_ypixel = ypixel)
86 
87 #define CharOf(a) ((unsigned char)(a))
88 #define OkPasswd(pw) *((pw)->pw_name)
89 #define TypeMallocN(t, l) emalloc(sizeof(t) * (l))
90 #define UIntClr(d, b)	(d) = (d) & ~(b)
91 
92 #define xtermVersion() "NetBSD"
93