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

📄 0934-0936.html

📁 linux-unix130.linux.and.unix.ebooks130 linux and unix ebookslinuxLearning Linux - Collection of 12 E
💻 HTML
字号:
<HTML>

<HEAD>

<TITLE>Linux Complete Command Reference:Library Functions:EarthWeb Inc.-</TITLE>

</HEAD>

<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
<SCRIPT>
<!--
function displayWindow(url, width, height) {
        var Win = window.open(url,"displayWindow",'width=' + width +
',height=' + height + ',resizable=1,scrollbars=yes');
}
//-->
</SCRIPT>
</HEAD>

 -->




<!-- ISBN=0672311046 //-->

<!-- TITLE=Linux Complete Command Reference//-->

<!-- AUTHOR=Red Hat//-->

<!-- PUBLISHER=Macmillan Computer Publishing//-->

<!-- IMPRINT=Sams//-->

<!-- CHAPTER=03 //-->

<!-- PAGES=0891-1062 //-->

<!-- UNASSIGNED1 //-->

<!-- UNASSIGNED2 //-->



<P><CENTER>

<a href="0930-0933.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0937-0938.html">Next</A></CENTER></P>







<A NAME="PAGENUM-934"><P>Page 934</P></A>



<!-- CODE SNIP //-->

<PRE>

        gid_t    gr_gid;      /* group id */

        char     **gr_mem;    /* group members */

};

</PRE>

<!-- END CODE SNIP //-->



<P><B>RETURN VALUE

</P></B>



<P>The getgrnam()and getgrgid() functions return the group information structure, or

NULL if the matching entry is not found or an error occurs.</P>



<P><B>ERRORS

</P></B>



<TABLE>



<TR><TD>

ENOMEM

</TD><TD>

Insufficient memory to allocate group information structure.

</TD></TR></TABLE>



<P><B>

FILES

</P></B>



<P>/etc/group group database file</P>



<P><B>CONFORMS TO

</P></B>



<P>SVID 3, POSIX, BSD 4.3</P>



<P></B>SEE ALSO

</P></B>



<P>fgetgrent(3), getgrent(3), setgrent(3),

endgrent(3)</P>



<P>GNU, 4 April 1993</P>



<H3><A NAME="ch03_ 81">

getlogin, cuserid

</A></H3>



<P>getlogin, cuserid&#151;Get username</P>



<P><B>SYNOPSIS

</P></B>



<!-- CODE SNIP //-->

<PRE>

#include &lt;unistd.h&gt;

char * getlogin ( void );

#include &lt;stdio.h&gt;

char * cuserid ( char *string );

</PRE>

<!-- END CODE SNIP //-->



<P><B>DESCRIPTION

</P></B>



<P>getlogin returns a pointer to a string containing the name of the user logged in on the controlling terminal of the process,

or a null pointer if this information cannot be determined. The string is statically allocated and might be overwritten

on subsequent calls to this function or to cuserid.</P>



<P>cuserid returns a pointer to a string containing a username associated with the effective user ID of the process. If

string is not a null pointer, it should be an array that can hold at least

L_cuserid characters; the string is returned in this

array. Otherwise, a pointer to a string in a static area is returned. This string is statically allocated and might be overwritten

on subsequent calls to this function or to

getlogin.</P>



<P>The macro L_cuserid is an integer constant that indicates how long an array you might need to store a username.

L_cuserid is declared in stdio.h.</P>



<P>These functions let your program positively identify the user who is running

(cuserid) or the user who logged in this session

(getlogin). (These can differ when setuid programs are involved.) The user cannot do anything to fool these functions.</P>



<P>For most purposes, it is more useful to use the environment variable

LOGNAME to find out who the user is. This is more

flexible precisely because the user can set

LOGNAME arbitrarily.</P>



<P><B>ERRORS

</P></B>



<TABLE>



<TR><TD>

ENOMEM

</TD><TD>

Insufficient memory to allocate passwd structure.

</TD></TR></TABLE>





<A NAME="PAGENUM-935"><P>Page 935</P></A>







<P>getmntent, setmntent, addmntent, endmntent,

hasmntopt</P>



<P><B>

FILES

</P></B>



<P>The /etc/passwd password database file

/etc/utmp (or /var/adm/utmp, or wherever your utmp file lives these days&#151;the

proper location depends on your libc version)</P>



<P><B>CONFORMS TO

</P></B>



<P>POSIX.1. System V has a cuserid function that uses the real user ID rather than the effective user ID. The

cuserid function was included in the 1988 version of POSIX, but was removed from the 1990 version.</P>



<P><B>BUGS

</P></B>



<P>Unfortunately, it is often rather easy to fool

getlogin(). Sometimes it does not work at all, because some program messed

up the utmp file. Often, it gives only the first eight characters of the login name. The user currently logged in on the

controlling tty of your program need not be the user who started it.</P>



