📄 0943-0945.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="0939-0942.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0946-0949.html">Next</A></CENTER></P>
<A NAME="PAGENUM-943"><P>Page 943</P></A>
<P><B>
FILES
</P></B>
<P>/etc/passwd Password database file</P>
<P></B>SEE ALSO
</P></B>
<P>fgetpwent(3), getpwent(3), setpwent(3),
endpwent(3), getpwnam(3), getpwuid(3), putpwent(3),
passwd(5)</P>
<P>GNU, 27 May 1996</P>
<H3><A NAME="ch03_ 88">
getpwent, setpwent, endpwent
</A></H3>
<P>getpwent, setpwent, endpwent—get password file entry</P>
<P><B>SYNOPSIS
</P></B>
<!-- CODE SNIP //-->
<PRE>
#include <pwd.h>
#include <sys/types.h>
struct passwd *getpwent(void);
void setpwent(void);
void endpwent(void);
</PRE>
<!-- END CODE SNIP //-->
<P><B>DESCRIPTION
</P></B>
<P>The getpwent() function returns a pointer to a structure containing the broken-out fields of a line from
/etc/passwd. The first time it is called it returns the first entry; thereafter, it returns successive entries.</P>
<P>The setpwent() function rewinds the file pointer to the beginning of the
/etc/passwd file.</P>
<P>The endpwent() function closes the /etc/passwd file.</P>
<P>The passwd structure is defined in
<pwd.h> as follows:</P>
<!-- CODE //-->
<PRE>
struct passwd {
char *pw_name; /*username*/
char *pw_passwd; /* user password */
uid_t pw_uid; /* user id */
gid_t pw_gid; /* group id */
char *pw_gecos; /* real name */
char *pw_dir; /* home directory */
char *pw_shell; /* shell program */
};
</PRE>
<!-- END CODE //-->
<P><B>RETURN VALUE
</P></B>
<P>The getpwent()function returns the passwd structure, or
NULL if there are no more entries or an error occurs.</P>
<P><B>ERRORS
</P></B>
<TABLE>
<TR><TD>
ENOMEM
</TD><TD>
Insufficient memory to allocate passwd structure.
</TD></TR></TABLE>
<P><B>
FILES
</P></B>
<P>/etc/passwd Password database file</P>
<P><B>CONFORMS TO
</P></B>
<P>SVID 3, BSD 4.3</P>
<P></B>SEE ALSO
</P></B>
<P>fgetpwent(3), getpwnam(3), getpwuid(3),
getpw(3), putpwent(3), passwd(5).</P>
<P>GNU, 27 May 1996</P>
<A NAME="PAGENUM-944"><P>Page 944</P></A>
<H3><A NAME="ch03_ 89">
getpwnam, getpwuid
</A></H3>
<P>getpwnam, getpwuid—Get password file entry</P>
<P><B>SYNOPSIS
</P></B>
<!-- CODE SNIP //-->
<PRE>
#include <pwd.h>
#include <sys/types.h>
struct passwd *getpwnam(const char * name);
struct passwd *getpwuid(uid_t uid);
</PRE>
<!-- END CODE SNIP //-->
<P><B>DESCRIPTION
</P></B>
<P>The getpwnam() function returns a pointer to a structure containing the broken out fields of a line from
/etc/passwd for the entry that matches the username
name.</P>
<P>The getpwuid() function returns a pointer to a structure containing the broken-out fields of a line from
/etc/passwd for the entry that matches the user UID
uid.</P>
<P>The passwd structure is defined in
<pwd.h> as follows:</P>
<!-- CODE //-->
<PRE>
struct passwd {
char *pw_name; /*username*/
char *pw_passwd; /* user password */
uid_t pw_uid; /* user id */
gid_t pw_gid; /* group id */
char *pw_gecos; /* real name */
char *pw_dir; /* home directory */
char *pw_shell; /* shell program */
};
</PRE>
<!-- END CODE //-->
<P><B>RETURN VALUE
</P></B>
<P>The getpwnam()and getpwuid() functions return the
passwd 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 passwd structure.
</TD></TR></TABLE>
<P><B>
FILES
</P></B>
<TABLE>
<TR><TD>
/etc/passwd
</TD><TD>
Password database file
</TD></TR></TABLE>
<P><B>CONFORMS TO
</P></B>
<P>SVID 3, POSIX, BSD 4.3</P>
<P></B>SEE ALSO
</P></B>
<P>fgetpwent(3), getpwent(3), setpwent(3),
endpwent(3), getpw(3), putpwent(3), passwd(5)</P>
<P>GNU, 27 May 1996</P>
<H3><A NAME="ch03_ 90">
fgetc, fgets, getc, getchar, gets, ungetc
</A></H3>
<P>fgetc, fgets, getc, getchar, gets, ungetc—Input of characters and strings</P>
<P><B>SYNOPSIS
</P></B>
<!-- CODE SNIP //-->
<PRE>
#include <stdio.h>
int fgetc(FILE *stream);
char *fgets(char *s,int size, FILE *stream);
</PRE>
<!-- END CODE SNIP //-->
<A NAME="PAGENUM-945"><P>Page 945</P></A>
<!-- CODE SNIP //-->
<PRE>
int getc(FILE *stream);
int getchar(void);
char *gets(char *s);
int ungetc(int c, FILE *stream);
</PRE>
<!-- END CODE SNIP //-->
<P><B>DESCRIPTION
</P></B>
<P>fgetc() reads the next character from stream and returns it as an
unsigned char cast to an int, or EOF on end of file or error.</P>
<P>getc() is equivalent to fgetc() except that it can be implemented as a macro that evaluates
stream more than once.</P>
<P>getchar() is equivalent to getc(stdin).</P>
<P>gets()reads a line from stdin into the buffer pointed to by
s until either a terminating newline or EOF, which it
replaces with \0. No check for buffer overrun is performed (see the following "Bus" section).</P>
<P>fgets() reads in at most one less than n characters from
stream and stores them into the buffer pointed to by
s. Reading stops after an EOF or a newline. If a newline is read, it is stored into the buffer.
\0 is stored after the last character in the buffer.</P>
<P>ungetc() pushes c back to stream, cast to unsigned
char, where it is available for subsequent read operations.
Pushed-back characters will be returned in reverse order; only one pushback is guaranteed.</P>
<P>Calls to the functions described here can be mixed with each other and with calls to other input functions from the
stdio library for the same input stream.</P>
<P><B>RETURN VALUES
</P></B>
<P>fgetc(), getc(), and getchar() return the character read as an
unsigned char cast to an int, or EOF on end of file or error.</P>
<P>gets() and fgets() return s on success, and
NULL on error or when end of file occurs while no characters have been read.</P>
<P>ungetc() returns c on success, or EOF on error.</P>
<P><B>CONFORMS TO
</P></B>
<P>ANSI—C, POSIX.1</P>
<P><B>BUGS
</P></B>
<P>Because it is impossible to tell without knowing the data in advance how many characters
gets() will read, and because gets() will continue to store characters past the end of the buffer, it is extremely dangerous to use. It has been used to
break computer security. Use fgets() instead.</P>
<P>It is not advisable to mix calls to input functions from the stdio library with low-level calls to
read() for the file descriptor associated with the input stream; the results will be undefined and very probably not what you want.
<P></B>SEE ALSO
</P></B>
<P>read(2), write(2), fopen(3), fread(3), scanf(3),
puts(3), fseek(3), ferror(3)</P>
<P>GNU, 4 April 1993</P>
<H3><A NAME="ch03_ 91">
getservent, getservbyname, getservbyport,
setservent, <BR>endservent
</A></H3>
<P>getservent, getservbyname, getservbyport,
setservent, endservent—Get service entry</P>
<P><B>SYNOPSIS
</P></B>
<!-- CODE //-->
<PRE>
#include <netdb.h>
struct servent *getservent(void);
struct servent *getservbyname(const char *name, const char *proto);
struct servent *getservbyport(int port, const char *proto);
</PRE>
<!-- END CODE //-->
<P><CENTER>
<a href="0939-0942.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0946-0949.html">Next</A></CENTER></P>
</td>
</tr>
</table>
<!-- begin footer information -->
</body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -