1 /* Copyright (C) 1997-2024 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <https://www.gnu.org/licenses/>. */
25 main (int argc
, char *argv
[])
34 while ((i
= getopt (argc
, argv
, "bcdeEgmopqstT")) != -1)
38 glob_flags
|= GLOB_BRACE
;
41 glob_flags
|= GLOB_NOCHECK
;
44 glob_flags
|= GLOB_ONLYDIR
;
47 glob_flags
|= GLOB_NOESCAPE
;
50 glob_flags
|= GLOB_ERR
;
53 glob_flags
|= GLOB_NOMAGIC
;
56 glob_flags
|= GLOB_MARK
;
59 glob_flags
|= GLOB_DOOFFS
;
63 glob_flags
|= GLOB_PERIOD
;
69 glob_flags
|= GLOB_NOSORT
;
72 glob_flags
|= GLOB_TILDE
;
75 glob_flags
|= GLOB_TILDE_CHECK
;
81 if (optind
>= argc
|| chdir (argv
[optind
]))
85 if (optind
+ 1 >= argc
)
88 /* Do a glob on each remaining argument. */
89 for (j
= optind
+ 1; j
< argc
; j
++) {
90 i
= glob (argv
[j
], glob_flags
, NULL
, &g
);
93 glob_flags
|= GLOB_APPEND
;
96 /* Was there an error? */
97 if (i
== GLOB_NOSPACE
)
98 puts ("GLOB_NOSPACE");
99 else if (i
== GLOB_ABORTED
)
100 puts ("GLOB_ABORTED");
101 else if (i
== GLOB_NOMATCH
)
102 puts ("GLOB_NOMATCH");
104 /* If we set an offset, fill in the first field.
105 (Unless glob() has filled it in already - which is an error) */
106 if ((glob_flags
& GLOB_DOOFFS
) && g
.gl_pathv
[0] == NULL
)
107 g
.gl_pathv
[0] = (char *) "abc";
109 /* Print out the names. Unless otherwise specified, quote them. */
112 for (i
= 0; i
< g
.gl_offs
+ g
.gl_pathc
; ++i
)
113 printf ("%s%s%s\n", quotes
? "`" : "",
114 g
.gl_pathv
[i
] ? g
.gl_pathv
[i
] : "(null)",