<P>Nobody knows precisely what cuserid() does; so</P>



<UL>

<LI>          Avoid it in portable programs

<LI>          Avoid it altogether

<LI>          Use getpwuid (geteuid()) instead, if that is what you meant.

</UL>



<P>Simply, do not use cuserid().</P>



<P></B>SEE ALSO

</P></B>



<P>geteuid(2), getuid(2)</P>



<P>Linux 1.2.13, 3 September 1995</P>



<H3><A NAME="ch03_ 82">

getmntent, setmntent, addmntent, endmntent, hasmntopt

</A></H3>



<P>getmntent, setmntent, addmntent, endmntent,

hasmntopt&#151;Get filesystem descriptor file entry</P>



<P><B>SYNOPSIS

</P></B>



<!-- CODE //-->

<PRE>

#include &lt;stdio.h&gt;

#include &lt;mntent.h&gt;

FILE *setmntent(const char *filep, const char *type);

struct mntent *getmntent(FILE *filep);

int addmntent(FILE *filep, const struct mntent *mnt);

int endmntent(FILE *filep);

char *hasmntopt(const struct mntent *mnt, const char *opt);

</PRE>

<!-- END CODE //-->



<P><B>DESCRIPTION

</P></B>



<P>These routines are used to access the filesystem description file

/etc/fstab and the mounted filesystem description file

/etc/mstab.</P>



<P>The setmntent() function opens the filesystem description file

filep and returns a file pointer that can be used

by getmntent(). The argument type is the type of access required and can take the same values as the

mode argument of fopen(3).</P>



<P>The getmntent() function reads the next line from the filesystem description file

filep and returns a pointer to a structure containing the broken-out fields from a line in the file. The pointer points to a static area of memory that is overwritten

by subsequent calls to getmntent().</P>



<P>The addmntent() function adds the mntent structure

mnt to the end of the open file filep.</P>



<P>The endmntent() function closes the filesystem description file

filep.</P>



<P>The hasmntopt() function scans the mnt_opts field of the

mntent structure mnt for a substring that matches

opt. (See &lt;mntent.h&gt; for valid mount options.)</P>





<A NAME="PAGENUM-936"><P>Page 936</P></A>





<P>The mntent structure is defined in

&lt;mntent.h&gt; as follows:</P>



<!-- CODE //-->

<PRE>

struct mntent {

        char     *mnt_fsname;     /* name of mounted filesystem */

        char     *mnt_dir;       /* filesystem path prefix */

        char     *mnt_type;      /* mount type (see mntent.h) */

        char     *mnt_opts;      /* mount options (see mntent.h) */

        int      mnt_freq;       /* dump frequency in days */

        int      mnt_passno;     /* pass number on parallel fsck */

};

</PRE>

<!-- END CODE //-->



<P><B>RETURN VALUE

</P></B>



<P>The getmntent() function returns a pointer to the

mntent structure or NULL on failure.</P>



<P>The addmntent() function returns 0 on success and

1 on failure.</P>



<P>The endmntent() functions always returns 1.</P>



<P>The hasmntopt() function returns the address of the substring if a match is found, and

NULL otherwise.</P>



<P><B>

FILES

</P></B>





<P>/etc/fstab filesystem description file</P>



<P>/etc/mtab mounted filesystem description file</P>



<P><B>CONFORMS TO

</P></B>



<P>BSD 4.3</P>



<P></B>SEE ALSO

</P></B>



<P>fopen(3), fstab(5)</P>



<P>27 June 1993</P>



<H3><A NAME="ch03_ 83">

getnetent, getnetbyaddr, getnetbyname, setnetent, endnetent

</A></H3>



<P>getnetent, getnetbyaddr, getnetbyname,

setnetent, endnetent&#151;Get network entry</P>



<P><B>

SYNTAX

</P></B>



<!-- CODE //-->

<PRE>

#include &lt;netdb.h&gt;

struct netent *getnetent()

struct netent *getnetbyname(name)

char *name;

struct netent *getnetbyaddr(net, type)

long net; int type;

void setnetent(stayopen)

int stayopen;

void endnetent()

</PRE>

<!-- END CODE //-->



<P><B>DESCRIPTION

</P></B>



<P>The getnetent, getnetbyname, and getnetbyaddr subroutines each return a pointer to an object with the following

structure, containing the broken-out fields of a line in the network database,

/etc/networks:</P>



<!-- CODE //-->

<PRE>

struct netent {

        char     *n_name;      /* official name of net */

        char     **n_aliases;  /* alias list */

        int      n_addrtype;   /* net number type */

        long     n_net;        /* net number */

};

</PRE>

<!-- END CODE //-->









<P><CENTER>

<a href="0930-0933.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0937-0938.html">Next</A></CENTER></P>







</td>
</tr>
</table>

<!-- begin footer information -->







</body></html>

⌨️ 快捷键说明

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