This is the mail archive of the libc-hacker@sourceware.cygnus.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Implementation of glob64


Hi,

Here is my implementation of glob64.  Since the glob code is used by a
few other GNU packages, all use of the glibc macros that flag the
level of LFS support are protected by checking for __GLIBC__ to be
defined first.

Currently there is only support for Linux.  For obvious reasons,
Linux/alpha and Linux/sparc64 are untested.

I tested this patch with make-3.77.  After copying `posix/glob.h' and
`sysdeps/generic/glob.c' from `glibc' over to the `glob' directory of
the `make' distribution, and applying the patch for Solaris 2.6 posted
to gnu.utils.bug by Paul Eggert to `configure.in' in the `glob'
directory, it works without problems.

Mark

PS Applying this patch needs my previous ``preparation'' patch.
Otherwise you'll get problems with multiple defined macros and
compilation will fail.


1998-08-09  Mark Kettenis  <kettenis@phys.uva.nl>

	* posix/glob.h [__GLIBC__]: Include <features.h>.  Add LFS support
	for glob and globfree.
	* posix/Versions [GLIBC_2.1]: Add glob64 and globfree64.
	* posix/Makefile (routines): Add glob64.
	* sysdeps/generic/glob64.c: New file.
	* sysdeps/unix/sysv/linux/glob64.c: New file.
	* sysdeps/unix/sysv/linux/alpha/glob64.c: New file.
	* sysdeps/unix/sysv/linux/sparc/sparc64/glob64.c: New file.
	* sysdeps/generic/glob.c [_LIBC && glob] (__glob_pattern_p):
	Elide function. 
	* sysdeps/unix/sysv/linux/alpha/glob.c: Add glob64 as a weak alias
	for __new_glob.  Likewise for globfree64.
	* sysdeps/unix/sysv/linux/sparc/sparc64/glob.c: New file.


Index: posix/Makefile
--- 0.4/posix/Makefile Sun, 09 Aug 1998 14:24:02 +0200 kettenis (libc/27_Makefile 1.1 666)
+++ Local.6(w)/posix/Makefile Sat, 08 Aug 1998 23:07:09 +0200 kettenis (libc/27_Makefile 1.2 666)
@@ -44,7 +44,7 @@
 	getpgid setpgid getpgrp bsd-getpgrp setpgrp getsid setsid	      \
 	getlogin getlogin_r setlogin					      \
 	pathconf sysconf fpathconf					      \
-	glob fnmatch regex						      \
+	glob glob64 fnmatch regex					      \
 	confstr								      \
 	getopt getopt1 getopt_init					      \
 	sched_setp sched_getp sched_sets sched_gets sched_yield sched_primax  \
Index: posix/Versions
--- 0.4/posix/Versions Sun, 09 Aug 1998 14:24:02 +0200 kettenis (libc/28_Versions 1.1 666)
+++ Local.6(w)/posix/Versions Sun, 09 Aug 1998 00:13:56 +0200 kettenis (libc/28_Versions 1.2 666)
@@ -73,7 +73,7 @@
     __pread64; __pwrite64;
 
     # g*
-    gai_strerror; getnameinfo;
+    gai_strerror; getnameinfo; glob64; globfree64;
 
     # p*
     pread; pread64; pwrite; pwrite64;
Index: posix/glob.h
--- 0.4/posix/glob.h Sun, 09 Aug 1998 14:24:02 +0200 kettenis (libc/29_glob.h 1.1 666)
+++ Local.6(w)/posix/glob.h Sun, 09 Aug 1998 03:55:34 +0200 kettenis (libc/29_glob.h 1.2 666)
@@ -18,6 +18,10 @@
 #ifndef	_GLOB_H
 #define	_GLOB_H	1
 
+#ifdef __GLIBC__
+# include <features.h>
+#endif
+
 #ifdef	__cplusplus
 extern "C" {
 #endif
@@ -112,6 +116,25 @@
     int (*gl_stat) __PMT ((__const char *, struct stat *));
   } glob_t;
 
