1/* Copyright (C) 1998-2022 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3
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.
8
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.
13
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/>. */
17
18/* This file contains only wrappers around the real glob functions. It
19 became necessary since the glob_t structure changed. */
20#include <sys/types.h>
21#include <glob.h>
22#include <shlib-compat.h>
23
24#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
25
26/* This is the old structure. The difference is that the gl_pathc and
27 gl_offs elements have type `int'. */
28typedef struct
29 {
30 int gl_pathc; /* Count of paths matched by the pattern. */
31 char **gl_pathv; /* List of matched pathnames. */
32 int gl_offs; /* Slots to reserve in `gl_pathv'. */
33 int gl_flags; /* Set to FLAGS, maybe | GLOB_MAGCHAR. */
34
35 /* If the GLOB_ALTDIRFUNC flag is set, the following functions
36 are used instead of the normal file access functions. */
37 void (*gl_closedir) (void *);
38 struct dirent *(*gl_readdir) (void *);
39 void *(*gl_opendir) (const char *);
40 int (*gl_lstat) (const char *, struct stat *);
41 int (*gl_stat) (const char *, struct stat *);
42 } old_glob_t;
43
44
45int
46attribute_compat_text_section
47__old_glob (const char *pattern, int flags,
48 int (*errfunc) (const char *, int),
49 old_glob_t *pglob)
50{
51 glob_t correct;
52 int result;
53
54 /* Construct an object of correct type. */
55 correct.gl_pathc = pglob->gl_pathc;
56 correct.gl_pathv = pglob->gl_pathv;
57 correct.gl_offs = pglob->gl_offs;
58 correct.gl_flags = pglob->gl_flags;
59 correct.gl_closedir = pglob->gl_closedir;
60 correct.gl_readdir = pglob->gl_readdir;
61 correct.gl_opendir = pglob->gl_opendir;
62 /* Set gl_lstat and gl_stat for both gl_stat for compatibility with old
63 implementation that did not follow dangling symlinks. */
64 correct.gl_lstat = pglob->gl_stat;
65 correct.gl_stat = pglob->gl_stat;
66
67 result = glob (pattern, flags, errfunc, &correct);
68
69 /* And convert it back. */
70 pglob->gl_pathc = correct.gl_pathc;
71 pglob->gl_pathv = correct.gl_pathv;
72 pglob->gl_offs = correct.gl_offs;
73 pglob->gl_flags = correct.gl_flags;
74 pglob->gl_closedir = correct.gl_closedir;
75 pglob->gl_readdir = correct.gl_readdir;
76 pglob->gl_opendir = correct.gl_opendir;
77 /* Only need to restore gl_stat. */
78 pglob->gl_stat = correct.gl_stat;
79
80 return result;
81}
82compat_symbol (libc, __old_glob, glob, GLIBC_2_0);
83
84
85/* Free storage allocated in PGLOB by a previous `glob' call. */
86void
87attribute_compat_text_section
88__old_globfree (old_glob_t *pglob)
89{
90 glob_t correct;
91
92 /* We only need these two symbols. */
93 correct.gl_pathc = pglob->gl_pathc;
94 correct.gl_pathv = pglob->gl_pathv;
95 correct.gl_offs = pglob->gl_offs;
96
97 globfree (&correct);
98}
99compat_symbol (libc, __old_globfree, globfree, GLIBC_2_0);
100
101#endif
102

source code of glibc/sysdeps/unix/sysv/linux/alpha/oldglob.c