move cuserid() to libcompat, POSIX no longer requires it
[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)
dec638bc 9static char sccsid[] = "@(#)getlogin.c 5.10 (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 32}