+#if defined __GLIBC__ && defined __USE_LARGEFILE64
+struct stat64;
+typedef struct
+  {
+    size_t gl_pathc;
+    char **gl_pathv;
+    size_t gl_offs;
+    int gl_flags;
+
+    /* If the GLOB_ALTDIRFUNC flag is set, the following functions
+       are used instead of the normal file access functions.  */
+    void (*gl_closedir) __PMT ((void *));
+    struct dirent64 *(*gl_readdir) __PMT ((void *));
+    __ptr_t (*gl_opendir) __PMT ((__const char *));
+    int (*gl_lstat) __PMT ((__const char *, struct stat64 *));
+    int (*gl_stat) __PMT ((__const char *, struct stat64 *));
+  } glob64_t;
+#endif
+  
 /* Do glob searching for PATTERN, placing results in PGLOB.
    The bits defined above may be set in FLAGS.
    If a directory cannot be opened or read and ERRFUNC is not nil,
@@ -120,12 +143,42 @@
    `glob' returns GLOB_ABEND; if it returns zero, the error is ignored.
    If memory cannot be allocated for PGLOB, GLOB_NOSPACE is returned.
    Otherwise, `glob' returns zero.  */
+#if !defined __GLIBC__ || !defined __USE_FILE_OFFSET64
 extern int glob __P ((__const char *__pattern, int __flags,
 		      int (*__errfunc) __P ((__const char *, int)),
 		      glob_t *__pglob));
+#else
+# if defined __GLIBC__ && defined __REDIRECT
+extern int __REDIRECT (glob,
+		       __P ((__const char *__pattern, int __flags,
+			     int (*__errfunc) __P ((__const char *, int)),
+			     glob_t *__pglob)),
+		       glob64);
+# else
+#  define glob glob64
+# endif
+#endif
+#if defined __GLIBC__ && defined __USE_LARGEFILE64
+extern int glob64 __P ((__const char *__pattern, int __flags,
+			int (*__errfunc) __P ((__const char *, int)),
+			glob64_t *__pglob));
+#endif
 
 /* Free storage allocated in PGLOB by a previous `glob' call.  */
+#if !defined __GLIBC__ || !defined __USE_FILE_OFFSET64
 extern void globfree __P ((glob_t *__pglob));
+#else
+# if defined __GLIBC__ && defined __REDIRECT
+extern void __REDIRECT (globfree,
+		       __P ((glob_t *__pglob)),
+		       globfree64);
+# else
+#  define globfree globfree64
+# endif
+#endif
+#if defined __GLIBC__ && defined __USE_LARGEFILE64
+extern void globfree64 __P ((glob64_t *__pglob));
+#endif
 
 
 #ifdef _GNU_SOURCE
Index: sysdeps/unix/sysv/linux/alpha/glob.c
--- 0.4/sysdeps/unix/sysv/linux/alpha/glob.c Sun, 09 Aug 1998 14:24:02 +0200 kettenis (libc/30_glob.c 1.1 666)
+++ Local.6(w)/sysdeps/unix/sysv/linux/alpha/glob.c Sun, 09 Aug 1998 00:23:53 +0200 kettenis (libc/30_glob.c 1.2 666)
@@ -15,6 +15,9 @@
    write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.  */
 
+#define glob64 __no_glob64_decl
+#define globfree64 __no_globfree64_decl
+
 #include <sys/types.h>
 #include <glob.h>
 
@@ -37,3 +40,6 @@
 
 default_symbol_version(__new_glob, glob, GLIBC_2.1);
 default_symbol_version(__new_globfree, globfree, GLIBC_2.1);
+
+weak_alias (__new_glob, glob64)
+weak_alias (__new_globfree, globfree64)
Index: sysdeps/generic/glob.c
--- 0.4/sysdeps/generic/glob.c Sun, 09 Aug 1998 14:24:02 +0200 kettenis (libc/31_glob.c 1.1 666)
+++ Local.6(w)/sysdeps/generic/glob.c Sun, 09 Aug 1998 14:31:02 +0200 kettenis (libc/31_glob.c 1.2 666)
@@ -1121,6 +1121,7 @@
 }
 
 
+#if !defined _LIBC || !defined glob
 /* Return nonzero if PATTERN contains any metacharacters.
    Metacharacters can be quoted with backslashes if QUOTE is nonzero.  */
 int
@@ -1155,10 +1156,10 @@
 
   return 0;
 }
-#ifdef _LIBC
+# ifdef _LIBC
 weak_alias (__glob_pattern_p, glob_pattern_p)
+# endif
 #endif
