Back to index

glibc  2.9
oldglob.c
Go to the documentation of this file.
00001 /* Copyright (C) 1998, 2000, 2004, 2005 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003 
00004    The GNU C Library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Lesser General Public
00006    License as published by the Free Software Foundation; either
00007    version 2.1 of the License, or (at your option) any later version.
00008 
00009    The GNU C Library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Lesser General Public License for more details.
00013 
00014    You should have received a copy of the GNU Lesser General Public
00015    License along with the GNU C Library; if not, write to the Free
00016    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00017    02111-1307 USA.  */
00018 
00019 /* This file contains only wrappers around the real glob functions.  It
00020    became necessary since the glob_t structure changed.  */
00021 #include <sys/types.h>
00022 #include <glob.h>
00023 #include <shlib-compat.h>
00024 
00025 #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
00026 
00027 /* This is the old structure.  The difference is that the gl_pathc and
00028    gl_offs elements have type `int'.  */
00029 typedef struct
00030   {
00031     int gl_pathc;           /* Count of paths matched by the pattern.  */
00032     char **gl_pathv;        /* List of matched pathnames.  */
00033     int gl_offs;            /* Slots to reserve in `gl_pathv'.  */
00034     int gl_flags;           /* Set to FLAGS, maybe | GLOB_MAGCHAR.  */
00035 
00036     /* If the GLOB_ALTDIRFUNC flag is set, the following functions
00037        are used instead of the normal file access functions.  */
00038     void (*gl_closedir) (void *);
00039     struct dirent *(*gl_readdir) (void *);
00040     __ptr_t (*gl_opendir) (__const char *);
00041     int (*gl_lstat) (__const char *, struct stat *);
00042     int (*gl_stat) (__const char *, struct stat *);
00043   } old_glob_t;
00044 
00045 
00046 int
00047 attribute_compat_text_section
00048 __old_glob (const char *pattern, int flags,
00049            int (*errfunc) (const char *, int),
00050            old_glob_t *pglob)
00051 {
00052   glob_t correct;
00053   int result;
00054 
00055   /* Construct an object of correct type.  */
00056   correct.gl_pathc = pglob->gl_pathc;
00057   correct.gl_pathv = pglob->gl_pathv;
00058   correct.gl_offs = pglob->gl_offs;
00059   correct.gl_flags = pglob->gl_flags;
00060   correct.gl_closedir = pglob->gl_closedir;
00061   correct.gl_readdir = pglob->gl_readdir;
00062   correct.gl_opendir = pglob->gl_opendir;
00063   correct.gl_lstat = pglob->gl_lstat;
00064   correct.gl_stat = pglob->gl_stat;
00065 
00066   result = glob (pattern, flags, errfunc, &correct);
00067 
00068   /* And convert it back.  */
00069   pglob->gl_pathc = correct.gl_pathc;
00070   pglob->gl_pathv = correct.gl_pathv;
00071   pglob->gl_offs = correct.gl_offs;
00072   pglob->gl_flags = correct.gl_flags;
00073   pglob->gl_closedir = correct.gl_closedir;
00074   pglob->gl_readdir = correct.gl_readdir;
00075   pglob->gl_opendir = correct.gl_opendir;
00076   pglob->gl_lstat = correct.gl_lstat;
00077   pglob->gl_stat = correct.gl_stat;
00078 
00079   return result;
00080 }
00081 compat_symbol (libc, __old_glob, glob, GLIBC_2_0);
00082 
00083 
00084 /* Free storage allocated in PGLOB by a previous `glob' call.  */
00085 void
00086 attribute_compat_text_section
00087 __old_globfree (old_glob_t *pglob)
00088 {
00089   glob_t correct;
00090 
00091   /* We only need these two symbols.  */
00092   correct.gl_pathc = pglob->gl_pathc;
00093   correct.gl_pathv = pglob->gl_pathv;
00094   correct.gl_offs = pglob->gl_offs;
00095 
00096   globfree (&correct);
00097 }
00098 compat_symbol (libc, __old_globfree, globfree, GLIBC_2_0);
00099 
00100 #endif