1*74010a1aSgutteridge /* $NetBSD: resize.h,v 1.3 2023/04/20 22:23:53 gutteridge Exp $ */
266a2df67Schristos
366a2df67Schristos /*-
466a2df67Schristos * Copyright (c) 2021 The NetBSD Foundation, Inc.
566a2df67Schristos * All rights reserved.
666a2df67Schristos *
766a2df67Schristos * This code is derived from software contributed to The NetBSD Foundation
866a2df67Schristos * by Christos Zoulas.
966a2df67Schristos *
1066a2df67Schristos * Redistribution and use in source and binary forms, with or without
1166a2df67Schristos * modification, are permitted provided that the following conditions
1266a2df67Schristos * are met:
1366a2df67Schristos * 1. Redistributions of source code must retain the above copyright
1466a2df67Schristos * notice, this list of conditions and the following disclaimer.
1566a2df67Schristos * 2. Redistributions in binary form must reproduce the above copyright
1666a2df67Schristos * notice, this list of conditions and the following disclaimer in the
1766a2df67Schristos * documentation and/or other materials provided with the distribution.
1866a2df67Schristos *
1966a2df67Schristos * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2066a2df67Schristos * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2166a2df67Schristos * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2266a2df67Schristos * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2366a2df67Schristos * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2466a2df67Schristos * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2566a2df67Schristos * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2666a2df67Schristos * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2766a2df67Schristos * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2866a2df67Schristos * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2966a2df67Schristos * POSSIBILITY OF SUCH DAMAGE.
3066a2df67Schristos */
3166a2df67Schristos
3266a2df67Schristos #include <time.h>
3366a2df67Schristos #include <termios.h>
3466a2df67Schristos #include <pwd.h>
3566a2df67Schristos #include <string.h>
3666a2df67Schristos #include <stdlib.h>
3766a2df67Schristos #include <unistd.h>
3866a2df67Schristos #include <fcntl.h>
3966a2df67Schristos #include <errno.h>
4066a2df67Schristos #include <fcntl.h>
4166a2df67Schristos #include <util.h>
4266a2df67Schristos #include <signal.h>
4366a2df67Schristos #include <libgen.h>
4466a2df67Schristos #include <sys/ioctl.h>
4566a2df67Schristos
4666a2df67Schristos #define DFT_TERMTYPE "vt100"
4766a2df67Schristos
4866a2df67Schristos #define USE_TERMINFO
4966a2df67Schristos #define USE_STRUCT_WINSIZE
5066a2df67Schristos #define USE_TERMIOS
5166a2df67Schristos
5266a2df67Schristos #define GCC_NORETURN __dead
5366a2df67Schristos #define GCC_UNUSED __unused
5466a2df67Schristos
5566a2df67Schristos #define IGNORE_RC(a) (void)(a)
5666a2df67Schristos #define ENVP_ARG , char **envp
5766a2df67Schristos
5866a2df67Schristos #define TTYSIZE_STRUCT struct winsize
5966a2df67Schristos #define TTYSIZE_ROWS(ws) (ws).ws_row
6066a2df67Schristos #define TTYSIZE_COLS(ws) (ws).ws_col
618e0f0751Schristos #define SET_TTYSIZE(fd, ws) ioctl((fd), TIOCSWINSZ, &(ws))
6266a2df67Schristos
63*74010a1aSgutteridge #define x_basename(a) estrdup(basename(a))
6466a2df67Schristos #define x_strdup(a) estrdup(a)
6566a2df67Schristos #define x_getenv(a) getenv(a)
6666a2df67Schristos #define x_getlogin(u, p) __nothing
6766a2df67Schristos #define x_strindex(s, c) strstr((s), (c))
6866a2df67Schristos
6966a2df67Schristos static int
x_getpwuid(uid_t uid,struct passwd * pw)7066a2df67Schristos x_getpwuid(uid_t uid, struct passwd *pw)
7166a2df67Schristos {
7266a2df67Schristos struct passwd *p = getpwuid(uid);
7366a2df67Schristos if (p == NULL) {
7466a2df67Schristos memset(pw, 0, sizeof(*pw));
7566a2df67Schristos return 1;
7666a2df67Schristos }
7766a2df67Schristos *pw = *p;
7866a2df67Schristos return 0;
7966a2df67Schristos }
8066a2df67Schristos
8166a2df67Schristos #define setup_winsize(ws, row, col, xpixel, ypixel) \
8266a2df67Schristos (void)((ws).ws_row = row, \
8366a2df67Schristos (ws).ws_col = col, \
8466a2df67Schristos (ws).ws_xpixel = xpixel, \
8566a2df67Schristos (ws).ws_ypixel = ypixel)
8666a2df67Schristos
8766a2df67Schristos #define CharOf(a) ((unsigned char)(a))
8866a2df67Schristos #define OkPasswd(pw) *((pw)->pw_name)
8966a2df67Schristos #define TypeMallocN(t, l) emalloc(sizeof(t) * (l))
9066a2df67Schristos #define UIntClr(d, b) (d) = (d) & ~(b)
9166a2df67Schristos
9266a2df67Schristos #define xtermVersion() "NetBSD"
93