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

📄 0930-0933.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="0927-0929.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0934-0936.html">Next</A></CENTER></P>







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





<P></B>SEE ALSO

</P></B>



<P>ipc(5), msgget(2), semget(2), shmget(2), stat(2)</P>



<P>Linux 0.99.13, 1 November 1993</P>



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

ftw

</A></H3>



<P>ftw&#151;File tree walk</P>



<P><B>SYNOPSIS

</P></B>



<!-- CODE SNIP //-->

<PRE>

#include &lt;ftw.h&gt;

int ftw(const char *directory,

int(*funcptr)(const char *file, struct stat *sb, int flag), int depth);

</PRE>

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



<P><B>DESCRIPTION

</P></B>



<P>ftw() walks through the directory tree, starting from the indicated

directory. For each found entry in the tree, it calls

funcptr with the full pathname of the entry relative to

directory, a pointer to the stat(2) structure for the entry and an int

whose value will be one of the following:</P>



<TABLE>



<TR><TD>

FTW_F

</TD><TD>

Item is a normal file

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

FTW_D

</TD><TD>

Item is a directory

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

FTW_NS

</TD><TD>

The stat failed on the item

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

FTW_DNR

</TD><TD>

Item is a directory which can't be read

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



<P>Warning: Anything other than directories, such as symbolic links, gets the

FTW_F tag.</P>



<P>ftw() recursively calls itself for traversing found directories. To avoid using up all a program's file descriptors,

depth specifies the number of simultaneous open directories. When the depth is exceeded,

ftw() will become slower because directories have to be closed and reopened.</P>



<P>To stop the tree walk, funcptr returns a nonzero value; this value will become the return value of

ftp(). Otherwise, ftw() will continue until it has traversed the entire tree (in which case it will return

0), or until it hits an error such as a malloc(3) failure, in which case it will return

_1.</P>



<P>Because ftp() uses dynamic data structures, the only safe way to exit a tree walk is to return a nonzero value. To

handle interrupts, for example, mark that the interrupt occurred and return a nonzero value&#151;don't use

longjmp(3) unless the program is going to terminate.</P>



<P></B>SEE ALSO

</P></B>



<P>stat(2)</P>



<P>Linux, 18 July 1993</P>



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

gcvt

</A></H3>



<P>gcvt&#151;Converts a floating-point number to a string</P>



<P><B>SYNOPSIS

</P></B>



<!-- CODE SNIP //-->

<PRE>

#include &lt;stdlib.h&gt;

char *gcvt(double number, size_t ndigit, char *buf);

</PRE>

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



<P><B>DESCRIPTION

</P></B>



<P>The gcvt() function converts number to a minimal-length, NULL-terminated ASCII string and stores the result in

buf. It produces ndigit significant digits in either

printf() F format or E format.</P>





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





<P><B>RETURN VALUE

</P></B>



<P>The gcvt() function returns the address of the string pointed to by

buf.</P>



<P></B>SEE ALSO

</P></B>



<P>ecvt(3), fcvt(3), sprintf(3)</P>



<P>29 March 1993</P>



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

getcwd, get_current_dir_name, getwd

</A></H3>



<P>getcwd, get_current_dir_name, getwd&#151;Get current working directory</P>



<P><B>SYNOPSIS

</P></B>



<!-- CODE //-->

<PRE>

#include &lt;unistd.h&gt;

char *getcwd(char *buf, size_t size);

char *get_current_working_dir_name(void);

char *getwd(char *buf);

</PRE>

<!-- END CODE //-->



<P><B>DESCRIPTION

</P></B>



<P>The getcwd() function copies the absolute pathname of the current working directory to the array pointed to by

buf, which is of length size.</P>



<P>If the current absolute pathname would require a buffer longer than

size elements, NULL is returned, and errno is set

to ERANGE; an application should check for this error, and allocate a larger buffer if necessary.</P>



<P>As an extension to the POSIX.1 standard,

getcwd() allocates the buffer dynamically using

malloc() if buf is NULL on call. In this case, the allocated buffer has the length

size unless size is less than 0, when buf is allocated as large as necessary. It

is possible (and, indeed, advisable) to free the buffers if they have been obtained this way.</P>



<P>get_current_dir_name, which is only prototyped if

__USE_GNU is defined, will malloc(3) an array big enough to hold

the current directory name. If the environment variable

PWD is set, and its value is correct, that value will be returned.</P>



<P>getwd, which is only prototyped if __USE_BSD is defined, will not

malloc(3) any memory. The buf argument should be a pointer to an array at least

PATH_MAX bytes long. getwd returns only the first

PATH_MAX bytes of the actual pathname.</P>



<P><B>RETURN VALUE

</P></B>



<P>NULL on failure  (for example, if the current directory is not readable), with

