#define root and root's parent fts_level values in <fts.h>
[unix-history] / usr / src / lib / libc / gen / getlogin.c
CommitLineData
05e7d7bc
KF
1/*
2 * Copyright (c) 1988 The Regents of the University of California.
3 * All rights reserved.
4 *
269a7923 5 * %sccs.include.redist.c%
05e7d7bc
KF
6 */
7
2ce81398 8#if defined(LIBC_SCCS) && !defined(lint)
c5980113 9static char sccsid[] = "@(#)getlogin.c 5.9 (Berkeley) %G%";
05e7d7bc 10#endif /* LIBC_SCCS and not lint */
056d5bbd 11
0373dae5 12#include <sys/param.h>
05e7d7bc 13#include <pwd.h>
d144c87e 14#include <utmp.h>
c5980113
DS
15#include <stdio.h>
16#include <string.h>
17#include <unistd.h>
d144c87e 18
e24b3d64 19int _logname_valid; /* known to setlogin() */
d144c87e
SL
20
21char *
22getlogin()
23{
0373dae5 24 static char logname[MAXLOGNAME + 1];
05e7d7bc 25
e24b3d64
MK
26 if (_logname_valid == 0) {
27 if (_getlogin(logname, sizeof(logname) - 1) < 0)
28 return ((char *)NULL);
29 _logname_valid = 1;
05e7d7bc 30 }
e24b3d64 31 return (*logname ? logname : (char *)NULL);
05e7d7bc
KF
32}
33
05e7d7bc
KF
34char *
35cuserid(s)
e24b3d64 36 char *s;
05e7d7bc
KF
37{
38 register struct passwd *pwd;
39
e658abae
KB
40 if ((pwd = getpwuid(geteuid())) == NULL) {
41 if (s)
05e7d7bc 42 *s = '\0';
e24b3d64 43 return (s);
05e7d7bc 44 }
e658abae
KB
45 if (s) {
46 (void)strncpy(s, pwd->pw_name, L_cuserid);
e24b3d64 47 return (s);
056d5bbd 48 }
e24b3d64 49 return (pwd->pw_name);
d144c87e 50}