annotate lib/glob.c @ 16201:8250f2777afc

maint: update all copyright year number ranges Run "make update-copyright".
author Jim Meyering <meyering@redhat.com>
date Sun, 01 Jan 2012 10:04:58 +0100
parents e6b64482119f
children 18a38c9615f0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
16201
8250f2777afc maint: update all copyright year number ranges
Jim Meyering <meyering@redhat.com>
parents: 16127
diff changeset
1 /* Copyright (C) 1991-2012 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
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
18 # include <config.h>
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
19 #endif
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
20
12422
f7842310a565 New module 'arg-nonnull'. Declare which arguments expect non-NULL values.
Bruno Haible <bruno@clisp.org>
parents: 12421
diff changeset
21 /* Don't use __attribute__ __nonnull__ in this compilation unit. Otherwise gcc
f7842310a565 New module 'arg-nonnull'. Declare which arguments expect non-NULL values.
Bruno Haible <bruno@clisp.org>
parents: 12421
diff changeset
22 optimizes away the pattern == NULL || pglob == NULL tests below. */
f7842310a565 New module 'arg-nonnull'. Declare which arguments expect non-NULL values.
Bruno Haible <bruno@clisp.org>
parents: 12421
diff changeset
23 #define _GL_ARG_NONNULL(params)
f7842310a565 New module 'arg-nonnull'. Declare which arguments expect non-NULL values.
Bruno Haible <bruno@clisp.org>
parents: 12421
diff changeset
24
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
25 #include <glob.h>
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
26
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
27 #include <errno.h>
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
28 #include <sys/types.h>
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
29 #include <sys/stat.h>
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
30 #include <stddef.h>
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
31
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
32 /* 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
33 /* #define NDEBUG 1 */
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
34 #include <assert.h>
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
35
9892
0b3ccf361045 Include stdbool, for 'true' and 'false'.
Bruno Haible <bruno@clisp.org>
parents: 9557
diff changeset
36 #include <stdbool.h>
0b3ccf361045 Include stdbool, for 'true' and 'false'.
Bruno Haible <bruno@clisp.org>
parents: 9557
diff changeset
37
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
38 #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
39
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
40 #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
41
93d578c7aa44 * lib/c-stack.c: Include unistd.h unconditionally, since we now assume
Paul Eggert <eggert@cs.ucla.edu>
parents: 6655
diff changeset
42 #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
43 #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
44 # define POSIX
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
45 #endif
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
46
10423
51c125f4cd8d Make glob work on mingw.
Bruno Haible <bruno@clisp.org>
parents: 9892
diff changeset
47 #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
51c125f4cd8d Make glob work on mingw.
Bruno Haible <bruno@clisp.org>
parents: 9892
diff changeset
48 # define WINDOWS32
51c125f4cd8d Make glob work on mingw.
Bruno Haible <bruno@clisp.org>
parents: 9892
diff changeset
49 #endif
51c125f4cd8d Make glob work on mingw.
Bruno Haible <bruno@clisp.org>
parents: 9892
diff changeset
50
51c125f4cd8d Make glob work on mingw.
Bruno Haible <bruno@clisp.org>
parents: 9892
diff changeset
51 #ifndef WINDOWS32
51c125f4cd8d Make glob work on mingw.
Bruno Haible <bruno@clisp.org>
parents: 9892
diff changeset
52 # include <pwd.h>
51c125f4cd8d Make glob work on mingw.
Bruno Haible <bruno@clisp.org>
parents: 9892
diff changeset
53 #endif
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
54
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
55 #include <errno.h>
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
56 #ifndef __set_errno
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
57 # 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
58 #endif
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
59
6949
96af1224c6fa * backupfile.c, dirfd.h, fts.c, getcwd.c, glob.c, glob_.h:
Paul Eggert <eggert@cs.ucla.edu>
parents: 6934
diff changeset
60 #include <dirent.h>
5898
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
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
63 /* 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
64 #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
65 # 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
66 #endif
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
67
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
68 /* When used in the GNU libc the symbol _DIRENT_HAVE_D_TYPE is available
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
69 if the `d_type' member for `struct dirent' is available.
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
70 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
71 #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
72 /* 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
73 # 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
74
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
75 /* 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
76 # 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
77 ((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
78
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
79 /* 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
80 # 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
81 ((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
82
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
83 #else /* !HAVE_D_TYPE */
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
84 # define DIRENT_MUST_BE(d, t) false
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
85 # define DIRENT_MIGHT_BE_SYMLINK(d) true
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
86 # 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
87 #endif /* HAVE_D_TYPE */
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
88
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
89 /* If the system has the `struct dirent64' type we use it internally. */
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
90 #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
91 # 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
92 # 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
93 # else
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
94 # 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
95 (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
96 # endif
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
97
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
98 # 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
99 # 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
100 (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
101 # else
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
102 # 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
103 # endif
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
104
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
105 # define CONVERT_DIRENT_DIRENT64(d64, d32) \
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
106 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
107 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
108 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
109 #endif
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
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
112 #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
113 /* 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
114 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
115 # 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
116 #else
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
117 # 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
118 #endif /* POSIX */
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
119
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
120 #include <stdlib.h>
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
121 #include <string.h>
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
122
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
123 /* 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
124 #include <limits.h>
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
125 #ifndef NAME_MAX
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
126 # 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
127 #endif
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
128
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
129 #include <alloca.h>
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
130
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
131 #ifdef _LIBC
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
132 # undef strdup
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
133 # 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
134 # 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
135 # 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
136 # 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
137 # 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
138 # 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
139 __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
140 # ifndef __stat64
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
141 # 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
142 # endif
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
143 # 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
144 #else /* !_LIBC */
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
145 # 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
146 # 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
147 # define struct_stat64 struct stat
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
148 # define __alloca alloca
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
149 # define __readdir readdir
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
150 # 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
151 #endif /* _LIBC */
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
152
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
153 #include <fnmatch.h>
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
154
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
155 #ifdef _SC_GETPW_R_SIZE_MAX
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
156 # 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
157 #else
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
158 # 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
159 #endif
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
160 #ifdef _SC_LOGIN_NAME_MAX
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
161 # 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
162 #else
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
163 # 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
164 #endif
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
165
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
166 static const char *next_brace_sub (const char *begin, int flags) __THROW;
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
167
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
168 #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
169
9351
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
170 #ifndef attribute_hidden
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
171 # define attribute_hidden
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
172 #endif
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
173
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
174 #ifndef __attribute_noinline__
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
175 # 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
176 # define __attribute_noinline__ /* Ignore */
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
177 #else
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
178 # define __attribute_noinline__ __attribute__ ((__noinline__))
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 #endif
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
181
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
182 #if ! defined __builtin_expect && __GNUC__ < 3
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
183 # define __builtin_expect(expr, expected) (expr)
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
184 #endif
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
185
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
186 #ifndef _LIBC
7863
cb2590895141 New module 'fchdir'.
Bruno Haible <bruno@clisp.org>
parents: 7581
diff changeset
187 /* 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
188 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
189 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
190 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
191 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
192 # undef opendir
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
193 # undef closedir
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
194
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
195 # if HAVE_ALLOCA
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
196 /* 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
197 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
198 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
199 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
200 # 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
201 # else
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
202 /* 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
203 # define __libc_use_alloca(n) 0
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
204 # endif
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
205 #endif
7863
cb2590895141 New module 'fchdir'.
Bruno Haible <bruno@clisp.org>
parents: 7581
diff changeset
206
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
207 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
208 int flags, int (*errfunc) (const char *, int),
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
209 glob_t *pglob);
9351
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
210 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
211 attribute_hidden;
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
212
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
213 #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
214 static int prefix_array (const char *prefix, char **array, size_t n) __THROW;
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
215 static int collated_compare (const void *, const void *) __THROW;
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
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
218 /* 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
219 static const char *
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
220 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
221 {
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
222 unsigned int depth = 0;
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
223 while (*cp != '\0')
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
224 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
225 {
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
226 if (*++cp == '\0')
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
227 break;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
228 ++cp;
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
229 }
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
230 else
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
231 {
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
232 if ((*cp == '}' && depth-- == 0) || (*cp == ',' && depth == 0))
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
233 break;
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
234
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
235 if (*cp++ == '{')
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
236 depth++;
5898
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
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
239 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
240 }
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
241
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
242 #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
243
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
244 /* 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
245 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
246 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
247 it is called with the pathname that caused the error, and the
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
248 `errno' value from the failing call; if it returns non-zero
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
249 `glob' returns GLOB_ABORTED; if it returns zero, the error is ignored.
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
250 If memory cannot be allocated for PGLOB, GLOB_NOSPACE is returned.
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
251 Otherwise, `glob' returns zero. */
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
252 int
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
253 #ifdef GLOB_ATTRIBUTE
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
254 GLOB_ATTRIBUTE
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
255 #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
256 glob (pattern, flags, errfunc, pglob)
8439
d8182f376307 2007-03-15 Bruno Haible <bruno@clisp.org>
Bruno Haible <bruno@clisp.org>
parents: 8222
diff changeset
257 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
258 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
259 int (*errfunc) (const char *, int);
8439
d8182f376307 2007-03-15 Bruno Haible <bruno@clisp.org>
Bruno Haible <bruno@clisp.org>
parents: 8222
diff changeset
260 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
261 {
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
262 const char *filename;
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
263 const char *dirname;
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
264 size_t dirlen;
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
265 int status;
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
266 size_t oldcount;
9351
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
267 int meta;
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
268 int dirname_modified;
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
269 glob_t dirs;
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
270
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
271 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
272 {
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
273 __set_errno (EINVAL);
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
274 return -1;
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
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
277 if (!(flags & GLOB_DOOFFS))
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
278 /* Have to do this so `globfree' knows where to start freeing. It
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
279 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
280 pglob->gl_offs = 0;
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
281
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
282 if (flags & GLOB_BRACE)
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
283 {
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
284 const char *begin;
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
285
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
286 if (flags & GLOB_NOESCAPE)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
287 begin = strchr (pattern, '{');
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
288 else
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
289 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
290 begin = pattern;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
291 while (1)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
292 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
293 if (*begin == '\0')
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
294 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
295 begin = NULL;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
296 break;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
297 }
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
298
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
299 if (*begin == '\\' && begin[1] != '\0')
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
300 ++begin;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
301 else if (*begin == '{')
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
302 break;
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
303
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
304 ++begin;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
305 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
306 }
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
307
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
308 if (begin != NULL)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
309 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
310 /* 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
311 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
312 size_t firstc;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
313 char *alt_start;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
314 const char *p;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
315 const char *next;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
316 const char *rest;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
317 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
318 #ifdef __GNUC__
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
319 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
320 #else
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
321 char *onealt = malloc (strlen (pattern) - 1);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
322 if (onealt == NULL)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
323 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
324 if (!(flags & GLOB_APPEND))
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
325 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
326 pglob->gl_pathc = 0;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
327 pglob->gl_pathv = NULL;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
328 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
329 return GLOB_NOSPACE;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
330 }
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
331 #endif
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
332
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
333 /* We know the prefix for all sub-patterns. */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
334 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
335
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
336 /* 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
337 rest after the closing brace. */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
338 next = next_brace_sub (begin + 1, flags);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
339 if (next == NULL)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
340 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
341 /* 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
342 #ifndef __GNUC__
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
343 free (onealt);
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
344 #endif
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
345 return glob (pattern, flags & ~GLOB_BRACE, errfunc, pglob);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
346 }
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
347
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
348 /* 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
349 rest = next;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
350 while (*rest != '}')
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
351 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
352 rest = next_brace_sub (rest + 1, flags);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
353 if (rest == NULL)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
354 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
355 /* 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
356 #ifndef __GNUC__
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
357 free (onealt);
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
358 #endif
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
359 return glob (pattern, flags & ~GLOB_BRACE, errfunc, pglob);
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 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
362 /* 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
363 is well-formed. */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
364 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
365
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
366 /* 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
367 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
368 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
369 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
370 GLOB_APPEND. */
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
371
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
372 if (!(flags & GLOB_APPEND))
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
373 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
374 /* 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
375 vector so we can append to it. */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
376 pglob->gl_pathc = 0;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
377 pglob->gl_pathv = NULL;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
378 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
379 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
380
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
381 p = begin + 1;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
382 while (1)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
383 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
384 int result;
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
385
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
386 /* Construct the new glob expression. */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
387 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
388
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
389 result = glob (onealt,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
390 ((flags & ~(GLOB_NOCHECK | GLOB_NOMAGIC))
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
391 | 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
392
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
393 /* If we got an error, return it. */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
394 if (result && result != GLOB_NOMATCH)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
395 {
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
396 #ifndef __GNUC__
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
397 free (onealt);
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
398 #endif
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
399 if (!(flags & GLOB_APPEND))
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
400 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
401 globfree (pglob);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
402 pglob->gl_pathc = 0;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
403 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
404 return result;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
405 }
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
406
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
407 if (*next == '}')
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
408 /* We saw the last entry. */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
409 break;
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
410
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
411 p = next + 1;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
412 next = next_brace_sub (p, flags);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
413 assert (next != NULL);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
414 }
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
415
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
416 #ifndef __GNUC__
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
417 free (onealt);
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
418 #endif
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
419
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
420 if (pglob->gl_pathc != firstc)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
421 /* We found some entries. */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
422 return 0;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
423 else if (!(flags & (GLOB_NOCHECK|GLOB_NOMAGIC)))
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
424 return GLOB_NOMATCH;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
425 }
5898
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
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
428 /* Find the filename. */
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
429 filename = strrchr (pattern, '/');
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
430 #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
431 /* The case of "d:pattern". Since `:' is not allowed in
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
432 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
433 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
434 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
435 if (filename == NULL)
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
436 filename = strchr (pattern, ':');
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
437 #endif /* __MSDOS__ || WINDOWS32 */
9351
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
438 dirname_modified = 0;
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
439 if (filename == NULL)
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
440 {
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
441 /* 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
442 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
443 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
444 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
445 dirname = pattern;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
446 dirlen = strlen (pattern);
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
447
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
448 /* 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
449 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
450 this special case below. */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
451 filename = NULL;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
452 }
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
453 else
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
454 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
455 filename = pattern;
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
456 #ifdef _AMIGA
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
457 dirname = "";
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
458 #else
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
459 dirname = ".";
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
460 #endif
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
461 dirlen = 0;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
462 }
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
463 }
9351
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
464 else if (filename == pattern
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
465 || (filename == pattern + 1 && pattern[0] == '\\'
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
466 && (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
467 {
9351
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
468 /* "/pattern" or "\\/pattern". */
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
469 dirname = "/";
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
470 dirlen = 1;
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
471 ++filename;
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
472 }
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
473 else
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
474 {
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
475 char *newp;
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
476 dirlen = filename - pattern;
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
477 #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
478 if (*filename == ':'
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
479 || (filename > pattern + 1 && filename[-1] == ':'))
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
480 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
481 char *drive_spec;
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
482
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
483 ++dirlen;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
484 drive_spec = __alloca (dirlen + 1);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
485 *((char *) mempcpy (drive_spec, pattern, dirlen)) = '\0';
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
486 /* 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
487 prevent infinite recursion in glob. */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
488 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
489 return GLOB_NOMATCH;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
490 /* If this is "d:pattern", we need to copy `:' to DIRNAME
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
491 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
492 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
493 }
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
494 #endif
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
495 newp = __alloca (dirlen + 1);
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
496 *((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
497 dirname = newp;
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
498 ++filename;
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
499
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
500 if (filename[0] == '\0'
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
501 #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
502 && dirname[dirlen - 1] != ':'
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
503 && (dirlen < 3 || dirname[dirlen - 2] != ':'
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
504 || dirname[dirlen - 1] != '/')
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
505 #endif
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
506 && dirlen > 1)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
507 /* "pattern/". Expand "pattern", appending slashes. */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
508 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
509 int orig_flags = flags;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
510 int val;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
511 if (!(flags & GLOB_NOESCAPE) && dirname[dirlen - 1] == '\\')
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
512 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
513 /* "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
514 been quoted. */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
515 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
516
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
517 while (p > dirname && p[-1] == '\\') --p;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
518 if ((&dirname[dirlen] - p) & 1)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
519 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
520 *(char *) &dirname[--dirlen] = '\0';
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
521 flags &= ~(GLOB_NOCHECK | GLOB_NOMAGIC);
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 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
524 val = glob (dirname, flags | GLOB_MARK, errfunc, pglob);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
525 if (val == 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
526 pglob->gl_flags = ((pglob->gl_flags & ~GLOB_MARK)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
527 | (flags & GLOB_MARK));
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
528 else if (val == GLOB_NOMATCH && flags != orig_flags)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
529 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
530 /* Make sure globfree (&dirs); is a nop. */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
531 dirs.gl_pathv = NULL;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
532 flags = orig_flags;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
533 oldcount = pglob->gl_pathc + pglob->gl_offs;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
534 goto no_matches;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
535 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
536 return val;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
537 }
5898
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
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
540 if (!(flags & GLOB_APPEND))
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
541 {
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
542 pglob->gl_pathc = 0;
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
543 if (!(flags & GLOB_DOOFFS))
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
544 pglob->gl_pathv = NULL;
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
545 else
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
546 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
547 size_t i;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
548 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
549 if (pglob->gl_pathv == NULL)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
550 return GLOB_NOSPACE;
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
551
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
552 for (i = 0; i <= pglob->gl_offs; ++i)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
553 pglob->gl_pathv[i] = NULL;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
554 }
5898
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
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
557 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
558
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
559 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
560 {
9351
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
561 if (dirname[1] == '\0' || dirname[1] == '/'
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
562 || (!(flags & GLOB_NOESCAPE) && dirname[1] == '\\'
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
563 && (dirname[2] == '\0' || dirname[2] == '/')))
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
564 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
565 /* Look up home directory. */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
566 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
567 # ifdef _AMIGA
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
568 if (home_dir == NULL || home_dir[0] == '\0')
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
569 home_dir = "SYS:";
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
570 # else
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
571 # ifdef WINDOWS32
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
572 /* 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
573 to HOME, because the user can change HOME. */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
574 if (home_dir == NULL || home_dir[0] == '\0')
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
575 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
576 const char *home_drive = getenv ("HOMEDRIVE");
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
577 const char *home_path = getenv ("HOMEPATH");
10423
51c125f4cd8d Make glob work on mingw.
Bruno Haible <bruno@clisp.org>
parents: 9892
diff changeset
578
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
579 if (home_drive != NULL && home_path != NULL)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
580 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
581 size_t home_drive_len = strlen (home_drive);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
582 size_t home_path_len = strlen (home_path);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
583 char *mem = alloca (home_drive_len + home_path_len + 1);
10423
51c125f4cd8d Make glob work on mingw.
Bruno Haible <bruno@clisp.org>
parents: 9892
diff changeset
584
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
585 memcpy (mem, home_drive, home_drive_len);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
586 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
587 home_dir = mem;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
588 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
589 else
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
590 home_dir = "c:/users/default"; /* poor default */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
591 }
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
592 # else
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
593 if (home_dir == NULL || home_dir[0] == '\0')
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
594 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
595 int success;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
596 char *name;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
597 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
598
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
599 if (buflen == 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
600 /* `sysconf' does not support _SC_LOGIN_NAME_MAX. Try
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
601 a moderate value. */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
602 buflen = 20;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
603 name = __alloca (buflen);
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
604
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
605 success = getlogin_r (name, buflen) == 0;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
606 if (success)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
607 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
608 struct passwd *p;
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
609 # if defined HAVE_GETPWNAM_R || defined _LIBC
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
610 long int pwbuflen = GETPW_R_SIZE_MAX ();
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
611 char *pwtmpbuf;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
612 struct passwd pwbuf;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
613 int save = errno;
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
614
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
615 # ifndef _LIBC
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
616 if (pwbuflen == -1)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
617 /* `sysconf' does not support _SC_GETPW_R_SIZE_MAX.
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
618 Try a moderate value. */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
619 pwbuflen = 1024;
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
620 # endif
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
621 pwtmpbuf = __alloca (pwbuflen);
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
622
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
623 while (getpwnam_r (name, &pwbuf, pwtmpbuf, pwbuflen, &p)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
624 != 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
625 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
626 if (errno != ERANGE)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
627 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
628 p = NULL;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
629 break;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
630 }
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
631 # ifdef _LIBC
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
632 pwtmpbuf = extend_alloca (pwtmpbuf, pwbuflen,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
633 2 * pwbuflen);
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
634 # else
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
635 pwbuflen *= 2;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
636 pwtmpbuf = __alloca (pwbuflen);
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
637 # endif
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
638 __set_errno (save);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
639 }
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
640 # else
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
641 p = getpwnam (name);
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
642 # endif
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
643 if (p != NULL)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
644 home_dir = p->pw_dir;
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 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
647 if (home_dir == NULL || home_dir[0] == '\0')
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
648 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
649 if (flags & GLOB_TILDE_CHECK)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
650 return GLOB_NOMATCH;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
651 else
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
652 home_dir = "~"; /* No luck. */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
653 }
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
654 # endif /* WINDOWS32 */
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
655 # endif
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
656 /* Now construct the full directory. */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
657 if (dirname[1] == '\0')
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
658 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
659 dirname = home_dir;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
660 dirlen = strlen (dirname);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
661 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
662 else
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
663 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
664 char *newp;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
665 size_t home_len = strlen (home_dir);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
666 newp = __alloca (home_len + dirlen);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
667 mempcpy (mempcpy (newp, home_dir, home_len),
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
668 &dirname[1], dirlen);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
669 dirname = newp;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
670 dirlen += home_len - 1;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
671 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
672 dirname_modified = 1;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
673 }
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
674 # 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
675 else
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
676 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
677 char *end_name = strchr (dirname, '/');
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
678 const char *user_name;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
679 const char *home_dir;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
680 char *unescape = NULL;
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
681
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
682 if (!(flags & GLOB_NOESCAPE))
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
683 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
684 if (end_name == NULL)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
685 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
686 unescape = strchr (dirname, '\\');
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
687 if (unescape)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
688 end_name = strchr (unescape, '\0');
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
689 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
690 else
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
691 unescape = memchr (dirname, '\\', end_name - dirname);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
692 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
693 if (end_name == NULL)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
694 user_name = dirname + 1;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
695 else
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
696 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
697 char *newp;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
698 newp = __alloca (end_name - dirname);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
699 *((char *) mempcpy (newp, dirname + 1, end_name - dirname))
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
700 = '\0';
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
701 if (unescape != NULL)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
702 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
703 char *p = mempcpy (newp, dirname + 1,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
704 unescape - dirname - 1);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
705 char *q = unescape;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
706 while (*q != '\0')
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
707 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
708 if (*q == '\\')
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
709 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
710 if (q[1] == '\0')
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
711 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
712 /* "~fo\\o\\" unescape to user_name "foo\\",
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
713 but "~fo\\o\\/" unescape to user_name
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
714 "foo". */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
715 if (filename == NULL)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
716 *p++ = '\\';
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
717 break;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
718 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
719 ++q;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
720 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
721 *p++ = *q++;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
722 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
723 *p = '\0';
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
724 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
725 else
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
726 *((char *) mempcpy (newp, dirname + 1, end_name - dirname))
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
727 = '\0';
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
728 user_name = newp;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
729 }
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
730
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
731 /* Look up specific user's home directory. */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
732 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
733 struct passwd *p;
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
734 # if defined HAVE_GETPWNAM_R || defined _LIBC
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
735 long int buflen = GETPW_R_SIZE_MAX ();
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
736 char *pwtmpbuf;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
737 struct passwd pwbuf;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
738 int save = errno;
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
739
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
740 # ifndef _LIBC
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
741 if (buflen == -1)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
742 /* `sysconf' does not support _SC_GETPW_R_SIZE_MAX. Try a
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
743 moderate value. */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
744 buflen = 1024;
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
745 # endif
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
746 pwtmpbuf = __alloca (buflen);
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
747
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
748 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
749 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
750 if (errno != ERANGE)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
751 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
752 p = NULL;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
753 break;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
754 }
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
755 # ifdef _LIBC
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
756 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
757 # else
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
758 buflen *= 2;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
759 pwtmpbuf = __alloca (buflen);
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
760 # endif
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
761 __set_errno (save);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
762 }
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
763 # else
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
764 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
765 # endif
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
766 if (p != NULL)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
767 home_dir = p->pw_dir;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
768 else
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
769 home_dir = NULL;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
770 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
771 /* If we found a home directory use this. */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
772 if (home_dir != NULL)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
773 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
774 char *newp;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
775 size_t home_len = strlen (home_dir);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
776 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
777 newp = __alloca (home_len + rest_len + 1);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
778 *((char *) mempcpy (mempcpy (newp, home_dir, home_len),
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
779 end_name, rest_len)) = '\0';
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
780 dirname = newp;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
781 dirlen = home_len + rest_len;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
782 dirname_modified = 1;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
783 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
784 else
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
785 if (flags & GLOB_TILDE_CHECK)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
786 /* 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
787 home directory. */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
788 return GLOB_NOMATCH;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
789 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
790 # 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
791 }
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
792
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
793 /* 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
794 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
795 if (filename == NULL)
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
796 {
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
797 struct stat st;
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
798 struct_stat64 st64;
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
799
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
800 /* 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
801 if ((flags & GLOB_NOCHECK)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
802 || (((__builtin_expect (flags & GLOB_ALTDIRFUNC, 0))
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
803 ? ((*pglob->gl_stat) (dirname, &st) == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
804 && S_ISDIR (st.st_mode))
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
805 : (__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
806 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
807 int newcount = pglob->gl_pathc + pglob->gl_offs;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
808 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
809
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
810 new_gl_pathv
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
811 = 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
812 if (new_gl_pathv == NULL)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
813 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
814 nospace:
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
815 free (pglob->gl_pathv);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
816 pglob->gl_pathv = NULL;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
817 pglob->gl_pathc = 0;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
818 return GLOB_NOSPACE;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
819 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
820 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
821
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
822 if (flags & GLOB_MARK)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
823 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
824 char *p;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
825 pglob->gl_pathv[newcount] = malloc (dirlen + 2);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
826 if (pglob->gl_pathv[newcount] == NULL)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
827 goto nospace;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
828 p = mempcpy (pglob->gl_pathv[newcount], dirname, dirlen);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
829 p[0] = '/';
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
830 p[1] = '\0';
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
831 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
832 else
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
833 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
834 pglob->gl_pathv[newcount] = strdup (dirname);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
835 if (pglob->gl_pathv[newcount] == NULL)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
836 goto nospace;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
837 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
838 pglob->gl_pathv[++newcount] = NULL;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
839 ++pglob->gl_pathc;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
840 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
841
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
842 return 0;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
843 }
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
844
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
845 /* Not found. */
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
846 return GLOB_NOMATCH;
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
847 }
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
848
9351
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
849 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
850 /* 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
851 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
852 [ 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
853 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
854 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
855 if (meta & 5)
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
856 {
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
857 /* The directory name contains metacharacters, so we
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
858 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
859 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
860 size_t i;
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
861
9351
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
862 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
863 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
864 /* "foo\\/bar". Remove the final backslash from dirname
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
865 if it has not been quoted. */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
866 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
867
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
868 while (p > dirname && p[-1] == '\\') --p;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
869 if ((&dirname[dirlen] - p) & 1)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
870 *(char *) &dirname[--dirlen] = '\0';
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
871 }
9351
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
872
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
873 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
874 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
875 /* 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
876 call. */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
877 dirs.gl_opendir = pglob->gl_opendir;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
878 dirs.gl_readdir = pglob->gl_readdir;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
879 dirs.gl_closedir = pglob->gl_closedir;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
880 dirs.gl_stat = pglob->gl_stat;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
881 dirs.gl_lstat = pglob->gl_lstat;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
882 }
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
883
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
884 status = glob (dirname,
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
885 ((flags & (GLOB_ERR | GLOB_NOESCAPE
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
886 | GLOB_ALTDIRFUNC))
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
887 | GLOB_NOSORT | GLOB_ONLYDIR),
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
888 errfunc, &dirs);
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
889 if (status != 0)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
890 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
891 if ((flags & GLOB_NOCHECK) == 0 || status != GLOB_NOMATCH)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
892 return status;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
893 goto no_matches;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
894 }
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
895
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
896 /* 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
897 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
898 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
899 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
900 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
901 int old_pathc;
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
902
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
903 #ifdef SHELL
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
904 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
905 /* Make globbing interruptible in the bash shell. */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
906 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
907
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
908 if (interrupt_state)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
909 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
910 globfree (&dirs);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
911 return GLOB_ABORTED;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
912 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
913 }
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
914 #endif /* SHELL. */
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
915
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
916 old_pathc = pglob->gl_pathc;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
917 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
918 ((flags | GLOB_APPEND)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
919 & ~(GLOB_NOCHECK | GLOB_NOMAGIC)),
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
920 errfunc, pglob);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
921 if (status == GLOB_NOMATCH)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
922 /* No matches in this directory. Try the next. */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
923 continue;
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
924
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
925 if (status != 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
926 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
927 globfree (&dirs);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
928 globfree (pglob);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
929 pglob->gl_pathc = 0;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
930 return status;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
931 }
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
932
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
933 /* 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
934 if (prefix_array (dirs.gl_pathv[i],
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
935 &pglob->gl_pathv[old_pathc + pglob->gl_offs],
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
936 pglob->gl_pathc - old_pathc))
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
937 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
938 globfree (&dirs);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
939 globfree (pglob);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
940 pglob->gl_pathc = 0;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
941 return GLOB_NOSPACE;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
942 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
943 }
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
944
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
945 flags |= GLOB_MAGCHAR;
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
946
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
947 /* 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
948 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
949 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
950 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
951 {
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 /* No matches. */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
954 if (flags & GLOB_NOCHECK)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
955 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
956 int newcount = pglob->gl_pathc + pglob->gl_offs;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
957 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
958
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
959 new_gl_pathv = realloc (pglob->gl_pathv,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
960 (newcount + 2) * sizeof (char *));
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
961 if (new_gl_pathv == NULL)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
962 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
963 globfree (&dirs);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
964 return GLOB_NOSPACE;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
965 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
966 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
967
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
968 pglob->gl_pathv[newcount] = strdup (pattern);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
969 if (pglob->gl_pathv[newcount] == NULL)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
970 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
971 globfree (&dirs);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
972 globfree (pglob);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
973 pglob->gl_pathc = 0;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
974 return GLOB_NOSPACE;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
975 }
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
976
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
977 ++pglob->gl_pathc;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
978 ++newcount;
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
979
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
980 pglob->gl_pathv[newcount] = NULL;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
981 pglob->gl_flags = flags;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
982 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
983 else
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
984 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
985 globfree (&dirs);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
986 return GLOB_NOMATCH;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
987 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
988 }
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
989
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
990 globfree (&dirs);
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
991 }
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
992 else
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
993 {
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
994 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
995 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
996
9351
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
997 if (meta & 2)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
998 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
999 char *p = strchr (dirname, '\\'), *q;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1000 /* 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
1001 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
1002 or dirname wouldn't contain backslashes. */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1003 q = p;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1004 do
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1005 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1006 if (*p == '\\')
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1007 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1008 *q = *++p;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1009 --dirlen;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1010 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1011 else
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1012 *q = *p;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1013 ++q;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1014 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1015 while (*p++ != '\0');
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1016 dirname_modified = 1;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1017 }
9351
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
1018 if (dirname_modified)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1019 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
1020 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
1021 if (status != 0)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1022 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1023 if (status == GLOB_NOMATCH && flags != orig_flags
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1024 && pglob->gl_pathc + pglob->gl_offs == oldcount)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1025 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1026 /* Make sure globfree (&dirs); is a nop. */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1027 dirs.gl_pathv = NULL;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1028 flags = orig_flags;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1029 goto no_matches;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1030 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1031 return status;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1032 }
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1033
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1034 if (dirlen > 0)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1035 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1036 /* 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
1037 if (prefix_array (dirname,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1038 &pglob->gl_pathv[old_pathc + pglob->gl_offs],
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1039 pglob->gl_pathc - old_pathc))
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1040 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1041 globfree (pglob);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1042 pglob->gl_pathc = 0;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1043 return GLOB_NOSPACE;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1044 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1045 }
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1046 }
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1047
9351
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
1048 if (flags & GLOB_MARK)
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
1049 {
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
1050 /* Append slashes to directory names. */
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
1051 size_t i;
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
1052 struct stat st;
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
1053 struct_stat64 st64;
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
1054
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
1055 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
1056 if ((__builtin_expect (flags & GLOB_ALTDIRFUNC, 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1057 ? ((*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
1058 && S_ISDIR (st.st_mode))
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1059 : (__stat64 (pglob->gl_pathv[i], &st64) == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1060 && S_ISDIR (st64.st_mode))))
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1061 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1062 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
1063 char *new = realloc (pglob->gl_pathv[i], len);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1064 if (new == NULL)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1065 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1066 globfree (pglob);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1067 pglob->gl_pathc = 0;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1068 return GLOB_NOSPACE;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1069 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1070 strcpy (&new[len - 2], "/");
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1071 pglob->gl_pathv[i] = new;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1072 }
9351
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
1073 }
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
1074
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1075 if (!(flags & GLOB_NOSORT))
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1076 {
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1077 /* Sort the vector. */
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1078 qsort (&pglob->gl_pathv[oldcount],
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1079 pglob->gl_pathc + pglob->gl_offs - oldcount,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1080 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
1081 }
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1082
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1083 return 0;
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1084 }
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1085 #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
1086 libc_hidden_def (glob)
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1087 #endif
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
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1090 #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
1091
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1092 /* Free storage allocated in PGLOB by a previous `glob' call. */
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1093 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
1094 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
1095 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
1096 {
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1097 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
1098 {
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1099 size_t i;
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1100 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
1101 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
1102 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
1103 free (pglob->gl_pathv);
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1104 pglob->gl_pathv = NULL;
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 }
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1107 #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
1108 libc_hidden_def (globfree)
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1109 #endif
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
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1112 /* 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
1113 static int
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1114 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
1115 {
6860
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 *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
1117 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
1118
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1119 if (s1 == s2)
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1120 return 0;
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1121 if (s1 == NULL)
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1122 return 1;
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1123 if (s2 == NULL)
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1124 return -1;
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1125 return strcoll (s1, s2);
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
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1129 /* 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
1130 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
1131 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
1132 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
1133 static int
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1134 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
1135 {
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1136 register size_t i;
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1137 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
1138 #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
1139 int sep_char = '/';
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1140 # 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
1141 #else
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1142 # define DIRSEP_CHAR '/'
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1143 #endif
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1144
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1145 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
1146 /* 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
1147 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
1148 dirlen = 0;
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1149 #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
1150 else if (dirlen > 1)
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1151 {
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1152 if (dirname[dirlen - 1] == '/' && dirname[dirlen - 2] == ':')
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1153 /* 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
1154 --dirlen;
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1155 else if (dirname[dirlen - 1] == ':')
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1156 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1157 /* DIRNAME is "d:". Use `:' instead of `/'. */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1158 --dirlen;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1159 sep_char = ':';
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1160 }
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1161 }
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1162 #endif
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1163
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1164 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
1165 {
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1166 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
1167 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
1168 if (new == NULL)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1169 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1170 while (i > 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1171 free (array[--i]);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1172 return 1;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1173 }
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1174
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1175 {
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1176 char *endp = mempcpy (new, dirname, dirlen);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1177 *endp++ = DIRSEP_CHAR;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1178 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
1179 }
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1180 free (array[i]);
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1181 array[i] = new;
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
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1184 return 0;
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
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1188 /* 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
1189 #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
1190 int
9351
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
1191 __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
1192 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
1193 int quote;
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1194 {
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1195 register const char *p;
9351
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
1196 int ret = 0;
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1197
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1198 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
1199 switch (*p)
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1200 {
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1201 case '?':
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1202 case '*':
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1203 return 1;
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1204
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1205 case '\\':
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1206 if (quote)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1207 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1208 if (p[1] != '\0')
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1209 ++p;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1210 ret |= 2;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1211 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1212 break;
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1213
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1214 case '[':
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1215 ret |= 4;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1216 break;
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1217
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1218 case ']':
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1219 if (ret & 4)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1220 return 1;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1221 break;
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1222 }
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1223
9351
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
1224 return ret;
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
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
1227 /* 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
1228 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
1229 int
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
1230 __glob_pattern_p (pattern, quote)
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
1231 const char *pattern;
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
1232 int quote;
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
1233 {
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
1234 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
1235 }
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1236 # ifdef _LIBC
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1237 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
1238 # endif
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1239 #endif
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1240
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1241 #endif /* !GLOB_ONLY_P */
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1242
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1243
9557
81a0ee2e4e00 Ensure that 'glob' stays under LGPLv2+.
Bruno Haible <bruno@clisp.org>
parents: 9549
diff changeset
1244 #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
1245 /* 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
1246 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
1247 static int
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
1248 __attribute_noinline__
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
1249 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
1250 glob_t *pglob
9557
81a0ee2e4e00 Ensure that 'glob' stays under LGPLv2+.
Bruno Haible <bruno@clisp.org>
parents: 9549
diff changeset
1251 # if !defined _LIBC && !HAVE_FSTATAT
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1252 , int flags
9557
81a0ee2e4e00 Ensure that 'glob' stays under LGPLv2+.
Bruno Haible <bruno@clisp.org>
parents: 9549
diff changeset
1253 # endif
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1254 )
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1255 {
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1256 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
1257 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
1258 struct stat st;
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1259
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1260 mempcpy (mempcpy (mempcpy (fullname, dir, dirlen), "/", 1),
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1261 fname, fnamelen + 1);
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1262
9557
81a0ee2e4e00 Ensure that 'glob' stays under LGPLv2+.
Bruno Haible <bruno@clisp.org>
parents: 9549
diff changeset
1263 # if !defined _LIBC && !HAVE_FSTATAT
81a0ee2e4e00 Ensure that 'glob' stays under LGPLv2+.
Bruno Haible <bruno@clisp.org>
parents: 9549
diff changeset
1264 if (__builtin_expect ((flags & GLOB_ALTDIRFUNC) == 0, 1))
81a0ee2e4e00 Ensure that 'glob' stays under LGPLv2+.
Bruno Haible <bruno@clisp.org>
parents: 9549
diff changeset
1265 {
81a0ee2e4e00 Ensure that 'glob' stays under LGPLv2+.
Bruno Haible <bruno@clisp.org>
parents: 9549
diff changeset
1266 struct_stat64 st64;
81a0ee2e4e00 Ensure that 'glob' stays under LGPLv2+.
Bruno Haible <bruno@clisp.org>
parents: 9549
diff changeset
1267 return __stat64 (fullname, &st64) == 0;
81a0ee2e4e00 Ensure that 'glob' stays under LGPLv2+.
Bruno Haible <bruno@clisp.org>
parents: 9549
diff changeset
1268 }
81a0ee2e4e00 Ensure that 'glob' stays under LGPLv2+.
Bruno Haible <bruno@clisp.org>
parents: 9549
diff changeset
1269 # endif
9351
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
1270 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
1271 }
9357
75e43b0e5159 Modify glob.c to use fstatat and dirfd, to simplify it.
Paul Eggert <eggert@cs.ucla.edu>
parents: 9351
diff changeset
1272
75e43b0e5159 Modify glob.c to use fstatat and dirfd, to simplify it.
Paul Eggert <eggert@cs.ucla.edu>
parents: 9351
diff changeset
1273 /* 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
1274 static int
75e43b0e5159 Modify glob.c to use fstatat and dirfd, to simplify it.
Paul Eggert <eggert@cs.ucla.edu>
parents: 9351
diff changeset
1275 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
1276 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
1277 {
9557
81a0ee2e4e00 Ensure that 'glob' stays under LGPLv2+.
Bruno Haible <bruno@clisp.org>
parents: 9549
diff changeset
1278 # 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
1279 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
1280 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
1281 else
75e43b0e5159 Modify glob.c to use fstatat and dirfd, to simplify it.
Paul Eggert <eggert@cs.ucla.edu>
parents: 9351
diff changeset
1282 {
13676
223800d7ac7d fts, getcwd, glob: audit for dirfd returning -1
Paul Eggert <eggert@cs.ucla.edu>
parents: 12559
diff changeset
1283 /* 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
1284 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
1285 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
1286 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
1287 }
9557
81a0ee2e4e00 Ensure that 'glob' stays under LGPLv2+.
Bruno Haible <bruno@clisp.org>
parents: 9549
diff changeset
1288 # else
81a0ee2e4e00 Ensure that 'glob' stays under LGPLv2+.
Bruno Haible <bruno@clisp.org>
parents: 9549
diff changeset
1289 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
1290 # endif
9357
75e43b0e5159 Modify glob.c to use fstatat and dirfd, to simplify it.
Paul Eggert <eggert@cs.ucla.edu>
parents: 9351
diff changeset
1291 }
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1292 #endif
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1293
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1294
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1295 /* Like `glob', but PATTERN is a final pathname component,
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1296 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
1297 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
1298 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
1299 static int
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1300 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
1301 int (*errfunc) (const char *, int),
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1302 glob_t *pglob)
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1303 {
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1304 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
1305 void *stream = NULL;
9351
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
1306 struct globnames
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1307 {
9351
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
1308 struct globnames *next;
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
1309 size_t count;
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
1310 char *name[64];
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1311 };
9351
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
1312 #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
1313 struct globnames init_names;
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
1314 struct globnames *names = &init_names;
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
1315 struct globnames *names_alloca = &init_names;
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
1316 size_t nfound = 0;
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
1317 size_t allocasize = sizeof (init_names);
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
1318 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
1319 int meta;
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1320 int save;
9351
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
1321 int result;
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1322
9351
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
1323 init_names.next = NULL;
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
1324 init_names.count = INITIAL_COUNT;
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
1325
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
1326 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
1327 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
1328 {
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1329 /* 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
1330 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
1331 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
1332 flags |= GLOB_NOCHECK;
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1333 }
9351
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
1334 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
1335 {
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1336 /* 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
1337 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
1338 struct stat st;
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1339 struct_stat64 st64;
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1340 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
1341 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
1342
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1343 mempcpy (mempcpy (mempcpy (fullname, directory, dirlen),
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1344 "/", 1),
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1345 pattern, patlen + 1);
9351
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
1346 if ((__builtin_expect (flags & GLOB_ALTDIRFUNC, 0)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1347 ? (*pglob->gl_stat) (fullname, &st)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1348 : __stat64 (fullname, &st64)) == 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1349 /* 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
1350 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
1351 flags |= GLOB_NOCHECK;
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1352 }
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1353 else
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1354 {
9351
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
1355 stream = (__builtin_expect (flags & GLOB_ALTDIRFUNC, 0)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1356 ? (*pglob->gl_opendir) (directory)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1357 : opendir (directory));
9351
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
1358 if (stream == NULL)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1359 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1360 if (errno != ENOTDIR
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1361 && ((errfunc != NULL && (*errfunc) (directory, errno))
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1362 || (flags & GLOB_ERR)))
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1363 return GLOB_ABORTED;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1364 }
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1365 else
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1366 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1367 int dfd = (__builtin_expect (flags & GLOB_ALTDIRFUNC, 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1368 ? -1 : dirfd ((DIR *) stream));
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1369 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
1370 | ((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
1371 #if defined _AMIGA || defined VMS
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1372 | FNM_CASEFOLD
9351
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
1373 #endif
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1374 );
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1375 flags |= GLOB_MAGCHAR;
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1376
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1377 while (1)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1378 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1379 const char *name;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1380 size_t len;
9351
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
1381 #if defined _LIBC && !defined COMPILE_GLOB64
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1382 struct dirent64 *d;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1383 union
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1384 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1385 struct dirent64 d64;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1386 char room [offsetof (struct dirent64, d_name[0])
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1387 + NAME_MAX + 1];
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1388 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1389 d64buf;
9351
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
1390
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1391 if (__builtin_expect (flags & GLOB_ALTDIRFUNC, 0))
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1392 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1393 struct dirent *d32 = (*pglob->gl_readdir) (stream);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1394 if (d32 != NULL)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1395 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1396 CONVERT_DIRENT_DIRENT64 (&d64buf.d64, d32);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1397 d = &d64buf.d64;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1398 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1399 else
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1400 d = NULL;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1401 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1402 else
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1403 d = __readdir64 (stream);
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1404 #else
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1405 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
1406 ? ((struct dirent *)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1407 (*pglob->gl_readdir) (stream))
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1408 : __readdir (stream));
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1409 #endif
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1410 if (d == NULL)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1411 break;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1412 if (! REAL_DIR_ENTRY (d))
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1413 continue;
9351
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
1414
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1415 /* 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
1416 provided by the dirent call if possible. */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1417 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
1418 continue;
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1419
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1420 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
1421
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1422 if (fnmatch (pattern, name, fnm_flags) == 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1423 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1424 /* 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
1425 make sure the target file exists. */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1426 if (!DIRENT_MIGHT_BE_SYMLINK (d)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1427 || link_exists_p (dfd, directory, dirlen, name, pglob,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1428 flags))
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1429 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1430 if (cur == names->count)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1431 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1432 struct globnames *newnames;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1433 size_t count = names->count * 2;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1434 size_t size = (sizeof (struct globnames)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1435 + ((count - INITIAL_COUNT)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1436 * sizeof (char *)));
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1437 allocasize += size;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1438 if (__libc_use_alloca (allocasize))
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1439 newnames = names_alloca = __alloca (size);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1440 else if ((newnames = malloc (size))
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1441 == NULL)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1442 goto memory_error;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1443 newnames->count = count;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1444 newnames->next = names;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1445 names = newnames;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1446 cur = 0;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1447 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1448 len = _D_EXACT_NAMLEN (d);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1449 names->name[cur] = malloc (len + 1);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1450 if (names->name[cur] == NULL)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1451 goto memory_error;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1452 *((char *) mempcpy (names->name[cur++], name, len))
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1453 = '\0';
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1454 ++nfound;
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 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1458 }
5898
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
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1461 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
1462 {
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1463 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
1464 nfound = 1;
9351
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
1465 names->name[cur] = malloc (len + 1);
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
1466 if (names->name[cur] == NULL)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1467 goto memory_error;
9351
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
1468 *((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
1469 }
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1470
9351
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
1471 result = GLOB_NOMATCH;
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1472 if (nfound != 0)
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1473 {
9351
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
1474 char **new_gl_pathv
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1475 = realloc (pglob->gl_pathv,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1476 (pglob->gl_pathc + pglob->gl_offs + nfound + 1)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1477 * sizeof (char *));
9351
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
1478 result = 0;
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1479
9351
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
1480 if (new_gl_pathv == NULL)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1481 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1482 memory_error:
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1483 while (1)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1484 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1485 struct globnames *old = names;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1486 size_t i;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1487 for (i = 0; i < cur; ++i)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1488 free (names->name[i]);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1489 names = names->next;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1490 /* 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
1491 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
1492 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
1493 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
1494 if (names == NULL)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1495 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1496 assert (old == &init_names);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1497 break;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1498 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1499 cur = names->count;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1500 if (old == names_alloca)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1501 names_alloca = names;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1502 else
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1503 free (old);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1504 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1505 result = GLOB_NOSPACE;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1506 }
9351
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
1507 else
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1508 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1509 while (1)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1510 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1511 struct globnames *old = names;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1512 size_t i;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1513 for (i = 0; i < cur; ++i)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1514 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
1515 = names->name[i];
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1516 names = names->next;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1517 /* 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
1518 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
1519 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
1520 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
1521 if (names == NULL)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1522 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1523 assert (old == &init_names);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1524 break;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1525 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1526 cur = names->count;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1527 if (old == names_alloca)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1528 names_alloca = names;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1529 else
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1530 free (old);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1531 }
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1532
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1533 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
1534
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1535 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
1536
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1537 pglob->gl_flags = flags;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1538 }
5898
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
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1541 if (stream != NULL)
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1542 {
9351
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
1543 save = errno;
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
1544 if (__builtin_expect (flags & GLOB_ALTDIRFUNC, 0))
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1545 (*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
1546 else
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12002
diff changeset
1547 closedir (stream);
9351
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
1548 __set_errno (save);
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1549 }
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1550
9351
7ab454b59c21 Merge glibc changes into lib/glob.c.
Paul Eggert <eggert@cs.ucla.edu>
parents: 8439
diff changeset
1551 return result;
5898
429b55c14554 * MODULES.html.sh: Add glob to Enhanced POSIX.2001 section.
Derek R. Price <derek@ximbiot.com>
parents:
diff changeset
1552 }