~ubuntu-branches/ubuntu/trusty/bash/trusty-security

« back to all changes in this revision

Viewing changes to lib/glob/glob_loop.c

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2014-03-03 22:52:05 UTC
  • mfrom: (1.3.5) (2.2.6 experimental)
  • Revision ID: package-import@ubuntu.com-20140303225205-87ltrt5kspeq0g1b
Tags: 4.3-1ubuntu1
* Merge with Debian; remaining changes:
  - skel.bashrc:
    - Run lesspipe.
    - Enable ls aliases.
    - Set options in ll alias to -alF.
    - Define an alert alias.
    - Enabled colored grep aliases.
  - etc.bash.bashrc:
    - Add sudo hint.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 1991-2005 Free Software Foundation, Inc.
 
2
 
 
3
   This file is part of GNU Bash, the Bourne Again SHell.
 
4
   
 
5
   Bash is free software: you can redistribute it and/or modify
 
6
   it under the terms of the GNU General Public License as published by
 
7
   the Free Software Foundation, either version 3 of the License, or
 
8
   (at your option) any later version.
 
9
 
 
10
   Bash is distributed in the hope that it will be useful,
 
11
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
   GNU General Public License for more details.
 
14
 
 
15
   You should have received a copy of the GNU General Public License
 
16
   along with Bash.  If not, see <http://www.gnu.org/licenses/>.
 
17
*/
 
18
 
 
19
static int INTERNAL_GLOB_PATTERN_P __P((const CHAR *));
 
20
 
 
21
/* Return nonzero if PATTERN has any special globbing chars in it.
 
22
   Compiled twice, once each for single-byte and multibyte characters. */
 
23
static int
 
24
INTERNAL_GLOB_PATTERN_P (pattern)
 
25
     const CHAR *pattern;
 
26
{
 
27
  register const CHAR *p;
 
28
  register CHAR c;
 
29
  int bopen;
 
30
 
 
31
  p = pattern;
 
32
  bopen = 0;
 
33
 
 
34
  while ((c = *p++) != L('\0'))
 
35
    switch (c)
 
36
      {
 
37
      case L('?'):
 
38
      case L('*'):
 
39
        return 1;
 
40
 
 
41
      case L('['):      /* Only accept an open brace if there is a close */
 
42
        bopen++;        /* brace to match it.  Bracket expressions must be */
 
43
        continue;       /* complete, according to Posix.2 */
 
44
      case L(']'):
 
45
        if (bopen)
 
46
          return 1;
 
47
        continue;
 
48
 
 
49
      case L('+'):         /* extended matching operators */
 
50
      case L('@'):
 
51
      case L('!'):
 
52
        if (*p == L('('))  /*) */
 
53
          return 1;
 
54
        continue;
 
55
 
 
56
      case L('\\'):
 
57
        if (*p++ == L('\0'))
 
58
          return 0;
 
59
      }
 
60
 
 
61
  return 0;
 
62
}
 
63
 
 
64
#undef INTERNAL_GLOB_PATTERN_P
 
65
#undef L
 
66
#undef INT
 
67
#undef CHAR