-
 
 /* Like `glob', but PATTERN is a final pathname component,
    and matches are searched for in DIRECTORY.
Index: sysdeps/unix/sysv/linux/sparc/sparc64/glob.c
--- libc/sysdeps/unix/sysv/linux/sparc/sparc64/glob.c Sun, 09 Aug 1998 15:40:47 +0200 kettenis ()
+++ libc/sysdeps/unix/sysv/linux/sparc/sparc64/glob.c Sun, 09 Aug 1998 00:22:55 +0200 kettenis (libc/32_glob.c 1.1 644)
@@ -0,0 +1,7 @@
+#define glob64 __no_glob64_decl
+#define globfree64 __no_globfree64_decl
+#include <sysdeps/generic/glob.c>
+#undef glob64
+#undef globfree64
+weak_alias (glob, glob64)
+weak_alias (globfree, globfree64)
Index: sysdeps/unix/sysv/linux/sparc/sparc64/glob64.c
--- libc/sysdeps/unix/sysv/linux/sparc/sparc64/glob64.c Sun, 09 Aug 1998 15:40:47 +0200 kettenis ()
+++ libc/sysdeps/unix/sysv/linux/sparc/sparc64/glob64.c Sun, 09 Aug 1998 00:17:32 +0200 kettenis (libc/33_glob64.c 1.1 644)
@@ -0,0 +1 @@
+/* glob64 is in glob.c */
Index: sysdeps/unix/sysv/linux/alpha/glob64.c
--- libc/sysdeps/unix/sysv/linux/alpha/glob64.c Sun, 09 Aug 1998 15:40:47 +0200 kettenis ()
+++ libc/sysdeps/unix/sysv/linux/alpha/glob64.c Sun, 09 Aug 1998 00:15:35 +0200 kettenis (libc/34_glob64.c 1.1 644)
@@ -0,0 +1 @@
+/* glob64 is in glob.c */
Index: sysdeps/unix/sysv/linux/glob64.c
--- libc/sysdeps/unix/sysv/linux/glob64.c Sun, 09 Aug 1998 15:40:47 +0200 kettenis ()
+++ libc/sysdeps/unix/sysv/linux/glob64.c Sun, 09 Aug 1998 00:40:10 +0200 kettenis (libc/35_glob64.c 1.1 644)
@@ -0,0 +1,18 @@
+#include <dirent.h>
+#include <glob.h>
+#include <sys/stat.h>
+
+#define dirent dirent64
+#define __readdir(dirp) __readdir64(dirp)
+		
+#define glob_t glob64_t
+#define glob(pattern, flags, errfunc, pglob) \
+  glob64 (pattern, flags, errfunc, pglob)
+#define globfree(pglob) globfree64 (pglob)
+
+#undef stat
+#define stat stat64
+#undef __stat
+#define __stat(file, buf) stat64(file, buf)
+
+#include <sysdeps/generic/glob.c>
Index: sysdeps/generic/glob64.c
--- libc/sysdeps/generic/glob64.c Sun, 09 Aug 1998 15:40:47 +0200 kettenis ()
+++ libc/sysdeps/generic/glob64.c Sat, 08 Aug 1998 22:29:10 +0200 kettenis (libc/36_glob64.c 1.1 644)
@@ -0,0 +1,47 @@
+/* Copyright (C) 1998 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Library General Public License as
+   published by the Free Software Foundation; either version 2 of the
+   License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with the GNU C Library; see the file COPYING.LIB.  If not,
+   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
+
+/* Do glob searching for PATTERN, placing results in PGLOB.
+   The bits defined above may be set in FLAGS.
+   If a directory cannot be opened or read and ERRFUNC is not nil,
+   it is called with the pathname that caused the error, and the
+   `errno' value from the failing call; if it returns non-zero
+   `glob' returns GLOB_ABORTED; if it returns zero, the error is ignored.
+   If memory cannot be allocated for PGLOB, GLOB_NOSPACE is returned.
+   Otherwise, `glob' returns zero.  */
+int
+glob64 (const char *pattern, int flags,
+	int (*errfunc) (const char *, int), glib64_t *pglob);
+{
+  if (pattern == NULL || pglob == NULL || (flags & ~__GLOB_FLAGS) != 0)
+    {
+      __set_errno (EINVAL);
+      return -1;
+    }
+
+  __set_errno (ENOSYS);
+  return -1;
+}
+
+void
+globfree64 (glob64_t *pglob)
+{
+}
+
+stub_warning (glob64)
+#include <stub-tag.h>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]