2004-11-03 13:51:07 +00:00
|
|
|
.\" Copyright (c) 2001-2003 The Open Group, All Rights Reserved
|
2007-06-20 22:33:04 +00:00
|
|
|
.TH "GETLOGIN" 3P 2003 "IEEE/The Open Group" "POSIX Programmer's Manual"
|
2004-11-03 13:51:07 +00:00
|
|
|
.\" getlogin
|
2007-09-20 06:03:25 +00:00
|
|
|
.SH PROLOG
|
|
|
|
This manual page is part of the POSIX Programmer's Manual.
|
|
|
|
The Linux implementation of this interface may differ (consult
|
|
|
|
the corresponding Linux manual page for details of Linux behavior),
|
|
|
|
or the interface may not be implemented on Linux.
|
2004-11-03 13:51:07 +00:00
|
|
|
.SH NAME
|
|
|
|
getlogin, getlogin_r \- get login name
|
|
|
|
.SH SYNOPSIS
|
|
|
|
.LP
|
|
|
|
\fB#include <unistd.h>
|
|
|
|
.br
|
|
|
|
.sp
|
|
|
|
char *getlogin(void);
|
|
|
|
.br
|
|
|
|
\fP
|
|
|
|
.LP
|
|
|
|
\fBint getlogin_r(char *\fP\fIname\fP\fB, size_t\fP \fInamesize\fP\fB);
|
|
|
|
\fP
|
|
|
|
\fB
|
|
|
|
.br
|
|
|
|
\fP
|
|
|
|
.SH DESCRIPTION
|
|
|
|
.LP
|
|
|
|
The \fIgetlogin\fP() function shall return a pointer to a string containing
|
|
|
|
the user name associated by the login activity with
|
|
|
|
the controlling terminal of the current process. If \fIgetlogin\fP()
|
|
|
|
returns a non-null pointer, then that pointer points to the
|
|
|
|
name that the user logged in under, even if there are several login
|
|
|
|
names with the same user ID.
|
|
|
|
.LP
|
|
|
|
The \fIgetlogin\fP() function need not be reentrant. A function that
|
|
|
|
is not required to be reentrant is not required to be
|
|
|
|
thread-safe.
|
|
|
|
.LP
|
|
|
|
The \fIgetlogin_r\fP() function shall put the name associated by the
|
|
|
|
login activity with the controlling terminal of the current
|
|
|
|
process in the character array pointed to by \fIname\fP. The array
|
|
|
|
is \fInamesize\fP characters long and should have space for
|
|
|
|
the name and the terminating null character. The maximum size of the
|
|
|
|
login name is {LOGIN_NAME_MAX}.
|
|
|
|
.LP
|
|
|
|
If \fIgetlogin_r\fP() is successful, \fIname\fP points to the name
|
|
|
|
the user used at login, even if there are several login
|
|
|
|
names with the same user ID.
|
|
|
|
.SH RETURN VALUE
|
|
|
|
.LP
|
|
|
|
Upon successful completion, \fIgetlogin\fP() shall return a pointer
|
|
|
|
to the login name or a null pointer if the user's login
|
|
|
|
name cannot be found. Otherwise, it shall return a null pointer and
|
|
|
|
set \fIerrno\fP to indicate the error.
|
|
|
|
.LP
|
|
|
|
The return value from \fIgetlogin\fP() may point to static data whose
|
|
|
|
content is overwritten by each call.
|
|
|
|
.LP
|
|
|
|
If successful, the \fIgetlogin_r\fP() function shall return zero;
|
|
|
|
otherwise, an error number shall be returned to indicate the
|
|
|
|
error.
|
|
|
|
.SH ERRORS
|
|
|
|
.LP
|
|
|
|
The \fIgetlogin\fP() and \fIgetlogin_r\fP() functions may fail if:
|
|
|
|
.TP 7
|
|
|
|
.B EMFILE
|
|
|
|
{OPEN_MAX} file descriptors are currently open in the calling process.
|
|
|
|
.TP 7
|
|
|
|
.B ENFILE
|
|
|
|
The maximum allowable number of files is currently open in the system.
|
|
|
|
.TP 7
|
|
|
|
.B ENXIO
|
|
|
|
The calling process has no controlling terminal.
|
|
|
|
.sp
|
|
|
|
.LP
|
|
|
|
The \fIgetlogin_r\fP() function may fail if:
|
|
|
|
.TP 7
|
|
|
|
.B ERANGE
|
|
|
|
The value of \fInamesize\fP is smaller than the length of the string
|
|
|
|
to be returned including the terminating null character.
|
|
|
|
.sp
|
|
|
|
.LP
|
|
|
|
\fIThe following sections are informative.\fP
|
|
|
|
.SH EXAMPLES
|
|
|
|
.SS Getting the User Login Name
|
|
|
|
.LP
|
|
|
|
The following example calls the \fIgetlogin\fP() function to obtain
|
|
|
|
the name of the user associated with the calling process,
|
|
|
|
and passes this information to the \fIgetpwnam\fP() function to get
|
|
|
|
the associated user
|
|
|
|
database information.
|
|
|
|
.sp
|
|
|
|
.RS
|
|
|
|
.nf
|
|
|
|
|
|
|
|
\fB#include <unistd.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <pwd.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
\&...
|
|
|
|
char *lgn;
|
|
|
|
struct passwd *pw;
|
|
|
|
\&...
|
|
|
|
if ((lgn = getlogin()) == NULL || (pw = getpwnam(lgn)) == NULL) {
|
|
|
|
fprintf(stderr, "Get of user information failed.\\n"); exit(1);
|
|
|
|
}
|
|
|
|
\fP
|
|
|
|
.fi
|
|
|
|
.RE
|
|
|
|
.SH APPLICATION USAGE
|
|
|
|
.LP
|
|
|
|
Three names associated with the current process can be determined:
|
|
|
|
\fIgetpwuid\fP( \fIgeteuid\fP()) shall return the name associated
|
|
|
|
with the effective user ID of the process;
|
|
|
|
\fIgetlogin\fP() shall return the name associated with the current
|
|
|
|
login activity; and \fIgetpwuid\fP( \fIgetuid\fP()) shall return the
|
|
|
|
name associated with the real user ID of the process.
|
|
|
|
.LP
|
|
|
|
The \fIgetlogin_r\fP() function is thread-safe and returns values
|
|
|
|
in a user-supplied buffer instead of possibly using a static
|
|
|
|
data area that may be overwritten by each call.
|
|
|
|
.SH RATIONALE
|
|
|
|
.LP
|
|
|
|
The \fIgetlogin\fP() function returns a pointer to the user's login
|
|
|
|
name. The same user ID may be shared by several login
|
|
|
|
names. If it is desired to get the user database entry that is used
|
|
|
|
during login, the result of \fIgetlogin\fP() should be used to
|
|
|
|
provide the argument to the \fIgetpwnam\fP() function. (This might
|
|
|
|
be used to determine
|
|
|
|
the user's login shell, particularly where a single user has multiple
|
|
|
|
login shells with distinct login names, but the same user
|
|
|
|
ID.)
|
|
|
|
.LP
|
|
|
|
The information provided by the \fIcuserid\fP() function, which was
|
|
|
|
originally defined in the POSIX.1-1988 standard and
|
|
|
|
subsequently removed, can be obtained by the following:
|
|
|
|
.sp
|
|
|
|
.RS
|
|
|
|
.nf
|
|
|
|
|
|
|
|
\fBgetpwuid(geteuid())
|
|
|
|
\fP
|
|
|
|
.fi
|
|
|
|
.RE
|
|
|
|
.LP
|
|
|
|
while the information provided by historical implementations of \fIcuserid\fP()
|
|
|
|
can be obtained by:
|
|
|
|
.sp
|
|
|
|
.RS
|
|
|
|
.nf
|
|
|
|
|
|
|
|
\fBgetpwuid(getuid())
|
|
|
|
\fP
|
|
|
|
.fi
|
|
|
|
.RE
|
|
|
|
.LP
|
|
|
|
The thread-safe version of this function places the user name in a
|
|
|
|
user-supplied buffer and returns a non-zero value if it
|
|
|
|
fails. The non-thread-safe version may return the name in a static
|
|
|
|
data area that may be overwritten by each call.
|
|
|
|
.SH FUTURE DIRECTIONS
|
|
|
|
.LP
|
|
|
|
None.
|
|
|
|
.SH SEE ALSO
|
|
|
|
.LP
|
2007-09-20 17:56:19 +00:00
|
|
|
\fIgetpwnam\fP(), \fIgetpwuid\fP(), \fIgeteuid\fP(), \fIgetuid\fP(),
|
|
|
|
the Base Definitions volume of
|
2004-11-03 13:51:07 +00:00
|
|
|
IEEE\ Std\ 1003.1-2001, \fI<limits.h>\fP, \fI<unistd.h>\fP
|
|
|
|
.SH COPYRIGHT
|
|
|
|
Portions of this text are reprinted and reproduced in electronic form
|
|
|
|
from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
|
|
|
|
-- Portable Operating System Interface (POSIX), The Open Group Base
|
|
|
|
Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
|
|
|
|
Electrical and Electronics Engineers, Inc and The Open Group. In the
|
|
|
|
event of any discrepancy between this version and the original IEEE and
|
|
|
|
The Open Group Standard, the original IEEE and The Open Group Standard
|
|
|
|
is the referee document. The original Standard can be obtained online at
|
|
|
|
http://www.opengroup.org/unix/online.html .
|