xref: /illumos-gate/usr/src/cmd/bnu/uucpname.c (revision 2a8bcb4e)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 1995 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
28 /*	  All Rights Reserved  	*/
29 
30 #include "uucp.h"
31 
32 /*
33  * get the uucp name
34  * return:
35  *	none
36  */
37 void
uucpname(name)38 uucpname(name)
39 register char *name;
40 {
41 	char *s;
42 	char NameBuf[MAXBASENAME + 1];
43 	FILE *NameFile;
44 
45 	NameBuf[0] = '\0';
46 	if ((NameFile = fopen(SYSNAMEFILE, "r")) != NULL) {
47 		if (fscanf(NameFile, "%14s", NameBuf) != 1) {
48 			(void) fprintf(stderr,
49 				gettext("No system name specified in %s\n"),
50 				SYSNAMEFILE);
51 			cleanup(-1);
52 		}
53 		s = NameBuf;
54 		(void) fclose(NameFile);
55 	} else {
56 #ifdef BSD4_2
57 	char	NameBuf[MAXBASENAME + 1];
58 
59 	gethostname(NameBuf, MAXBASENAME);
60 	/* strip off any domain name part */
61 	if ((s = index(NameBuf, '.')) != NULL)
62 		*s = '\0';
63 	s = NameBuf;
64 	s[MAXBASENAME] = '\0';
65 #else /* !BSD4_2 */
66 #ifdef UNAME
67 	struct utsname utsn;
68 
69 	uname(&utsn);
70 	s = utsn.nodename;
71 #else /* !UNAME */
72 	char	NameBuf[MAXBASENAME + 1], *strchr();
73 	FILE	*NameFile;
74 
75 	s = MYNAME;
76 	NameBuf[0] = '\0';
77 
78 	if ((NameFile = fopen("/etc/whoami", "r")) != NULL) {
79 		/* etc/whoami wins */
80 		(void) fgets(NameBuf, MAXBASENAME + 1, NameFile);
81 		(void) fclose(NameFile);
82 		NameBuf[MAXBASENAME] = '\0';
83 		if (NameBuf[0] != '\0') {
84 			if ((s = strchr(NameBuf, '\n')) != NULL)
85 				*s = '\0';
86 			s = NameBuf;
87 		}
88 	}
89 #endif /* UNAME */
90 #endif /* BSD4_2 */
91 	}
92 
93 	(void) strncpy(name, s, MAXBASENAME);
94 	name[MAXBASENAME] = '\0';
95 	/* strip off any domain name from the host name */
96 	if ((s = strchr(name, '.')) != NULL)
97 		*s = '\0';
98 	return;
99 }
100