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