blob: 41f898451c75a7b95834e958988a8e5835286959 [file] [log] [blame]
<html lang="en">
<head>
<title>Flags for Globbing - The GNU C Library</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="The GNU C Library">
<meta name="generator" content="makeinfo 4.13">
<link title="Top" rel="start" href="index.html#Top">
<link rel="up" href="Globbing.html#Globbing" title="Globbing">
<link rel="prev" href="Calling-Glob.html#Calling-Glob" title="Calling Glob">
<link rel="next" href="More-Flags-for-Globbing.html#More-Flags-for-Globbing" title="More Flags for Globbing">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
<!--
This file documents the GNU C library.
This is Edition 0.12, last updated 2007-10-27,
of `The GNU C Library Reference Manual', for version
2.8 (Sourcery G++ Lite 2011.03-41).
Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2001, 2002,
2003, 2007, 2008, 2010 Free Software Foundation, Inc.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with the
Invariant Sections being ``Free Software Needs Free Documentation''
and ``GNU Lesser General Public License'', the Front-Cover texts being
``A GNU Manual'', and with the Back-Cover Texts as in (a) below. A
copy of the license is included in the section entitled "GNU Free
Documentation License".
(a) The FSF's Back-Cover Text is: ``You have the freedom to
copy and modify this GNU manual. Buying copies from the FSF
supports it in developing GNU and promoting software freedom.''-->
<meta http-equiv="Content-Style-Type" content="text/css">
<style type="text/css"><!--
pre.display { font-family:inherit }
pre.format { font-family:inherit }
pre.smalldisplay { font-family:inherit; font-size:smaller }
pre.smallformat { font-family:inherit; font-size:smaller }
pre.smallexample { font-size:smaller }
pre.smalllisp { font-size:smaller }
span.sc { font-variant:small-caps }
span.roman { font-family:serif; font-weight:normal; }
span.sansserif { font-family:sans-serif; font-weight:normal; }
--></style>
<link rel="stylesheet" type="text/css" href="../cs.css">
</head>
<body>
<div class="node">
<a name="Flags-for-Globbing"></a>
<p>
Next:&nbsp;<a rel="next" accesskey="n" href="More-Flags-for-Globbing.html#More-Flags-for-Globbing">More Flags for Globbing</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="Calling-Glob.html#Calling-Glob">Calling Glob</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="Globbing.html#Globbing">Globbing</a>
<hr>
</div>
<h4 class="subsection">10.2.2 Flags for Globbing</h4>
<p>This section describes the flags that you can specify in the
<var>flags</var> argument to <code>glob</code>. Choose the flags you want,
and combine them with the C bitwise OR operator <code>|</code>.
<dl>
<!-- glob.h -->
<!-- POSIX.2 -->
<dt><code>GLOB_APPEND</code><a name="index-GLOB_005fAPPEND-860"></a><dd>Append the words from this expansion to the vector of words produced by
previous calls to <code>glob</code>. This way you can effectively expand
several words as if they were concatenated with spaces between them.
<p>In order for appending to work, you must not modify the contents of the
word vector structure between calls to <code>glob</code>. And, if you set
<code>GLOB_DOOFFS</code> in the first call to <code>glob</code>, you must also
set it when you append to the results.
<p>Note that the pointer stored in <code>gl_pathv</code> may no longer be valid
after you call <code>glob</code> the second time, because <code>glob</code> might
have relocated the vector. So always fetch <code>gl_pathv</code> from the
<code>glob_t</code> structure after each <code>glob</code> call; <strong>never</strong> save
the pointer across calls.
<!-- glob.h -->
<!-- POSIX.2 -->
<br><dt><code>GLOB_DOOFFS</code><a name="index-GLOB_005fDOOFFS-861"></a><dd>Leave blank slots at the beginning of the vector of words.
The <code>gl_offs</code> field says how many slots to leave.
The blank slots contain null pointers.
<!-- glob.h -->
<!-- POSIX.2 -->
<br><dt><code>GLOB_ERR</code><a name="index-GLOB_005fERR-862"></a><dd>Give up right away and report an error if there is any difficulty
reading the directories that must be read in order to expand <var>pattern</var>
fully. Such difficulties might include a directory in which you don't
have the requisite access. Normally, <code>glob</code> tries its best to keep
on going despite any errors, reading whatever directories it can.
<p>You can exercise even more control than this by specifying an
error-handler function <var>errfunc</var> when you call <code>glob</code>. If
<var>errfunc</var> is not a null pointer, then <code>glob</code> doesn't give up
right away when it can't read a directory; instead, it calls
<var>errfunc</var> with two arguments, like this:
<pre class="smallexample"> (*<var>errfunc</var>) (<var>filename</var>, <var>error-code</var>)
</pre>
<p class="noindent">The argument <var>filename</var> is the name of the directory that
<code>glob</code> couldn't open or couldn't read, and <var>error-code</var> is the
<code>errno</code> value that was reported to <code>glob</code>.
<p>If the error handler function returns nonzero, then <code>glob</code> gives up
right away. Otherwise, it continues.
<!-- glob.h -->
<!-- POSIX.2 -->
<br><dt><code>GLOB_MARK</code><a name="index-GLOB_005fMARK-863"></a><dd>If the pattern matches the name of a directory, append &lsquo;<samp><span class="samp">/</span></samp>&rsquo; to the
directory's name when returning it.
<!-- glob.h -->
<!-- POSIX.2 -->
<br><dt><code>GLOB_NOCHECK</code><a name="index-GLOB_005fNOCHECK-864"></a><dd>If the pattern doesn't match any file names, return the pattern itself
as if it were a file name that had been matched. (Normally, when the
pattern doesn't match anything, <code>glob</code> returns that there were no
matches.)
<!-- glob.h -->
<!-- POSIX.2 -->
<br><dt><code>GLOB_NOSORT</code><a name="index-GLOB_005fNOSORT-865"></a><dd>Don't sort the file names; return them in no particular order.
(In practice, the order will depend on the order of the entries in
the directory.) The only reason <em>not</em> to sort is to save time.
<!-- glob.h -->
<!-- POSIX.2 -->
<br><dt><code>GLOB_NOESCAPE</code><a name="index-GLOB_005fNOESCAPE-866"></a><dd>Don't treat the &lsquo;<samp><span class="samp">\</span></samp>&rsquo; character specially in patterns. Normally,
&lsquo;<samp><span class="samp">\</span></samp>&rsquo; quotes the following character, turning off its special meaning
(if any) so that it matches only itself. When quoting is enabled, the
pattern &lsquo;<samp><span class="samp">\?</span></samp>&rsquo; matches only the string &lsquo;<samp><span class="samp">?</span></samp>&rsquo;, because the question
mark in the pattern acts like an ordinary character.
<p>If you use <code>GLOB_NOESCAPE</code>, then &lsquo;<samp><span class="samp">\</span></samp>&rsquo; is an ordinary character.
<p><code>glob</code> does its work by calling the function <code>fnmatch</code>
repeatedly. It handles the flag <code>GLOB_NOESCAPE</code> by turning on the
<code>FNM_NOESCAPE</code> flag in calls to <code>fnmatch</code>.
</dl>
</body></html>