Blame sysdeps/unix/sysv/linux/alpha/oldglob.c

Packit 6c4009
/* Copyright (C) 1998-2018 Free Software Foundation, Inc.
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
Packit 6c4009
   The GNU C Library is free software; you can redistribute it and/or
Packit 6c4009
   modify it under the terms of the GNU Lesser General Public
Packit 6c4009
   License as published by the Free Software Foundation; either
Packit 6c4009
   version 2.1 of the License, or (at your option) any later version.
Packit 6c4009
Packit 6c4009
   The GNU C Library is distributed in the hope that it will be useful,
Packit 6c4009
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c4009
   Lesser General Public License for more details.
Packit 6c4009
Packit 6c4009
   You should have received a copy of the GNU Lesser General Public
Packit 6c4009
   License along with the GNU C Library.  If not, see
Packit 6c4009
   <http://www.gnu.org/licenses/>.  */
Packit 6c4009
Packit 6c4009
/* This file contains only wrappers around the real glob functions.  It
Packit 6c4009
   became necessary since the glob_t structure changed.  */
Packit 6c4009
#include <sys/types.h>
Packit 6c4009
#include <glob.h>
Packit 6c4009
#include <shlib-compat.h>
Packit 6c4009
Packit 6c4009
#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
Packit 6c4009
Packit 6c4009
/* This is the old structure.  The difference is that the gl_pathc and
Packit 6c4009
   gl_offs elements have type `int'.  */
Packit 6c4009
typedef struct
Packit 6c4009
  {
Packit 6c4009
    int gl_pathc;		/* Count of paths matched by the pattern.  */
Packit 6c4009
    char **gl_pathv;		/* List of matched pathnames.  */
Packit 6c4009
    int gl_offs;		/* Slots to reserve in `gl_pathv'.  */
Packit 6c4009
    int gl_flags;		/* Set to FLAGS, maybe | GLOB_MAGCHAR.  */
Packit 6c4009
Packit 6c4009
    /* If the GLOB_ALTDIRFUNC flag is set, the following functions
Packit 6c4009
       are used instead of the normal file access functions.  */
Packit 6c4009
    void (*gl_closedir) (void *);
Packit 6c4009
    struct dirent *(*gl_readdir) (void *);
Packit 6c4009
    void *(*gl_opendir) (const char *);
Packit 6c4009
    int (*gl_lstat) (const char *, struct stat *);
Packit 6c4009
    int (*gl_stat) (const char *, struct stat *);
Packit 6c4009
  } old_glob_t;
Packit 6c4009
Packit 6c4009
Packit 6c4009
int
Packit 6c4009
attribute_compat_text_section
Packit 6c4009
__old_glob (const char *pattern, int flags,
Packit 6c4009
	    int (*errfunc) (const char *, int),
Packit 6c4009
	    old_glob_t *pglob)
Packit 6c4009
{
Packit 6c4009
  glob_t correct;
Packit 6c4009
  int result;
Packit 6c4009
Packit 6c4009
  /* Construct an object of correct type.  */
Packit 6c4009
  correct.gl_pathc = pglob->gl_pathc;
Packit 6c4009
  correct.gl_pathv = pglob->gl_pathv;
Packit 6c4009
  correct.gl_offs = pglob->gl_offs;
Packit 6c4009
  correct.gl_flags = pglob->gl_flags;
Packit 6c4009
  correct.gl_closedir = pglob->gl_closedir;
Packit 6c4009
  correct.gl_readdir = pglob->gl_readdir;
Packit 6c4009
  correct.gl_opendir = pglob->gl_opendir;
Packit 6c4009
  /* Set gl_lstat and gl_stat for both gl_stat for compatibility with old
Packit 6c4009
     implementation that did not follow dangling symlinks.  */
Packit 6c4009
  correct.gl_lstat = pglob->gl_stat;
Packit 6c4009
  correct.gl_stat = pglob->gl_stat;
Packit 6c4009
Packit 6c4009
  result = glob (pattern, flags, errfunc, &correct);
Packit 6c4009
Packit 6c4009
  /* And convert it back.  */
Packit 6c4009
  pglob->gl_pathc = correct.gl_pathc;
Packit 6c4009
  pglob->gl_pathv = correct.gl_pathv;
Packit 6c4009
  pglob->gl_offs = correct.gl_offs;
Packit 6c4009
  pglob->gl_flags = correct.gl_flags;
Packit 6c4009
  pglob->gl_closedir = correct.gl_closedir;
Packit 6c4009
  pglob->gl_readdir = correct.gl_readdir;
Packit 6c4009
  pglob->gl_opendir = correct.gl_opendir;
Packit 6c4009
  /* Only need to restore gl_stat.  */
Packit 6c4009
  pglob->gl_stat = correct.gl_stat;
Packit 6c4009
Packit 6c4009
  return result;
Packit 6c4009
}
Packit 6c4009
compat_symbol (libc, __old_glob, glob, GLIBC_2_0);
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* Free storage allocated in PGLOB by a previous `glob' call.  */
Packit 6c4009
void
Packit 6c4009
attribute_compat_text_section
Packit 6c4009
__old_globfree (old_glob_t *pglob)
Packit 6c4009
{
Packit 6c4009
  glob_t correct;
Packit 6c4009
Packit 6c4009
  /* We only need these two symbols.  */
Packit 6c4009
  correct.gl_pathc = pglob->gl_pathc;
Packit 6c4009
  correct.gl_pathv = pglob->gl_pathv;
Packit 6c4009
  correct.gl_offs = pglob->gl_offs;
Packit 6c4009
Packit 6c4009
  globfree (&correct);
Packit 6c4009
}
Packit 6c4009
compat_symbol (libc, __old_globfree, globfree, GLIBC_2_0);
Packit 6c4009
Packit 6c4009
#endif