⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 getlogin.html

📁 IEEE 1003.1-2003, Single Unix Specification v3
💻 HTML
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta name="generator" content="HTML Tidy, see www.w3.org"><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><link type="text/css" rel="stylesheet" href="style.css"><!-- Generated by The Open Group's rhtm tool v1.2.1 --><!-- Copyright (c) 2001-2003 The Open Group, All Rights Reserved --><title>getlogin</title></head><body bgcolor="white"><script type="text/javascript" language="JavaScript" src="../jscript/codes.js"></script><basefont size="3"> <a name="getlogin"></a> <a name="tag_03_230"></a><!-- getlogin --> <!--header start--><center><font size="2">The Open Group Base Specifications Issue 6<br>IEEE Std 1003.1, 2003 Edition<br>Copyright &copy; 2001-2003 The IEEE and The Open Group, All Rights reserved.</font></center><!--header end--><hr size="2" noshade><h4><a name="tag_03_230_01"></a>NAME</h4><blockquote>getlogin, getlogin_r - get login name</blockquote><h4><a name="tag_03_230_02"></a>SYNOPSIS</h4><blockquote class="synopsis"><p><code><tt>#include &lt;<a href="../basedefs/unistd.h.html">unistd.h</a>&gt;<br><br> char *getlogin(void);<br></tt></code></p><div class="box"><code><tt><sup>[<a href="javascript:open_code('TSF')">TSF</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> int getlogin_r(char *</tt><i>name</i><tt>, size_t</tt> <i>namesize</i><tt>); <img src="../images/opt-end.gif" alt="[Option End]" border="0"></tt></code></div><tt><br></tt></blockquote><h4><a name="tag_03_230_03"></a>DESCRIPTION</h4><blockquote><p>The <i>getlogin</i>() function shall return a pointer to a string containing the user name associated by the login activity withthe controlling terminal of the current process. If <i>getlogin</i>() returns a non-null pointer, then that pointer points to thename that the user logged in under, even if there are several login names with the same user ID.</p><p>The <i>getlogin</i>() function need not be reentrant. A function that is not required to be reentrant is not required to bethread-safe.</p><p><sup>[<a href="javascript:open_code('TSF')">TSF</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">The <i>getlogin_r</i>() function shall put the name associated by the login activity with the controlling terminal of the currentprocess in the character array pointed to by <i>name</i>. The array is <i>namesize</i> characters long and should have space forthe name and the terminating null character. The maximum size of the login name is {LOGIN_NAME_MAX}.</p><p>If <i>getlogin_r</i>() is successful, <i>name</i> points to the name the user used at login, even if there are several loginnames with the same user ID. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></p></blockquote><h4><a name="tag_03_230_04"></a>RETURN VALUE</h4><blockquote><p>Upon successful completion, <i>getlogin</i>() shall return a pointer to the login name or a null pointer if the user's loginname cannot be found. Otherwise, it shall return a null pointer and set <i>errno</i> to indicate the error.</p><p>The return value from <i>getlogin</i>() may point to static data whose content is overwritten by each call.</p><p><sup>[<a href="javascript:open_code('TSF')">TSF</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">If successful, the <i>getlogin_r</i>() function shall return zero; otherwise, an error number shall be returned to indicate theerror. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></p></blockquote><h4><a name="tag_03_230_05"></a>ERRORS</h4><blockquote><p>The <i>getlogin</i>() and <i>getlogin_r</i>() functions may fail if:</p><dl compact><dt>[EMFILE]</dt><dd>{OPEN_MAX} file descriptors are currently open in the calling process.</dd><dt>[ENFILE]</dt><dd>The maximum allowable number of files is currently open in the system.</dd><dt>[ENXIO]</dt><dd>The calling process has no controlling terminal.</dd></dl><p>The <i>getlogin_r</i>() function may fail if:</p><dl compact><dt>[ERANGE]</dt><dd><sup>[<a href="javascript:open_code('TSF')">TSF</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">The value of <i>namesize</i> is smaller than the length of the string to be returned including the terminating null character. <imgsrc="../images/opt-end.gif" alt="[Option End]" border="0"></dd></dl></blockquote><hr><div class="box"><em>The following sections are informative.</em></div><h4><a name="tag_03_230_06"></a>EXAMPLES</h4><blockquote><h5><a name="tag_03_230_06_01"></a>Getting the User Login Name</h5><p>The following example calls the <i>getlogin</i>() function to obtain the name of the user associated with the calling process,and passes this information to the <a href="../functions/getpwnam.html"><i>getpwnam</i>()</a> function to get the associated userdatabase information.</p><pre><tt>#include &lt;unistd.h&gt;#include &lt;sys/types.h&gt;#include &lt;pwd.h&gt;#include &lt;stdio.h&gt;...char *lgn;struct passwd *pw;...if ((lgn = getlogin()) == NULL || (pw = getpwnam(lgn)) == NULL) {    fprintf(stderr, "Get of user information failed.\n"); exit(1);    }</tt></pre></blockquote><h4><a name="tag_03_230_07"></a>APPLICATION USAGE</h4><blockquote><p>Three names associated with the current process can be determined: <i>getpwuid</i>( <a href="../functions/geteuid.html"><i>geteuid</i>()</a>) shall return the name associated with the effective user ID of the process;<i>getlogin</i>() shall return the name associated with the current login activity; and <i>getpwuid</i>( <a href="../functions/getuid.html"><i>getuid</i>()</a>) shall return the name associated with the real user ID of the process.</p><p>The <i>getlogin_r</i>() function is thread-safe and returns values in a user-supplied buffer instead of possibly using a staticdata area that may be overwritten by each call.</p></blockquote><h4><a name="tag_03_230_08"></a>RATIONALE</h4><blockquote><p>The <i>getlogin</i>() function returns a pointer to the user's login name. The same user ID may be shared by several loginnames. If it is desired to get the user database entry that is used during login, the result of <i>getlogin</i>() should be used toprovide the argument to the <a href="../functions/getpwnam.html"><i>getpwnam</i>()</a> function. (This might be used to determinethe user's login shell, particularly where a single user has multiple login shells with distinct login names, but the same userID.)</p><p>The information provided by the <i>cuserid</i>() function, which was originally defined in the POSIX.1-1988 standard andsubsequently removed, can be obtained by the following:</p><pre><tt>getpwuid(geteuid())</tt></pre><p>while the information provided by historical implementations of <i>cuserid</i>() can be obtained by:</p><pre><tt>getpwuid(getuid())</tt></pre><p>The thread-safe version of this function places the user name in a user-supplied buffer and returns a non-zero value if itfails. The non-thread-safe version may return the name in a static data area that may be overwritten by each call.</p></blockquote><h4><a name="tag_03_230_09"></a>FUTURE DIRECTIONS</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_03_230_10"></a>SEE ALSO</h4><blockquote><p><a href="getpwnam.html"><i>getpwnam</i>()</a> , <a href="getpwuid.html"><i>getpwuid</i>()</a> , <a href="geteuid.html"><i>geteuid</i>()</a> , <a href="getuid.html"><i>getuid</i>()</a> , the Base Definitions volume ofIEEE&nbsp;Std&nbsp;1003.1-2001, <a href="../basedefs/limits.h.html"><i>&lt;limits.h&gt;</i></a>, <a href="../basedefs/unistd.h.html"><i>&lt;unistd.h&gt;</i></a></p></blockquote><h4><a name="tag_03_230_11"></a>CHANGE HISTORY</h4><blockquote><p>First released in Issue 1. Derived from System V Release 2.0.</p></blockquote><h4><a name="tag_03_230_12"></a>Issue 5</h4><blockquote><p>Normative text previously in the APPLICATION USAGE section is moved to the RETURN VALUE section.</p><p>The <i>getlogin_r</i>() function is included for alignment with the POSIX Threads Extension.</p><p>A note indicating that the <i>getlogin</i>() function need not be reentrant is added to the DESCRIPTION.</p></blockquote><h4><a name="tag_03_230_13"></a>Issue 6</h4><blockquote><p>The <i>getlogin_r</i>() function is marked as part of the Thread-Safe Functions option.</p><p>In the DESCRIPTION, the note about reentrancy is expanded to cover thread-safety.</p><p>The following new requirements on POSIX implementations derive from alignment with the Single UNIX Specification:</p><ul><li><p>In the RETURN VALUE section, the requirement to set <i>errno</i> on error is added.</p></li><li><p>The [EMFILE], [ENFILE], and [ENXIO] optional error conditions are added.</p></li></ul><p>The APPLICATION USAGE section is updated to include a note on the thread-safe function and its avoidance of possibly using astatic data area.</p></blockquote><div class="box"><em>End of informative text.</em></div><hr><hr size="2" noshade><center><font size="2"><!--footer start-->UNIX &reg; is a registered Trademark of The Open Group.<br>POSIX &reg; is a registered Trademark of The IEEE.<br>[ <a href="../mindex.html">Main Index</a> | <a href="../basedefs/contents.html">XBD</a> | <a href="../utilities/contents.html">XCU</a> | <a href="../functions/contents.html">XSH</a> | <a href="../xrat/contents.html">XRAT</a>]</font></center><!--footer end--><hr size="2" noshade></body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -