Mercurial > hg > octave-nkf > gnulib-hg
annotate lib/glob.c @ 17907:0a1c2535cad9
euidaccess: Fix Android build
* modules/euidaccess (Depends-on): Add fcntl-h to ensure that
AT_EACCESS gets declared.
author | Kevin Cernekee <cernekee@google.com> |
---|---|
date | Wed, 11 Feb 2015 15:22:54 -0800 |
parents | ab58d4870664 |
children |
rev | line source |
---|---|
17848 | 1 /* Copyright (C) 1991-2015 Free Software Foundation, Inc. |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
2 This file is part of the GNU C Library. |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
3 |
12002
f295924fa612
Use the standard header with GPL copyright.
Bruno Haible <bruno@clisp.org>
parents:
11938
diff
changeset
|
4 This program is free software: you can redistribute it and/or modify |
f295924fa612
Use the standard header with GPL copyright.
Bruno Haible <bruno@clisp.org>
parents:
11938
diff
changeset
|
5 it under the terms of the GNU General Public License as published by |
f295924fa612
Use the standard header with GPL copyright.
Bruno Haible <bruno@clisp.org>
parents:
11938
diff
changeset
|
6 the Free Software Foundation; either version 3 of the License, or |
f295924fa612
Use the standard header with GPL copyright.
Bruno Haible <bruno@clisp.org>
parents:
11938
diff
changeset
|
7 (at your option) any later version. |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
8 |
12002
f295924fa612
Use the standard header with GPL copyright.
Bruno Haible <bruno@clisp.org>
parents:
11938
diff
changeset
|
9 This program is distributed in the hope that it will be useful, |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
10 but WITHOUT ANY WARRANTY; without even the implied warranty of |
12002
f295924fa612
Use the standard header with GPL copyright.
Bruno Haible <bruno@clisp.org>
parents:
11938
diff
changeset
|
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
f295924fa612
Use the standard header with GPL copyright.
Bruno Haible <bruno@clisp.org>
parents:
11938
diff
changeset
|
12 GNU General Public License for more details. |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
13 |
12002
f295924fa612
Use the standard header with GPL copyright.
Bruno Haible <bruno@clisp.org>
parents:
11938
diff
changeset
|
14 You should have received a copy of the GNU General Public License |
f295924fa612
Use the standard header with GPL copyright.
Bruno Haible <bruno@clisp.org>
parents:
11938
diff
changeset
|
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
16 |
7302
8a1a9361108c
* _fpending.c: Include <config.h> unconditionally, since we no
Paul Eggert <eggert@cs.ucla.edu>
parents:
6954
diff
changeset
|
17 #ifndef _LIBC |
17334
bb52d9cece01
unsetenv etc.: port to Solaris 11 + GNU Emacs
Paul Eggert <eggert@cs.ucla.edu>
parents:
17249
diff
changeset
|
18 /* Don't use __attribute__ __nonnull__ in this compilation unit. Otherwise gcc |
bb52d9cece01
unsetenv etc.: port to Solaris 11 + GNU Emacs
Paul Eggert <eggert@cs.ucla.edu>
parents:
17249
diff
changeset
|
19 optimizes away the pattern == NULL || pglob == NULL tests below. */ |
bb52d9cece01
unsetenv etc.: port to Solaris 11 + GNU Emacs
Paul Eggert <eggert@cs.ucla.edu>
parents:
17249
diff
changeset
|
20 # define _GL_ARG_NONNULL(params) |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
21 # include <config.h> |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
22 #endif |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
23 |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
24 #include <glob.h> |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
25 |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
26 #include <errno.h> |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
27 #include <sys/types.h> |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
28 #include <sys/stat.h> |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
29 #include <stddef.h> |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
30 |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
31 /* Outcomment the following line for production quality code. */ |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
32 /* #define NDEBUG 1 */ |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
33 #include <assert.h> |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
34 |
9892
0b3ccf361045
Include stdbool, for 'true' and 'false'.
Bruno Haible <bruno@clisp.org>
parents:
9557
diff
changeset
|
35 #include <stdbool.h> |
0b3ccf361045
Include stdbool, for 'true' and 'false'.
Bruno Haible <bruno@clisp.org>
parents:
9557
diff
changeset
|
36 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
37 #include <stdio.h> /* Needed on stupid SunOS for assert. */ |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
38 |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
39 #if !defined _LIBC || !defined GLOB_ONLY_P |
6689
93d578c7aa44
* lib/c-stack.c: Include unistd.h unconditionally, since we now assume
Paul Eggert <eggert@cs.ucla.edu>
parents:
6655
diff
changeset
|
40 |
93d578c7aa44
* lib/c-stack.c: Include unistd.h unconditionally, since we now assume
Paul Eggert <eggert@cs.ucla.edu>
parents:
6655
diff
changeset
|
41 #include <unistd.h> |
93d578c7aa44
* lib/c-stack.c: Include unistd.h unconditionally, since we now assume
Paul Eggert <eggert@cs.ucla.edu>
parents:
6655
diff
changeset
|
42 #if !defined POSIX && defined _POSIX_VERSION |
93d578c7aa44
* lib/c-stack.c: Include unistd.h unconditionally, since we now assume
Paul Eggert <eggert@cs.ucla.edu>
parents:
6655
diff
changeset
|
43 # define POSIX |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
44 #endif |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
45 |
10423 | 46 #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ |
47 # define WINDOWS32 | |
48 #endif | |
49 | |
50 #ifndef WINDOWS32 | |
51 # include <pwd.h> | |
52 #endif | |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
53 |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
54 #include <errno.h> |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
55 #ifndef __set_errno |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
56 # define __set_errno(val) errno = (val) |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
57 #endif |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
58 |
6949
96af1224c6fa
* backupfile.c, dirfd.h, fts.c, getcwd.c, glob.c, glob_.h:
Paul Eggert <eggert@cs.ucla.edu>
parents:
6934
diff
changeset
|
59 #include <dirent.h> |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
60 |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
61 |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
62 /* In GNU systems, <dirent.h> defines this macro for us. */ |
6949
96af1224c6fa
* backupfile.c, dirfd.h, fts.c, getcwd.c, glob.c, glob_.h:
Paul Eggert <eggert@cs.ucla.edu>
parents:
6934
diff
changeset
|
63 #ifndef _D_EXACT_NAMLEN |
96af1224c6fa
* backupfile.c, dirfd.h, fts.c, getcwd.c, glob.c, glob_.h:
Paul Eggert <eggert@cs.ucla.edu>
parents:
6934
diff
changeset
|
64 # define _D_EXACT_NAMLEN(dirent) strlen ((dirent)->d_name) |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
65 #endif |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
66 |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
67 /* When used in the GNU libc the symbol _DIRENT_HAVE_D_TYPE is available |
16235
18a38c9615f0
In commentary, do not use ` to quote.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
68 if the 'd_type' member for 'struct dirent' is available. |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
69 HAVE_STRUCT_DIRENT_D_TYPE plays the same role in GNULIB. */ |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
70 #if defined _DIRENT_HAVE_D_TYPE || defined HAVE_STRUCT_DIRENT_D_TYPE |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
71 /* True if the directory entry D must be of type T. */ |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
72 # define DIRENT_MUST_BE(d, t) ((d)->d_type == (t)) |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
73 |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
74 /* True if the directory entry D might be a symbolic link. */ |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
75 # define DIRENT_MIGHT_BE_SYMLINK(d) \ |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
76 ((d)->d_type == DT_UNKNOWN || (d)->d_type == DT_LNK) |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
77 |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
78 /* True if the directory entry D might be a directory. */ |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
79 # define DIRENT_MIGHT_BE_DIR(d) \ |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
80 ((d)->d_type == DT_DIR || DIRENT_MIGHT_BE_SYMLINK (d)) |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
81 |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
82 #else /* !HAVE_D_TYPE */ |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
83 # define DIRENT_MUST_BE(d, t) false |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
84 # define DIRENT_MIGHT_BE_SYMLINK(d) true |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
85 # define DIRENT_MIGHT_BE_DIR(d) true |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
86 #endif /* HAVE_D_TYPE */ |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
87 |
16235
18a38c9615f0
In commentary, do not use ` to quote.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
88 /* If the system has the 'struct dirent64' type we use it internally. */ |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
89 #if defined _LIBC && !defined COMPILE_GLOB64 |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
90 # if (defined POSIX || defined WINDOWS32) && !defined __GNU_LIBRARY__ |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
91 # define CONVERT_D_INO(d64, d32) |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
92 # else |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
93 # define CONVERT_D_INO(d64, d32) \ |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
94 (d64)->d_ino = (d32)->d_ino; |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
95 # endif |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
96 |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
97 # ifdef _DIRENT_HAVE_D_TYPE |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
98 # define CONVERT_D_TYPE(d64, d32) \ |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
99 (d64)->d_type = (d32)->d_type; |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
100 # else |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
101 # define CONVERT_D_TYPE(d64, d32) |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
102 # endif |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
103 |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
104 # define CONVERT_DIRENT_DIRENT64(d64, d32) \ |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
105 memcpy ((d64)->d_name, (d32)->d_name, _D_EXACT_NAMLEN (d32) + 1); \ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
106 CONVERT_D_INO (d64, d32) \ |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
107 CONVERT_D_TYPE (d64, d32) |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
108 #endif |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
109 |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
110 |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
111 #if (defined POSIX || defined WINDOWS32) && !defined __GNU_LIBRARY__ |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
112 /* Posix does not require that the d_ino field be present, and some |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
113 systems do not provide it. */ |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
114 # define REAL_DIR_ENTRY(dp) 1 |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
115 #else |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
116 # define REAL_DIR_ENTRY(dp) (dp->d_ino != 0) |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
117 #endif /* POSIX */ |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
118 |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
119 #include <stdlib.h> |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
120 #include <string.h> |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
121 |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
122 /* NAME_MAX is usually defined in <dirent.h> or <limits.h>. */ |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
123 #include <limits.h> |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
124 #ifndef NAME_MAX |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
125 # define NAME_MAX (sizeof (((struct dirent *) 0)->d_name)) |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
126 #endif |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
127 |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
128 #include <alloca.h> |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
129 |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
130 #ifdef _LIBC |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
131 # undef strdup |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
132 # define strdup(str) __strdup (str) |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
133 # define sysconf(id) __sysconf (id) |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
134 # define closedir(dir) __closedir (dir) |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
135 # define opendir(name) __opendir (name) |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
136 # define readdir(str) __readdir64 (str) |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
137 # define getpwnam_r(name, bufp, buf, len, res) \ |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
138 __getpwnam_r (name, bufp, buf, len, res) |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
139 # ifndef __stat64 |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
140 # define __stat64(fname, buf) __xstat64 (_STAT_VER, fname, buf) |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
141 # endif |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
142 # define struct_stat64 struct stat64 |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
143 #else /* !_LIBC */ |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
144 # define __stat64(fname, buf) stat (fname, buf) |
9357
75e43b0e5159
Modify glob.c to use fstatat and dirfd, to simplify it.
Paul Eggert <eggert@cs.ucla.edu>
parents:
9351
diff
changeset
|
145 # define __fxstatat64(_, d, f, st, flag) fstatat (d, f, st, flag) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
146 # define struct_stat64 struct stat |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
147 # define __alloca alloca |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
148 # define __readdir readdir |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
149 # define __glob_pattern_p glob_pattern_p |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
150 #endif /* _LIBC */ |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
151 |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
152 #include <fnmatch.h> |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
153 |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
154 #ifdef _SC_GETPW_R_SIZE_MAX |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
155 # define GETPW_R_SIZE_MAX() sysconf (_SC_GETPW_R_SIZE_MAX) |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
156 #else |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
157 # define GETPW_R_SIZE_MAX() (-1) |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
158 #endif |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
159 #ifdef _SC_LOGIN_NAME_MAX |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
160 # define GET_LOGIN_NAME_MAX() sysconf (_SC_LOGIN_NAME_MAX) |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
161 #else |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
162 # define GET_LOGIN_NAME_MAX() (-1) |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
163 #endif |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
164 |
17485
a226f0d99b73
glob: avoid -Wattribute warnings on glibc
Eric Blake <eblake@redhat.com>
parents:
17334
diff
changeset
|
165 static const char *next_brace_sub (const char *begin, int flags) __THROWNL; |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
166 |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
167 #endif /* !defined _LIBC || !defined GLOB_ONLY_P */ |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
168 |
9351
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
169 #ifndef attribute_hidden |
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
170 # define attribute_hidden |
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
171 #endif |
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
172 |
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
173 #ifndef __attribute_noinline__ |
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
174 # if __GNUC__ < 3 || (__GNUC__ == 3 && __GNUC_MINOR__ < 1) |
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
175 # define __attribute_noinline__ /* Ignore */ |
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
176 #else |
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
177 # define __attribute_noinline__ __attribute__ ((__noinline__)) |
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
178 # endif |
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
179 #endif |
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
180 |
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
181 #if ! defined __builtin_expect && __GNUC__ < 3 |
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
182 # define __builtin_expect(expr, expected) (expr) |
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
183 #endif |
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
184 |
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
185 #ifndef _LIBC |
7863 | 186 /* The results of opendir() in this file are not used with dirfd and fchdir, |
11938
7cbcde229d97
backupfile, chdir-long, fts, savedir: make safer
Eric Blake <ebb9@byu.net>
parents:
10663
diff
changeset
|
187 and we do not leak fds to any single-threaded code that could use stdio, |
7cbcde229d97
backupfile, chdir-long, fts, savedir: make safer
Eric Blake <ebb9@byu.net>
parents:
10663
diff
changeset
|
188 therefore save some unnecessary recursion in fchdir.c and opendir_safer.c. |
7cbcde229d97
backupfile, chdir-long, fts, savedir: make safer
Eric Blake <ebb9@byu.net>
parents:
10663
diff
changeset
|
189 FIXME - if the kernel ever adds support for multi-thread safety for |
7cbcde229d97
backupfile, chdir-long, fts, savedir: make safer
Eric Blake <ebb9@byu.net>
parents:
10663
diff
changeset
|
190 avoiding standard fds, then we should use opendir_safer. */ |
9351
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
191 # undef opendir |
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
192 # undef closedir |
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
193 |
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
194 # if HAVE_ALLOCA |
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
195 /* The OS usually guarantees only one guard page at the bottom of the stack, |
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
196 and a page size can be as small as 4096 bytes. So we cannot safely |
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
197 allocate anything larger than 4096 bytes. Also care for the possibility |
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
198 of a few compiler-allocated temporary stack slots. */ |
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
199 # define __libc_use_alloca(n) ((n) < 4032) |
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
200 # else |
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
201 /* alloca is implemented with malloc, so just use malloc. */ |
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
202 # define __libc_use_alloca(n) 0 |
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
203 # endif |
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
204 #endif |
7863 | 205 |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
206 static int glob_in_dir (const char *pattern, const char *directory, |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
207 int flags, int (*errfunc) (const char *, int), |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
208 glob_t *pglob); |
9351
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
209 extern int __glob_pattern_type (const char *pattern, int quote) |
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
210 attribute_hidden; |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
211 |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
212 #if !defined _LIBC || !defined GLOB_ONLY_P |
17485
a226f0d99b73
glob: avoid -Wattribute warnings on glibc
Eric Blake <eblake@redhat.com>
parents:
17334
diff
changeset
|
213 static int prefix_array (const char *prefix, char **array, size_t n) __THROWNL; |
a226f0d99b73
glob: avoid -Wattribute warnings on glibc
Eric Blake <eblake@redhat.com>
parents:
17334
diff
changeset
|
214 static int collated_compare (const void *, const void *) __THROWNL; |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
215 |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
216 |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
217 /* Find the end of the sub-pattern in a brace expression. */ |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
218 static const char * |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
219 next_brace_sub (const char *cp, int flags) |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
220 { |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
221 unsigned int depth = 0; |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
222 while (*cp != '\0') |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
223 if ((flags & GLOB_NOESCAPE) == 0 && *cp == '\\') |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
224 { |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
225 if (*++cp == '\0') |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
226 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
227 ++cp; |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
228 } |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
229 else |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
230 { |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
231 if ((*cp == '}' && depth-- == 0) || (*cp == ',' && depth == 0)) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
232 break; |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
233 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
234 if (*cp++ == '{') |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
235 depth++; |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
236 } |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
237 |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
238 return *cp != '\0' ? cp : NULL; |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
239 } |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
240 |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
241 #endif /* !defined _LIBC || !defined GLOB_ONLY_P */ |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
242 |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
243 /* Do glob searching for PATTERN, placing results in PGLOB. |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
244 The bits defined above may be set in FLAGS. |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
245 If a directory cannot be opened or read and ERRFUNC is not nil, |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
246 it is called with the pathname that caused the error, and the |
16235
18a38c9615f0
In commentary, do not use ` to quote.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
247 'errno' value from the failing call; if it returns non-zero |
18a38c9615f0
In commentary, do not use ` to quote.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
248 'glob' returns GLOB_ABORTED; if it returns zero, the error is ignored. |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
249 If memory cannot be allocated for PGLOB, GLOB_NOSPACE is returned. |
16235
18a38c9615f0
In commentary, do not use ` to quote.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
250 Otherwise, 'glob' returns zero. */ |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
251 int |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
252 #ifdef GLOB_ATTRIBUTE |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
253 GLOB_ATTRIBUTE |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
254 #endif |
6218
71a1ca6e85c0
* lib/glob.c (glob, globfree, __glob_pattern_p): Use old-style function
Paul Eggert <eggert@cs.ucla.edu>
parents:
6198
diff
changeset
|
255 glob (pattern, flags, errfunc, pglob) |
8439
d8182f376307
2007-03-15 Bruno Haible <bruno@clisp.org>
Bruno Haible <bruno@clisp.org>
parents:
8222
diff
changeset
|
256 const char * restrict pattern; |
6218
71a1ca6e85c0
* lib/glob.c (glob, globfree, __glob_pattern_p): Use old-style function
Paul Eggert <eggert@cs.ucla.edu>
parents:
6198
diff
changeset
|
257 int flags; |
71a1ca6e85c0
* lib/glob.c (glob, globfree, __glob_pattern_p): Use old-style function
Paul Eggert <eggert@cs.ucla.edu>
parents:
6198
diff
changeset
|
258 int (*errfunc) (const char *, int); |
8439
d8182f376307
2007-03-15 Bruno Haible <bruno@clisp.org>
Bruno Haible <bruno@clisp.org>
parents:
8222
diff
changeset
|
259 glob_t * restrict pglob; |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
260 { |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
261 const char *filename; |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
262 const char *dirname; |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
263 size_t dirlen; |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
264 int status; |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
265 size_t oldcount; |
9351
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
266 int meta; |
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
267 int dirname_modified; |
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
268 glob_t dirs; |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
269 |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
270 if (pattern == NULL || pglob == NULL || (flags & ~__GLOB_FLAGS) != 0) |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
271 { |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
272 __set_errno (EINVAL); |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
273 return -1; |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
274 } |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
275 |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
276 if (!(flags & GLOB_DOOFFS)) |
16235
18a38c9615f0
In commentary, do not use ` to quote.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
277 /* Have to do this so 'globfree' knows where to start freeing. It |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
278 also makes all the code that uses gl_offs simpler. */ |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
279 pglob->gl_offs = 0; |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
280 |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
281 if (flags & GLOB_BRACE) |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
282 { |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
283 const char *begin; |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
284 |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
285 if (flags & GLOB_NOESCAPE) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
286 begin = strchr (pattern, '{'); |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
287 else |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
288 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
289 begin = pattern; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
290 while (1) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
291 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
292 if (*begin == '\0') |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
293 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
294 begin = NULL; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
295 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
296 } |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
297 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
298 if (*begin == '\\' && begin[1] != '\0') |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
299 ++begin; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
300 else if (*begin == '{') |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
301 break; |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
302 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
303 ++begin; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
304 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
305 } |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
306 |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
307 if (begin != NULL) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
308 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
309 /* Allocate working buffer large enough for our work. Note that |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
310 we have at least an opening and closing brace. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
311 size_t firstc; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
312 char *alt_start; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
313 const char *p; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
314 const char *next; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
315 const char *rest; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
316 size_t rest_len; |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
317 #ifdef __GNUC__ |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
318 char onealt[strlen (pattern) - 1]; |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
319 #else |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
320 char *onealt = malloc (strlen (pattern) - 1); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
321 if (onealt == NULL) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
322 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
323 if (!(flags & GLOB_APPEND)) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
324 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
325 pglob->gl_pathc = 0; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
326 pglob->gl_pathv = NULL; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
327 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
328 return GLOB_NOSPACE; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
329 } |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
330 #endif |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
331 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
332 /* We know the prefix for all sub-patterns. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
333 alt_start = mempcpy (onealt, pattern, begin - pattern); |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
334 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
335 /* Find the first sub-pattern and at the same time find the |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
336 rest after the closing brace. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
337 next = next_brace_sub (begin + 1, flags); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
338 if (next == NULL) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
339 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
340 /* It is an invalid expression. */ |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
341 #ifndef __GNUC__ |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
342 free (onealt); |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
343 #endif |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
344 return glob (pattern, flags & ~GLOB_BRACE, errfunc, pglob); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
345 } |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
346 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
347 /* Now find the end of the whole brace expression. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
348 rest = next; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
349 while (*rest != '}') |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
350 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
351 rest = next_brace_sub (rest + 1, flags); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
352 if (rest == NULL) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
353 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
354 /* It is an invalid expression. */ |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
355 #ifndef __GNUC__ |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
356 free (onealt); |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
357 #endif |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
358 return glob (pattern, flags & ~GLOB_BRACE, errfunc, pglob); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
359 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
360 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
361 /* Please note that we now can be sure the brace expression |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
362 is well-formed. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
363 rest_len = strlen (++rest) + 1; |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
364 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
365 /* We have a brace expression. BEGIN points to the opening {, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
366 NEXT points past the terminator of the first element, and END |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
367 points past the final }. We will accumulate result names from |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
368 recursive runs for each brace alternative in the buffer using |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
369 GLOB_APPEND. */ |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
370 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
371 if (!(flags & GLOB_APPEND)) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
372 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
373 /* This call is to set a new vector, so clear out the |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
374 vector so we can append to it. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
375 pglob->gl_pathc = 0; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
376 pglob->gl_pathv = NULL; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
377 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
378 firstc = pglob->gl_pathc; |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
379 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
380 p = begin + 1; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
381 while (1) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
382 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
383 int result; |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
384 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
385 /* Construct the new glob expression. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
386 mempcpy (mempcpy (alt_start, p, next - p), rest, rest_len); |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
387 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
388 result = glob (onealt, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
389 ((flags & ~(GLOB_NOCHECK | GLOB_NOMAGIC)) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
390 | GLOB_APPEND), errfunc, pglob); |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
391 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
392 /* If we got an error, return it. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
393 if (result && result != GLOB_NOMATCH) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
394 { |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
395 #ifndef __GNUC__ |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
396 free (onealt); |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
397 #endif |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
398 if (!(flags & GLOB_APPEND)) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
399 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
400 globfree (pglob); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
401 pglob->gl_pathc = 0; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
402 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
403 return result; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
404 } |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
405 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
406 if (*next == '}') |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
407 /* We saw the last entry. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
408 break; |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
409 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
410 p = next + 1; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
411 next = next_brace_sub (p, flags); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
412 assert (next != NULL); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
413 } |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
414 |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
415 #ifndef __GNUC__ |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
416 free (onealt); |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
417 #endif |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
418 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
419 if (pglob->gl_pathc != firstc) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
420 /* We found some entries. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
421 return 0; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
422 else if (!(flags & (GLOB_NOCHECK|GLOB_NOMAGIC))) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
423 return GLOB_NOMATCH; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
424 } |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
425 } |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
426 |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
427 /* Find the filename. */ |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
428 filename = strrchr (pattern, '/'); |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
429 #if defined __MSDOS__ || defined WINDOWS32 |
16235
18a38c9615f0
In commentary, do not use ` to quote.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
430 /* The case of "d:pattern". Since ':' is not allowed in |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
431 file names, we can safely assume that wherever it |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
432 happens in pattern, it signals the filename part. This |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
433 is so we could some day support patterns like "[a-z]:foo". */ |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
434 if (filename == NULL) |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
435 filename = strchr (pattern, ':'); |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
436 #endif /* __MSDOS__ || WINDOWS32 */ |
9351
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
437 dirname_modified = 0; |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
438 if (filename == NULL) |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
439 { |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
440 /* This can mean two things: a simple name or "~name". The latter |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
441 case is nothing but a notation for a directory. */ |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
442 if ((flags & (GLOB_TILDE|GLOB_TILDE_CHECK)) && pattern[0] == '~') |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
443 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
444 dirname = pattern; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
445 dirlen = strlen (pattern); |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
446 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
447 /* Set FILENAME to NULL as a special flag. This is ugly but |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
448 other solutions would require much more code. We test for |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
449 this special case below. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
450 filename = NULL; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
451 } |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
452 else |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
453 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
454 filename = pattern; |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
455 #ifdef _AMIGA |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
456 dirname = ""; |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
457 #else |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
458 dirname = "."; |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
459 #endif |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
460 dirlen = 0; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
461 } |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
462 } |
9351
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
463 else if (filename == pattern |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
464 || (filename == pattern + 1 && pattern[0] == '\\' |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
465 && (flags & GLOB_NOESCAPE) == 0)) |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
466 { |
9351
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
467 /* "/pattern" or "\\/pattern". */ |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
468 dirname = "/"; |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
469 dirlen = 1; |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
470 ++filename; |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
471 } |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
472 else |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
473 { |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
474 char *newp; |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
475 dirlen = filename - pattern; |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
476 #if defined __MSDOS__ || defined WINDOWS32 |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
477 if (*filename == ':' |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
478 || (filename > pattern + 1 && filename[-1] == ':')) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
479 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
480 char *drive_spec; |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
481 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
482 ++dirlen; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
483 drive_spec = __alloca (dirlen + 1); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
484 *((char *) mempcpy (drive_spec, pattern, dirlen)) = '\0'; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
485 /* For now, disallow wildcards in the drive spec, to |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
486 prevent infinite recursion in glob. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
487 if (__glob_pattern_p (drive_spec, !(flags & GLOB_NOESCAPE))) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
488 return GLOB_NOMATCH; |
16235
18a38c9615f0
In commentary, do not use ` to quote.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
489 /* If this is "d:pattern", we need to copy ':' to DIRNAME |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
490 as well. If it's "d:/pattern", don't remove the slash |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
491 from "d:/", since "d:" and "d:/" are not the same.*/ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
492 } |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
493 #endif |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
494 newp = __alloca (dirlen + 1); |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
495 *((char *) mempcpy (newp, pattern, dirlen)) = '\0'; |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
496 dirname = newp; |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
497 ++filename; |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
498 |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
499 if (filename[0] == '\0' |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
500 #if defined __MSDOS__ || defined WINDOWS32 |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
501 && dirname[dirlen - 1] != ':' |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
502 && (dirlen < 3 || dirname[dirlen - 2] != ':' |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
503 || dirname[dirlen - 1] != '/') |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
504 #endif |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
505 && dirlen > 1) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
506 /* "pattern/". Expand "pattern", appending slashes. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
507 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
508 int orig_flags = flags; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
509 int val; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
510 if (!(flags & GLOB_NOESCAPE) && dirname[dirlen - 1] == '\\') |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
511 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
512 /* "pattern\\/". Remove the final backslash if it hasn't |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
513 been quoted. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
514 char *p = (char *) &dirname[dirlen - 1]; |
9351
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
515 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
516 while (p > dirname && p[-1] == '\\') --p; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
517 if ((&dirname[dirlen] - p) & 1) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
518 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
519 *(char *) &dirname[--dirlen] = '\0'; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
520 flags &= ~(GLOB_NOCHECK | GLOB_NOMAGIC); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
521 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
522 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
523 val = glob (dirname, flags | GLOB_MARK, errfunc, pglob); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
524 if (val == 0) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
525 pglob->gl_flags = ((pglob->gl_flags & ~GLOB_MARK) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
526 | (flags & GLOB_MARK)); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
527 else if (val == GLOB_NOMATCH && flags != orig_flags) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
528 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
529 /* Make sure globfree (&dirs); is a nop. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
530 dirs.gl_pathv = NULL; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
531 flags = orig_flags; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
532 oldcount = pglob->gl_pathc + pglob->gl_offs; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
533 goto no_matches; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
534 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
535 return val; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
536 } |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
537 } |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
538 |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
539 if (!(flags & GLOB_APPEND)) |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
540 { |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
541 pglob->gl_pathc = 0; |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
542 if (!(flags & GLOB_DOOFFS)) |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
543 pglob->gl_pathv = NULL; |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
544 else |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
545 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
546 size_t i; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
547 pglob->gl_pathv = malloc ((pglob->gl_offs + 1) * sizeof (char *)); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
548 if (pglob->gl_pathv == NULL) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
549 return GLOB_NOSPACE; |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
550 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
551 for (i = 0; i <= pglob->gl_offs; ++i) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
552 pglob->gl_pathv[i] = NULL; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
553 } |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
554 } |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
555 |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
556 oldcount = pglob->gl_pathc + pglob->gl_offs; |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
557 |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
558 if ((flags & (GLOB_TILDE|GLOB_TILDE_CHECK)) && dirname[0] == '~') |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
559 { |
9351
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
560 if (dirname[1] == '\0' || dirname[1] == '/' |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
561 || (!(flags & GLOB_NOESCAPE) && dirname[1] == '\\' |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
562 && (dirname[2] == '\0' || dirname[2] == '/'))) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
563 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
564 /* Look up home directory. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
565 const char *home_dir = getenv ("HOME"); |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
566 # ifdef _AMIGA |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
567 if (home_dir == NULL || home_dir[0] == '\0') |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
568 home_dir = "SYS:"; |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
569 # else |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
570 # ifdef WINDOWS32 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
571 /* Windows NT defines HOMEDRIVE and HOMEPATH. But give preference |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
572 to HOME, because the user can change HOME. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
573 if (home_dir == NULL || home_dir[0] == '\0') |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
574 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
575 const char *home_drive = getenv ("HOMEDRIVE"); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
576 const char *home_path = getenv ("HOMEPATH"); |
10423 | 577 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
578 if (home_drive != NULL && home_path != NULL) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
579 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
580 size_t home_drive_len = strlen (home_drive); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
581 size_t home_path_len = strlen (home_path); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
582 char *mem = alloca (home_drive_len + home_path_len + 1); |
10423 | 583 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
584 memcpy (mem, home_drive, home_drive_len); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
585 memcpy (mem + home_drive_len, home_path, home_path_len + 1); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
586 home_dir = mem; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
587 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
588 else |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
589 home_dir = "c:/users/default"; /* poor default */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
590 } |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
591 # else |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
592 if (home_dir == NULL || home_dir[0] == '\0') |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
593 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
594 int success; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
595 char *name; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
596 size_t buflen = GET_LOGIN_NAME_MAX () + 1; |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
597 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
598 if (buflen == 0) |
16235
18a38c9615f0
In commentary, do not use ` to quote.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
599 /* 'sysconf' does not support _SC_LOGIN_NAME_MAX. Try |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
600 a moderate value. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
601 buflen = 20; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
602 name = __alloca (buflen); |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
603 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
604 success = getlogin_r (name, buflen) == 0; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
605 if (success) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
606 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
607 struct passwd *p; |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
608 # if defined HAVE_GETPWNAM_R || defined _LIBC |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
609 long int pwbuflen = GETPW_R_SIZE_MAX (); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
610 char *pwtmpbuf; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
611 struct passwd pwbuf; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
612 int save = errno; |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
613 |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
614 # ifndef _LIBC |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
615 if (pwbuflen == -1) |
16235
18a38c9615f0
In commentary, do not use ` to quote.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
616 /* 'sysconf' does not support _SC_GETPW_R_SIZE_MAX. |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
617 Try a moderate value. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
618 pwbuflen = 1024; |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
619 # endif |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
620 pwtmpbuf = __alloca (pwbuflen); |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
621 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
622 while (getpwnam_r (name, &pwbuf, pwtmpbuf, pwbuflen, &p) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
623 != 0) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
624 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
625 if (errno != ERANGE) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
626 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
627 p = NULL; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
628 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
629 } |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
630 # ifdef _LIBC |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
631 pwtmpbuf = extend_alloca (pwtmpbuf, pwbuflen, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
632 2 * pwbuflen); |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
633 # else |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
634 pwbuflen *= 2; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
635 pwtmpbuf = __alloca (pwbuflen); |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
636 # endif |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
637 __set_errno (save); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
638 } |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
639 # else |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
640 p = getpwnam (name); |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
641 # endif |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
642 if (p != NULL) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
643 home_dir = p->pw_dir; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
644 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
645 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
646 if (home_dir == NULL || home_dir[0] == '\0') |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
647 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
648 if (flags & GLOB_TILDE_CHECK) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
649 return GLOB_NOMATCH; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
650 else |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
651 home_dir = "~"; /* No luck. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
652 } |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
653 # endif /* WINDOWS32 */ |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
654 # endif |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
655 /* Now construct the full directory. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
656 if (dirname[1] == '\0') |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
657 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
658 dirname = home_dir; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
659 dirlen = strlen (dirname); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
660 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
661 else |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
662 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
663 char *newp; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
664 size_t home_len = strlen (home_dir); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
665 newp = __alloca (home_len + dirlen); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
666 mempcpy (mempcpy (newp, home_dir, home_len), |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
667 &dirname[1], dirlen); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
668 dirname = newp; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
669 dirlen += home_len - 1; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
670 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
671 dirname_modified = 1; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
672 } |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
673 # if !defined _AMIGA && !defined WINDOWS32 |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
674 else |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
675 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
676 char *end_name = strchr (dirname, '/'); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
677 const char *user_name; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
678 const char *home_dir; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
679 char *unescape = NULL; |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
680 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
681 if (!(flags & GLOB_NOESCAPE)) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
682 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
683 if (end_name == NULL) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
684 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
685 unescape = strchr (dirname, '\\'); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
686 if (unescape) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
687 end_name = strchr (unescape, '\0'); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
688 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
689 else |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
690 unescape = memchr (dirname, '\\', end_name - dirname); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
691 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
692 if (end_name == NULL) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
693 user_name = dirname + 1; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
694 else |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
695 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
696 char *newp; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
697 newp = __alloca (end_name - dirname); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
698 *((char *) mempcpy (newp, dirname + 1, end_name - dirname)) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
699 = '\0'; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
700 if (unescape != NULL) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
701 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
702 char *p = mempcpy (newp, dirname + 1, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
703 unescape - dirname - 1); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
704 char *q = unescape; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
705 while (*q != '\0') |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
706 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
707 if (*q == '\\') |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
708 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
709 if (q[1] == '\0') |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
710 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
711 /* "~fo\\o\\" unescape to user_name "foo\\", |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
712 but "~fo\\o\\/" unescape to user_name |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
713 "foo". */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
714 if (filename == NULL) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
715 *p++ = '\\'; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
716 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
717 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
718 ++q; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
719 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
720 *p++ = *q++; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
721 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
722 *p = '\0'; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
723 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
724 else |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
725 *((char *) mempcpy (newp, dirname + 1, end_name - dirname)) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
726 = '\0'; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
727 user_name = newp; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
728 } |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
729 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
730 /* Look up specific user's home directory. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
731 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
732 struct passwd *p; |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
733 # if defined HAVE_GETPWNAM_R || defined _LIBC |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
734 long int buflen = GETPW_R_SIZE_MAX (); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
735 char *pwtmpbuf; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
736 struct passwd pwbuf; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
737 int save = errno; |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
738 |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
739 # ifndef _LIBC |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
740 if (buflen == -1) |
16235
18a38c9615f0
In commentary, do not use ` to quote.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
741 /* 'sysconf' does not support _SC_GETPW_R_SIZE_MAX. Try a |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
742 moderate value. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
743 buflen = 1024; |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
744 # endif |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
745 pwtmpbuf = __alloca (buflen); |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
746 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
747 while (getpwnam_r (user_name, &pwbuf, pwtmpbuf, buflen, &p) != 0) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
748 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
749 if (errno != ERANGE) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
750 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
751 p = NULL; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
752 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
753 } |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
754 # ifdef _LIBC |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
755 pwtmpbuf = extend_alloca (pwtmpbuf, buflen, 2 * buflen); |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
756 # else |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
757 buflen *= 2; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
758 pwtmpbuf = __alloca (buflen); |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
759 # endif |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
760 __set_errno (save); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
761 } |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
762 # else |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
763 p = getpwnam (user_name); |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
764 # endif |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
765 if (p != NULL) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
766 home_dir = p->pw_dir; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
767 else |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
768 home_dir = NULL; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
769 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
770 /* If we found a home directory use this. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
771 if (home_dir != NULL) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
772 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
773 char *newp; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
774 size_t home_len = strlen (home_dir); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
775 size_t rest_len = end_name == NULL ? 0 : strlen (end_name); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
776 newp = __alloca (home_len + rest_len + 1); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
777 *((char *) mempcpy (mempcpy (newp, home_dir, home_len), |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
778 end_name, rest_len)) = '\0'; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
779 dirname = newp; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
780 dirlen = home_len + rest_len; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
781 dirname_modified = 1; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
782 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
783 else |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
784 if (flags & GLOB_TILDE_CHECK) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
785 /* We have to regard it as an error if we cannot find the |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
786 home directory. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
787 return GLOB_NOMATCH; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
788 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
789 # endif /* Not Amiga && not WINDOWS32. */ |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
790 } |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
791 |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
792 /* Now test whether we looked for "~" or "~NAME". In this case we |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
793 can give the answer now. */ |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
794 if (filename == NULL) |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
795 { |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
796 struct stat st; |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
797 struct_stat64 st64; |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
798 |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
799 /* Return the directory if we don't check for error or if it exists. */ |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
800 if ((flags & GLOB_NOCHECK) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
801 || (((__builtin_expect (flags & GLOB_ALTDIRFUNC, 0)) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
802 ? ((*pglob->gl_stat) (dirname, &st) == 0 |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
803 && S_ISDIR (st.st_mode)) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
804 : (__stat64 (dirname, &st64) == 0 && S_ISDIR (st64.st_mode))))) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
805 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
806 int newcount = pglob->gl_pathc + pglob->gl_offs; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
807 char **new_gl_pathv; |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
808 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
809 new_gl_pathv |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
810 = realloc (pglob->gl_pathv, (newcount + 1 + 1) * sizeof (char *)); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
811 if (new_gl_pathv == NULL) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
812 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
813 nospace: |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
814 free (pglob->gl_pathv); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
815 pglob->gl_pathv = NULL; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
816 pglob->gl_pathc = 0; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
817 return GLOB_NOSPACE; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
818 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
819 pglob->gl_pathv = new_gl_pathv; |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
820 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
821 if (flags & GLOB_MARK) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
822 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
823 char *p; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
824 pglob->gl_pathv[newcount] = malloc (dirlen + 2); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
825 if (pglob->gl_pathv[newcount] == NULL) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
826 goto nospace; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
827 p = mempcpy (pglob->gl_pathv[newcount], dirname, dirlen); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
828 p[0] = '/'; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
829 p[1] = '\0'; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
830 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
831 else |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
832 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
833 pglob->gl_pathv[newcount] = strdup (dirname); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
834 if (pglob->gl_pathv[newcount] == NULL) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
835 goto nospace; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
836 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
837 pglob->gl_pathv[++newcount] = NULL; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
838 ++pglob->gl_pathc; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
839 pglob->gl_flags = flags; |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
840 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
841 return 0; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
842 } |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
843 |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
844 /* Not found. */ |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
845 return GLOB_NOMATCH; |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
846 } |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
847 |
9351
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
848 meta = __glob_pattern_type (dirname, !(flags & GLOB_NOESCAPE)); |
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
849 /* meta is 1 if correct glob pattern containing metacharacters. |
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
850 If meta has bit (1 << 2) set, it means there was an unterminated |
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
851 [ which we handle the same, using fnmatch. Broken unterminated |
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
852 pattern bracket expressions ought to be rare enough that it is |
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
853 not worth special casing them, fnmatch will do the right thing. */ |
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
854 if (meta & 5) |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
855 { |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
856 /* The directory name contains metacharacters, so we |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
857 have to glob for the directory, and then glob for |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
858 the pattern in each directory found. */ |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
859 size_t i; |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
860 |
9351
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
861 if (!(flags & GLOB_NOESCAPE) && dirlen > 0 && dirname[dirlen - 1] == '\\') |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
862 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
863 /* "foo\\/bar". Remove the final backslash from dirname |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
864 if it has not been quoted. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
865 char *p = (char *) &dirname[dirlen - 1]; |
9351
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
866 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
867 while (p > dirname && p[-1] == '\\') --p; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
868 if ((&dirname[dirlen] - p) & 1) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
869 *(char *) &dirname[--dirlen] = '\0'; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
870 } |
9351
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
871 |
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
872 if (__builtin_expect ((flags & GLOB_ALTDIRFUNC) != 0, 0)) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
873 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
874 /* Use the alternative access functions also in the recursive |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
875 call. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
876 dirs.gl_opendir = pglob->gl_opendir; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
877 dirs.gl_readdir = pglob->gl_readdir; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
878 dirs.gl_closedir = pglob->gl_closedir; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
879 dirs.gl_stat = pglob->gl_stat; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
880 dirs.gl_lstat = pglob->gl_lstat; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
881 } |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
882 |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
883 status = glob (dirname, |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
884 ((flags & (GLOB_ERR | GLOB_NOESCAPE |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
885 | GLOB_ALTDIRFUNC)) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
886 | GLOB_NOSORT | GLOB_ONLYDIR), |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
887 errfunc, &dirs); |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
888 if (status != 0) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
889 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
890 if ((flags & GLOB_NOCHECK) == 0 || status != GLOB_NOMATCH) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
891 return status; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
892 goto no_matches; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
893 } |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
894 |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
895 /* We have successfully globbed the preceding directory name. |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
896 For each name we found, call glob_in_dir on it and FILENAME, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
897 appending the results to PGLOB. */ |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
898 for (i = 0; i < dirs.gl_pathc; ++i) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
899 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
900 int old_pathc; |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
901 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
902 #ifdef SHELL |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
903 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
904 /* Make globbing interruptible in the bash shell. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
905 extern int interrupt_state; |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
906 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
907 if (interrupt_state) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
908 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
909 globfree (&dirs); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
910 return GLOB_ABORTED; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
911 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
912 } |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
913 #endif /* SHELL. */ |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
914 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
915 old_pathc = pglob->gl_pathc; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
916 status = glob_in_dir (filename, dirs.gl_pathv[i], |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
917 ((flags | GLOB_APPEND) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
918 & ~(GLOB_NOCHECK | GLOB_NOMAGIC)), |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
919 errfunc, pglob); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
920 if (status == GLOB_NOMATCH) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
921 /* No matches in this directory. Try the next. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
922 continue; |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
923 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
924 if (status != 0) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
925 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
926 globfree (&dirs); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
927 globfree (pglob); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
928 pglob->gl_pathc = 0; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
929 return status; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
930 } |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
931 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
932 /* Stick the directory on the front of each name. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
933 if (prefix_array (dirs.gl_pathv[i], |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
934 &pglob->gl_pathv[old_pathc + pglob->gl_offs], |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
935 pglob->gl_pathc - old_pathc)) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
936 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
937 globfree (&dirs); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
938 globfree (pglob); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
939 pglob->gl_pathc = 0; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
940 return GLOB_NOSPACE; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
941 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
942 } |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
943 |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
944 flags |= GLOB_MAGCHAR; |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
945 |
16235
18a38c9615f0
In commentary, do not use ` to quote.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
946 /* We have ignored the GLOB_NOCHECK flag in the 'glob_in_dir' calls. |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
947 But if we have not found any matching entry and the GLOB_NOCHECK |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
948 flag was set we must return the input pattern itself. */ |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
949 if (pglob->gl_pathc + pglob->gl_offs == oldcount) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
950 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
951 no_matches: |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
952 /* No matches. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
953 if (flags & GLOB_NOCHECK) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
954 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
955 int newcount = pglob->gl_pathc + pglob->gl_offs; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
956 char **new_gl_pathv; |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
957 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
958 new_gl_pathv = realloc (pglob->gl_pathv, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
959 (newcount + 2) * sizeof (char *)); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
960 if (new_gl_pathv == NULL) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
961 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
962 globfree (&dirs); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
963 return GLOB_NOSPACE; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
964 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
965 pglob->gl_pathv = new_gl_pathv; |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
966 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
967 pglob->gl_pathv[newcount] = strdup (pattern); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
968 if (pglob->gl_pathv[newcount] == NULL) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
969 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
970 globfree (&dirs); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
971 globfree (pglob); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
972 pglob->gl_pathc = 0; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
973 return GLOB_NOSPACE; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
974 } |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
975 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
976 ++pglob->gl_pathc; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
977 ++newcount; |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
978 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
979 pglob->gl_pathv[newcount] = NULL; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
980 pglob->gl_flags = flags; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
981 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
982 else |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
983 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
984 globfree (&dirs); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
985 return GLOB_NOMATCH; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
986 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
987 } |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
988 |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
989 globfree (&dirs); |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
990 } |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
991 else |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
992 { |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
993 int old_pathc = pglob->gl_pathc; |
9351
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
994 int orig_flags = flags; |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
995 |
9351
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
996 if (meta & 2) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
997 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
998 char *p = strchr (dirname, '\\'), *q; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
999 /* We need to unescape the dirname string. It is certainly |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1000 allocated by alloca, as otherwise filename would be NULL |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1001 or dirname wouldn't contain backslashes. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1002 q = p; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1003 do |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1004 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1005 if (*p == '\\') |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1006 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1007 *q = *++p; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1008 --dirlen; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1009 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1010 else |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1011 *q = *p; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1012 ++q; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1013 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1014 while (*p++ != '\0'); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1015 dirname_modified = 1; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1016 } |
9351
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
1017 if (dirname_modified) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1018 flags &= ~(GLOB_NOCHECK | GLOB_NOMAGIC); |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1019 status = glob_in_dir (filename, dirname, flags, errfunc, pglob); |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1020 if (status != 0) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1021 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1022 if (status == GLOB_NOMATCH && flags != orig_flags |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1023 && pglob->gl_pathc + pglob->gl_offs == oldcount) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1024 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1025 /* Make sure globfree (&dirs); is a nop. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1026 dirs.gl_pathv = NULL; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1027 flags = orig_flags; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1028 goto no_matches; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1029 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1030 return status; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1031 } |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1032 |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1033 if (dirlen > 0) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1034 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1035 /* Stick the directory on the front of each name. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1036 if (prefix_array (dirname, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1037 &pglob->gl_pathv[old_pathc + pglob->gl_offs], |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1038 pglob->gl_pathc - old_pathc)) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1039 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1040 globfree (pglob); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1041 pglob->gl_pathc = 0; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1042 return GLOB_NOSPACE; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1043 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1044 } |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1045 } |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1046 |
9351
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
1047 if (flags & GLOB_MARK) |
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
1048 { |
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
1049 /* Append slashes to directory names. */ |
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
1050 size_t i; |
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
1051 struct stat st; |
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
1052 struct_stat64 st64; |
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
1053 |
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
1054 for (i = oldcount; i < pglob->gl_pathc + pglob->gl_offs; ++i) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1055 if ((__builtin_expect (flags & GLOB_ALTDIRFUNC, 0) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1056 ? ((*pglob->gl_stat) (pglob->gl_pathv[i], &st) == 0 |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1057 && S_ISDIR (st.st_mode)) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1058 : (__stat64 (pglob->gl_pathv[i], &st64) == 0 |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1059 && S_ISDIR (st64.st_mode)))) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1060 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1061 size_t len = strlen (pglob->gl_pathv[i]) + 2; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1062 char *new = realloc (pglob->gl_pathv[i], len); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1063 if (new == NULL) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1064 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1065 globfree (pglob); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1066 pglob->gl_pathc = 0; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1067 return GLOB_NOSPACE; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1068 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1069 strcpy (&new[len - 2], "/"); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1070 pglob->gl_pathv[i] = new; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1071 } |
9351
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
1072 } |
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
1073 |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1074 if (!(flags & GLOB_NOSORT)) |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1075 { |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1076 /* Sort the vector. */ |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1077 qsort (&pglob->gl_pathv[oldcount], |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1078 pglob->gl_pathc + pglob->gl_offs - oldcount, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1079 sizeof (char *), collated_compare); |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1080 } |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1081 |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1082 return 0; |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1083 } |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1084 #if defined _LIBC && !defined glob |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1085 libc_hidden_def (glob) |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1086 #endif |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1087 |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1088 |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1089 #if !defined _LIBC || !defined GLOB_ONLY_P |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1090 |
16235
18a38c9615f0
In commentary, do not use ` to quote.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
1091 /* Free storage allocated in PGLOB by a previous 'glob' call. */ |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1092 void |
6218
71a1ca6e85c0
* lib/glob.c (glob, globfree, __glob_pattern_p): Use old-style function
Paul Eggert <eggert@cs.ucla.edu>
parents:
6198
diff
changeset
|
1093 globfree (pglob) |
71a1ca6e85c0
* lib/glob.c (glob, globfree, __glob_pattern_p): Use old-style function
Paul Eggert <eggert@cs.ucla.edu>
parents:
6198
diff
changeset
|
1094 register glob_t *pglob; |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1095 { |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1096 if (pglob->gl_pathv != NULL) |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1097 { |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1098 size_t i; |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1099 for (i = 0; i < pglob->gl_pathc; ++i) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1100 if (pglob->gl_pathv[pglob->gl_offs + i] != NULL) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1101 free (pglob->gl_pathv[pglob->gl_offs + i]); |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1102 free (pglob->gl_pathv); |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1103 pglob->gl_pathv = NULL; |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1104 } |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1105 } |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1106 #if defined _LIBC && !defined globfree |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1107 libc_hidden_def (globfree) |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1108 #endif |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1109 |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1110 |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1111 /* Do a collated comparison of A and B. */ |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1112 static int |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1113 collated_compare (const void *a, const void *b) |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1114 { |
6860
58381f8b1b9b
* glob.c (collated_compare): Remove 'const' uses that weren't needed.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6689
diff
changeset
|
1115 char *const *ps1 = a; char *s1 = *ps1; |
58381f8b1b9b
* glob.c (collated_compare): Remove 'const' uses that weren't needed.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6689
diff
changeset
|
1116 char *const *ps2 = b; char *s2 = *ps2; |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1117 |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1118 if (s1 == s2) |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1119 return 0; |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1120 if (s1 == NULL) |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1121 return 1; |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1122 if (s2 == NULL) |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1123 return -1; |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1124 return strcoll (s1, s2); |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1125 } |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1126 |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1127 |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1128 /* Prepend DIRNAME to each of N members of ARRAY, replacing ARRAY's |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1129 elements in place. Return nonzero if out of memory, zero if successful. |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1130 A slash is inserted between DIRNAME and each elt of ARRAY, |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1131 unless DIRNAME is just "/". Each old element of ARRAY is freed. */ |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1132 static int |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1133 prefix_array (const char *dirname, char **array, size_t n) |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1134 { |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1135 register size_t i; |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1136 size_t dirlen = strlen (dirname); |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1137 #if defined __MSDOS__ || defined WINDOWS32 |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1138 int sep_char = '/'; |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1139 # define DIRSEP_CHAR sep_char |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1140 #else |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1141 # define DIRSEP_CHAR '/' |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1142 #endif |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1143 |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1144 if (dirlen == 1 && dirname[0] == '/') |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1145 /* DIRNAME is just "/", so normal prepending would get us "//foo". |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1146 We want "/foo" instead, so don't prepend any chars from DIRNAME. */ |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1147 dirlen = 0; |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1148 #if defined __MSDOS__ || defined WINDOWS32 |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1149 else if (dirlen > 1) |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1150 { |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1151 if (dirname[dirlen - 1] == '/' && dirname[dirlen - 2] == ':') |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1152 /* DIRNAME is "d:/". Don't prepend the slash from DIRNAME. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1153 --dirlen; |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1154 else if (dirname[dirlen - 1] == ':') |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1155 { |
16235
18a38c9615f0
In commentary, do not use ` to quote.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
1156 /* DIRNAME is "d:". Use ':' instead of '/'. */ |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1157 --dirlen; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1158 sep_char = ':'; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1159 } |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1160 } |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1161 #endif |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1162 |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1163 for (i = 0; i < n; ++i) |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1164 { |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1165 size_t eltlen = strlen (array[i]) + 1; |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1166 char *new = malloc (dirlen + 1 + eltlen); |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1167 if (new == NULL) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1168 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1169 while (i > 0) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1170 free (array[--i]); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1171 return 1; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1172 } |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1173 |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1174 { |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1175 char *endp = mempcpy (new, dirname, dirlen); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1176 *endp++ = DIRSEP_CHAR; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1177 mempcpy (endp, array[i], eltlen); |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1178 } |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1179 free (array[i]); |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1180 array[i] = new; |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1181 } |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1182 |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1183 return 0; |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1184 } |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1185 |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1186 |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1187 /* We must not compile this function twice. */ |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1188 #if !defined _LIBC || !defined NO_GLOB_PATTERN_P |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1189 int |
9351
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
1190 __glob_pattern_type (pattern, quote) |
6218
71a1ca6e85c0
* lib/glob.c (glob, globfree, __glob_pattern_p): Use old-style function
Paul Eggert <eggert@cs.ucla.edu>
parents:
6198
diff
changeset
|
1191 const char *pattern; |
71a1ca6e85c0
* lib/glob.c (glob, globfree, __glob_pattern_p): Use old-style function
Paul Eggert <eggert@cs.ucla.edu>
parents:
6198
diff
changeset
|
1192 int quote; |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1193 { |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1194 register const char *p; |
9351
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
1195 int ret = 0; |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1196 |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1197 for (p = pattern; *p != '\0'; ++p) |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1198 switch (*p) |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1199 { |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1200 case '?': |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1201 case '*': |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1202 return 1; |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1203 |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1204 case '\\': |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1205 if (quote) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1206 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1207 if (p[1] != '\0') |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1208 ++p; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1209 ret |= 2; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1210 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1211 break; |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1212 |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1213 case '[': |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1214 ret |= 4; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1215 break; |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1216 |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1217 case ']': |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1218 if (ret & 4) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1219 return 1; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1220 break; |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1221 } |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1222 |
9351
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
1223 return ret; |
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
1224 } |
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
1225 |
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
1226 /* Return nonzero if PATTERN contains any metacharacters. |
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
1227 Metacharacters can be quoted with backslashes if QUOTE is nonzero. */ |
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
1228 int |
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
1229 __glob_pattern_p (pattern, quote) |
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
1230 const char *pattern; |
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
1231 int quote; |
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
1232 { |
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
1233 return __glob_pattern_type (pattern, quote) == 1; |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1234 } |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1235 # ifdef _LIBC |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1236 weak_alias (__glob_pattern_p, glob_pattern_p) |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1237 # endif |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1238 #endif |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1239 |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1240 #endif /* !GLOB_ONLY_P */ |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1241 |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1242 |
9557
81a0ee2e4e00
Ensure that 'glob' stays under LGPLv2+.
Bruno Haible <bruno@clisp.org>
parents:
9549
diff
changeset
|
1243 #if !defined _LIBC || !defined GLOB_ONLY_P |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1244 /* We put this in a separate function mainly to allow the memory |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1245 allocated with alloca to be recycled. */ |
9351
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
1246 static int |
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
1247 __attribute_noinline__ |
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
1248 link_exists2_p (const char *dir, size_t dirlen, const char *fname, |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1249 glob_t *pglob |
9557
81a0ee2e4e00
Ensure that 'glob' stays under LGPLv2+.
Bruno Haible <bruno@clisp.org>
parents:
9549
diff
changeset
|
1250 # if !defined _LIBC && !HAVE_FSTATAT |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1251 , int flags |
9557
81a0ee2e4e00
Ensure that 'glob' stays under LGPLv2+.
Bruno Haible <bruno@clisp.org>
parents:
9549
diff
changeset
|
1252 # endif |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1253 ) |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1254 { |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1255 size_t fnamelen = strlen (fname); |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1256 char *fullname = __alloca (dirlen + 1 + fnamelen + 1); |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1257 struct stat st; |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1258 |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1259 mempcpy (mempcpy (mempcpy (fullname, dir, dirlen), "/", 1), |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1260 fname, fnamelen + 1); |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1261 |
9557
81a0ee2e4e00
Ensure that 'glob' stays under LGPLv2+.
Bruno Haible <bruno@clisp.org>
parents:
9549
diff
changeset
|
1262 # if !defined _LIBC && !HAVE_FSTATAT |
81a0ee2e4e00
Ensure that 'glob' stays under LGPLv2+.
Bruno Haible <bruno@clisp.org>
parents:
9549
diff
changeset
|
1263 if (__builtin_expect ((flags & GLOB_ALTDIRFUNC) == 0, 1)) |
81a0ee2e4e00
Ensure that 'glob' stays under LGPLv2+.
Bruno Haible <bruno@clisp.org>
parents:
9549
diff
changeset
|
1264 { |
81a0ee2e4e00
Ensure that 'glob' stays under LGPLv2+.
Bruno Haible <bruno@clisp.org>
parents:
9549
diff
changeset
|
1265 struct_stat64 st64; |
81a0ee2e4e00
Ensure that 'glob' stays under LGPLv2+.
Bruno Haible <bruno@clisp.org>
parents:
9549
diff
changeset
|
1266 return __stat64 (fullname, &st64) == 0; |
81a0ee2e4e00
Ensure that 'glob' stays under LGPLv2+.
Bruno Haible <bruno@clisp.org>
parents:
9549
diff
changeset
|
1267 } |
81a0ee2e4e00
Ensure that 'glob' stays under LGPLv2+.
Bruno Haible <bruno@clisp.org>
parents:
9549
diff
changeset
|
1268 # endif |
9351
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
1269 return (*pglob->gl_stat) (fullname, &st) == 0; |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1270 } |
9357
75e43b0e5159
Modify glob.c to use fstatat and dirfd, to simplify it.
Paul Eggert <eggert@cs.ucla.edu>
parents:
9351
diff
changeset
|
1271 |
75e43b0e5159
Modify glob.c to use fstatat and dirfd, to simplify it.
Paul Eggert <eggert@cs.ucla.edu>
parents:
9351
diff
changeset
|
1272 /* Return true if DIR/FNAME exists. */ |
75e43b0e5159
Modify glob.c to use fstatat and dirfd, to simplify it.
Paul Eggert <eggert@cs.ucla.edu>
parents:
9351
diff
changeset
|
1273 static int |
75e43b0e5159
Modify glob.c to use fstatat and dirfd, to simplify it.
Paul Eggert <eggert@cs.ucla.edu>
parents:
9351
diff
changeset
|
1274 link_exists_p (int dfd, const char *dir, size_t dirlen, const char *fname, |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1275 glob_t *pglob, int flags) |
9357
75e43b0e5159
Modify glob.c to use fstatat and dirfd, to simplify it.
Paul Eggert <eggert@cs.ucla.edu>
parents:
9351
diff
changeset
|
1276 { |
9557
81a0ee2e4e00
Ensure that 'glob' stays under LGPLv2+.
Bruno Haible <bruno@clisp.org>
parents:
9549
diff
changeset
|
1277 # if defined _LIBC || HAVE_FSTATAT |
9357
75e43b0e5159
Modify glob.c to use fstatat and dirfd, to simplify it.
Paul Eggert <eggert@cs.ucla.edu>
parents:
9351
diff
changeset
|
1278 if (__builtin_expect (flags & GLOB_ALTDIRFUNC, 0)) |
75e43b0e5159
Modify glob.c to use fstatat and dirfd, to simplify it.
Paul Eggert <eggert@cs.ucla.edu>
parents:
9351
diff
changeset
|
1279 return link_exists2_p (dir, dirlen, fname, pglob); |
75e43b0e5159
Modify glob.c to use fstatat and dirfd, to simplify it.
Paul Eggert <eggert@cs.ucla.edu>
parents:
9351
diff
changeset
|
1280 else |
75e43b0e5159
Modify glob.c to use fstatat and dirfd, to simplify it.
Paul Eggert <eggert@cs.ucla.edu>
parents:
9351
diff
changeset
|
1281 { |
13676
223800d7ac7d
fts, getcwd, glob: audit for dirfd returning -1
Paul Eggert <eggert@cs.ucla.edu>
parents:
12559
diff
changeset
|
1282 /* dfd cannot be -1 here, because dirfd never returns -1 on |
223800d7ac7d
fts, getcwd, glob: audit for dirfd returning -1
Paul Eggert <eggert@cs.ucla.edu>
parents:
12559
diff
changeset
|
1283 glibc, or on hosts that have fstatat. */ |
9357
75e43b0e5159
Modify glob.c to use fstatat and dirfd, to simplify it.
Paul Eggert <eggert@cs.ucla.edu>
parents:
9351
diff
changeset
|
1284 struct_stat64 st64; |
75e43b0e5159
Modify glob.c to use fstatat and dirfd, to simplify it.
Paul Eggert <eggert@cs.ucla.edu>
parents:
9351
diff
changeset
|
1285 return __fxstatat64 (_STAT_VER, dfd, fname, &st64, 0) == 0; |
75e43b0e5159
Modify glob.c to use fstatat and dirfd, to simplify it.
Paul Eggert <eggert@cs.ucla.edu>
parents:
9351
diff
changeset
|
1286 } |
9557
81a0ee2e4e00
Ensure that 'glob' stays under LGPLv2+.
Bruno Haible <bruno@clisp.org>
parents:
9549
diff
changeset
|
1287 # else |
81a0ee2e4e00
Ensure that 'glob' stays under LGPLv2+.
Bruno Haible <bruno@clisp.org>
parents:
9549
diff
changeset
|
1288 return link_exists2_p (dir, dirlen, fname, pglob, flags); |
81a0ee2e4e00
Ensure that 'glob' stays under LGPLv2+.
Bruno Haible <bruno@clisp.org>
parents:
9549
diff
changeset
|
1289 # endif |
9357
75e43b0e5159
Modify glob.c to use fstatat and dirfd, to simplify it.
Paul Eggert <eggert@cs.ucla.edu>
parents:
9351
diff
changeset
|
1290 } |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1291 #endif |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1292 |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1293 |
16235
18a38c9615f0
In commentary, do not use ` to quote.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
1294 /* Like 'glob', but PATTERN is a final pathname component, |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1295 and matches are searched for in DIRECTORY. |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1296 The GLOB_NOSORT bit in FLAGS is ignored. No sorting is ever done. |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1297 The GLOB_APPEND flag is assumed to be set (always appends). */ |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1298 static int |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1299 glob_in_dir (const char *pattern, const char *directory, int flags, |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1300 int (*errfunc) (const char *, int), |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1301 glob_t *pglob) |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1302 { |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1303 size_t dirlen = strlen (directory); |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1304 void *stream = NULL; |
9351
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
1305 struct globnames |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1306 { |
9351
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
1307 struct globnames *next; |
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
1308 size_t count; |
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
1309 char *name[64]; |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1310 }; |
9351
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
1311 #define INITIAL_COUNT sizeof (init_names.name) / sizeof (init_names.name[0]) |
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
1312 struct globnames init_names; |
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
1313 struct globnames *names = &init_names; |
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
1314 struct globnames *names_alloca = &init_names; |
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
1315 size_t nfound = 0; |
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
1316 size_t allocasize = sizeof (init_names); |
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
1317 size_t cur = 0; |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1318 int meta; |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1319 int save; |
9351
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
1320 int result; |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1321 |
9351
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
1322 init_names.next = NULL; |
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
1323 init_names.count = INITIAL_COUNT; |
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
1324 |
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
1325 meta = __glob_pattern_type (pattern, !(flags & GLOB_NOESCAPE)); |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1326 if (meta == 0 && (flags & (GLOB_NOCHECK|GLOB_NOMAGIC))) |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1327 { |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1328 /* We need not do any tests. The PATTERN contains no meta |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1329 characters and we must not return an error therefore the |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1330 result will always contain exactly one name. */ |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1331 flags |= GLOB_NOCHECK; |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1332 } |
9351
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
1333 else if (meta == 0) |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1334 { |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1335 /* Since we use the normal file functions we can also use stat() |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1336 to verify the file is there. */ |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1337 struct stat st; |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1338 struct_stat64 st64; |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1339 size_t patlen = strlen (pattern); |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1340 char *fullname = __alloca (dirlen + 1 + patlen + 1); |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1341 |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1342 mempcpy (mempcpy (mempcpy (fullname, directory, dirlen), |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1343 "/", 1), |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1344 pattern, patlen + 1); |
9351
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
1345 if ((__builtin_expect (flags & GLOB_ALTDIRFUNC, 0) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1346 ? (*pglob->gl_stat) (fullname, &st) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1347 : __stat64 (fullname, &st64)) == 0) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1348 /* We found this file to be existing. Now tell the rest |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1349 of the function to copy this name into the result. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1350 flags |= GLOB_NOCHECK; |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1351 } |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1352 else |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1353 { |
9351
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
1354 stream = (__builtin_expect (flags & GLOB_ALTDIRFUNC, 0) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1355 ? (*pglob->gl_opendir) (directory) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1356 : opendir (directory)); |
9351
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
1357 if (stream == NULL) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1358 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1359 if (errno != ENOTDIR |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1360 && ((errfunc != NULL && (*errfunc) (directory, errno)) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1361 || (flags & GLOB_ERR))) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1362 return GLOB_ABORTED; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1363 } |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1364 else |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1365 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1366 int dfd = (__builtin_expect (flags & GLOB_ALTDIRFUNC, 0) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1367 ? -1 : dirfd ((DIR *) stream)); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1368 int fnm_flags = ((!(flags & GLOB_PERIOD) ? FNM_PERIOD : 0) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1369 | ((flags & GLOB_NOESCAPE) ? FNM_NOESCAPE : 0) |
9351
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
1370 #if defined _AMIGA || defined VMS |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1371 | FNM_CASEFOLD |
9351
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
1372 #endif |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1373 ); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1374 flags |= GLOB_MAGCHAR; |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1375 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1376 while (1) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1377 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1378 const char *name; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1379 size_t len; |
9351
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
1380 #if defined _LIBC && !defined COMPILE_GLOB64 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1381 struct dirent64 *d; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1382 union |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1383 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1384 struct dirent64 d64; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1385 char room [offsetof (struct dirent64, d_name[0]) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1386 + NAME_MAX + 1]; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1387 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1388 d64buf; |
9351
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
1389 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1390 if (__builtin_expect (flags & GLOB_ALTDIRFUNC, 0)) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1391 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1392 struct dirent *d32 = (*pglob->gl_readdir) (stream); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1393 if (d32 != NULL) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1394 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1395 CONVERT_DIRENT_DIRENT64 (&d64buf.d64, d32); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1396 d = &d64buf.d64; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1397 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1398 else |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1399 d = NULL; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1400 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1401 else |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1402 d = __readdir64 (stream); |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1403 #else |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1404 struct dirent *d = (__builtin_expect (flags & GLOB_ALTDIRFUNC, 0) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1405 ? ((struct dirent *) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1406 (*pglob->gl_readdir) (stream)) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1407 : __readdir (stream)); |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1408 #endif |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1409 if (d == NULL) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1410 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1411 if (! REAL_DIR_ENTRY (d)) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1412 continue; |
9351
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
1413 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1414 /* If we shall match only directories use the information |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1415 provided by the dirent call if possible. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1416 if ((flags & GLOB_ONLYDIR) && !DIRENT_MIGHT_BE_DIR (d)) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1417 continue; |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1418 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1419 name = d->d_name; |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1420 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1421 if (fnmatch (pattern, name, fnm_flags) == 0) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1422 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1423 /* If the file we found is a symlink we have to |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1424 make sure the target file exists. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1425 if (!DIRENT_MIGHT_BE_SYMLINK (d) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1426 || link_exists_p (dfd, directory, dirlen, name, pglob, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1427 flags)) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1428 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1429 if (cur == names->count) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1430 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1431 struct globnames *newnames; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1432 size_t count = names->count * 2; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1433 size_t size = (sizeof (struct globnames) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1434 + ((count - INITIAL_COUNT) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1435 * sizeof (char *))); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1436 allocasize += size; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1437 if (__libc_use_alloca (allocasize)) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1438 newnames = names_alloca = __alloca (size); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1439 else if ((newnames = malloc (size)) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1440 == NULL) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1441 goto memory_error; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1442 newnames->count = count; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1443 newnames->next = names; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1444 names = newnames; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1445 cur = 0; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1446 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1447 len = _D_EXACT_NAMLEN (d); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1448 names->name[cur] = malloc (len + 1); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1449 if (names->name[cur] == NULL) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1450 goto memory_error; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1451 *((char *) mempcpy (names->name[cur++], name, len)) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1452 = '\0'; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1453 ++nfound; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1454 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1455 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1456 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1457 } |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1458 } |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1459 |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1460 if (nfound == 0 && (flags & GLOB_NOCHECK)) |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1461 { |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1462 size_t len = strlen (pattern); |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1463 nfound = 1; |
9351
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
1464 names->name[cur] = malloc (len + 1); |
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
1465 if (names->name[cur] == NULL) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1466 goto memory_error; |
9351
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
1467 *((char *) mempcpy (names->name[cur++], pattern, len)) = '\0'; |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1468 } |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1469 |
9351
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
1470 result = GLOB_NOMATCH; |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1471 if (nfound != 0) |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1472 { |
9351
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
1473 char **new_gl_pathv |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1474 = realloc (pglob->gl_pathv, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1475 (pglob->gl_pathc + pglob->gl_offs + nfound + 1) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1476 * sizeof (char *)); |
9351
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
1477 result = 0; |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1478 |
9351
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
1479 if (new_gl_pathv == NULL) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1480 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1481 memory_error: |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1482 while (1) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1483 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1484 struct globnames *old = names; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1485 size_t i; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1486 for (i = 0; i < cur; ++i) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1487 free (names->name[i]); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1488 names = names->next; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1489 /* NB: we will not leak memory here if we exit without |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1490 freeing the current block assigned to OLD. At least |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1491 the very first block is always allocated on the stack |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1492 and this is the block assigned to OLD here. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1493 if (names == NULL) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1494 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1495 assert (old == &init_names); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1496 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1497 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1498 cur = names->count; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1499 if (old == names_alloca) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1500 names_alloca = names; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1501 else |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1502 free (old); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1503 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1504 result = GLOB_NOSPACE; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1505 } |
9351
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
1506 else |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1507 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1508 while (1) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1509 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1510 struct globnames *old = names; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1511 size_t i; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1512 for (i = 0; i < cur; ++i) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1513 new_gl_pathv[pglob->gl_offs + pglob->gl_pathc++] |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1514 = names->name[i]; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1515 names = names->next; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1516 /* NB: we will not leak memory here if we exit without |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1517 freeing the current block assigned to OLD. At least |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1518 the very first block is always allocated on the stack |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1519 and this is the block assigned to OLD here. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1520 if (names == NULL) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1521 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1522 assert (old == &init_names); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1523 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1524 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1525 cur = names->count; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1526 if (old == names_alloca) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1527 names_alloca = names; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1528 else |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1529 free (old); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1530 } |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1531 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1532 pglob->gl_pathv = new_gl_pathv; |
9351
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
1533 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1534 pglob->gl_pathv[pglob->gl_offs + pglob->gl_pathc] = NULL; |
9351
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
1535 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1536 pglob->gl_flags = flags; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1537 } |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1538 } |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1539 |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1540 if (stream != NULL) |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1541 { |
9351
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
1542 save = errno; |
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
1543 if (__builtin_expect (flags & GLOB_ALTDIRFUNC, 0)) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1544 (*pglob->gl_closedir) (stream); |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1545 else |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12002
diff
changeset
|
1546 closedir (stream); |
9351
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
1547 __set_errno (save); |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1548 } |
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1549 |
9351
7ab454b59c21
Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
8439
diff
changeset
|
1550 return result; |
5898
429b55c14554
* MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff
changeset
|
1551 } |