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

📄 glob.html

📁 IEEE 1003.1-2003, Single Unix Specification v3
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta name="generator" content="HTML Tidy, see www.w3.org"><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><link type="text/css" rel="stylesheet" href="style.css"><!-- Generated by The Open Group's rhtm tool v1.2.1 --><!-- Copyright (c) 2001-2003 The Open Group, All Rights Reserved --><title>glob</title></head><body bgcolor="white"><basefont size="3"> <a name="glob"></a> <a name="tag_03_260"></a><!-- glob --> <!--header start--><center><font size="2">The Open Group Base Specifications Issue 6<br>IEEE Std 1003.1, 2003 Edition<br>Copyright &copy; 2001-2003 The IEEE and The Open Group, All Rights reserved.</font></center><!--header end--><hr size="2" noshade><h4><a name="tag_03_260_01"></a>NAME</h4><blockquote>glob, globfree - generate pathnames matching a pattern</blockquote><h4><a name="tag_03_260_02"></a>SYNOPSIS</h4><blockquote class="synopsis"><p><code><tt>#include &lt;<a href="../basedefs/glob.h.html">glob.h</a>&gt;<br><br> int glob(const char *restrict</tt> <i>pattern</i><tt>, int</tt> <i>flags</i><tt>,<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int(*</tt><i>errfunc</i><tt>)(const char *</tt><i>epath</i><tt>, int</tt><i>eerrno</i><tt>),<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; glob_t *restrict</tt> <i>pglob</i><tt>);<br> void globfree(glob_t *</tt><i>pglob</i><tt>);<br></tt></code></p></blockquote><h4><a name="tag_03_260_03"></a>DESCRIPTION</h4><blockquote><p>The <i>glob</i>() function is a pathname generator that shall implement the rules defined in the Shell and Utilities volume ofIEEE&nbsp;Std&nbsp;1003.1-2001, <a href="../utilities/xcu_chap02.html#tag_02_13">Section 2.13, Pattern Matching Notation</a>, withoptional support for rule 3 in the Shell and Utilities volume of IEEE&nbsp;Std&nbsp;1003.1-2001, <a href="../utilities/xcu_chap02.html#tag_02_13_02">Section 2.13.3, Patterns Used for Filename Expansion</a>.</p><p>The structure type <b>glob_t</b> is defined in <a href="../basedefs/glob.h.html"><i>&lt;glob.h&gt;</i></a> and includes at leastthe following members:</p><center><table border="1" cellpadding="3" align="center"><tr valign="top"><th align="center"><p class="tent"><b>Member Type</b></p></th><th align="center"><p class="tent"><b>Member Name</b></p></th><th align="center"><p class="tent"><b>Description</b></p></th></tr><tr valign="top"><td align="left"><p class="tent"><b>size_t</b></p></td><td align="left"><p class="tent"><i>gl_pathc</i></p></td><td align="left"><p class="tent">Count of paths matched by <i>pattern</i>.</p></td></tr><tr valign="top"><td align="left"><p class="tent"><b>char **</b></p></td><td align="left"><p class="tent"><i>gl_pathv</i></p></td><td align="left"><p class="tent">Pointer to a list of matched pathnames.</p></td></tr><tr valign="top"><td align="left"><p class="tent"><b>size_t</b></p></td><td align="left"><p class="tent"><i>gl_offs</i></p></td><td align="left"><p class="tent">Slots to reserve at the beginning of <i>gl_pathv</i>.</p></td></tr></table></center><p>The argument <i>pattern</i> is a pointer to a pathname pattern to be expanded. The <i>glob</i>() function shall match allaccessible pathnames against this pattern and develop a list of all pathnames that match. In order to have access to a pathname,<i>glob</i>() requires search permission on every component of a path except the last, and read permission on each directory of anyfilename component of <i>pattern</i> that contains any of the following special characters: <tt>'*'</tt> , <tt>'?'</tt> , and<tt>'['</tt> .</p><p>The <i>glob</i>() function shall store the number of matched pathnames into <i>pglob</i>-&gt;<i>gl_pathc</i> and a pointer to alist of pointers to pathnames into <i>pglob</i>-&gt;<i>gl_pathv</i>. The pathnames shall be in sort order as defined by the currentsetting of the <i>LC_COLLATE</i> category; see the Base Definitions volume of IEEE&nbsp;Std&nbsp;1003.1-2001, <a href="../basedefs/xbd_chap07.html#tag_07_03_02">Section 7.3.2, LC_COLLATE</a>. The first pointer after the last pathname shall be a nullpointer. If the pattern does not match any pathnames, the returned number of matched paths is set to 0, and the contents of<i>pglob</i>-&gt;<i>gl_pathv</i> are implementation-defined.</p><p>It is the caller's responsibility to create the structure pointed to by <i>pglob</i>. The <i>glob</i>() function shall allocateother space as needed, including the memory pointed to by <i>gl_pathv</i>. The <i>globfree</i>() function shall free any spaceassociated with <i>pglob</i> from a previous call to <i>glob</i>().</p><p>The <i>flags</i> argument is used to control the behavior of <i>glob</i>(). The value of <i>flags</i> is a bitwise-inclusive ORof zero or more of the following constants, which are defined in <a href="../basedefs/glob.h.html"><i>&lt;glob.h&gt;</i></a>:</p><dl compact><dt>GLOB_APPEND</dt><dd>Append pathnames generated to the ones from a previous call to <i>glob</i>().</dd><dt>GLOB_DOOFFS</dt><dd>Make use of <i>pglob</i>-&gt;<i>gl_offs</i>. If this flag is set, <i>pglob</i>-&gt;<i>gl_offs</i> is used to specify how manynull pointers to add to the beginning of <i>pglob</i>-&gt;<i>gl_pathv</i>. In other words, <i>pglob</i>-&gt;<i>gl_pathv</i> shallpoint to <i>pglob</i>-&gt;<i>gl_offs</i> null pointers, followed by <i>pglob</i>-&gt;<i>gl_pathc</i> pathname pointers, followed bya null pointer.</dd><dt>GLOB_ERR</dt><dd>Cause <i>glob</i>() to return when it encounters a directory that it cannot open or read. Ordinarily, <i>glob</i>() continuesto find matches.</dd><dt>GLOB_MARK</dt><dd>Each pathname that is a directory that matches <i>pattern</i> shall have a slash appended.</dd><dt>GLOB_NOCHECK</dt><dd>Supports rule 3 in the Shell and Utilities volume of IEEE&nbsp;Std&nbsp;1003.1-2001, <a href="../utilities/xcu_chap02.html#tag_02_13_02">Section 2.13.3, Patterns Used for Filename Expansion</a>. If <i>pattern</i> does notmatch any pathname, then <i>glob</i>() shall return a list consisting of only <i>pattern</i>, and the number of matched pathnamesis 1.</dd><dt>GLOB_NOESCAPE</dt><dd>Disable backslash escaping.</dd><dt>GLOB_NOSORT</dt><dd>Ordinarily, <i>glob</i>() sorts the matching pathnames according to the current setting of the <i>LC_COLLATE</i> category; seethe Base Definitions volume of IEEE&nbsp;Std&nbsp;1003.1-2001, <a href="../basedefs/xbd_chap07.html#tag_07_03_02">Section 7.3.2,LC_COLLATE</a>. When this flag is used, the order of pathnames returned is unspecified.</dd></dl><p>The GLOB_APPEND flag can be used to append a new set of pathnames to those found in a previous call to <i>glob</i>(). Thefollowing rules apply to applications when two or more calls to <i>glob</i>() are made with the same value of <i>pglob</i> andwithout intervening calls to <i>globfree</i>():</p><ol><li><p>The first such call shall not set GLOB_APPEND. All subsequent calls shall set it.</p></li><li><p>All the calls shall set GLOB_DOOFFS, or all shall not set it.</p></li><li><p>After the second call, <i>pglob</i>-&gt;<i>gl_pathv</i> points to a list containing the following:</p><ol type="a"><li><p>Zero or more null pointers, as specified by GLOB_DOOFFS and <i>pglob</i>-&gt;<i>gl_offs</i>.</p></li><li><p>Pointers to the pathnames that were in the <i>pglob</i>-&gt;<i>gl_pathv</i> list before the call, in the same order asbefore.</p></li><li><p>Pointers to the new pathnames generated by the second call, in the specified order.</p></li></ol></li><li><p>The count returned in <i>pglob</i>-&gt;<i>gl_pathc</i> shall be the total number of pathnames from the two calls.</p></li><li><p>The application can change any of the fields after a call to <i>glob</i>(). If it does, the application shall reset them to theoriginal value before a subsequent call, using the same <i>pglob</i> value, to <i>globfree</i>() or <i>glob</i>() with theGLOB_APPEND flag.</p></li></ol><p>If, during the search, a directory is encountered that cannot be opened or read and <i>errfunc</i> is not a null pointer,<i>glob</i>() calls (<i>*errfunc</i>()) with two arguments:</p><ol><li><p>The <i>epath</i> argument is a pointer to the path that failed.</p>

⌨️ 快捷键说明

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