1da2e3ebdSchin /***********************************************************************
2da2e3ebdSchin *                                                                      *
3da2e3ebdSchin *               This software is part of the ast package               *
4*b30d1939SAndy Fiddaman *          Copyright (c) 1992-2012 AT&T Intellectual Property          *
5da2e3ebdSchin *                      and is licensed under the                       *
6*b30d1939SAndy Fiddaman *                 Eclipse Public License, Version 1.0                  *
77c2fbfb3SApril Chin *                    by AT&T Intellectual Property                     *
8da2e3ebdSchin *                                                                      *
9da2e3ebdSchin *                A copy of the License is available at                 *
10*b30d1939SAndy Fiddaman *          http://www.eclipse.org/org/documents/epl-v10.html           *
11*b30d1939SAndy Fiddaman *         (with md5 checksum b35adb5213ca9657e911e9befb180842)         *
12da2e3ebdSchin *                                                                      *
13da2e3ebdSchin *              Information and Software Systems Research               *
14da2e3ebdSchin *                            AT&T Research                             *
15da2e3ebdSchin *                           Florham Park NJ                            *
16da2e3ebdSchin *                                                                      *
17da2e3ebdSchin *                 Glenn Fowler <gsf@research.att.com>                  *
18da2e3ebdSchin *                  David Korn <dgk@research.att.com>                   *
19da2e3ebdSchin *                                                                      *
20da2e3ebdSchin ***********************************************************************/
21da2e3ebdSchin #pragma prototyped
22da2e3ebdSchin /*
23da2e3ebdSchin  * David Korn
24da2e3ebdSchin  * Glenn Fowler
25da2e3ebdSchin  * AT&T Research
26da2e3ebdSchin  *
27da2e3ebdSchin  * uname
28da2e3ebdSchin  */
30da2e3ebdSchin static const char usage[] =
317c2fbfb3SApril Chin "[-?\n@(#)$Id: uname (AT&T Research) 2007-04-19 $\n]"
32da2e3ebdSchin USAGE_LICENSE
33da2e3ebdSchin "[+NAME?uname - identify the current system ]"
34da2e3ebdSchin "[+DESCRIPTION?By default \buname\b writes the operating system name to"
35da2e3ebdSchin "	standard output. When options are specified, one or more"
36da2e3ebdSchin "	system characteristics are written to standard output, space"
373e14f97fSRoger A. Faulkner "	separated, on a single line. When more than one option is specified"
38da2e3ebdSchin "	the output is in the order specfied by the \b-A\b option below."
39da2e3ebdSchin "	Unsupported option values are listed as \a[option]]\a. If any unknown"
40da2e3ebdSchin "	options are specified then the local \b/usr/bin/uname\b is called.]"
41da2e3ebdSchin "[+?If any \aname\a operands are specified then the \bsysinfo\b(2) values"
42da2e3ebdSchin "	for each \aname\a are listed, separated by space, on one line."
43da2e3ebdSchin "	\bgetconf\b(1), a pre-existing \astandard\a interface, provides"
44da2e3ebdSchin "	access to the same information; vendors should spend more time"
45da2e3ebdSchin "	using standards than inventing them.]"
46da2e3ebdSchin "[+?Selected information is printed in the same order as the options below.]"
47da2e3ebdSchin "[a:all?Equivalent to \b-snrvmpio\b.]"
48da2e3ebdSchin "[s:system|sysname|kernel-name?The detailed kernel name. This is the default.]"
49da2e3ebdSchin "[n:nodename?The hostname or nodename.]"
50da2e3ebdSchin "[r:release|kernel-release?The kernel release level.]"
51da2e3ebdSchin "[v:version|kernel-version?The kernel version level.]"
52da2e3ebdSchin "[m:machine?The name of the hardware type the system is running on.]"
53da2e3ebdSchin "[p:processor?The name of the processor instruction set architecture.]"
54da2e3ebdSchin "[i:implementation|platform|hardware-platform?The hardware implementation;"
55da2e3ebdSchin "	this is \b--host-id\b on some systems.]"
56da2e3ebdSchin "[o:operating-system?The generic operating system name.]"
57da2e3ebdSchin "[h:host-id|id?The host id in hex.]"
58da2e3ebdSchin "[d:domain?The domain name returned by \agetdomainname\a(2).]"
59da2e3ebdSchin "[R:extended-release?The extended release name.]"
60da2e3ebdSchin "[A:everything?Equivalent to \b-snrvmpiohdR\b.]"
61da2e3ebdSchin "[f:list?List all \bsysinfo\b(2) names and values, one per line.]"
62da2e3ebdSchin "[S:sethost?Set the hostname or nodename to \aname\a. No output is"
63da2e3ebdSchin "	written to standard output.]:[name]"
647c2fbfb3SApril Chin "\n"
657c2fbfb3SApril Chin "\n[ name ... ]\n"
667c2fbfb3SApril Chin "\n"
67da2e3ebdSchin "[+SEE ALSO?\bhostname\b(1), \bgetconf\b(1), \buname\b(2),"
68da2e3ebdSchin "	\bsysconf\b(2), \bsysinfo\b(2)]"
69da2e3ebdSchin ;
71da2e3ebdSchin #if defined(__STDPP__directive) && defined(__STDPP__hide)
72da2e3ebdSchin __STDPP__directive pragma pp:hide getdomainname gethostid gethostname sethostname
73da2e3ebdSchin #else
74da2e3ebdSchin #define getdomainname	______getdomainname
75da2e3ebdSchin #define gethostid	______gethostid
76da2e3ebdSchin #define gethostname	______gethostname
77da2e3ebdSchin #define sethostname	______sethostname
78da2e3ebdSchin #endif
80da2e3ebdSchin #include <cmd.h>
81da2e3ebdSchin #include <ctype.h>
82da2e3ebdSchin #include <proc.h>
84da2e3ebdSchin #include "FEATURE/utsname"
86da2e3ebdSchin #define MAXHOSTNAME	64
88da2e3ebdSchin #if _lib_uname && _sys_utsname
90da2e3ebdSchin #include <sys/utsname.h>
92da2e3ebdSchin #endif
94da2e3ebdSchin #if defined(__STDPP__directive) && defined(__STDPP__hide)
95da2e3ebdSchin __STDPP__directive pragma pp:nohide getdomainname gethostid gethostname sethostname
96da2e3ebdSchin #else
97da2e3ebdSchin #undef	getdomainname
98da2e3ebdSchin #undef	gethostid
99da2e3ebdSchin #undef	gethostname
100da2e3ebdSchin #undef	sethostname
101da2e3ebdSchin #endif
103da2e3ebdSchin #if _lib_getdomainname
104da2e3ebdSchin extern int	getdomainname(char*, size_t);
105da2e3ebdSchin #endif
106da2e3ebdSchin #if _lib_gethostid
10734f9b3eeSRoland Mainz extern long	gethostid(void);
108da2e3ebdSchin #endif
109da2e3ebdSchin #if _lib_gethostname
110da2e3ebdSchin extern int	gethostname(char*, size_t);
111da2e3ebdSchin #endif
112da2e3ebdSchin #if _lib_sethostname
113da2e3ebdSchin extern int	sethostname(const char*, size_t);
114da2e3ebdSchin #endif
116da2e3ebdSchin #ifndef HOSTTYPE
117da2e3ebdSchin #define HOSTTYPE	"unknown"
118da2e3ebdSchin #endif
120da2e3ebdSchin static const char	hosttype[] = HOSTTYPE;
122da2e3ebdSchin #if !_lib_uname || !_sys_utsname
124da2e3ebdSchin #if defined(__STDPP__)
125da2e3ebdSchin #define SYSNAME		#(getprd machine)
126da2e3ebdSchin #define RELEASE		#(getprd release)
127da2e3ebdSchin #define VERSION		#(getprd version)
128da2e3ebdSchin #define MACHINE		#(getprd architecture)
129da2e3ebdSchin #else
130da2e3ebdSchin #define SYSNAME		""
131da2e3ebdSchin #define RELEASE		""
132da2e3ebdSchin #define VERSION		""
133da2e3ebdSchin #define MACHINE		""
134da2e3ebdSchin #endif
136da2e3ebdSchin struct utsname
137da2e3ebdSchin {
138da2e3ebdSchin 	char*	sysname;
139da2e3ebdSchin 	char	nodename[MAXHOSTNAME];
140da2e3ebdSchin 	char*	release;
141da2e3ebdSchin 	char*	version;
142da2e3ebdSchin 	char*	machine;
143da2e3ebdSchin };
145da2e3ebdSchin int
uname(register struct utsname * ut)146da2e3ebdSchin uname(register struct utsname* ut)
147da2e3ebdSchin {
148da2e3ebdSchin #ifdef HOSTTYPE
149da2e3ebdSchin 	char*		sys = 0;
150da2e3ebdSchin 	char*		arch = 0;
152da2e3ebdSchin 	if (*hosttype)
153da2e3ebdSchin 	{
154da2e3ebdSchin 		static char	buf[sizeof(hosttype)];
156da2e3ebdSchin 		strcpy(buf, hosttype);
157da2e3ebdSchin 		sys = buf;
158da2e3ebdSchin 		if (arch = strchr(sys, '.'))
159da2e3ebdSchin 		{
160da2e3ebdSchin 			*arch++ = 0;
161da2e3ebdSchin 			if (!*arch)
162da2e3ebdSchin 				arch = 0;
163da2e3ebdSchin 		}
164da2e3ebdSchin 		if (!*sys)
165da2e3ebdSchin 			sys = 0;
166da2e3ebdSchin 	}
167da2e3ebdSchin #endif
168da2e3ebdSchin #ifdef _lib_gethostname
169da2e3ebdSchin 	if (gethostname(ut->nodename, sizeof(ut->nodename) - 1))
170da2e3ebdSchin 		return -1;
171da2e3ebdSchin #else
172da2e3ebdSchin 	strncpy(ut->nodename, "local", sizeof(ut->nodename) - 1);
173da2e3ebdSchin #endif
174da2e3ebdSchin #ifdef HOSTTYPE
175da2e3ebdSchin 	if (!(ut->sysname = sys))
176da2e3ebdSchin #endif
177da2e3ebdSchin 	if (!*(ut->sysname = SYSNAME))
178da2e3ebdSchin 		ut->sysname = ut->nodename;
179da2e3ebdSchin #ifdef HOSTTYPE
180da2e3ebdSchin 	if (!(ut->machine = arch))
181da2e3ebdSchin #endif
182da2e3ebdSchin 	ut->machine = MACHINE;
183da2e3ebdSchin 	ut->release = RELEASE;
184da2e3ebdSchin 	ut->version = VERSION;
185da2e3ebdSchin 	return 0;
186da2e3ebdSchin }
188da2e3ebdSchin #endif
190da2e3ebdSchin #define OPT_system		(1<<0)
191da2e3ebdSchin #define OPT_nodename		(1<<1)
192da2e3ebdSchin #define OPT_release		(1<<2)
193da2e3ebdSchin #define OPT_version		(1<<3)
194da2e3ebdSchin #define OPT_machine		(1<<4)
195da2e3ebdSchin #define OPT_processor		(1<<5)
197da2e3ebdSchin #define OPT_STANDARD		6
199da2e3ebdSchin #define OPT_implementation	(1<<6)
200da2e3ebdSchin #define OPT_operating_system	(1<<7)
202da2e3ebdSchin #define OPT_ALL			8
204da2e3ebdSchin #define OPT_hostid		(1<<8)
205da2e3ebdSchin #define OPT_vendor		(1<<9)
206da2e3ebdSchin #define OPT_domain		(1<<10)
207da2e3ebdSchin #define OPT_machine_type	(1<<11)
208da2e3ebdSchin #define OPT_base		(1<<12)
209da2e3ebdSchin #define OPT_extended_release	(1<<13)
210da2e3ebdSchin #define OPT_extra		(1<<14)
212da2e3ebdSchin #define OPT_TOTAL		15
214da2e3ebdSchin #define OPT_all			(1L<<29)
215da2e3ebdSchin #define OPT_total		(1L<<30)
216da2e3ebdSchin #define OPT_standard		((1<<OPT_STANDARD)-1)
218da2e3ebdSchin #ifndef MACHINE
219da2e3ebdSchin #if defined(__STDPP__)
220da2e3ebdSchin #define MACHINE			#(getprd architecture)
221da2e3ebdSchin #else
222da2e3ebdSchin #define MACHINE			""
223da2e3ebdSchin #endif
224da2e3ebdSchin #endif
226da2e3ebdSchin #ifndef HOSTTYPE
227da2e3ebdSchin #define HOSTTYPE		"unknown"
228da2e3ebdSchin #endif
230da2e3ebdSchin #define extra(m)        do \
231da2e3ebdSchin 			{ \
232da2e3ebdSchin 				if ((char*)&ut.m[sizeof(ut.m)] > last) \
233da2e3ebdSchin 					last = (char*)&ut.m[sizeof(ut.m)]; \
234da2e3ebdSchin 			} while(0)
236da2e3ebdSchin #define output(f,v,u)	do \
237da2e3ebdSchin 			{ \
238da2e3ebdSchin 				if ((flags&(f))&&(*(v)||(flags&(OPT_all|OPT_total))==OPT_all&&((f)&OPT_standard)||!(flags&(OPT_all|OPT_total)))) \
239da2e3ebdSchin 				{ \
240da2e3ebdSchin 					if (sep) \
241da2e3ebdSchin 						sfputc(sfstdout, ' '); \
242da2e3ebdSchin 					else \
243da2e3ebdSchin 						sep = 1; \
244da2e3ebdSchin 					if (*(v)) \
245da2e3ebdSchin 						sfputr(sfstdout, v, -1); \
246da2e3ebdSchin 					else \
247da2e3ebdSchin 						sfprintf(sfstdout, "[%s]", u); \
248da2e3ebdSchin 				} \
249da2e3ebdSchin 			} while (0)
251da2e3ebdSchin int
b_uname(int argc,char ** argv,Shbltin_t * context)252*b30d1939SAndy Fiddaman b_uname(int argc, char** argv, Shbltin_t* context)
253da2e3ebdSchin {
254da2e3ebdSchin 	register long	flags = 0;
255da2e3ebdSchin 	register int	sep = 0;
256da2e3ebdSchin 	register int	n;
257da2e3ebdSchin 	register char*	s;
258da2e3ebdSchin 	char*		t;
259da2e3ebdSchin 	char*		e;
260da2e3ebdSchin 	char*		sethost = 0;
261da2e3ebdSchin 	int		list = 0;
262da2e3ebdSchin 	struct utsname	ut;
263da2e3ebdSchin 	char		buf[257];
265da2e3ebdSchin 	cmdinit(argc, argv, context, ERROR_CATALOG, 0);
266da2e3ebdSchin 	for (;;)
267da2e3ebdSchin 	{
268da2e3ebdSchin 		switch (optget(argv, usage))
269da2e3ebdSchin 		{
270da2e3ebdSchin 		case 'a':
271da2e3ebdSchin 			flags |= OPT_all|((1L<<OPT_ALL)-1);
272da2e3ebdSchin 			continue;
273da2e3ebdSchin 		case 'b':
274da2e3ebdSchin 			flags |= OPT_base;
275da2e3ebdSchin 			continue;
276da2e3ebdSchin 		case 'c':
277da2e3ebdSchin 			flags |= OPT_vendor;
278da2e3ebdSchin 			continue;
279da2e3ebdSchin 		case 'd':
280da2e3ebdSchin 			flags |= OPT_domain;
281da2e3ebdSchin 			continue;
282da2e3ebdSchin 		case 'f':
283da2e3ebdSchin 			list = 1;
284da2e3ebdSchin 			continue;
285da2e3ebdSchin 		case 'h':
286da2e3ebdSchin 			flags |= OPT_hostid;
287da2e3ebdSchin 			continue;
288da2e3ebdSchin 		case 'i':
289da2e3ebdSchin 			flags |= OPT_implementation;
290da2e3ebdSchin 			continue;
291da2e3ebdSchin 		case 'm':
292da2e3ebdSchin 			flags |= OPT_machine;
293da2e3ebdSchin 			continue;
294da2e3ebdSchin 		case 'n':
295da2e3ebdSchin 			flags |= OPT_nodename;
296da2e3ebdSchin 			continue;
297da2e3ebdSchin 		case 'o':
298da2e3ebdSchin 			flags |= OPT_operating_system;
299da2e3ebdSchin 			continue;
300da2e3ebdSchin 		case 'p':
301da2e3ebdSchin 			flags |= OPT_processor;
302da2e3ebdSchin 			continue;
303da2e3ebdSchin 		case 'r':
304da2e3ebdSchin 			flags |= OPT_release;
305da2e3ebdSchin 			continue;
306da2e3ebdSchin 		case 's':
307da2e3ebdSchin 			flags |= OPT_system;
308da2e3ebdSchin 			continue;
309da2e3ebdSchin 		case 't':
310da2e3ebdSchin 			flags |= OPT_machine_type;
311da2e3ebdSchin 			continue;
312da2e3ebdSchin 		case 'v':
313da2e3ebdSchin 			flags |= OPT_version;
314da2e3ebdSchin 			continue;
315da2e3ebdSchin 		case 'x':
316da2e3ebdSchin 			flags |= OPT_extra;
317da2e3ebdSchin 			continue;
318da2e3ebdSchin 		case 'A':
319da2e3ebdSchin 			flags |= OPT_total|((1L<<OPT_TOTAL)-1);
320da2e3ebdSchin 			continue;
321da2e3ebdSchin 		case 'R':
322da2e3ebdSchin 			flags |= OPT_extended_release;
323da2e3ebdSchin 			continue;
324da2e3ebdSchin 		case 'S':
325da2e3ebdSchin 			sethost = opt_info.arg;
326da2e3ebdSchin 			continue;
327da2e3ebdSchin 		case ':':
328da2e3ebdSchin 			s = "/usr/bin/uname";
329da2e3ebdSchin 			if (!streq(argv[0], s) && (!eaccess(s, X_OK) || !eaccess(s+=4, X_OK)))
330da2e3ebdSchin 			{
331da2e3ebdSchin 				argv[0] = s;
3327c2fbfb3SApril Chin 				return sh_run(context, argc, argv);
333da2e3ebdSchin 			}
334da2e3ebdSchin 			error(2, "%s", opt_info.arg);
335da2e3ebdSchin 			break;
336da2e3ebdSchin 		case '?':
337da2e3ebdSchin 			error(ERROR_usage(2), "%s", opt_info.arg);
338da2e3ebdSchin 			break;
339da2e3ebdSchin 		}
340da2e3ebdSchin 		break;
341da2e3ebdSchin 	}
342da2e3ebdSchin 	argv += opt_info.index;
343da2e3ebdSchin 	if (error_info.errors || *argv && (flags || sethost) || sethost && flags)
344da2e3ebdSchin 		error(ERROR_usage(2), "%s", optusage(NiL));
345da2e3ebdSchin 	if (sethost)
346da2e3ebdSchin 	{
347da2e3ebdSchin #if _lib_sethostname
348da2e3ebdSchin 		if (sethostname(sethost, strlen(sethost) + 1))
349da2e3ebdSchin #else
350da2e3ebdSchin #ifdef	ENOSYS
351da2e3ebdSchin 		errno = ENOSYS;
352da2e3ebdSchin #else
353da2e3ebdSchin 		errno = EPERM;
354da2e3ebdSchin #endif
355da2e3ebdSchin #endif
356da2e3ebdSchin 		error(ERROR_system(1), "%s: cannot set host name", sethost);
357da2e3ebdSchin 	}
358da2e3ebdSchin 	else if (list)
359da2e3ebdSchin 		astconflist(sfstdout, NiL, ASTCONF_base|ASTCONF_defined|ASTCONF_lower|ASTCONF_quote|ASTCONF_matchcall, "CS|SI");
360da2e3ebdSchin 	else if (*argv)
361da2e3ebdSchin 	{
362da2e3ebdSchin 		e = &buf[sizeof(buf)-1];
363da2e3ebdSchin 		while (s = *argv++)
364da2e3ebdSchin 		{
365da2e3ebdSchin 			t = buf;
366da2e3ebdSchin 			*t++ = 'C';
367da2e3ebdSchin 			*t++ = 'S';
368da2e3ebdSchin 			*t++ = '_';
369da2e3ebdSchin 			while (t < e && (n = *s++))
370da2e3ebdSchin 				*t++ = islower(n) ? toupper(n) : n;
371da2e3ebdSchin 			*t = 0;
3727c2fbfb3SApril Chin 			sfprintf(sfstdout, "%s%c", *(t = astconf(buf, NiL, NiL)) ? t : *(t = astconf(buf+3, NiL, NiL)) ? t :  "unknown", *argv ? ' ' : '\n');
373da2e3ebdSchin 		}
374da2e3ebdSchin 	}
375da2e3ebdSchin 	else
376da2e3ebdSchin 	{
377da2e3ebdSchin 		s = buf;
378da2e3ebdSchin 		if (!flags)
379da2e3ebdSchin 			flags = OPT_system;
380da2e3ebdSchin 		memzero(&ut, sizeof(ut));
381da2e3ebdSchin 		if (uname(&ut) < 0)
382da2e3ebdSchin 			error(ERROR_usage(2), "information unavailable");
383da2e3ebdSchin 		output(OPT_system, ut.sysname, "sysname");
384da2e3ebdSchin 		if (flags & OPT_nodename)
385da2e3ebdSchin 		{
386da2e3ebdSchin #if !_mem_nodeext_utsname && _lib_gethostname
387da2e3ebdSchin 			if (sizeof(ut.nodename) > 9 || gethostname(s, sizeof(buf)))
388da2e3ebdSchin #endif
389da2e3ebdSchin 			s = ut.nodename;
390da2e3ebdSchin 			output(OPT_nodename, s, "nodename");
391da2e3ebdSchin 		}
392da2e3ebdSchin 		output(OPT_release, ut.release, "release");
393da2e3ebdSchin 		output(OPT_version, ut.version, "version");
394da2e3ebdSchin 		output(OPT_machine, ut.machine, "machine");
395da2e3ebdSchin 		if (flags & OPT_processor)
396da2e3ebdSchin 		{
397da2e3ebdSchin 			if (!*(s = astconf("ARCHITECTURE", NiL, NiL)))
398da2e3ebdSchin 				s = ut.machine;
399da2e3ebdSchin 			output(OPT_processor, s, "processor");
400da2e3ebdSchin 		}
401da2e3ebdSchin 		if (flags & OPT_implementation)
402da2e3ebdSchin 		{
403da2e3ebdSchin 			if (!*(s = astconf("PLATFORM", NiL, NiL)) && !*(s = astconf("HW_NAME", NiL, NiL)))
404da2e3ebdSchin 			{
405da2e3ebdSchin 				if (t = strchr(hosttype, '.'))
406da2e3ebdSchin 					t++;
407da2e3ebdSchin 				else
408da2e3ebdSchin 					t = (char*)hosttype;
409da2e3ebdSchin 				strncpy(s = buf, t, sizeof(buf) - 1);
410da2e3ebdSchin 			}
411da2e3ebdSchin 			output(OPT_implementation, s, "implementation");
412da2e3ebdSchin 		}
413da2e3ebdSchin 		if (flags & OPT_operating_system)
414da2e3ebdSchin 		{
415da2e3ebdSchin 			s = astconf("OPERATING_SYSTEM", NiL, NiL);
416da2e3ebdSchin 			if (!*s)
417da2e3ebdSchin #ifdef _UNAME_os_DEFAULT
418da2e3ebdSchin 				s = _UNAME_os_DEFAULT;
419da2e3ebdSchin #else
420da2e3ebdSchin 				s = ut.sysname;
421da2e3ebdSchin #endif
422da2e3ebdSchin 			output(OPT_operating_system, s, "operating-system");
423da2e3ebdSchin 		}
424da2e3ebdSchin 		if (flags & OPT_extended_release)
425da2e3ebdSchin 		{
426da2e3ebdSchin 			s = astconf("RELEASE", NiL, NiL);
427da2e3ebdSchin 			output(OPT_extended_release, s, "extended-release");
428da2e3ebdSchin 		}
429da2e3ebdSchin #if _mem_idnumber_utsname
430da2e3ebdSchin 		output(OPT_hostid, ut.idnumber, "hostid");
431da2e3ebdSchin #else
432da2e3ebdSchin 		if (flags & OPT_hostid)
433da2e3ebdSchin 		{
434da2e3ebdSchin 			if (!*(s = astconf("HW_SERIAL", NiL, NiL)))
435da2e3ebdSchin #if _lib_gethostid
436da2e3ebdSchin 				sfsprintf(s = buf, sizeof(buf), "%08x", gethostid());
437da2e3ebdSchin #else
438*b30d1939SAndy Fiddaman 				{/*NOP*/};
439da2e3ebdSchin #endif
440da2e3ebdSchin 			output(OPT_hostid, s, "hostid");
441da2e3ebdSchin 		}
442da2e3ebdSchin #endif
443da2e3ebdSchin 		if (flags & OPT_vendor)
444da2e3ebdSchin 		{
445da2e3ebdSchin 			s = astconf("HW_PROVIDER", NiL, NiL);
446da2e3ebdSchin 			output(OPT_vendor, s, "vendor");
447da2e3ebdSchin 		}
448da2e3ebdSchin 		if (flags & OPT_domain)
449da2e3ebdSchin 		{
450da2e3ebdSchin 			if (!*(s = astconf("SRPC_DOMAIN", NiL, NiL)))
451da2e3ebdSchin #if _lib_getdomainname
452da2e3ebdSchin 				getdomainname(s, sizeof(buf));
453da2e3ebdSchin #else
454*b30d1939SAndy Fiddaman 				{/*NOP*/};
455da2e3ebdSchin #endif
456da2e3ebdSchin 			output(OPT_domain, s, "domain");
457da2e3ebdSchin 		}
458da2e3ebdSchin #if _mem_m_type_utsname
459da2e3ebdSchin 		s = ut.m_type;
460da2e3ebdSchin #else
461da2e3ebdSchin 		s = astconf("MACHINE", NiL, NiL);
462da2e3ebdSchin #endif
463da2e3ebdSchin 		output(OPT_machine_type, s, "m_type");
464da2e3ebdSchin #if _mem_base_rel_utsname
465da2e3ebdSchin 		s = ut.base_rel;
466da2e3ebdSchin #else
467da2e3ebdSchin 		s = astconf("BASE", NiL, NiL);
468da2e3ebdSchin #endif
469da2e3ebdSchin 		output(OPT_base, s, "base_rel");
470da2e3ebdSchin 		if (flags & OPT_extra)
471da2e3ebdSchin 		{
472da2e3ebdSchin 			char*	last = (char*)&ut;
474da2e3ebdSchin 			extra(sysname);
475da2e3ebdSchin 			extra(nodename);
476da2e3ebdSchin 			extra(release);
477da2e3ebdSchin 			extra(version);
478da2e3ebdSchin 			extra(machine);
479da2e3ebdSchin #if _mem_idnumber_utsname
480da2e3ebdSchin 			extra(idnumber);
481da2e3ebdSchin #endif
482da2e3ebdSchin #if _mem_m_type_utsname
483da2e3ebdSchin 			extra(m_type);
484da2e3ebdSchin #endif
485da2e3ebdSchin #if _mem_base_rel_utsname
486da2e3ebdSchin 			extra(base_rel);
487da2e3ebdSchin #endif
488da2e3ebdSchin 			if (last < ((char*)(&ut + 1)))
489da2e3ebdSchin 			{
490da2e3ebdSchin 				s = t = last;
491da2e3ebdSchin 				while (s < (char*)(&ut + 1))
492da2e3ebdSchin 				{
493da2e3ebdSchin 					if (!(n = *s++))
494da2e3ebdSchin 					{
495da2e3ebdSchin 						if ((s - t) > 1)
496da2e3ebdSchin 						{
497da2e3ebdSchin 							if (sep)
498da2e3ebdSchin 								sfputc(sfstdout, ' ');
499da2e3ebdSchin 							else
500da2e3ebdSchin 								sep = 1;
501da2e3ebdSchin 							sfputr(sfstdout, t, -1);
502da2e3ebdSchin 						}
503da2e3ebdSchin 						t = s;
504da2e3ebdSchin 					}
505da2e3ebdSchin 					else if (!isprint(n))
506da2e3ebdSchin 						break;
507da2e3ebdSchin 				}
508da2e3ebdSchin 			}
509da2e3ebdSchin 		}
510da2e3ebdSchin 		if (sep)
511da2e3ebdSchin 			sfputc(sfstdout, '\n');
512da2e3ebdSchin 	}
513da2e3ebdSchin 	return error_info.errors;
514da2e3ebdSchin }