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

📄 dirlib.html

📁 Vxworks API操作系统和驱动程序设计API。压缩的HTML文件
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<html><head><!-- /vobs/wpwr/docs/vxworks/ref/dirLib.html - generated by refgen from dirLib.c --> <title> dirLib </title></head><body bgcolor="#FFFFFF"> <hr><a name="top"></a><p align=right><a href="libIndex.htm"><i>VxWorks API Reference :  OS Libraries</i></a></p></blockquote><h1>dirLib</h1> <blockquote></a></blockquote><h4>NAME</h4><blockquote>  <p><strong>dirLib</strong> - directory handling library (POSIX) </p></blockquote><h4>ROUTINES</h4><blockquote><p><p><b><a href="./dirLib.html#opendir">opendir</a>(&nbsp;)</b>  -  open a directory for searching (POSIX)<br><b><a href="./dirLib.html#readdir">readdir</a>(&nbsp;)</b>  -  read one entry from a directory (POSIX)<br><b><a href="./dirLib.html#rewinddir">rewinddir</a>(&nbsp;)</b>  -  reset position to the start of a directory (POSIX)<br><b><a href="./dirLib.html#closedir">closedir</a>(&nbsp;)</b>  -  close a directory (POSIX)<br><b><a href="./dirLib.html#fstat">fstat</a>(&nbsp;)</b>  -  get file status information (POSIX)<br><b><a href="./dirLib.html#stat">stat</a>(&nbsp;)</b>  -  get file status information using a pathname (POSIX)<br><b><a href="./dirLib.html#fstatfs">fstatfs</a>(&nbsp;)</b>  -  get file status information (POSIX)<br><b><a href="./dirLib.html#statfs">statfs</a>(&nbsp;)</b>  -  get file status information using a pathname (POSIX)<br><b><a href="./dirLib.html#utime">utime</a>(&nbsp;)</b>  -  update time on a file<br><p></blockquote><h4>DESCRIPTION</h4><blockquote><p>This library provides POSIX-defined routines for opening, reading, andclosing directories on a file system.  It also provides routines to obtainmore detailed information on a file or directory.<p></blockquote><h4>SEARCHING DIRECTORIES</h4><blockquote><p>Basic directory operations, including <b><a href="./dirLib.html#opendir">opendir</a>(&nbsp;)</b>, <b><a href="./dirLib.html#readdir">readdir</a>(&nbsp;)</b>, <b><a href="./dirLib.html#rewinddir">rewinddir</a>(&nbsp;)</b>,and <b><a href="./dirLib.html#closedir">closedir</a>(&nbsp;)</b>, determine the names of files and subdirectories in adirectory.<p>A directory is opened for reading using <b><a href="./dirLib.html#opendir">opendir</a>(&nbsp;)</b>, specifying the name ofthe directory to be opened.  The <b><a href="./dirLib.html#opendir">opendir</a>(&nbsp;)</b> call returns a pointer to adirectory descriptor, which identifies a directory stream.  The stream isinitially positioned at the first entry in the directory.<p>Once a directory stream is opened, <b><a href="./dirLib.html#readdir">readdir</a>(&nbsp;)</b> is used to obtain individualentries from it.  Each call to <b><a href="./dirLib.html#readdir">readdir</a>(&nbsp;)</b> returns one directory entry, insequence from the start of the directory.  The <b><a href="./dirLib.html#readdir">readdir</a>(&nbsp;)</b> routine returns apointer to a <b>dirent</b> structure, which contains the name of the file (orsubdirectory) in the <b>d_name</b> field.<p>The <b><a href="./dirLib.html#rewinddir">rewinddir</a>(&nbsp;)</b> routine resets the directory stream to the start of thedirectory.  After <b><a href="./dirLib.html#rewinddir">rewinddir</a>(&nbsp;)</b> has been called, the next <b><a href="./dirLib.html#readdir">readdir</a>(&nbsp;)</b> will causethe current directory state to be read in, just as if a new <b><a href="./dirLib.html#opendir">opendir</a>(&nbsp;)</b> hadoccurred.  The first entry in the directory will be returned by the first<b><a href="./dirLib.html#readdir">readdir</a>(&nbsp;)</b>.<p>The directory stream is closed by calling <b><a href="./dirLib.html#closedir">closedir</a>(&nbsp;)</b>.<p></blockquote><h4>GETTING FILE INFORMATION</h4><blockquote><p>The directory stream operations described above provide a mechanism todetermine the names of the entries in a directory, but they do not provideany other information about those entries.  More detailed information isprovided by <b><a href="./dirLib.html#stat">stat</a>(&nbsp;)</b> and <b><a href="./dirLib.html#fstat">fstat</a>(&nbsp;)</b>.<p>The <b><a href="./dirLib.html#stat">stat</a>(&nbsp;)</b> and <b><a href="./dirLib.html#fstat">fstat</a>(&nbsp;)</b> routines are essentially the same, except for howthe file is specified.  The <b><a href="./dirLib.html#stat">stat</a>(&nbsp;)</b> routine takes the name of the file asan input parameter, while <b><a href="./dirLib.html#fstat">fstat</a>(&nbsp;)</b> takes a file descriptor number asreturned by <b><a href="./ioLib.html#open">open</a>(&nbsp;)</b> or <b><a href="./ioLib.html#creat">creat</a>(&nbsp;)</b>.  Both routines place the information from adirectory entry in a <b>stat</b> structure whose address is passed as an inputparameter.  This structure is defined in the include file <b>stat.h</b>.  Thefields in the structure include the file size, modification date/time,whether it is a directory or regular file, and various other values.<p>The <b>st_mode</b> field contains the file type; several macro functions areprovided to test the type easily.  These macros operate on the <b>st_mode</b>field and evaluate to TRUE or FALSE depending on whether the file is aspecific type.  The macro names are:<p><dl><dt><b>S_ISREG</b><dd>test if the file is a regular file<dt><b>S_ISDIR</b><dd>test if the file is a directory<dt><b>S_ISCHR</b><dd>test if the file is a character special file<dt><b>S_ISBLK</b><dd>test if the file is a block special file<dt><b>S_ISFIFO</b><dd>test if the file is a FIFO special file<p></dl>Only the regular file and directory types are used for VxWorks localfile systems.  However, the other file types may appear when gettingfile status from a remote file system (using NFS).<p>As an example, the <b>S_ISDIR</b> macro tests whether a particular entry describesa directory.  It is used as follows:<pre>    char          *filename;    struct stat   fileStat;    stat (filename, &amp;fileStat);    if (S_ISDIR (fileStat.st_mode))        printf ("%s is a directory.\n", filename);    else        printf ("%s is not a directory.\n", filename);</pre>See the <b><a href="./usrFsLib.html#ls">ls</a>(&nbsp;)</b> routine in <b><a href="./usrLib.html#top">usrLib</a></b> for an illustration of how to combinethe directory stream operations with the <b><a href="./dirLib.html#stat">stat</a>(&nbsp;)</b> routine.<p></blockquote><h4>INCLUDE FILES</h4><blockquote><p><b>dirent.h</b>, <b>stat.h</b><hr><a name="opendir"></a><p align=right><a href="rtnIndex.htm"><i>OS Libraries :  Routines</i></a></p></blockquote><h1>opendir(&nbsp;)</h1> <blockquote></a></blockquote><h4>NAME</h4><blockquote>  <p><strong>opendir(&nbsp;)</strong> - open a directory for searching (POSIX)</p></blockquote><h4>SYNOPSIS</h4><blockquote><p><pre>DIR *opendir    (    char * dirName            /* name of directory to open */    )</pre></blockquote><h4>DESCRIPTION</h4><blockquote><p>This routine opens the directory named by <i>dirName</i> and allocates adirectory descriptor (DIR) for it.  A pointer to the DIR structure isreturned.  The return of a NULL pointer indicates an error.<p>After the directory is opened, <b><a href="./dirLib.html#readdir">readdir</a>(&nbsp;)</b> is used to extract individualdirectory entries.  Finally, <b><a href="./dirLib.html#closedir">closedir</a>(&nbsp;)</b> is used to close the directory.<p></blockquote><h4>WARNING</h4><blockquote><p>For remote file systems mounted over <b><a href="./netDrv.html#top">netDrv</a></b>, <b><a href="./dirLib.html#opendir">opendir</a>(&nbsp;)</b> fails,because the <b><a href="./netDrv.html#top">netDrv</a></b> implementation strategy does not provide a way to distinguish directories from plain files.  To permit use of <b><a href="./dirLib.html#opendir">opendir</a>(&nbsp;)</b> on remote files, use NFS rather than <b><a href="./netDrv.html#top">netDrv</a></b>.<p></blockquote><h4>RETURNS</h4><blockquote><p>A pointer to a directory descriptor, or NULL if there is an error.<p></blockquote><h4>SEE ALSO</h4><blockquote><p><b><a href="./dirLib.html#top">dirLib</a></b>, <b><a href="./dirLib.html#closedir">closedir</a>(&nbsp;)</b>, <b><a href="./dirLib.html#readdir">readdir</a>(&nbsp;)</b>, <b><a href="./dirLib.html#rewinddir">rewinddir</a>(&nbsp;)</b>, <b><a href="./usrFsLib.html#ls">ls</a>(&nbsp;)</b><hr><a name="readdir"></a><p align=right><a href="rtnIndex.htm"><i>OS Libraries :  Routines</i></a></p></blockquote><h1>readdir(&nbsp;)</h1> <blockquote></a></blockquote><h4>NAME</h4><blockquote>  <p><strong>readdir(&nbsp;)</strong> - read one entry from a directory (POSIX)</p></blockquote><h4>SYNOPSIS</h4><blockquote><p><pre>struct dirent *readdir    (    DIR * pDir                /* pointer to directory descriptor */    )</pre></blockquote><h4>DESCRIPTION</h4><blockquote><p>This routine obtains directory entry data for the next file from anopen directory.  The <i>pDir</i> parameter is the pointer to a directorydescriptor (DIR) which was returned by a previous <b><a href="./dirLib.html#opendir">opendir</a>(&nbsp;)</b>.<p>This routine returns a pointer to a <b>dirent</b> structure which containsthe name of the next file.  Empty directory entries and MS-DOS volumelabel entries are not reported.  The name of the file (or subdirectory)described by the directory entry is returned in the <b>d_name</b> fieldof the <b>dirent</b> structure.  The name is a single null-terminated string.<p>The returned <b>dirent</b> pointer will be NULL, if it is at the end of thedirectory or if an error occurred.  Because there are two conditions whichmight cause NULL to be returned, the task's error number (<b>errno</b>) must beused to determine if there was an actual error.  Before calling <b><a href="./dirLib.html#readdir">readdir</a>(&nbsp;)</b>,set <b>errno</b> to OK.  If a NULL pointer is returned, check the newvalue of <b>errno</b>.  If <b>errno</b> is still OK, the end of the directory wasreached; if not, <b>errno</b> contains the error code for an actual error whichoccurred.<p></blockquote><h4>RETURNS</h4><blockquote><p>A pointer to a <b>dirent</b> structure,or NULL if there is an end-of-directory marker or error.<p></blockquote><h4>SEE ALSO</h4><blockquote><p><b><a href="./dirLib.html#top">dirLib</a></b>, <b><a href="./dirLib.html#opendir">opendir</a>(&nbsp;)</b>, <b><a href="./dirLib.html#closedir">closedir</a>(&nbsp;)</b>, <b><a href="./dirLib.html#rewinddir">rewinddir</a>(&nbsp;)</b>, <b><a href="./usrFsLib.html#ls">ls</a>(&nbsp;)</b><hr><a name="rewinddir"></a><p align=right><a href="rtnIndex.htm"><i>OS Libraries :  Routines</i></a></p></blockquote><h1>rewinddir(&nbsp;)</h1> <blockquote></a></blockquote><h4>NAME</h4><blockquote>  <p><strong>rewinddir(&nbsp;)</strong> - reset position to the start of a directory (POSIX)</p></blockquote><h4>SYNOPSIS</h4><blockquote><p><pre>void rewinddir    (    DIR * pDir                /* pointer to directory descriptor */    )

⌨️ 快捷键说明

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