errno set accordingly, and buf on success.</P>



<P><B>CONFORMS TO

</P></B>



<P>POSIX.1</P>



<P></B>SEE ALSO

</P></B>



<P>chdir(2), free(3), malloc(3).</P>



<P>GNU, 21 July 1993</P>



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

getdirentries

</A></H3>



<P>getdirentries&#151;Gets directory entries in a filesystem-independent format</P>



<P><B>SYNOPSIS

</P></B>



<!-- CODE SNIP //-->

<PRE>

#define __USE_BSD  or  #define __USE_MISC

#include &lt;dirent.h&gt;

ssize_t getdirentries(int fd, char *buf, size_t nbytes ,offt *basep);

</PRE>

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



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





<P><B>DESCRIPTION

</P></B>



<P>This function reads directory entries from the directory specified by

fd into buf. At most, nbytes are read. Reading starts

at offset *basep, and *basep is updated with the new position after reading.</P>



<P><B>RETURN VALUE

</P></B>



<P>getdirentries returns the number of bytes read, or

0 when at the end of the directory. If an error occurs,

_1 is returned, and errno is set appropriately.</P>



<P><B>ERRORS

</P></B>



<P>See the Linux library source code for details.</P>



<P></B>SEE ALSO

</P></B>



<P>open(2), lseek(2)</P>



<P>BSD/MISC, 22 July 1993</P>



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

getenv

</A></H3>



<P>getenv&#151;Gets an environment variable</P>



<P><B>SYNOPSIS

</P></B>



<!-- CODE SNIP //-->

<PRE>

#include &lt;stdlib.h&gt;

char *getenv(const char *name);

</PRE>

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



<P><B>DESCRIPTION

</P></B>



<P>The getenv() function searches the environment list for a string that matches the string pointed to by

name. The strings are of the form name=value.</P>



<P><B>RETURN VALUE

</P></B>



<P>The getenv() function returns a pointer to the value in the environment, or

NULL if there is no match.</P>



<P><B>CONFORMS TO

</P></B>



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



<P></B>SEE ALSO

</P></B>



<P>putenv(3), setenv(3), unsetenv(3)</P>



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



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

getgrent, setgrent, endgrent

</A></H3>



<P>getgrent, setgrent, endgrent&#151;Get group file entry</P>



<P><B>SYNOPSIS

</P></B>



<!-- CODE SNIP //-->

<PRE>

#include &lt;grp.h&gt;

#include &lt;sys/types.h&gt;

struct group *getgrent(void);

void setgrent(void);

void endgrent(void);

</PRE>

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





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





<P><B>DESCRIPTION

</P></B>



<P>The getgrent() function returns a pointer to a structure containing the group information from

/etc/group. The first time it is called it returns the first entry; thereafter, it returns successive entries.</P>



<P>The setgrent() function rewinds the file pointer to the beginning of the

/etc/group file.</P>



<P>The endgrent() function closes the /etc/group file.</P>



<P>The group structure is defined in &lt;grp.h&gt; as follows:</P>



<!-- CODE //-->

<PRE>

struct group {

        char    *gr_name;    /* group name */

        char    *gr_passwd;  /* group password */

        gid_t   gr_gid;      /* group id */

        char    **gr_mem;    /* group members */

};

</PRE>

<!-- END CODE //-->



<P><B>RETURN VALUE

</P></B>



<P>The getgrent()function returns the group information 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 group information structure.

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



<P><B>

FILES

</P></B>



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



<P><B>CONFORMS TO</P>

</P></B>



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



<P></B>SEE ALSO

</P></B>



<P>fgetgrent(3), getgrnam(3), getgrgid(3)</P>



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



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

getgrnam, getgrgid

</A></H3>



<P>getgrnam, getgrgid&#151;Get group file entry</P>



<P><B>SYNOPSIS

</P></B>



<!-- CODE SNIP //-->

<PRE>

#include &lt;grp.h&gt;

#include &lt;sys/types.h&gt;

struct group *getgrnam(const char *name);

struct group *getgrgid(gid_t gid);

</PRE>

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



<P><B>DESCRIPTION

</P></B>



<P>The getgrnam() function returns a pointer to a structure containing the group information from

/etc/group for the entry that matches the group name

name.</P>



<P>The getgrgid() function returns a pointer to a structure containing the group information from

/etc/group for the entry that matches the group id

gid.</P>



<P>The group structure is defined in &lt;grp.h&gt; as follows:</P>



<!-- CODE SNIP //-->

<PRE>

struct group {

        char     *gr_name;    /* group name */

        char     *gr_passwd;  /* group password */

</PRE>

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









<P><CENTER>

<a href="0927-0929.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0934-0936.html">Next</A></CENTER></P>







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

<!-- begin footer information -->







</body></html>

⌨️ 快捷键说明

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