diff options
Diffstat (limited to 'man3p/getlogin.3p')
-rw-r--r-- | man3p/getlogin.3p | 172 |
1 files changed, 172 insertions, 0 deletions
diff --git a/man3p/getlogin.3p b/man3p/getlogin.3p new file mode 100644 index 000000000..66c7e9202 --- /dev/null +++ b/man3p/getlogin.3p @@ -0,0 +1,172 @@ +.\" Copyright (c) 2001-2003 The Open Group, All Rights Reserved +.TH "GETLOGIN" P 2003 "IEEE/The Open Group" "POSIX Programmer's Manual" +.\" getlogin +.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 +\fIgetpwnam\fP() , \fIgetpwuid\fP() , \fIgeteuid\fP() , \fIgetuid\fP() +, the Base Definitions volume of +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 . |