xref: /original-bsd/lib/libcompat/4.4/cuserid.c (revision a32fa803)
1b9e339dbSbostic /*-
2*a32fa803Sbostic  * Copyright (c) 1992, 1993
3*a32fa803Sbostic  *	The Regents of the University of California.  All rights reserved.
4b9e339dbSbostic  *
5b9e339dbSbostic  * %sccs.include.redist.c%
6b9e339dbSbostic  */
7b9e339dbSbostic 
8b9e339dbSbostic #if defined(LIBC_SCCS) && !defined(lint)
9*a32fa803Sbostic static char sccsid[] = "@(#)cuserid.c	8.1 (Berkeley) 06/04/93";
10b9e339dbSbostic #endif /* LIBC_SCCS and not lint */
11b9e339dbSbostic 
12b9e339dbSbostic #include <pwd.h>
13b9e339dbSbostic #include <stdio.h>
14b9e339dbSbostic #include <string.h>
15b9e339dbSbostic #include <unistd.h>
16b9e339dbSbostic 
17b9e339dbSbostic char *
cuserid(s)18b9e339dbSbostic cuserid(s)
19b9e339dbSbostic 	char *s;
20b9e339dbSbostic {
21b9e339dbSbostic 	register struct passwd *pwd;
22b9e339dbSbostic 
23b9e339dbSbostic 	if ((pwd = getpwuid(geteuid())) == NULL) {
24b9e339dbSbostic 		if (s)
25b9e339dbSbostic 			*s = '\0';
26b9e339dbSbostic 		return (s);
27b9e339dbSbostic 	}
28b9e339dbSbostic 	if (s) {
29b9e339dbSbostic 		(void)strncpy(s, pwd->pw_name, L_cuserid);
30b9e339dbSbostic 		return (s);
31b9e339dbSbostic 	}
32b9e339dbSbostic 	return (pwd->pw_name);
33b9e339dbSbostic }
34