📄 0946-0949.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="0943-0945.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0950-0951.html">Next</A></CENTER></P>
<A NAME="PAGENUM-946"><P>Page 946</P></A>
<!-- CODE SNIP //-->
<PRE>
void setservent(int stayopen);
void endservent(void);
</PRE>
<!-- END CODE SNIP //-->
<P><B>DESCRIPTION
</P></B>
<P>The getservent()function reads the next line from the file
/etc/services and returns a structure, servent, containing
the broken out fields from the line. The
/etc/services file is opened if necessary.</P>
<P>The getservbyname()function returns a servent structure for the line from
/etc/services that matches the service name using protocol
proto.</P>
<P>The getservbyport()function returns a servent structure for the line that matches the port
port given in network byte order using protocol
proto.</P>
<P>The setservent()function opens and rewinds the
/etc/services file. If stayopen is true (1), the file will not be closed
between calls to getservbyname() and
getservbyport().</P>
<P>The endservent() function closes /etc/services.</P>
<P>The servent structure is defined in
<netdb.h> as follows:</P>
<!-- CODE //-->
<PRE>
struct servent {
char *s_name; /* official service name */
char **s_aliases; /* alias list */
int s_port; /* port number */
char *s_proto; /* protocol to use */
}
</PRE>
<!-- END CODE //-->
<P>The members of the servent structure are:</P>
<TABLE>
<TR><TD>
s_name
</TD><TD>
The official name of the service.
</TD></TR><TR><TD>
s_aliases
</TD><TD>
A zero-terminated list of alternative names for the service.
</TD></TR><TR><TD>
s_port
</TD><TD>
The port number for the service, given in network byte order.
</TD></TR><TR><TD>
s_proto
</TD><TD>
The name of the protocol to use with this service.
</TD></TR></TABLE>
<P><B>RETURN VALUE
</P></B>
<P>The getservent(), getservbyname(), and
getservbyport() functions return the servent structure, or a
NULL pointer if an error occurs or the end of the file is reached.</P>
<P><B>
FILES
</P></B>
<TABLE>
<TR><TD>
/etc/services
</TD><TD>
Services database file
</TD></TR></TABLE>
<P><B>CONFORMS TO
</P></B>
<P>BSD 4.3</P>
<P></B>SEE ALSO
</P></B>
<P>getprotoent(3), getnetent(3), services(5)</P>
<P>BSD, 22 April 1996</P>
<H3><A NAME="ch03_ 92">
getusershell, setusershell, endusershell
</A></H3>
<P>getusershell, setusershell, endusershell—Get legal user shells</P>
<P><B>SYNOPSIS
</P></B>
<!-- CODE SNIP //-->
<PRE>
#include <unistd.h>
char *getusershell(void);
</PRE>
<!-- END CODE SNIP //-->
<A NAME="PAGENUM-947"><P>Page 947</P></A>
<!-- CODE SNIP //-->
<PRE>
void setusershell(void);
void endusershell(void);
</PRE>
<!-- END CODE SNIP //-->
<P><B>DESCRIPTION
</P></B>
<P>The getusershell() function returns the next line from the file
/etc/shells, opening the file if necessary. The line
should contain the pathname of a valid user shell. If
/etc/shells does not exist or is unreadable,
getusershell() behaves as if /bin/sh and /bin/csh were listed in the file.</P>
<P>The setusershell() function rewinds /etc/shells.</P>
<P>The endusershell() function closes /etc/shells.</P>
<P><B>RETURN VALUE
</P></B>
<P>The getusershell() function returns a NULL pointer on end of file.</P>
<P><B>
FILES
</P></B>
<!-- CODE SNIP //-->
<PRE>
/etc/shells
</PRE>
<!-- END CODE SNIP //-->
<P><B>CONFORMS TO
</P></B>
<P>BSD 4.3</P>
<P></B>SEE ALSO
</P></B>
<P>shells(5)
<P>BSD, 4 July 1993
<H3><A NAME="ch03_ 93">
getutent, getutid, getutline, pututline, setutent,
endutent, <BR>utmpname
</A></H3>
<P>getutent, getutid, getutline, pututline,
setutent, endutent, utmpname—Access utmp file entries</P>
<P><B>SYNOPSIS
</P></B>
<!-- CODE //-->
<PRE>
#include <utmp.h>
struct utmp *getutent(void);
struct utmp *getutid(struct utmp *ut);
struct utmp *getutline(struct utmp *ut);
void pututline(struct utmp *ut);
void setutent(void);
void endutent(void);
void utmpname(const char *file);
</PRE>
<!-- END CODE //-->
<P><B>DESCRIPTION
</P></B>
<P>utmpname() sets the name of the utmp-format file for the other utmp functions to access. If
utmpname() is not used to set the filename before the other functions are used, they assume
PATH_UTMP, as defined in <paths.h>.</P>
<P>setutent() rewinds the file pointer to the beginning of the
utmp file. It is generally a good idea to call it before any of
the other functions.</P>
<P>endutent()closes the utmp file. It should be called when the user code is done accessing the file with the other functions.</P>
<P>getutent() reads a line from the current file position in the
utmp file. It returns a pointer to a structure containing the
fields of the line.</P>
<P>getutid()searches forward from the current file position in the
utmp file based on ut. If ut->ut_type is
RUN_LVL, BOOT_TIME, NEW_TIME, or OLD_TIME,
getutid() will find the first entry whose ut_type field matches
ut->ut_type. If ut->ut_type is</P>
<A NAME="PAGENUM-948"><P>Page 948</P></A>
<P>INIT_PROCESS, LOGIN_PROCESS, USER_PROCESS, or
DEAD_PROCESS, getutid() will find the first entry whose
ut_id field matches
ut->ut_id.</P>
<P>getutline() searches forward from the current file position in the utmp file. It scans entries whose
ut type is USER_PROCESS or LOGIN_PROCESS and returns the first one whose
ut_line field matches ut->ut_line.</P>
<P>pututline()writes the utmp structure ut into the
utmp file. It uses getutid() to search for the proper place in the file to
insert the new entry. If it cannot find an appropriate slot for
ut, pututline() will append the new entry to the end of the file.</P>
<P><B>RETURN VALUE
</P></B>
<P>getutent(), getutid(), and getutline() return a pointer to a struct
utmp, which is defined in <utmp.h>.</P>
<P><B>
FILES
</P></B>
<P>/var/run/utmp—Database of currently logged-in users</P>
<P>/var/log/wtmp—Database of past user logins</P>
<P><B>CONFORMS TO
</P></B>
<P>XPG 2, SVID 2, Linux FSSTND 1.2</P>
<P></B>SEE ALSO
</P></B>
<P>utmp(5)</P>
<P>Linux libc 5.0.0, 22 March 1995</P>
<H3><A NAME="ch03_ 94">
getw, putw
</A></H3>
<P>getw, putw—Input and output of words (ints)</P>
<P><B>SYNOPSIS
</P></B>
<!-- CODE SNIP //-->
<PRE>
#include <stdio.h>
int getw(FILE *stream);
int putw(int w,FILE*stream);
</PRE>
<!-- END CODE SNIP //-->
<P><B>DESCRIPTION
</P></B>
<P>getw reads a word (that is, an int) from stream. It's provided for compatibility with SVID. I recommend you use
fread(3) instead. putw writes the word w (that is, an
int) to stream. It is provided for compatibility with SVID, but I recommend
you use fwrite(3) instead.</P>
<P><B>RETURN VALUES
</P></B>
<P>Normally, getw returns the word read, and putw returns the word written. On error, they return
EOF.</P>
<P><B>BUGS
</P></B>
<P>The value returned on error is also a legitimate data value.
ferror(3) can be used to distinguish between the two cases.</P>
<P><B>CONFORMS TO
</P></B>
<P>SVID</P>
<P></B>SEE ALSO
</P></B>
<P>fread(3), fwrite(3), ferror(3), getc(3), putc(3)</P>
<P>GNU, 16 September 1995</P>
<A NAME="PAGENUM-949"><P>Page 949</P></A>
<H3><A NAME="ch03_ 95">
glob, globfree
</A></H3>
<P>glob, globfree—Find pathnames matching a pattern; free memory from
glob()</P>
<P><B>SYNOPSIS
</P></B>
<!-- CODE //-->
<PRE>
#include <glob.h>
int glob(const char *pattern, int flags,
int errfunc(const char * epath, int eerrno),
glob_t *pglob);
void globfree(glob_t *pglob);
</PRE>
<!-- END CODE //-->
<P><B>DESCRIPTION
</P></B>
<P>The glob() function searches for all the pathnames matching
pattern according to the rules used by the shell (see
glob(7)). No tilde expansion or parameter substitution is done.</P>
<P>The globfree() function frees the dynamically allocated storage from an earlier call to
glob().</P>
<P>The results of a glob() call are stored in the structure pointed to by
pglob, which is a glob_t that is declared in
<glob.h> as</P>
<!-- CODE //-->
<PRE>
typedef struct
{
int gl_pathc; /* Count of paths matched so far */
char **gl_pathv; /* List of matched pathnames. */
int gl_offs; /* Slots to reserve in `gl pathv'. */
int gl_flags; /* Flags for globbing */
} glob_t;
</PRE>
<!-- END CODE //-->
<P>Results are stored in dynamically allocated storage.</P>
<P>The parameter flags is made up of bitwise OR of zero or more the following symbolic constants, which modify the
of behavior of glob():</P>
<TABLE>
<TR><TD>
GLOB_ERR
</TD><TD>
Return on read error (because a directory does not have read permission, for example).
</TD></TR><TR><TD>
GLOB_MARK
</TD><TD>
Append a slash to each path which corresponds to a directory.
</TD></TR><TR><TD>
GLOB_NOSORT
</TD><TD>
Don't sort the returned pathnames (they are by default).
</TD></TR><TR><TD>
GLOB_DOOFS
</TD><TD>
pglob->gl_offs slots will be reserved at the beginning of the list of strings in
pglob->pathv.
</TD></TR><TR><TD>
GLOB_NOCHECK
</TD><TD>
If no pattern matches, return the original pattern.
</TD></TR><TR><TD>
GLOB_APPEND
</TD><TD>
Append to the results of a previous call. Do not set this flag on the first invocation of
glob().
</TD></TR><TR><TD>
GLOB_NOESCAPE
</TD><TD>
Meta characters cannot be quoted by backslashes.
</TD></TR><TR><TD>
GLOB_PERIOD
</TD><TD>
A leading period can be matched by meta characters.
</TD></TR></TABLE>
<P>If errfunc is not NULL, it will be called in case of an error with the arguments
epath, a pointer to the path that failed, and
eerrno, the value of errno as returned from one of the calls to
opendir(), readdir(), or stat(). If errfunc returns nonzero,
or if GLOB_ERR is set, glob() will terminate after the call to
errfunc.</P>
<P>Upon successful return, pglob->gl_pathc contains the number of matched pathnames and
pglob->gl_pathv a pointer to the list of matched pathnames. The first pointer after the last pathname is
NULL.</P>
<P>It is possible to call glob() several times. In that case, the
GLOB_APPEND flag has to be set in flags on the second and
later invocations.</P>
<P><B>RETURN VALUES
</P></B>
<P>On successful completion, glob() returns 0. Other possible returns are</P>
<TABLE>
<TR><TD>
GLOB_NOSPACE
</TD><TD>
For running out of memory,
</TD></TR><TR><TD>
GLOB_ABEND
</TD><TD>
For a read error, and
</TD></TR><TR><TD>
GLOB_NOMATCH
</TD><TD>
For no found matches.
</TD></TR></TABLE>
<P><CENTER>
<a href="0943-0945.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0950-0951.html">Next</A></CENTER></P>
</td>
</tr>
</table>
<!-- begin footer information -->
</body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -