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 ("CDDL"), version 1.0.
6  * You may use this file only in accordance with the terms of version
7  * 1.0 of the CDDL.
8  *
9  * A full copy of the text of the CDDL should have accompanied this
10  * source.  A copy of the CDDL is also available via the Internet at
11  * http://www.opensource.org/licenses/cddl1.txt
12  * See the License for the specific language governing permissions
13  * and limitations under the License.
14  *
15  * When distributing Covered Code, include this CDDL HEADER in each
16  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17  * If applicable, add the following below this CDDL HEADER, with the
18  * fields enclosed by brackets "[]" replaced with your own identifying
19  * information: Portions Copyright [yyyy] [name of copyright owner]
20  *
21  * CDDL HEADER END
22  */
23 /* Copyright (c) 1988 AT&T */
24 /* All Rights Reserved */
25 /*
26  * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
27  * Use is subject to license terms.
28  */
29 /*
30  * Copyright 2006-2018 J. Schilling
31  *
32  * @(#)logname.c	1.10 18/04/30 J. Schilling
33  */
34 #if defined(sun)
35 #pragma ident "@(#)logname.c 1.10 18/04/30 J. Schilling"
36 #endif
37 /*
38  * @(#)logname.c 1.7 06/12/12
39  */
40 
41 #if defined(sun)
42 #pragma ident	"@(#)logname.c"
43 #pragma ident	"@(#)sccs:lib/comobj/logname.c"
44 #endif
45 #include	<defines.h>
46 #include	<schily/pwd.h>
47 
48 char saveid[50];		/* sync with hdr/defines.h */
49 
50 char *
logname()51 logname()
52 {
53 	struct passwd *log_name;
54 	uid_t uid;
55 
56 	uid = getuid();
57 	log_name = getpwuid(uid);
58 	if (!log_name) {
59 		return (0);
60 	} else {
61 		strlcpy(saveid, log_name->pw_name, sizeof (saveid));
62 		sccs_user(saveid);
63 	}
64 	return (saveid);
65 }
66 
67 char *
sccs_user(uname)68 sccs_user(uname)
69 	char	*uname;
70 {
71 	register char	*p;
72 
73 	/*
74 	 * Cygwin allows usernames that include spaces.
75 	 * Since this would break our history file format,
76 	 * we replace spaces by underscores.
77 	 */
78 	for (p = uname; *p != '\0'; p++) {
79 		if (*p == ' ')
80 			*p = '_';
81 	}
82 	return (uname);
83 }
84