1 /*
2 * Check decoding of ioctl TIOC[GS]WINSZ commands.
3 *
4 * Copyright (c) 2022 Dmitry V. Levin <ldv@strace.io>
5 * All rights reserved.
6 *
7 * SPDX-License-Identifier: GPL-2.0-or-later
8 */
9
10 #include "tests.h"
11 #include <stdio.h>
12 #include <sys/ioctl.h>
13
14 int
15 main(void)
16 {
17 int rc;
18
19 rc = ioctl(-1, TIOCGWINSZ, 0);
20 printf("ioctl(-1, TIOCGWINSZ, NULL) = %s\n", sprintrc(rc));
21
22 rc = ioctl(-1, TIOCSWINSZ, 0);
23 printf("ioctl(-1, TIOCSWINSZ, NULL) = %s\n", sprintrc(rc));
24
25 TAIL_ALLOC_OBJECT_CONST_PTR(struct winsize, ws);
26 const void *const efault = ws + 1;
27 fill_memory(ws, sizeof(*ws));
28
29 rc = ioctl(-1, TIOCSWINSZ, efault);
30 printf("ioctl(-1, TIOCSWINSZ, %p) = %s\n", efault, sprintrc(rc));
31
32 rc = ioctl(-1, TIOCGWINSZ, ws);
33 printf("ioctl(-1, TIOCGWINSZ, %p) = %s\n", ws, sprintrc(rc));
34
35 rc = ioctl(-1, TIOCSWINSZ, ws);
36 printf("ioctl(-1, TIOCSWINSZ, {ws_row=%u, ws_col=%u"
37 ", ws_xpixel=%u, ws_ypixel=%u}) = %s\n",
38 ws->ws_row, ws->ws_col, ws->ws_xpixel, ws->ws_ypixel,
39 sprintrc(rc));
40
41 puts("+++ exited with 0 +++");
42 return 0;
43 }