Debian Codegraph @

tests/identify.c

raw
1 /* identify -- Probe system and report characteristica.
2 Copyright (C) 2013-2026 Free Software Foundation, Inc.
3
4 This file is part of GNU Inetutils.
5
6 GNU Inetutils is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or (at
9 your option) any later version.
10
11 GNU Inetutils is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see `http://www.gnu.org/licenses/'. */
18
19 /* Written by Mats Erik Andersson. */
20
21 /* Collect information about this system and report it.
22 * Some identified characteristica of relevance to GNU Inetutils
23 * are displayed for use in bug reporting and resolution.
24 */
25
26 #include <config.h>
27
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <string.h>
31 #include <unistd.h>
32
33 #include <sys/param.h>
34 #include <sys/utsname.h>
35 #include <sys/types.h>
36 #include <sys/socket.h>
37 #include <sys/un.h>
38
39 #ifdef HAVE_TERMIOS_H
40 # include <errno.h>
41 # if HAVE_FCNTL_H
42 # include <fcntl.h>
43 # endif
44 # include <termios.h>
45
46 # include <pty.h>
47 #endif /* HAVE_TERMIOS_H */
48
49 #define tell_macro(a,b) \
50 printf ("%s: %s\n", (b) ? "Available macro" : "Not defined", (a));
51
52 #ifdef HAVE_TCGETATTR
53 # define test_flag(a, b, name) \
54 if (tc.a & b) printf (" %s", name);
55
56 void
57 do_termcap (void)
58 {
59 int pty, tty;
60 struct termios tc;
61
62 pty = openpty (&pty, &tty, NULL, NULL, NULL);
63 if (pty < 0)
64 {
65 fprintf (stderr, "openpt: errno = %d, %s\n", errno, strerror (errno));
66 return;
67 }
68
69 if (tcgetattr (tty, &tc) < 0)
70 {
71 fprintf (stderr, "tcgetattr; errno = %d, %s\n",
72 errno, strerror (errno));
73 return;
74 }
75
76 printf ("_POSIX_VDISABLE = 0x%02x\n\n", _POSIX_VDISABLE);
77
78 /* Report the most interesting observations. */
79 puts ("Default terminal settings (octal and hexadecimal):");
80 printf ("iflag = 0%06o = 0x%04x, oflag = 0%06o = 0x%04x\n",
81 tc.c_iflag, tc.c_iflag, tc.c_oflag, tc.c_oflag);
82 printf ("cflag = 0%06o = 0x%04x, lflag = 0%06o = 0x%04x\n",
83 tc.c_cflag, tc.c_cflag, tc.c_lflag, tc.c_lflag);
84
85 puts ("\nThe most relevant properties being set:");
86
87 printf ("iflag:");
88 test_flag (c_iflag, IXOFF, "IXOFF");
89 test_flag (c_iflag, IXON, "IXON");
90 test_flag (c_iflag, IXANY, "IXANY");
91 test_flag (c_iflag, BRKINT, "BRKINT");
92 test_flag (c_iflag, ISTRIP, "ISTRIP");
93 test_flag (c_iflag, IGNCR, "IGNCR");
94 test_flag (c_iflag, INLCR, "INLCR");
95 test_flag (c_iflag, ICRNL, "ICRNL");
96 puts ("");
97
98 printf ("oflag:");
99 test_flag (c_oflag, OPOST, "OPOST");
100 test_flag (c_oflag, OCRNL, "OCRNL");
101 test_flag (c_oflag, ONLCR, "ONLCR");
102 test_flag (c_oflag, ONLRET, "ONLRET");
103
104 # ifdef TABDLY
105 printf (" TAB");
106 switch (tc.c_oflag & TABDLY)
107 {
108 case TAB3:
109 putchar ('3');
110 break;
111 # ifdef TAB2
112 case TAB2:
113 putchar ('2');
114 break;
115 # endif
116 /* TAB2 */
117 # ifdef TAB1
118 case TAB1:
119 putchar ('1');
120 break;
121 # endif
122 /* TAB1 */
123 case TAB0:
124 putchar ('0');
125 break;
126 }
127 # elif defined OXTABS /* !TABDLY */
128 test_flag (c_oflag, OXTABS, "OXTABS");
129 # endif/* OXTABS */
130
131 puts ("");
132
133 printf ("cflag:");
134 switch (tc.c_cflag & CSIZE)
135 {
136 case CS8:
137 printf (" CS8");
138 break;
139 case CS7:
140 printf (" CS7");
141 }
142 puts ("");
143
144 printf ("lflag:");
145 test_flag (c_lflag, ICANON, "ICANON");
146 test_flag (c_lflag, ISIG, "TRAPSIG");
147 test_flag (c_lflag, IEXTEN, "IEXTEN");
148 test_flag (c_lflag, ECHO, "ECHO");
149 test_flag (c_lflag, ECHOE, "ECHOE");
150 test_flag (c_lflag, ECHOK, "ECHOK");
151 test_flag (c_lflag, ECHOKE, "ECHOKE");
152 test_flag (c_lflag, ECHONL, "ECHONL");
153 test_flag (c_lflag, ECHOCTL, "ECHOCTL");
154 puts ("");
155
156 return;
157 }
158
159 # undef test_flag
160 #endif /* HAVE_TCGETATTR */
161
162
163 int
164 main (void)
165 {
166 int a, ux;
167 struct utsname uts;
168 struct sockaddr_un su;
169
170 if (uname (&uts) < 0)
171 {
172 fprintf (stderr, "Not able to identify running system.\n");
173 exit (EXIT_FAILURE);
174 }
175
176 /* Identify the hardware. */
177 printf ("Running system: %s, %s\n", uts.sysname, uts.machine);
178 printf (" Variant: %s\n", uts.release);
179 printf (" Variant: %s\n", uts.version);
180 puts ("");
181
182 /*
183 * Report on macros that determine alternate code.
184 * These depend on toolchains and hardware.
185 */
186 ux = 0;
187 #ifdef unix
188 ux = 1;
189 #endif
190 tell_macro ("unix", ux);
191
192 ux = 0;
193 #ifdef __unix
194 ux = 1;
195 #endif
196 tell_macro ("__unix", ux);
197
198 ux = 0;
199 #ifdef __unix__
200 ux = 1;
201 #endif
202 tell_macro ("__unix__", ux);
203
204 ux = 0;
205 #ifdef __sun
206 ux = 1;
207 #endif
208 tell_macro ("__sun", ux);
209
210 ux = 0;
211 #ifdef __sun__
212 ux = 1;
213 #endif
214 tell_macro ("__sun__", ux);
215
216 /*
217 * Implementation specific charateristica.
218 */
219 puts ("");
220
221 a = 0;
222 #ifdef BSD
223 a = 1;
224 #endif
225 tell_macro ("BSD", a);
226
227 printf ("Size of 'struct sockaddr_un.sun_path': %zu\n",
228 sizeof (su.sun_path));
229
230 #if HAVE_TCGETATTR
231 puts ("");
232 do_termcap ();
233 #endif
234
235 return 0;
236 }