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