1 diff -urN proftpd-1.2.1/Make.rules.in proftpd-1.2/Make.rules.in
2 --- proftpd-1.2.1/Make.rules.in Thu Feb 22 05:51:10 2001
3 +++ proftpd-1.2/Make.rules.in Mon Mar 19 23:11:35 2001
5 src/support.o src/inet.o src/log.o src/io.o src/ident.o \
6 src/data.o src/modules.o src/auth.o src/fs.o
8 -LIB_OBJS=getopt.o getopt1.o pr_fnmatch.o strsep.o vsnprintf.o glob.o pwgrent.o
9 +LIB_OBJS=getopt.o getopt1.o pr_fnmatch.o strsep.o vsnprintf.o glibc-glob.o pwgrent.o
11 FTPCOUNT_OBJS=ftpcount.o pool.o log.o utils.o
12 BUILD_FTPCOUNT_OBJS=src/ftpcount.o src/pool.o src/log.o src/utils.o
13 diff -urN proftpd-1.2.1/acconfig.h proftpd-1.2/acconfig.h
14 --- proftpd-1.2.1/acconfig.h Wed Feb 14 05:12:48 2001
15 +++ proftpd-1.2/acconfig.h Mon Mar 19 23:11:35 2001
17 /* Define if you have BSD sendfile() semantics */
18 #undef HAVE_BSD_SENDFILE
20 -/* Define if you have the <glob.h> header file. */
23 -/* Define if your <glob.h> defines GLOB_PERIOD macro. */
24 -#undef HAVE_GLOB_PERIOD
26 /* Define if you have Linux sendfile() semantics */
27 #undef HAVE_LINUX_SENDFILE
29 diff -urN proftpd-1.2.1/config.h.in proftpd-1.2/config.h.in
30 --- proftpd-1.2.1/config.h.in Fri Feb 23 03:47:26 2001
31 +++ proftpd-1.2/config.h.in Mon Mar 19 23:11:35 2001
33 /* Define if you have BSD sendfile() semantics */
34 #undef HAVE_BSD_SENDFILE
36 -/* Define if you have the <glob.h> header file. */
39 -/* Define if your <glob.h> defines GLOB_PERIOD macro. */
40 -#undef HAVE_GLOB_PERIOD
42 /* Define if you have Linux sendfile() semantics */
43 #undef HAVE_LINUX_SENDFILE
46 /* Define if you have the gettimeofday function. */
47 #undef HAVE_GETTIMEOFDAY
49 -/* Define if you have the glob function. */
52 /* Define if you have the inet_aton function. */
57 /* Define if you have the <libutil.h> header file. */
60 +/* Define if you have the <limits.h> header file. */
63 /* Define if you have the <memory.h> header file. */
65 diff -urN proftpd-1.2.1/configure.in proftpd-1.2/configure.in
66 --- proftpd-1.2.1/configure.in Thu Mar 1 04:18:43 2001
67 +++ proftpd-1.2/configure.in Mon Mar 19 23:11:35 2001
72 -AC_CHECK_HEADERS(ctype.h getopt.h crypt.h bstring.h strings.h)
73 +AC_CHECK_HEADERS(ctype.h getopt.h crypt.h bstring.h strings.h limits.h)
74 AC_CHECK_HEADERS(sys/types.h sys/param.h sys/file.h sys/uio.h)
75 AC_CHECK_HEADERS(netdb.h netinet/in.h netinet/tcp.h arpa/inet.h sys/stat.h)
76 AC_CHECK_HEADERS(errno.h sys/socket.h sys/termios.h sys/termio.h)
77 AC_CHECK_HEADERS(sys/statvfs.h sys/vfs.h sys/select.h)
78 AC_CHECK_HEADERS(utmpx.h)
79 AC_CHECK_HEADERS(regex.h)
80 -AC_CHECK_HEADER(glob.h,have_glob_h="yes",)
81 AC_CHECK_HEADER(syslog.h,have_syslog_h="yes",)
83 dnl Checks for typedefs, structures, and compiler characteristics.
88 -if test "$have_glob_h" = "yes"; then
89 - dnl See if we have GLOB_PERIOD
90 - AC_CACHE_CHECK(whether your glob.h defines GLOB_PERIOD,
91 - pr_cv_header_glob_period,
97 - ],pr_cv_header_glob_period="yes",pr_cv_header_glob_period="no"))
99 - dnl See if we have GLOB_ALTDIRFUNC
100 - if test "$pr_cv_header_glob_period" = "yes"; then
101 - AC_CACHE_CHECK(whether your glob.h defines GLOB_ALTDIRFUNC,
102 - pr_cv_header_glob_altdirfunc,
105 -#ifdef GLOB_ALTDIRFUNC
108 - ],pr_cv_header_glob_altdirfunc="yes",pr_cv_header_glob_altdirfunc="no"))
110 - if test "$pr_cv_header_glob_altdirfunc" = "yes"; then
111 - AC_DEFINE(HAVE_GLOB_H)
112 - AC_DEFINE(HAVE_GLOB_PERIOD)
117 dnl See if various LOG_ macros are defined
118 if test "$have_syslog_h" = "yes"; then
119 AC_DEFINE(HAVE_SYSLOG_H)
121 AC_DEFINE(HAVE_BSD_SENDFILE)
126 -dnl Only check for glob if we have glob.h, GLOB_PERIOD, and GLOB_ALTDIRFUNC
127 -if test "$have_glob_h" = "yes" && \
128 - test "$pr_cv_header_glob_period" = "yes" && \
129 - test "$pr_cv_header_glob_altdirfunc" = "yes"; then
130 - AC_CHECK_FUNCS(glob)
133 dnl Check for various argv[] replacing functions on various OSs
134 diff -urN proftpd-1.2.1/include/conf.h proftpd-1.2/include/conf.h
135 --- proftpd-1.2.1/include/conf.h Sun Aug 13 17:19:39 2000
136 +++ proftpd-1.2/include/conf.h Mon Mar 19 23:11:35 2001
140 /* Generic configuration and standard header file includes.
157 diff -urN proftpd-1.2.1/include/glibc-glob.h proftpd-1.2/include/glibc-glob.h
158 --- proftpd-1.2.1/include/glibc-glob.h Thu Jan 1 01:00:00 1970
159 +++ proftpd-1.2/include/glibc-glob.h Thu Mar 22 14:43:36 2001
161 +/* Copyright (C) 1991,92,95,96,97,98,2000,2001 Free Software Foundation, Inc.
163 + The GNU C Library is free software; you can redistribute it and/or
164 + modify it under the terms of the GNU Library General Public License as
165 + published by the Free Software Foundation; either version 2 of the
166 + License, or (at your option) any later version.
168 + The GNU C Library is distributed in the hope that it will be useful,
169 + but WITHOUT ANY WARRANTY; without even the implied warranty of
170 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
171 + Library General Public License for more details.
173 + You should have received a copy of the GNU Library General Public
174 + License along with the GNU C Library; see the file COPYING.LIB. If not,
175 + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
176 + Boston, MA 02111-1307, USA. */
186 +#if defined __cplusplus || (defined __STDC__ && __STDC__) || defined WINDOWS32
187 +# if !defined __GLIBC__ || !defined __P
190 +# define __P(protos) protos
191 +# define __PMT(protos) protos
192 +# if !defined __GNUC__ || __GNUC__ < 2
194 +# define __const const
197 +# define __ptr_t void *
198 +#else /* Not C++ or ANSI C. */
201 +# define __P(protos) ()
202 +# define __PMT(protos) ()
205 +# define __ptr_t char *
206 +#endif /* C++ or ANSI C. */
208 +/* We need `size_t' for the following definitions. */
210 +# if defined __GNUC__ && __GNUC__ >= 2
211 +typedef __SIZE_TYPE__ __size_t;
212 +# ifdef _XOPEN_SOURCE
213 +typedef __SIZE_TYPE__ size_t;
216 +/* This is a guess. */
217 +typedef unsigned long int __size_t;
220 +/* The GNU CC stddef.h version defines __size_t as empty. We need a real
223 +# define __size_t size_t
226 +/* Bits set in the FLAGS argument to `glob'. */
227 +#define GLOB_ERR (1 << 0)/* Return on read errors. */
228 +#define GLOB_MARK (1 << 1)/* Append a slash to each name. */
229 +#define GLOB_NOSORT (1 << 2)/* Don't sort the names. */
230 +#define GLOB_DOOFFS (1 << 3)/* Insert PGLOB->gl_offs NULLs. */
231 +#define GLOB_NOCHECK (1 << 4)/* If nothing matches, return the pattern. */
232 +#define GLOB_APPEND (1 << 5)/* Append to results of a previous call. */
233 +#define GLOB_NOESCAPE (1 << 6)/* Backslashes don't quote metacharacters. */
234 +#define GLOB_PERIOD (1 << 7)/* Leading `.' can be matched by metachars. */
236 +#if (!defined _POSIX_C_SOURCE || _POSIX_C_SOURCE < 2 || defined _BSD_SOURCE \
237 + || defined _GNU_SOURCE)
238 +# define GLOB_MAGCHAR (1 << 8)/* Set in gl_flags if any metachars seen. */
239 +# define GLOB_ALTDIRFUNC (1 << 9)/* Use gl_opendir et al functions. */
240 +# define GLOB_BRACE (1 << 10)/* Expand "{a,b}" to "a" "b". */
241 +# define GLOB_NOMAGIC (1 << 11)/* If no magic chars, return the pattern. */
242 +# define GLOB_TILDE (1 << 12)/* Expand ~user and ~ to home directories. */
243 +# define GLOB_ONLYDIR (1 << 13)/* Match only directories. */
244 +# define GLOB_TILDE_CHECK (1 << 14)/* Like GLOB_TILDE but return an error
245 + if the user name is not available. */
246 +# define __GLOB_FLAGS (GLOB_ERR|GLOB_MARK|GLOB_NOSORT|GLOB_DOOFFS| \
247 + GLOB_NOESCAPE|GLOB_NOCHECK|GLOB_APPEND| \
248 + GLOB_PERIOD|GLOB_ALTDIRFUNC|GLOB_BRACE| \
249 + GLOB_NOMAGIC|GLOB_TILDE|GLOB_ONLYDIR|GLOB_TILDE_CHECK)
251 +# define __GLOB_FLAGS (GLOB_ERR|GLOB_MARK|GLOB_NOSORT|GLOB_DOOFFS| \
252 + GLOB_NOESCAPE|GLOB_NOCHECK|GLOB_APPEND| \
256 +/* Error returns from `glob'. */
257 +#define GLOB_NOSPACE 1 /* Ran out of memory. */
258 +#define GLOB_ABORTED 2 /* Read error. */
259 +#define GLOB_NOMATCH 3 /* No matches found. */
260 +#define GLOB_NOSYS 4 /* Not implemented. */
262 +/* Previous versions of this file defined GLOB_ABEND instead of
263 + GLOB_ABORTED. Provide a compatibility definition here. */
264 +# define GLOB_ABEND GLOB_ABORTED
267 +/* Structure describing a globbing run. */
268 +#if !defined _AMIGA && !defined VMS /* Buggy compiler. */
275 + __size_t gl_pathc; /* Count of paths matched by the pattern. */
276 + char **gl_pathv; /* List of matched pathnames. */
277 + __size_t gl_offs; /* Slots to reserve in `gl_pathv'. */
278 + int gl_flags; /* Set to FLAGS, maybe | GLOB_MAGCHAR. */
280 + /* If the GLOB_ALTDIRFUNC flag is set, the following functions
281 + are used instead of the normal file access functions. */
282 + void (*gl_closedir) __PMT ((void *));
284 + struct dirent *(*gl_readdir) __PMT ((void *));
286 + void *(*gl_readdir) __PMT ((void *));
288 + __ptr_t (*gl_opendir) __PMT ((__const char *));
290 + int (*gl_lstat) __PMT ((__const char *,
292 + int (*gl_stat) __PMT ((__const char *, struct stat *));
294 + int (*gl_lstat) __PMT ((__const char *, void *));
295 + int (*gl_stat) __PMT ((__const char *, void *));
299 +#ifdef _LARGEFILE64_SOURCE
310 + /* If the GLOB_ALTDIRFUNC flag is set, the following functions
311 + are used instead of the normal file access functions. */
312 + void (*gl_closedir) __PMT ((void *));
314 + struct dirent64 *(*gl_readdir) __PMT ((void *));
316 + void *(*gl_readdir) __PMT ((void *));
318 + __ptr_t (*gl_opendir) __PMT ((__const char *));
320 + int (*gl_lstat) __PMT ((__const char *,
322 + int (*gl_stat) __PMT ((__const char *,
325 + int (*gl_lstat) __PMT ((__const char *, void *));
326 + int (*gl_stat) __PMT ((__const char *, void *));
331 +#if _FILE_OFFSET_BITS == 64 && __GNUC__ < 2
332 +# define glob glob64
333 +# define globfree globfree64
336 +/* Do glob searching for PATTERN, placing results in PGLOB.
337 + The bits defined above may be set in FLAGS.
338 + If a directory cannot be opened or read and ERRFUNC is not nil,
339 + it is called with the pathname that caused the error, and the
340 + `errno' value from the failing call; if it returns non-zero
341 + `glob' returns GLOB_ABEND; if it returns zero, the error is ignored.
342 + If memory cannot be allocated for PGLOB, GLOB_NOSPACE is returned.
343 + Otherwise, `glob' returns zero. */
344 +#if _FILE_OFFSET_BITS != 64 || __GNUC__ < 2
345 +extern int glob __P ((__const char *__pattern, int __flags,
346 + int (*__errfunc) (__const char *, int),
349 +/* Free storage allocated in PGLOB by a previous `glob' call. */
350 +extern void globfree __P ((glob_t *__pglob));
352 +extern int glob __P ((__const char *__pattern, int __flags,
353 + int (*__errfunc) (__const char *, int),
356 +extern void globfree __P ((glob_t *__pglob));
359 +#ifdef _LARGEFILE64_SOURCE
360 +extern int glob64 __P ((__const char *__pattern, int __flags,
361 + int (*__errfunc) (__const char *, int),
362 + glob64_t *__pglob));
364 +extern void globfree64 __P ((glob64_t *__pglob));
369 +/* Return nonzero if PATTERN contains any metacharacters.
370 + Metacharacters can be quoted with backslashes if QUOTE is nonzero.
372 + This function is not part of the interface specified by POSIX.2
373 + but several programs want to use it. */
374 +extern int glob_pattern_p __P ((__const char *__pattern, int __quote));
382 diff -urN proftpd-1.2.1/include/libsupp.h proftpd-1.2/include/libsupp.h
383 --- proftpd-1.2.1/include/libsupp.h Wed Aug 2 07:25:24 2000
384 +++ proftpd-1.2/include/libsupp.h Mon Mar 19 23:11:35 2001
387 /* ProFTPD support library definitions.
393 -#if !defined HAVE_GLOB && !defined __PROFTPD_SUPPORT_LIBRARY
399 -/* Bits set in the FLAGS argument to `glob'. */
400 -#define GLOB_ERR (1 << 0)/* Return on read errors. */
401 -#define GLOB_MARK (1 << 1)/* Append a slash to each name. */
402 -#define GLOB_NOSORT (1 << 2)/* Don't sort the names. */
403 -#define GLOB_DOOFFS (1 << 3)/* Insert PGLOB->gl_offs NULLs. */
404 -#define GLOB_NOCHECK (1 << 4)/* If nothing matches, return the pattern. */
405 -#define GLOB_APPEND (1 << 5)/* Append to results of a previous call. */
406 -#define GLOB_NOESCAPE (1 << 6)/* Backslashes don't quote metacharacters. */
407 -#define GLOB_PERIOD (1 << 7)/* Leading `.' can be matched by metachars. */
408 -# define GLOB_MAGCHAR (1 << 8)/* Set in gl_flags if any metachars seen. */
409 -# define GLOB_ALTDIRFUNC (1 << 9)/* Use gl_opendir et al functions. */
410 -# define GLOB_BRACE (1 << 10)/* Expand "{a,b}" to "a" "b". */
411 -# define GLOB_NOMAGIC (1 << 11)/* If no magic chars, return the pattern. */
412 -# define GLOB_TILDE (1 << 12)/* Expand ~user and ~ to home directories. */
413 -# define GLOB_ONLYDIR (1 << 13)/* Match only directories. */
414 -# define __GLOB_FLAGS (GLOB_ERR|GLOB_MARK|GLOB_NOSORT|GLOB_DOOFFS| \
415 - GLOB_NOESCAPE|GLOB_NOCHECK|GLOB_APPEND| \
416 - GLOB_PERIOD|GLOB_ALTDIRFUNC|GLOB_BRACE| \
417 - GLOB_NOMAGIC|GLOB_TILDE|GLOB_ONLYDIR)
418 -#define GLOB_NOSPACE 1 /* Ran out of memory. */
419 -#define GLOB_ABORTED 2 /* Read error. */
420 -#define GLOB_NOMATCH 3 /* No matches found. */
422 -/* Structure describing a globbing run. */
423 -#if !defined _AMIGA && !defined VMS /* Buggy compiler. */
428 - int gl_pathc; /* Count of paths matched by the pattern. */
429 - char **gl_pathv; /* List of matched pathnames. */
430 - int gl_offs; /* Slots to reserve in `gl_pathv'. */
431 - int gl_flags; /* Set to FLAGS, maybe | GLOB_MAGCHAR. */
433 - /* If the GLOB_ALTDIRFUNC flag is set, the following functions
434 - are used instead of the normal file access functions. */
435 - void (*gl_closedir) __P ((void *));
436 - struct dirent *(*gl_readdir) __P ((void *));
437 - void *(*gl_opendir) __P ((const char *));
438 - int (*gl_lstat) __P ((const char *, struct stat *));
439 - int (*gl_stat) __P ((const char *, struct stat *));
442 -extern int glob (const char *__pattern, int __flags,
443 - int (*__errfunc)(const char *, int),
445 -extern void globfree (glob_t *__pglob);
446 -extern int __glob_pattern_p (const char *__pattern, int __quote);
447 -extern int glob_pattern_p (const char *__pattern, int __quote);
449 -#endif /* HAVE_GLOB */
450 +#include <glibc-glob.h>
452 /* Bits set in the FLAGS argument to `pr_fnmatch'. */
453 #define PR_FNM_PATHNAME (1 << 0) /* No wildcard can ever match `/'. */
454 diff -urN proftpd-1.2.1/lib/Makefile.in proftpd-1.2/lib/Makefile.in
455 --- proftpd-1.2.1/lib/Makefile.in Thu Mar 1 17:02:10 2001
456 +++ proftpd-1.2/lib/Makefile.in Sun Feb 25 00:09:19 2001
458 # Dependancies written below
461 +pr_fnmatch.o: ../include/conf.h ../include/version.h ../config.h
462 +pr_fnmatch.o: ../include/default_paths.h ../include/options.h
463 +pr_fnmatch.o: ../include/libsupp.h pr_fnmatch_loop.c
464 getopt.o: ../include/conf.h ../include/version.h ../config.h
465 getopt.o: ../include/default_paths.h ../include/options.h getopt.h
466 getopt1.o: ../include/conf.h ../include/version.h ../config.h
467 getopt1.o: ../include/default_paths.h ../include/options.h getopt.h
468 glob.o: ../include/conf.h ../include/version.h ../config.h
469 glob.o: ../include/default_paths.h ../include/options.h ../include/libsupp.h
470 -pr_fnmatch.o: ../include/conf.h ../include/version.h ../config.h
471 -pr_fnmatch.o: ../include/default_paths.h ../include/options.h
472 -pr_fnmatch.o: ../include/libsupp.h pr_fnmatch_loop.c
473 pwgrent.o: ../include/conf.h ../include/version.h ../config.h
474 pwgrent.o: ../include/default_paths.h ../include/options.h
475 strsep.o: ../include/conf.h ../include/version.h ../config.h
476 diff -urN proftpd-1.2.1/lib/glibc-glob.c proftpd-1.2/lib/glibc-glob.c
477 --- proftpd-1.2.1/lib/glibc-glob.c Thu Jan 1 01:00:00 1970
478 +++ proftpd-1.2/lib/glibc-glob.c Sat Mar 17 21:34:31 2001
480 +/* Copyright (C) 1991-1999, 2000, 2001 Free Software Foundation, Inc.
482 + This library is free software; you can redistribute it and/or
483 + modify it under the terms of the GNU Library General Public License as
484 + published by the Free Software Foundation; either version 2 of the
485 + License, or (at your option) any later version.
487 + This library is distributed in the hope that it will be useful,
488 + but WITHOUT ANY WARRANTY; without even the implied warranty of
489 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
490 + Library General Public License for more details.
492 + You should have received a copy of the GNU Library General Public
493 + License along with this library; see the file COPYING.LIB. If not,
494 + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
495 + Boston, MA 02111-1307, USA. */
497 +/* AIX requires this to be the first thing in the file. */
499 +#if defined _AIX && !defined __GNUC__
505 +#define MAX_RECURSION 8
506 +#define MAX_RESULTS 100000UL
508 +/* Enable GNU extensions in glob.h. */
510 +# define _GNU_SOURCE 1
514 +#include <sys/types.h>
515 +#include <sys/stat.h>
517 +/* Outcomment the following line for production quality code. */
518 +/* #define NDEBUG 1 */
521 +#include <stdio.h> /* Needed on stupid SunOS for assert. */
524 +/* Comment out all this code if we are using the GNU C Library, and are not
525 + actually compiling the library itself. This code is part of the GNU C
526 + Library, but also included in many other GNU distributions. Compiling
527 + and linking in this code is a waste when using the GNU C library
528 + (especially if it is a shared library). Rather than having every GNU
529 + program understand `configure --with-gnu-libc' and omit the object files,
530 + it is simpler to just do this in the source for each such file. */
532 +/* Proftpd modification: always undefine __GNU_LIBRARY__ because we are not
533 + * compiling as part of glibc.
537 +#undef __GNU_LIBRARY__
539 +#define GLOB_INTERFACE_VERSION 1
540 +#if !defined _LIBC && defined __GNU_LIBRARY__ && __GNU_LIBRARY__ > 1
541 +# include <gnu-versions.h>
542 +# if _GNU_GLOB_INTERFACE_VERSION == GLOB_INTERFACE_VERSION
548 +#define __alloca alloca
549 +#define __readdir readdir
552 +#if !defined _LIBC || !defined GLOB_ONLY_P
554 +#if defined STDC_HEADERS || defined __GNU_LIBRARY__
555 +# include <stddef.h>
558 +#if defined HAVE_UNISTD_H || defined _LIBC
559 +# include <unistd.h>
561 +# ifdef _POSIX_VERSION
567 +#if !defined _AMIGA && !defined VMS && !defined WINDOWS32
571 +#if !defined __GNU_LIBRARY__ && !defined STDC_HEADERS
575 +# define __set_errno(val) errno = (val)
582 +#if defined HAVE_DIRENT_H || defined __GNU_LIBRARY__
583 +# include <dirent.h>
584 +# define NAMLEN(dirent) strlen((dirent)->d_name)
586 +# define dirent direct
587 +# define NAMLEN(dirent) (dirent)->d_namlen
588 +# ifdef HAVE_SYS_NDIR_H
589 +# include <sys/ndir.h>
591 +# ifdef HAVE_SYS_DIR_H
592 +# include <sys/dir.h>
597 +# ifdef HAVE_VMSDIR_H
598 +# include "vmsdir.h"
599 +# endif /* HAVE_VMSDIR_H */
603 +/* In GNU systems, <dirent.h> defines this macro for us. */
606 +# define NAMLEN(d) _D_NAMLEN(d)
609 +/* When used in the GNU libc the symbol _DIRENT_HAVE_D_TYPE is available
610 + if the `d_type' member for `struct dirent' is available. */
611 +#ifdef _DIRENT_HAVE_D_TYPE
612 +# define HAVE_D_TYPE 1
616 +# define HAVE_DIRENT64 1
619 +/* If the system has the `struct dirent64' type we use it internally. */
620 +#if defined HAVE_DIRENT64 && !defined COMPILE_GLOB64
621 +# if defined HAVE_DIRENT_H || defined __GNU_LIBRARY__
622 +# define CONVERT_D_NAMLEN(d64, d32)
624 +# define CONVERT_D_NAMLEN(d64, d32) \
625 + (d64)->d_namlen = (d32)->d_namlen;
628 +# if (defined POSIX || defined WINDOWS32) && !defined __GNU_LIBRARY__
629 +# define CONVERT_D_INO(d64, d32)
631 +# define CONVERT_D_INO(d64, d32) \
632 + (d64)->d_ino = (d32)->d_ino;
636 +# define CONVERT_D_TYPE(d64, d32) \
637 + (d64)->d_type = (d32)->d_type;
639 +# define CONVERT_D_TYPE(d64, d32)
642 +# define CONVERT_DIRENT_DIRENT64(d64, d32) \
643 + memcpy ((d64)->d_name, (d32)->d_name, NAMLEN (d32) + 1); \
644 + CONVERT_D_NAMLEN (d64, d32) \
645 + CONVERT_D_INO (d64, d32) \
646 + CONVERT_D_TYPE (d64, d32)
650 +#if (defined POSIX || defined WINDOWS32) && !defined __GNU_LIBRARY__
651 +/* Posix does not require that the d_ino field be present, and some
652 + systems do not provide it. */
653 +# define REAL_DIR_ENTRY(dp) 1
655 +# define REAL_DIR_ENTRY(dp) (dp->d_ino != 0)
658 +#if defined STDC_HEADERS || defined __GNU_LIBRARY__
659 +# include <stdlib.h>
660 +# include <string.h>
661 +# define ANSI_STRING
662 +#else /* No standard headers. */
664 +extern char *getenv ();
666 +# ifdef HAVE_STRING_H
667 +# include <string.h>
668 +# define ANSI_STRING
670 +# include <strings.h>
672 +# ifdef HAVE_MEMORY_H
673 +# include <memory.h>
676 +extern char *malloc (), *realloc ();
677 +extern void free ();
679 +extern void qsort ();
680 +extern void abort (), exit ();
682 +#endif /* Standard headers. */
687 +extern void bzero ();
690 +extern void bcopy ();
693 +# define memcpy(d, s, n) bcopy ((s), (d), (n))
694 +# define strrchr rindex
695 +/* memset is only used for zero here, but let's be paranoid. */
696 +# define memset(s, better_be_zero, n) \
697 + ((void) ((better_be_zero) == 0 ? (bzero((s), (n)), 0) : (abort(), 0)))
698 +#endif /* Not ANSI_STRING. */
700 +#if !defined HAVE_STRCOLL && !defined _LIBC
701 +# define strcoll strcmp
704 +#if !defined HAVE_MEMPCPY && __GLIBC__ - 0 == 2 && __GLIBC_MINOR__ >= 1
705 +# define HAVE_MEMPCPY 1
707 +# define mempcpy(Dest, Src, Len) __mempcpy (Dest, Src, Len)
710 +static unsigned long nbresults;
712 +#ifndef __GNU_LIBRARY__
726 + /* These casts are the for sake of the broken Ultrix compiler,
727 + which warns of illegal pointer combinations otherwise. */
729 + return (char *) malloc (n);
730 + return (char *) realloc (p, n);
732 +# define realloc my_realloc
733 +# endif /* __SASC */
734 +#endif /* __GNU_LIBRARY__ */
737 +#if !defined __alloca && !defined __GNU_LIBRARY__
741 +# define alloca(n) __builtin_alloca (n)
742 +# else /* Not GCC. */
743 +# ifdef HAVE_ALLOCA_H
744 +# include <alloca.h>
745 +# else /* Not HAVE_ALLOCA_H. */
748 +# include <malloc.h>
750 +extern char *alloca ();
751 +# endif /* WINDOWS32 */
752 +# endif /* Not _AIX. */
753 +# endif /* sparc or HAVE_ALLOCA_H. */
756 +# define __alloca alloca
760 +#ifndef __GNU_LIBRARY__
761 +# define __stat stat
762 +# ifdef STAT_MACROS_BROKEN
766 +# define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
772 +# define strdup(str) __strdup (str)
773 +# define sysconf(id) __sysconf (id)
774 +# define closedir(dir) __closedir (dir)
775 +# define opendir(name) __opendir (name)
776 +# define readdir(str) __readdir64 (str)
777 +# define getpwnam_r(name, bufp, buf, len, res) \
778 + __getpwnam_r (name, bufp, buf, len, res)
780 +# define __stat64(fname, buf) __xstat64 (_STAT_VER, fname, buf)
782 +# define HAVE_STAT64 1
786 +# define __stat64(fname, buf) __stat (fname, buf)
787 +/* This is the variable name we are using. */
791 +#if !(defined STDC_HEADERS || defined __GNU_LIBRARY__)
793 +# define size_t unsigned int
796 +/* Some system header files erroneously define these.
797 + We want our own definitions from <fnmatch.h> to take precedence. */
798 +#ifndef __GNU_LIBRARY__
799 +# undef FNM_PATHNAME
800 +# undef FNM_NOESCAPE
803 +#include <fnmatch.h>
805 +/* Some system header files erroneously define these.
806 + We want our own definitions from <glob.h> to take precedence. */
807 +#ifndef __GNU_LIBRARY__
812 +# undef GLOB_NOCHECK
814 +# undef GLOB_NOESCAPE
817 +#include <glibc-glob.h>
819 +#ifdef HAVE_GETLOGIN_R
820 +extern int getlogin_r __P ((char *, size_t));
822 +extern char *getlogin __P ((void));
826 +#if __GNUC__ - 0 >= 2
829 +const char *next_brace_sub __P ((const char *begin));
831 +#endif /* GLOB_ONLY_P */
833 +static int glob_in_dir __P ((const char *pattern, const char *directory,
835 + int (*errfunc) (const char *, int),
838 +/* Prototype __glob_pattern_p to avoid compiler warning.
841 +#if !defined _LIBC || !defined NO_GLOB_PATTERN_P
842 +/* Return nonzero if PATTERN contains any metacharacters.
843 + Metacharacters can be quoted with backslashes if QUOTE is nonzero. */
844 +int __glob_pattern_p (const char *pattern, int quote);
845 +#endif /* NO_GLOB_PATTERN_P */
847 +#if !defined _LIBC || !defined GLOB_ONLY_P
848 +static int prefix_array __P ((const char *prefix, char **array, size_t n));
849 +static int collated_compare __P ((const __ptr_t, const __ptr_t));
852 +/* Find the end of the sub-pattern in a brace expression. We define
853 + this as an inline function if the compiler permits. */
855 +#if __GNUC__ - 0 >= 2
859 +next_brace_sub (begin)
862 + unsigned int depth = 0;
863 + const char *cp = begin;
869 + if (*cp != ',' && *cp != '}' && *cp != '\0')
879 + while (*cp != '\0' && (*cp != '}' || depth > 0))
886 + /* An incorrectly terminated brace expression. */
897 +#endif /* !GLOB_ONLY_P */
900 +/* Do glob searching for PATTERN, placing results in PGLOB.
901 + The bits defined above may be set in FLAGS.
902 + If a directory cannot be opened or read and ERRFUNC is not nil,
903 + it is called with the pathname that caused the error, and the
904 + `errno' value from the failing call; if it returns non-zero
905 + `glob' returns GLOB_ABORTED; if it returns zero, the error is ignored.
906 + If memory cannot be allocated for PGLOB, GLOB_NOSPACE is returned.
907 + Otherwise, `glob' returns zero. */
909 +glob_limited (depth, pattern, flags, errfunc, pglob)
910 + unsigned int depth;
911 + const char *pattern;
913 + int (*errfunc) __P ((const char *, int));
916 + const char *filename;
917 + const char *dirname;
922 + if (depth > MAX_RECURSION) {
923 + return GLOB_NOSPACE;
925 + if (pattern == NULL || pglob == NULL || (flags & ~__GLOB_FLAGS) != 0)
927 + __set_errno (EINVAL);
931 + if (!(flags & GLOB_DOOFFS))
932 + /* Have to do this so `globfree' knows where to start freeing. It
933 + also makes all the code that uses gl_offs simpler. */
934 + pglob->gl_offs = 0;
936 + if (flags & GLOB_BRACE)
938 + const char *begin = strchr (pattern, '{');
941 + /* Allocate working buffer large enough for our work. Note that
942 + we have at least an opening and closing brace. */
950 + char onealt[strlen (pattern) - 1];
952 + char *onealt = (char *) malloc (strlen (pattern) - 1);
953 + if (onealt == NULL)
955 + if (!(flags & GLOB_APPEND))
957 + return GLOB_NOSPACE;
961 + /* We know the prefix for all sub-patterns. */
963 + alt_start = mempcpy (onealt, pattern, begin - pattern);
965 + memcpy (onealt, pattern, begin - pattern);
966 + alt_start = &onealt[begin - pattern];
969 + /* Find the first sub-pattern and at the same time find the
970 + rest after the closing brace. */
971 + next = next_brace_sub (begin + 1);
974 + /* It is an illegal expression. */
978 + return glob_limited (depth + 1U, pattern, flags & ~GLOB_BRACE, errfunc, pglob);
981 + /* Now find the end of the whole brace expression. */
983 + while (*rest != '}')
985 + rest = next_brace_sub (rest + 1);
988 + /* It is an illegal expression. */
992 + return glob_limited (depth + 1U, pattern, flags & ~GLOB_BRACE, errfunc, pglob);
995 + /* Please note that we now can be sure the brace expression
997 + rest_len = strlen (++rest) + 1;
999 + /* We have a brace expression. BEGIN points to the opening {,
1000 + NEXT points past the terminator of the first element, and END
1001 + points past the final }. We will accumulate result names from
1002 + recursive runs for each brace alternative in the buffer using
1005 + if (!(flags & GLOB_APPEND))
1007 + /* This call is to set a new vector, so clear out the
1008 + vector so we can append to it. */
1009 + pglob->gl_pathc = 0;
1010 + pglob->gl_pathv = NULL;
1012 + firstc = pglob->gl_pathc;
1019 + /* Construct the new glob expression. */
1020 +#ifdef HAVE_MEMPCPY
1021 + mempcpy (mempcpy (alt_start, p, next - p), rest, rest_len);
1023 + memcpy (alt_start, p, next - p);
1024 + memcpy (&alt_start[next - p], rest, rest_len);
1027 + result = glob_limited (depth + 1U, onealt,
1028 + ((flags & ~(GLOB_NOCHECK|GLOB_NOMAGIC))
1029 + | GLOB_APPEND), errfunc, pglob);
1031 + /* If we got an error, return it. */
1032 + if (result && result != GLOB_NOMATCH)
1037 + if (!(flags & GLOB_APPEND))
1043 + /* We saw the last entry. */
1047 + next = next_brace_sub (p);
1048 + assert (next != NULL);
1055 + if (pglob->gl_pathc != firstc)
1056 + /* We found some entries. */
1058 + else if (!(flags & (GLOB_NOCHECK|GLOB_NOMAGIC)))
1059 + return GLOB_NOMATCH;
1063 + /* Find the filename. */
1064 + filename = strrchr (pattern, '/');
1065 +#if defined __MSDOS__ || defined WINDOWS32
1066 + /* The case of "d:pattern". Since `:' is not allowed in
1067 + file names, we can safely assume that wherever it
1068 + happens in pattern, it signals the filename part. This
1069 + is so we could some day support patterns like "[a-z]:foo". */
1070 + if (filename == NULL)
1071 + filename = strchr (pattern, ':');
1072 +#endif /* __MSDOS__ || WINDOWS32 */
1073 + if (filename == NULL)
1075 + /* This can mean two things: a simple name or "~name". The latter
1076 + case is nothing but a notation for a directory. */
1077 + if ((flags & (GLOB_TILDE|GLOB_TILDE_CHECK)) && pattern[0] == '~')
1079 + dirname = pattern;
1080 + dirlen = strlen (pattern);
1082 + /* Set FILENAME to NULL as a special flag. This is ugly but
1083 + other solutions would require much more code. We test for
1084 + this special case below. */
1089 + filename = pattern;
1098 + else if (filename == pattern)
1108 + dirlen = filename - pattern;
1109 +#if defined __MSDOS__ || defined WINDOWS32
1110 + if (*filename == ':'
1111 + || (filename > pattern + 1 && filename[-1] == ':'))
1116 + drive_spec = (char *) __alloca (dirlen + 1);
1117 +#ifdef HAVE_MEMPCPY
1118 + *((char *) mempcpy (drive_spec, pattern, dirlen)) = '\0';
1120 + memcpy (drive_spec, pattern, dirlen);
1121 + drive_spec[dirlen] = '\0';
1123 + /* For now, disallow wildcards in the drive spec, to
1124 + prevent infinite recursion in glob. */
1125 + if (__glob_pattern_p (drive_spec, !(flags & GLOB_NOESCAPE)))
1126 + return GLOB_NOMATCH;
1127 + /* If this is "d:pattern", we need to copy `:' to DIRNAME
1128 + as well. If it's "d:/pattern", don't remove the slash
1129 + from "d:/", since "d:" and "d:/" are not the same.*/
1132 + newp = (char *) __alloca (dirlen + 1);
1133 +#ifdef HAVE_MEMPCPY
1134 + *((char *) mempcpy (newp, pattern, dirlen)) = '\0';
1136 + memcpy (newp, pattern, dirlen);
1137 + newp[dirlen] = '\0';
1142 + if (filename[0] == '\0'
1143 +#if defined __MSDOS__ || defined WINDOWS32
1144 + && dirname[dirlen - 1] != ':'
1145 + && (dirlen < 3 || dirname[dirlen - 2] != ':'
1146 + || dirname[dirlen - 1] != '/')
1149 + /* "pattern/". Expand "pattern", appending slashes. */
1151 + int val = glob_limited (depth + 1U, dirname, flags | GLOB_MARK, errfunc, pglob);
1153 + pglob->gl_flags = ((pglob->gl_flags & ~GLOB_MARK)
1154 + | (flags & GLOB_MARK));
1159 + if (!(flags & GLOB_APPEND))
1161 + pglob->gl_pathc = 0;
1162 + if (!(flags & GLOB_DOOFFS))
1163 + pglob->gl_pathv = NULL;
1167 + pglob->gl_pathv = (char **) malloc ((pglob->gl_offs + 1)
1168 + * sizeof (char *));
1169 + if (pglob->gl_pathv == NULL)
1170 + return GLOB_NOSPACE;
1172 + for (i = 0; i <= pglob->gl_offs; ++i)
1173 + pglob->gl_pathv[i] = NULL;
1177 + oldcount = pglob->gl_pathc + pglob->gl_offs;
1180 + if ((flags & (GLOB_TILDE|GLOB_TILDE_CHECK)) && dirname[0] == '~')
1182 + if (dirname[1] == '\0' || dirname[1] == '/')
1184 + /* Look up home directory. */
1185 + const char *home_dir = getenv ("HOME");
1187 + if (home_dir == NULL || home_dir[0] == '\0')
1188 + home_dir = "SYS:";
1191 + if (home_dir == NULL || home_dir[0] == '\0')
1192 + home_dir = "c:/users/default"; /* poor default */
1194 + if (home_dir == NULL || home_dir[0] == '\0')
1198 +# if defined HAVE_GETLOGIN_R || defined _LIBC
1199 + size_t buflen = sysconf (_SC_LOGIN_NAME_MAX) + 1;
1202 + /* `sysconf' does not support _SC_LOGIN_NAME_MAX. Try
1203 + a moderate value. */
1205 + name = (char *) __alloca (buflen);
1207 + success = getlogin_r (name, buflen) >= 0;
1209 + success = (name = getlogin ()) != NULL;
1214 +# if defined HAVE_GETPWNAM_R || defined _LIBC
1215 + long int pwbuflen = sysconf (_SC_GETPW_R_SIZE_MAX);
1217 + struct passwd pwbuf;
1220 + if (pwbuflen == -1)
1221 + /* `sysconf' does not support _SC_GETPW_R_SIZE_MAX.
1222 + Try a moderate value. */
1224 + pwtmpbuf = (char *) __alloca (pwbuflen);
1226 + while (getpwnam_r (name, &pwbuf, pwtmpbuf, pwbuflen, &p)
1229 + if (errno != ERANGE)
1235 + pwtmpbuf = (char *) __alloca (pwbuflen);
1236 + __set_errno (save);
1239 + p = getpwnam (name);
1242 + home_dir = p->pw_dir;
1245 + if (home_dir == NULL || home_dir[0] == '\0')
1247 + if (flags & GLOB_TILDE_CHECK)
1248 + return GLOB_NOMATCH;
1250 + home_dir = "~"; /* No luck. */
1252 +# endif /* WINDOWS32 */
1254 + /* Now construct the full directory. */
1255 + if (dirname[1] == '\0')
1256 + dirname = home_dir;
1260 + size_t home_len = strlen (home_dir);
1261 + newp = (char *) __alloca (home_len + dirlen);
1262 +# ifdef HAVE_MEMPCPY
1263 + mempcpy (mempcpy (newp, home_dir, home_len),
1264 + &dirname[1], dirlen);
1266 + memcpy (newp, home_dir, home_len);
1267 + memcpy (&newp[home_len], &dirname[1], dirlen);
1272 +# if !defined _AMIGA && !defined WINDOWS32
1275 + char *end_name = strchr (dirname, '/');
1276 + const char *user_name;
1277 + const char *home_dir;
1279 + if (end_name == NULL)
1280 + user_name = dirname + 1;
1284 + newp = (char *) __alloca (end_name - dirname);
1285 +# ifdef HAVE_MEMPCPY
1286 + *((char *) mempcpy (newp, dirname + 1, end_name - dirname))
1289 + memcpy (newp, dirname + 1, end_name - dirname);
1290 + newp[end_name - dirname - 1] = '\0';
1295 + /* Look up specific user's home directory. */
1298 +# if defined HAVE_GETPWNAM_R || defined _LIBC
1299 + long int buflen = sysconf (_SC_GETPW_R_SIZE_MAX);
1301 + struct passwd pwbuf;
1305 + /* `sysconf' does not support _SC_GETPW_R_SIZE_MAX. Try a
1306 + moderate value. */
1308 + pwtmpbuf = (char *) __alloca (buflen);
1310 + while (getpwnam_r (user_name, &pwbuf, pwtmpbuf, buflen, &p) != 0)
1312 + if (errno != ERANGE)
1318 + pwtmpbuf = __alloca (buflen);
1319 + __set_errno (save);
1322 + p = getpwnam (user_name);
1325 + home_dir = p->pw_dir;
1329 + /* If we found a home directory use this. */
1330 + if (home_dir != NULL)
1333 + size_t home_len = strlen (home_dir);
1334 + size_t rest_len = end_name == NULL ? 0 : strlen (end_name);
1335 + newp = (char *) __alloca (home_len + rest_len + 1);
1336 +# ifdef HAVE_MEMPCPY
1337 + *((char *) mempcpy (mempcpy (newp, home_dir, home_len),
1338 + end_name, rest_len)) = '\0';
1340 + memcpy (newp, home_dir, home_len);
1341 + memcpy (&newp[home_len], end_name, rest_len);
1342 + newp[home_len + rest_len] = '\0';
1347 + if (flags & GLOB_TILDE_CHECK)
1348 + /* We have to regard it as an error if we cannot find the
1349 + home directory. */
1350 + return GLOB_NOMATCH;
1352 +# endif /* Not Amiga && not WINDOWS32. */
1354 +#endif /* Not VMS. */
1356 + /* Now test whether we looked for "~" or "~NAME". In this case we
1357 + can give the answer now. */
1358 + if (filename == NULL)
1362 + struct stat64 st64;
1365 + /* Return the directory if we don't check for error or if it exists. */
1366 + if ((flags & GLOB_NOCHECK)
1367 + || (((flags & GLOB_ALTDIRFUNC)
1368 + ? ((*pglob->gl_stat) (dirname, &st) == 0
1369 + && S_ISDIR (st.st_mode))
1370 + : (__stat64 (dirname, &st64) == 0 && S_ISDIR (st64.st_mode)))))
1372 + int newcount = pglob->gl_pathc + pglob->gl_offs;
1375 + = (char **) realloc (pglob->gl_pathv,
1376 + (newcount + 1 + 1) * sizeof (char *));
1377 + if (pglob->gl_pathv == NULL)
1378 + return GLOB_NOSPACE;
1380 +#if defined HAVE_STRDUP || defined _LIBC
1381 + pglob->gl_pathv[newcount] = strdup (dirname);
1384 + size_t len = strlen (dirname) + 1;
1385 + char *dircopy = malloc (len);
1386 + if (dircopy != NULL)
1387 + pglob->gl_pathv[newcount] = memcpy (dircopy, dirname, len);
1390 + if (pglob->gl_pathv[newcount] == NULL)
1392 + free (pglob->gl_pathv);
1393 + return GLOB_NOSPACE;
1395 + pglob->gl_pathv[++newcount] = NULL;
1396 + ++pglob->gl_pathc;
1397 + pglob->gl_flags = flags;
1403 + return GLOB_NOMATCH;
1406 + if (__glob_pattern_p (dirname, !(flags & GLOB_NOESCAPE)))
1408 + /* The directory name contains metacharacters, so we
1409 + have to glob for the directory, and then glob for
1410 + the pattern in each directory found. */
1414 + if ((flags & GLOB_ALTDIRFUNC) != 0)
1416 + /* Use the alternative access functions also in the recursive
1418 + dirs.gl_opendir = pglob->gl_opendir;
1419 + dirs.gl_readdir = pglob->gl_readdir;
1420 + dirs.gl_closedir = pglob->gl_closedir;
1421 + dirs.gl_stat = pglob->gl_stat;
1422 + dirs.gl_lstat = pglob->gl_lstat;
1425 + status = glob_limited (depth + 1U, dirname,
1426 + ((flags & (GLOB_ERR | GLOB_NOCHECK | GLOB_NOESCAPE
1427 + | GLOB_ALTDIRFUNC))
1428 + | GLOB_NOSORT | GLOB_ONLYDIR),
1433 + /* We have successfully globbed the preceding directory name.
1434 + For each name we found, call glob_in_dir on it and FILENAME,
1435 + appending the results to PGLOB. */
1436 + for (i = 0; i < dirs.gl_pathc; ++i)
1442 + /* Make globbing interruptible in the bash shell. */
1443 + extern int interrupt_state;
1445 + if (interrupt_state)
1448 + return GLOB_ABORTED;
1451 +#endif /* SHELL. */
1453 + old_pathc = pglob->gl_pathc;
1454 + status = glob_in_dir (filename, dirs.gl_pathv[i],
1455 + ((flags | GLOB_APPEND) & ~GLOB_NOCHECK),
1457 + if (status == GLOB_NOMATCH)
1458 + /* No matches in this directory. Try the next. */
1468 + /* Stick the directory on the front of each name. */
1469 + if (prefix_array (dirs.gl_pathv[i],
1470 + &pglob->gl_pathv[old_pathc + pglob->gl_offs],
1471 + pglob->gl_pathc - old_pathc))
1475 + return GLOB_NOSPACE;
1479 + flags |= GLOB_MAGCHAR;
1481 + /* We have ignored the GLOB_NOCHECK flag in the `glob_in_dir' calls.
1482 + But if we have not found any matching entry and the GLOB_NOCHECK
1483 + flag was set we must return the list consisting of the disrectory
1484 + names followed by the filename. */
1485 + if (pglob->gl_pathc + pglob->gl_offs == oldcount)
1488 + if (flags & GLOB_NOCHECK)
1490 + size_t filename_len = strlen (filename) + 1;
1492 + int newcount = pglob->gl_pathc + pglob->gl_offs;
1495 + struct stat64 st64;
1498 + /* This is an pessimistic guess about the size. */
1500 + = (char **) realloc (pglob->gl_pathv,
1501 + (newcount + dirs.gl_pathc + 1)
1502 + * sizeof (char *));
1503 + if (pglob->gl_pathv == NULL)
1506 + return GLOB_NOSPACE;
1509 + for (i = 0; i < dirs.gl_pathc; ++i)
1511 + const char *dir = dirs.gl_pathv[i];
1512 + size_t dir_len = strlen (dir);
1514 + /* First check whether this really is a directory. */
1515 + if (((flags & GLOB_ALTDIRFUNC)
1516 + ? ((*pglob->gl_stat) (dir, &st) != 0
1517 + || !S_ISDIR (st.st_mode))
1518 + : (__stat64 (dir, &st64) != 0
1519 + || !S_ISDIR (st64.st_mode))))
1520 + /* No directory, ignore this entry. */
1523 + pglob->gl_pathv[newcount] = malloc (dir_len + 1
1525 + if (pglob->gl_pathv[newcount] == NULL)
1529 + return GLOB_NOSPACE;
1532 +#ifdef HAVE_MEMPCPY
1533 + mempcpy (mempcpy (mempcpy (pglob->gl_pathv[newcount],
1536 + filename, filename_len);
1538 + memcpy (pglob->gl_pathv[newcount], dir, dir_len);
1539 + pglob->gl_pathv[newcount][dir_len] = '/';
1540 + memcpy (&pglob->gl_pathv[newcount][dir_len + 1],
1541 + filename, filename_len);
1543 + ++pglob->gl_pathc;
1547 + pglob->gl_pathv[newcount] = NULL;
1548 + pglob->gl_flags = flags;
1550 + /* Now we know how large the gl_pathv vector must be. */
1551 + new_pathv = (char **) realloc (pglob->gl_pathv,
1553 + * sizeof (char *)));
1554 + if (new_pathv != NULL)
1555 + pglob->gl_pathv = new_pathv;
1560 + return GLOB_NOMATCH;
1568 + int old_pathc = pglob->gl_pathc;
1570 + status = glob_in_dir (filename, dirname, flags, errfunc, pglob);
1576 + /* Stick the directory on the front of each name. */
1577 + if (prefix_array (dirname,
1578 + &pglob->gl_pathv[old_pathc + pglob->gl_offs],
1579 + pglob->gl_pathc - old_pathc))
1582 + return GLOB_NOSPACE;
1587 + if (flags & GLOB_MARK)
1589 + /* Append slashes to directory names. */
1593 + struct stat64 st64;
1596 + for (i = oldcount; i < pglob->gl_pathc + pglob->gl_offs; ++i)
1597 + if (((flags & GLOB_ALTDIRFUNC)
1598 + ? ((*pglob->gl_stat) (pglob->gl_pathv[i], &st) == 0
1599 + && S_ISDIR (st.st_mode))
1600 + : (__stat64 (pglob->gl_pathv[i], &st64) == 0
1601 + && S_ISDIR (st64.st_mode))))
1603 + size_t len = strlen (pglob->gl_pathv[i]) + 2;
1604 + char *new = realloc (pglob->gl_pathv[i], len);
1608 + return GLOB_NOSPACE;
1610 + strcpy (&new[len - 2], "/");
1611 + pglob->gl_pathv[i] = new;
1615 + if (!(flags & GLOB_NOSORT))
1617 + /* Sort the vector. */
1618 + qsort ((__ptr_t) &pglob->gl_pathv[oldcount],
1619 + pglob->gl_pathc + pglob->gl_offs - oldcount,
1620 + sizeof (char *), collated_compare);
1627 +glob (pattern, flags, errfunc, pglob)
1629 + const char *pattern;
1631 + int (*errfunc) __P ((const char *, int));
1635 + return glob_limited(0U, pattern, flags, errfunc, pglob);
1638 +#if !defined _LIBC || !defined GLOB_ONLY_P
1640 +/* Free storage allocated in PGLOB by a previous `glob' call. */
1643 + register glob_t *pglob;
1645 + if (pglob->gl_pathv != NULL)
1648 + for (i = 0; i < pglob->gl_pathc; ++i)
1649 + if (pglob->gl_pathv[pglob->gl_offs + i] != NULL)
1650 + free ((__ptr_t) pglob->gl_pathv[pglob->gl_offs + i]);
1651 + free ((__ptr_t) pglob->gl_pathv);
1656 +/* Do a collated comparison of A and B. */
1658 +collated_compare (a, b)
1662 + const char *const s1 = *(const char *const * const) a;
1663 + const char *const s2 = *(const char *const * const) b;
1671 + return strcoll (s1, s2);
1675 +/* Prepend DIRNAME to each of N members of ARRAY, replacing ARRAY's
1676 + elements in place. Return nonzero if out of memory, zero if successful.
1677 + A slash is inserted between DIRNAME and each elt of ARRAY,
1678 + unless DIRNAME is just "/". Each old element of ARRAY is freed. */
1680 +prefix_array (dirname, array, n)
1681 + const char *dirname;
1685 + register size_t i;
1686 + size_t dirlen = strlen (dirname);
1687 +#if defined __MSDOS__ || defined WINDOWS32
1688 + int sep_char = '/';
1689 +# define DIRSEP_CHAR sep_char
1691 +# define DIRSEP_CHAR '/'
1694 + if (dirlen == 1 && dirname[0] == '/')
1695 + /* DIRNAME is just "/", so normal prepending would get us "//foo".
1696 + We want "/foo" instead, so don't prepend any chars from DIRNAME. */
1698 +#if defined __MSDOS__ || defined WINDOWS32
1699 + else if (dirlen > 1)
1701 + if (dirname[dirlen - 1] == '/' && dirname[dirlen - 2] == ':')
1702 + /* DIRNAME is "d:/". Don't prepend the slash from DIRNAME. */
1704 + else if (dirname[dirlen - 1] == ':')
1706 + /* DIRNAME is "d:". Use `:' instead of `/'. */
1713 + for (i = 0; i < n; ++i)
1715 + size_t eltlen = strlen (array[i]) + 1;
1716 + char *new = (char *) malloc (dirlen + 1 + eltlen);
1720 + free ((__ptr_t) array[--i]);
1724 +#ifdef HAVE_MEMPCPY
1726 + char *endp = (char *) mempcpy (new, dirname, dirlen);
1727 + *endp++ = DIRSEP_CHAR;
1728 + mempcpy (endp, array[i], eltlen);
1731 + memcpy (new, dirname, dirlen);
1732 + new[dirlen] = DIRSEP_CHAR;
1733 + memcpy (&new[dirlen + 1], array[i], eltlen);
1735 + free ((__ptr_t) array[i]);
1743 +/* We must not compile this function twice. */
1744 +#if !defined _LIBC || !defined NO_GLOB_PATTERN_P
1745 +/* Return nonzero if PATTERN contains any metacharacters.
1746 + Metacharacters can be quoted with backslashes if QUOTE is nonzero. */
1748 +__glob_pattern_p (pattern, quote)
1749 + const char *pattern;
1752 + register const char *p;
1755 + for (p = pattern; *p != '\0'; ++p)
1763 + if (quote && p[1] != '\0')
1780 +weak_alias (__glob_pattern_p, glob_pattern_p)
1784 +#endif /* !GLOB_ONLY_P */
1787 +/* Like `glob', but PATTERN is a final pathname component,
1788 + and matches are searched for in DIRECTORY.
1789 + The GLOB_NOSORT bit in FLAGS is ignored. No sorting is ever done.
1790 + The GLOB_APPEND flag is assumed to be set (always appends). */
1792 +glob_in_dir (pattern, directory, flags, errfunc, pglob)
1793 + const char *pattern;
1794 + const char *directory;
1796 + int (*errfunc) __P ((const char *, int));
1799 + __ptr_t stream = NULL;
1802 + struct globlink *next;
1805 + struct globlink *names = NULL;
1810 + meta = __glob_pattern_p (pattern, !(flags & GLOB_NOESCAPE));
1811 + if (meta == 0 && (flags & (GLOB_NOCHECK|GLOB_NOMAGIC)))
1813 + /* We need not do any tests. The PATTERN contains no meta
1814 + characters and we must not return an error therefore the
1815 + result will always contain exactly one name. */
1816 + flags |= GLOB_NOCHECK;
1819 + else if (meta == 0 &&
1820 + ((flags & GLOB_NOESCAPE) || strchr(pattern, '\\') == NULL))
1822 + /* Since we use the normal file functions we can also use stat()
1823 + to verify the file is there. */
1825 +# ifdef HAVE_STAT64
1826 + struct stat64 st64;
1828 + size_t patlen = strlen (pattern);
1829 + size_t dirlen = strlen (directory);
1830 + char *fullname = (char *) __alloca (dirlen + 1 + patlen + 1);
1832 +# ifdef HAVE_MEMPCPY
1833 + mempcpy (mempcpy (mempcpy (fullname, directory, dirlen),
1835 + pattern, patlen + 1);
1837 + memcpy (fullname, directory, dirlen);
1838 + fullname[dirlen] = '/';
1839 + memcpy (&fullname[dirlen + 1], pattern, patlen + 1);
1841 + if (((flags & GLOB_ALTDIRFUNC)
1842 + ? (*pglob->gl_stat) (fullname, &st)
1843 + : __stat64 (fullname, &st64)) == 0)
1844 + /* We found this file to be existing. Now tell the rest
1845 + of the function to copy this name into the result. */
1846 + flags |= GLOB_NOCHECK;
1852 + if (pattern[0] == '\0')
1854 + /* This is a special case for matching directories like in
1856 + names = (struct globlink *) __alloca (sizeof (struct globlink));
1857 + names->name = (char *) malloc (1);
1858 + if (names->name == NULL)
1859 + goto memory_error;
1860 + names->name[0] = '\0';
1861 + names->next = NULL;
1867 + stream = ((flags & GLOB_ALTDIRFUNC)
1868 + ? (*pglob->gl_opendir) (directory)
1869 + : (__ptr_t) opendir (directory));
1870 + if (stream == NULL)
1872 + if (errno != ENOTDIR
1873 + && ((errfunc != NULL && (*errfunc) (directory, errno))
1874 + || (flags & GLOB_ERR)))
1875 + return GLOB_ABORTED;
1881 + int fnm_flags = ((!(flags & GLOB_PERIOD) ? FNM_PERIOD : 0)
1882 + | ((flags & GLOB_NOESCAPE) ? FNM_NOESCAPE : 0)
1883 +#if defined _AMIGA || defined VMS
1888 + flags |= GLOB_MAGCHAR;
1894 +#if defined HAVE_DIRENT64 && !defined COMPILE_GLOB64
1895 + struct dirent64 *d;
1896 + struct dirent64 d64;
1898 + if (flags & GLOB_ALTDIRFUNC)
1900 + struct dirent *d32 = (*pglob->gl_readdir) (stream);
1903 + CONVERT_DIRENT_DIRENT64 (&d64, d32);
1910 + d = __readdir64 ((DIR *) stream);
1912 + struct dirent *d = ((flags & GLOB_ALTDIRFUNC)
1913 + ? ((struct dirent *)
1914 + (*pglob->gl_readdir) (stream))
1915 + : __readdir ((DIR *) stream));
1919 + if (nbresults > MAX_RESULTS) {
1923 + if (! REAL_DIR_ENTRY (d))
1927 + /* If we shall match only directories use the information
1928 + provided by the dirent call if possible. */
1929 + if ((flags & GLOB_ONLYDIR)
1930 + && d->d_type != DT_UNKNOWN && d->d_type != DT_DIR)
1936 + if (fnmatch (pattern, name, fnm_flags) == 0)
1938 + struct globlink *new = (struct globlink *)
1939 + __alloca (sizeof (struct globlink));
1941 + new->name = (char *) malloc (len + 1);
1942 + if (new->name == NULL)
1943 + goto memory_error;
1944 +#ifdef HAVE_MEMPCPY
1945 + *((char *) mempcpy ((__ptr_t) new->name, name, len))
1948 + memcpy ((__ptr_t) new->name, name, len);
1949 + new->name[len] = '\0';
1951 + new->next = names;
1960 + if (nfound == 0 && (flags & GLOB_NOCHECK))
1962 + size_t len = strlen (pattern);
1964 + names = (struct globlink *) __alloca (sizeof (struct globlink));
1965 + names->next = NULL;
1966 + names->name = (char *) malloc (len + 1);
1967 + if (names->name == NULL)
1968 + goto memory_error;
1969 +#ifdef HAVE_MEMPCPY
1970 + *((char *) mempcpy (names->name, pattern, len)) = '\0';
1972 + memcpy (names->name, pattern, len);
1973 + names->name[len] = '\0';
1980 + = (char **) realloc (pglob->gl_pathv,
1981 + (pglob->gl_pathc + pglob->gl_offs + nfound + 1)
1982 + * sizeof (char *));
1983 + if (pglob->gl_pathv == NULL)
1984 + goto memory_error;
1986 + for (; names != NULL; names = names->next)
1987 + pglob->gl_pathv[pglob->gl_offs + pglob->gl_pathc++] = names->name;
1988 + pglob->gl_pathv[pglob->gl_offs + pglob->gl_pathc] = NULL;
1990 + pglob->gl_flags = flags;
1994 + if (stream != NULL)
1996 + if (flags & GLOB_ALTDIRFUNC)
1997 + (*pglob->gl_closedir) (stream);
1999 + closedir ((DIR *) stream);
2001 + __set_errno (save);
2003 + return nfound == 0 ? GLOB_NOMATCH : 0;
2008 + if (flags & GLOB_ALTDIRFUNC)
2009 + (*pglob->gl_closedir) (stream);
2011 + closedir ((DIR *) stream);
2012 + __set_errno (save);
2014 + while (names != NULL)
2016 + if (names->name != NULL)
2017 + free ((__ptr_t) names->name);
2018 + names = names->next;
2020 + return GLOB_NOSPACE;
2023 +#endif /* Not ELIDE_CODE. */
2024 diff -urN proftpd-1.2.1/lib/glob.c proftpd-1.2/lib/glob.c
2025 --- proftpd-1.2.1/lib/glob.c Wed Jul 26 10:16:33 2000
2026 +++ proftpd-1.2/lib/glob.c Thu Jan 1 01:00:00 1970
2028 -/* Copyright (C) 1991, 92, 93, 94, 95, 96, 97 Free Software Foundation, Inc.
2030 - This library is free software; you can redistribute it and/or
2031 - modify it under the terms of the GNU Library General Public License as
2032 - published by the Free Software Foundation; either version 2 of the
2033 - License, or (at your option) any later version.
2035 - This library is distributed in the hope that it will be useful,
2036 - but WITHOUT ANY WARRANTY; without even the implied warranty of
2037 - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2038 - Library General Public License for more details.
2040 - You should have received a copy of the GNU Library General Public
2041 - License along with this library; see the file COPYING.LIB. If not,
2042 - write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
2043 - Boston, MA 02111-1307, USA. */
2045 -/* AIX requires this to be the first thing in the file. */
2046 -#if defined _AIX && !defined __GNUC__
2050 -/* Enable GNU extensions in glob.h. */
2051 -#ifndef _GNU_SOURCE
2052 -# define _GNU_SOURCE 1
2055 -/* Required to tell conf.h not to include the standard ProFTPD
2059 -#define __PROFTPD_SUPPORT_LIBRARY
2064 -#include <sys/types.h>
2065 -#include <sys/stat.h>
2067 -#include <assert.h>
2068 -#include <stdio.h> /* Needed on stupid SunOS for assert. */
2070 -#include <libsupp.h>
2073 -#undef __GNU_LIBRARY__
2077 -/* Comment out all this code if we are using the GNU C Library, and are not
2078 - actually compiling the library itself. This code is part of the GNU C
2079 - Library, but also included in many other GNU distributions. Compiling
2080 - and linking in this code is a waste when using the GNU C library
2081 - (especially if it is a shared library). Rather than having every GNU
2082 - program understand `configure --with-gnu-libc' and omit the object files,
2083 - it is simpler to just do this in the source for each such file. */
2085 -#if defined(STDC_HEADERS) || defined(__GNU_LIBRARY__)
2086 -# include <stddef.h>
2089 -#if defined(HAVE_UNISTD_H) || defined(_LIBC)
2090 -# include <unistd.h>
2092 -# ifdef _POSIX_VERSION
2098 -#if !defined(_AMIGA) && !defined(VMS) && !defined(WINDOWS32)
2102 -#if !defined(__GNU_LIBRARY__) && !defined(STDC_HEADERS)
2105 -#ifndef __set_errno
2106 -# define __set_errno(val) errno = (val)
2113 -#if defined HAVE_DIRENT_H || defined __GNU_LIBRARY__
2114 -# include <dirent.h>
2115 -# define NAMLEN(dirent) strlen((dirent)->d_name)
2117 -# define dirent direct
2118 -# define NAMLEN(dirent) (dirent)->d_namlen
2119 -# ifdef HAVE_SYS_NDIR_H
2120 -# include <sys/ndir.h>
2122 -# ifdef HAVE_SYS_DIR_H
2123 -# include <sys/dir.h>
2125 -# ifdef HAVE_NDIR_H
2128 -# ifdef HAVE_VMSDIR_H
2129 -# include "vmsdir.h"
2130 -# endif /* HAVE_VMSDIR_H */
2133 -/* In GNU systems, <dirent.h> defines this macro for us. */
2136 -# define NAMLEN(d) _D_NAMLEN(d)
2139 -#ifdef _DIRENT_HAVE_D_TYPE
2140 -# define HAVE_D_TYPE 1
2143 -#if (defined POSIX || defined WINDOWS32) && !defined __GNU_LIBRARY__
2144 -/* Posix does not require that the d_ino field be present, and some
2145 - systems do not provide it. */
2146 -# define REAL_DIR_ENTRY(dp) 1
2148 -# define REAL_DIR_ENTRY(dp) (dp->d_ino != 0)
2151 -#if defined STDC_HEADERS || defined __GNU_LIBRARY__
2152 -# include <stdlib.h>
2153 -# include <string.h>
2154 -# define ANSI_STRING
2155 -#else /* No standard headers. */
2157 -extern char *getenv ();
2159 -# ifdef HAVE_STRING_H
2160 -# include <string.h>
2161 -# define ANSI_STRING
2163 -# include <strings.h>
2165 -# ifdef HAVE_MEMORY_H
2166 -# include <memory.h>
2170 -extern char *malloc (), *realloc ();
2171 -extern void free ();
2173 -extern void qsort ();
2174 -extern void abort (), exit ();
2175 -#endif /* __osf__ */
2177 -#endif /* Standard headers. */
2179 -#ifndef ANSI_STRING
2182 -extern void bzero ();
2185 -extern void bcopy ();
2189 -# define memcpy(d, s, n) bcopy ((s), (d), (n))
2191 -# define strrchr rindex
2192 -/* memset is only used for zero here, but let's be paranoid. */
2194 -# define memset(s, better_be_zero, n) \
2195 - ((void) ((better_be_zero) == 0 ? (bzero((s), (n)), 0) : (abort(), 0)))
2196 -#endif /* Not ANSI_STRING. */
2198 -#if !defined HAVE_STRCOLL && !defined _LIBC
2199 -# define strcoll strcmp
2202 -#if !defined HAVE_MEMPCPY && __GLIBC__ - 0 == 2 && __GLIBC_MINOR__ >= 1
2203 -# define HAVE_MEMPCPY 1
2204 -# define mempcpy(Dest, Src, Len) __mempcpy (Dest, Src, Len)
2207 -#ifndef __GNU_LIBRARY__
2221 - /* These casts are the for sake of the broken Ultrix compiler,
2222 - which warns of illegal pointer combinations otherwise. */
2224 - return (char *) malloc (n);
2225 - return (char *) realloc (p, n);
2227 -# define realloc my_realloc
2228 -# endif /* __SASC */
2229 -#endif /* __GNU_LIBRARY__ */
2232 -#if !defined __alloca && !defined __GNU_LIBRARY__
2236 -# define alloca(n) __builtin_alloca (n)
2237 -# else /* Not GCC. */
2238 -# ifdef HAVE_ALLOCA_H
2239 -# include <alloca.h>
2240 -# else /* Not HAVE_ALLOCA_H. */
2243 -# include <malloc.h>
2245 -extern char *alloca ();
2246 -# endif /* WINDOWS32 */
2247 -# endif /* Not _AIX. */
2248 -# endif /* sparc or HAVE_ALLOCA_H. */
2251 -# define __alloca alloca
2255 -#ifndef __GNU_LIBRARY__
2256 -# define __stat stat
2257 -# ifdef STAT_MACROS_BROKEN
2261 -# define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
2265 -#if !(defined STDC_HEADERS || defined __GNU_LIBRARY__)
2267 -# define size_t unsigned int
2270 -/* Some system header files erroneously define these.
2271 - We want our own definitions from <glob.h> to take precedence. */
2276 -#undef GLOB_NOCHECK
2278 -#undef GLOB_NOESCAPE
2283 -#if __GNUC__ - 0 >= 2
2286 -const char *next_brace_sub __P ((const char *begin));
2287 -static int glob_in_dir __P ((const char *pattern, const char *directory,
2289 - int (*errfunc) __P ((const char *, int)),
2291 -static int prefix_array __P ((const char *prefix, char **array, size_t n));
2292 -static int collated_compare __P ((const __ptr_t, const __ptr_t));
2295 -/* Find the end of the sub-pattern in a brace expression. We define
2296 - this as an inline function if the compiler permits. */
2298 -#if __GNUC__ - 0 >= 2
2302 -next_brace_sub (begin)
2303 - const char *begin;
2305 - unsigned int depth = 0;
2306 - const char *cp = begin;
2312 - if (*cp != ',' && *cp != '}' && *cp != '\0')
2322 - while (*cp != '\0' && (*cp != '}' || depth > 0))
2329 - /* An incorrectly terminated brace expression. */
2340 -/* Do glob searching for PATTERN, placing results in PGLOB.
2341 - The bits defined above may be set in FLAGS.
2342 - If a directory cannot be opened or read and ERRFUNC is not nil,
2343 - it is called with the pathname that caused the error, and the
2344 - `errno' value from the failing call; if it returns non-zero
2345 - `glob' returns GLOB_ABORTED; if it returns zero, the error is ignored.
2346 - If memory cannot be allocated for PGLOB, GLOB_NOSPACE is returned.
2347 - Otherwise, `glob' returns zero. */
2349 -glob (pattern, flags, errfunc, pglob)
2350 - const char *pattern;
2352 - int (*errfunc) __P ((const char *, int));
2355 - const char *filename;
2361 - if (pattern == NULL || pglob == NULL || (flags & ~__GLOB_FLAGS) != 0)
2363 - __set_errno (EINVAL);
2367 - if (flags & GLOB_BRACE)
2369 - const char *begin = strchr (pattern, '{');
2370 - if (begin != NULL)
2372 - /* Allocate working buffer large enough for our work. Note that
2373 - we have at least an opening and closing brace. */
2381 - char onealt[strlen (pattern) - 1];
2383 - char *onealt = (char *) malloc (strlen (pattern) - 1);
2384 - if (onealt == NULL)
2386 - if (!(flags & GLOB_APPEND))
2388 - return GLOB_NOSPACE;
2392 - /* We know the prefix for all sub-patterns. */
2393 -#ifdef HAVE_MEMPCPY
2394 - alt_start = mempcpy (onealt, pattern, begin - pattern);
2396 - memcpy (onealt, pattern, begin - pattern);
2397 - alt_start = &onealt[begin - pattern];
2400 - /* Find the first sub-pattern and at the same time find the
2401 - rest after the closing brace. */
2402 - next = next_brace_sub (begin + 1);
2405 - /* It is an illegal expression. */
2409 - return glob (pattern, flags & ~GLOB_BRACE, errfunc, pglob);
2412 - /* Now find the end of the whole brace expression. */
2414 - while (*rest != '}')
2416 - rest = next_brace_sub (rest + 1);
2419 - /* It is an illegal expression. */
2423 - return glob (pattern, flags & ~GLOB_BRACE, errfunc, pglob);
2426 - /* Please note that we now can be sure the brace expression
2427 - is well-formed. */
2428 - rest_len = strlen (++rest) + 1;
2430 - /* We have a brace expression. BEGIN points to the opening {,
2431 - NEXT points past the terminator of the first element, and END
2432 - points past the final }. We will accumulate result names from
2433 - recursive runs for each brace alternative in the buffer using
2436 - if (!(flags & GLOB_APPEND))
2438 - /* This call is to set a new vector, so clear out the
2439 - vector so we can append to it. */
2440 - pglob->gl_pathc = 0;
2441 - pglob->gl_pathv = NULL;
2443 - firstc = pglob->gl_pathc;
2450 - /* Construct the new glob expression. */
2451 -#ifdef HAVE_MEMPCPY
2452 - mempcpy (mempcpy (alt_start, p, next - p), rest, rest_len);
2454 - memcpy (alt_start, p, next - p);
2455 - memcpy (&alt_start[next - p], rest, rest_len);
2458 - result = glob (onealt,
2459 - ((flags & ~(GLOB_NOCHECK|GLOB_NOMAGIC))
2460 - | GLOB_APPEND), errfunc, pglob);
2462 - /* If we got an error, return it. */
2463 - if (result && result != GLOB_NOMATCH)
2468 - if (!(flags & GLOB_APPEND))
2474 - /* We saw the last entry. */
2478 - next = next_brace_sub (p);
2479 - assert (next != NULL);
2486 - if (pglob->gl_pathc != firstc)
2487 - /* We found some entries. */
2489 - else if (!(flags & (GLOB_NOCHECK|GLOB_NOMAGIC)))
2490 - return GLOB_NOMATCH;
2494 - /* Find the filename. */
2495 - filename = strrchr (pattern, '/');
2496 - if (filename == NULL)
2498 - filename = pattern;
2500 - dirname = (char *) "";
2502 - dirname = (char *) ".";
2506 - else if (filename == pattern)
2509 - dirname = (char *) "/";
2515 - dirlen = filename - pattern;
2516 - dirname = (char *) __alloca (dirlen + 1);
2517 -#ifdef HAVE_MEMPCPY
2518 - *((char *) mempcpy (dirname, pattern, dirlen)) = '\0';
2520 - memcpy (dirname, pattern, dirlen);
2521 - dirname[dirlen] = '\0';
2526 - if (filename[0] == '\0' && dirlen > 1)
2527 - /* "pattern/". Expand "pattern", appending slashes. */
2529 - int val = glob (dirname, flags | GLOB_MARK, errfunc, pglob);
2531 - pglob->gl_flags = (pglob->gl_flags & ~GLOB_MARK) | (flags & GLOB_MARK);
2535 - if (!(flags & GLOB_APPEND))
2537 - pglob->gl_pathc = 0;
2538 - pglob->gl_pathv = NULL;
2541 - oldcount = pglob->gl_pathc;
2544 - if ((flags & GLOB_TILDE) && dirname[0] == '~')
2546 - if (dirname[1] == '\0' || dirname[1] == '/')
2548 - /* Look up home directory. */
2549 - char *home_dir = getenv ("HOME");
2551 - if (home_dir == NULL || home_dir[0] == '\0')
2552 - home_dir = "SYS:";
2555 - if (home_dir == NULL || home_dir[0] == '\0')
2556 - home_dir = "c:/users/default"; /* poor default */
2558 - if (home_dir == NULL || home_dir[0] == '\0')
2561 -# if defined HAVE_GETLOGIN_R || defined _LIBC
2562 - extern int getlogin_r __P ((char *, size_t));
2563 - size_t buflen = sysconf (_SC_LOGIN_NAME_MAX) + 1;
2567 - /* `sysconf' does not support _SC_LOGIN_NAME_MAX. Try
2568 - a moderate value. */
2570 - name = (char *) __alloca (buflen);
2572 - success = getlogin_r (name, buflen) >= 0;
2574 - extern char *getlogin __P ((void));
2577 - success = (name = getlogin ()) != NULL;
2581 -# if defined HAVE_GETPWNAM_R || defined _LIBC
2582 - size_t pwbuflen = sysconf (_SC_GETPW_R_SIZE_MAX);
2584 - struct passwd pwbuf, *p;
2586 - pwtmpbuf = (char *) __alloca (pwbuflen);
2588 - success = (__getpwnam_r (name, &pwbuf, pwtmpbuf,
2589 - pwbuflen, &p) >= 0);
2591 - struct passwd *p = getpwnam (name);
2592 - success = p != NULL;
2595 - home_dir = p->pw_dir;
2598 - if (home_dir == NULL || home_dir[0] == '\0')
2599 - home_dir = (char *) "~"; /* No luck. */
2600 -# endif /* WINDOWS32 */
2602 - /* Now construct the full directory. */
2603 - if (dirname[1] == '\0')
2604 - dirname = home_dir;
2608 - size_t home_len = strlen (home_dir);
2609 - newp = (char *) __alloca (home_len + dirlen);
2610 -# ifdef HAVE_MEMPCPY
2611 - mempcpy (mempcpy (newp, home_dir, home_len),
2612 - &dirname[1], dirlen);
2614 - memcpy (newp, home_dir, home_len);
2615 - memcpy (&newp[home_len], &dirname[1], dirlen);
2620 -# if !defined _AMIGA && !defined WINDOWS32
2623 - char *end_name = strchr (dirname, '/');
2627 - if (end_name == NULL)
2628 - user_name = dirname + 1;
2631 - user_name = (char *) __alloca (end_name - dirname);
2632 -# ifdef HAVE_MEMPCPY
2633 - *((char *) mempcpy (user_name, dirname + 1, end_name - dirname))
2636 - memcpy (user_name, dirname + 1, end_name - dirname);
2637 - user_name[end_name - dirname - 1] = '\0';
2641 - /* Look up specific user's home directory. */
2643 -# if defined HAVE_GETPWNAM_R || defined _LIBC
2644 - size_t buflen = sysconf (_SC_GETPW_R_SIZE_MAX);
2645 - char *pwtmpbuf = (char *) __alloca (buflen);
2646 - struct passwd pwbuf, *p;
2647 - if (__getpwnam_r (user_name, &pwbuf, pwtmpbuf, buflen, &p) >= 0)
2648 - home_dir = p->pw_dir;
2652 - struct passwd *p = getpwnam (user_name);
2654 - home_dir = p->pw_dir;
2659 - /* If we found a home directory use this. */
2660 - if (home_dir != NULL)
2663 - size_t home_len = strlen (home_dir);
2664 - size_t rest_len = end_name == NULL ? 0 : strlen (end_name);
2665 - newp = (char *) __alloca (home_len + rest_len + 1);
2666 -# ifdef HAVE_MEMPCPY
2667 - *((char *) mempcpy (mempcpy (newp, home_dir, home_len),
2668 - end_name, rest_len)) = '\0';
2670 - memcpy (newp, home_dir, home_len);
2671 - memcpy (&newp[home_len], end_name, rest_len);
2672 - newp[home_len + rest_len] = '\0';
2677 -# endif /* Not Amiga && not WINDOWS32. */
2679 -#endif /* Not VMS. */
2681 - if (__glob_pattern_p (dirname, !(flags & GLOB_NOESCAPE)))
2683 - /* The directory name contains metacharacters, so we
2684 - have to glob for the directory, and then glob for
2685 - the pattern in each directory found. */
2689 - status = glob (dirname,
2690 - ((flags & (GLOB_ERR | GLOB_NOCHECK | GLOB_NOESCAPE))
2691 - | GLOB_NOSORT | GLOB_ONLYDIR),
2696 - /* We have successfully globbed the preceding directory name.
2697 - For each name we found, call glob_in_dir on it and FILENAME,
2698 - appending the results to PGLOB. */
2699 - for (i = 0; i < dirs.gl_pathc; ++i)
2705 - /* Make globbing interruptible in the bash shell. */
2706 - extern int interrupt_state;
2708 - if (interrupt_state)
2711 - globfree (&files);
2712 - return GLOB_ABORTED;
2715 -#endif /* SHELL. */
2717 - oldcount = pglob->gl_pathc;
2718 - status = glob_in_dir (filename, dirs.gl_pathv[i],
2719 - ((flags | GLOB_APPEND)
2720 - & ~(GLOB_NOCHECK | GLOB_ERR)),
2722 - if (status == GLOB_NOMATCH)
2723 - /* No matches in this directory. Try the next. */
2733 - /* Stick the directory on the front of each name. */
2734 - if (prefix_array (dirs.gl_pathv[i],
2735 - &pglob->gl_pathv[oldcount],
2736 - pglob->gl_pathc - oldcount))
2740 - return GLOB_NOSPACE;
2744 - flags |= GLOB_MAGCHAR;
2746 - if (pglob->gl_pathc == oldcount)
2749 - if (flags & GLOB_NOCHECK)
2751 - size_t len = strlen (pattern) + 1;
2752 - char *patcopy = (char *) malloc (len);
2753 - if (patcopy == NULL)
2754 - return GLOB_NOSPACE;
2755 - memcpy (patcopy, pattern, len);
2758 - = (char **) realloc (pglob->gl_pathv,
2759 - (pglob->gl_pathc +
2760 - ((flags & GLOB_DOOFFS) ?
2761 - pglob->gl_offs : 0) +
2764 - if (pglob->gl_pathv == NULL)
2767 - return GLOB_NOSPACE;
2770 - if (flags & GLOB_DOOFFS)
2771 - while (pglob->gl_pathc < pglob->gl_offs)
2772 - pglob->gl_pathv[pglob->gl_pathc++] = NULL;
2774 - pglob->gl_pathv[pglob->gl_pathc++] = patcopy;
2775 - pglob->gl_pathv[pglob->gl_pathc] = NULL;
2776 - pglob->gl_flags = flags;
2779 - return GLOB_NOMATCH;
2785 - status = glob_in_dir (filename, dirname, flags, errfunc, pglob);
2791 - /* Stick the directory on the front of each name. */
2792 - if (prefix_array (dirname,
2793 - &pglob->gl_pathv[oldcount],
2794 - pglob->gl_pathc - oldcount))
2797 - return GLOB_NOSPACE;
2802 - if (flags & GLOB_MARK)
2804 - /* Append slashes to directory names. */
2807 - for (i = oldcount; i < pglob->gl_pathc; ++i)
2808 - if (((flags & GLOB_ALTDIRFUNC) ?
2809 - (*pglob->gl_stat) (pglob->gl_pathv[i], &st) :
2810 - __stat (pglob->gl_pathv[i], &st)) == 0 &&
2811 - S_ISDIR (st.st_mode))
2813 - size_t len = strlen (pglob->gl_pathv[i]) + 2;
2814 - char *new = realloc (pglob->gl_pathv[i], len);
2818 - return GLOB_NOSPACE;
2820 - strncpy (&new[len - 2], "/", 2);
2821 - pglob->gl_pathv[i] = new;
2825 - if (!(flags & GLOB_NOSORT))
2826 - /* Sort the vector. */
2827 - qsort ((__ptr_t) &pglob->gl_pathv[oldcount],
2828 - pglob->gl_pathc - oldcount,
2829 - sizeof (char *), collated_compare);
2835 -/* Free storage allocated in PGLOB by a previous `glob' call. */
2838 - register glob_t *pglob;
2840 - if (pglob->gl_pathv != NULL)
2843 - for (i = 0; i < pglob->gl_pathc; ++i)
2844 - if (pglob->gl_pathv[i] != NULL)
2845 - free ((__ptr_t) pglob->gl_pathv[i]);
2846 - free ((__ptr_t) pglob->gl_pathv);
2851 -/* Do a collated comparison of A and B. */
2853 -collated_compare (a, b)
2857 - const char *const s1 = *(const char *const * const) a;
2858 - const char *const s2 = *(const char *const * const) b;
2866 - return strcoll (s1, s2);
2870 -/* Prepend DIRNAME to each of N members of ARRAY, replacing ARRAY's
2871 - elements in place. Return nonzero if out of memory, zero if successful.
2872 - A slash is inserted between DIRNAME and each elt of ARRAY,
2873 - unless DIRNAME is just "/". Each old element of ARRAY is freed. */
2875 -prefix_array (dirname, array, n)
2876 - const char *dirname;
2880 - register size_t i;
2881 - size_t dirlen = strlen (dirname);
2883 - if (dirlen == 1 && dirname[0] == '/')
2884 - /* DIRNAME is just "/", so normal prepending would get us "//foo".
2885 - We want "/foo" instead, so don't prepend any chars from DIRNAME. */
2888 - for (i = 0; i < n; ++i)
2890 - size_t eltlen = strlen (array[i]) + 1;
2891 - char *new = (char *) malloc (dirlen + 1 + eltlen);
2895 - free ((__ptr_t) array[--i]);
2899 -#ifdef HAVE_MEMPCPY
2901 - char *endp = (char *) mempcpy (new, dirname, dirlen);
2903 - mempcpy (endp, array[i], eltlen);
2906 - memcpy (new, dirname, dirlen);
2907 - new[dirlen] = '/';
2908 - memcpy (&new[dirlen + 1], array[i], eltlen);
2910 - free ((__ptr_t) array[i]);
2918 -/* Return nonzero if PATTERN contains any metacharacters.
2919 - Metacharacters can be quoted with backslashes if QUOTE is nonzero. */
2921 -__glob_pattern_p (pattern, quote)
2922 - const char *pattern;
2925 - register const char *p;
2928 - for (p = pattern; *p != '\0'; ++p)
2936 - if (quote && p[1] != '\0')
2953 -weak_alias (__glob_pattern_p, glob_pattern_p)
2957 -/* Like `glob', but PATTERN is a final pathname component,
2958 - and matches are searched for in DIRECTORY.
2959 - The GLOB_NOSORT bit in FLAGS is ignored. No sorting is ever done.
2960 - The GLOB_APPEND flag is assumed to be set (always appends). */
2962 -glob_in_dir (pattern, directory, flags, errfunc, pglob)
2963 - const char *pattern;
2964 - const char *directory;
2966 - int (*errfunc) __P ((const char *, int));
2973 - struct globlink *next;
2976 - struct globlink *names = NULL;
2981 - stream = ((flags & GLOB_ALTDIRFUNC) ?
2982 - (*pglob->gl_opendir) (directory) :
2983 - (__ptr_t) opendir (directory));
2984 - if (stream == NULL)
2986 - if ((errfunc != NULL && (*errfunc) (directory, errno)) ||
2987 - (flags & GLOB_ERR))
2988 - return GLOB_ABORTED;
2992 - else if (pattern[0] == '\0')
2994 - /* This is a special case for matching directories like in
2996 - names = (struct globlink *) __alloca (sizeof (struct globlink));
2997 - names->name = (char *) malloc (1);
2998 - if (names->name == NULL)
2999 - goto memory_error;
3000 - names->name[0] = '\0';
3001 - names->next = NULL;
3008 - meta = __glob_pattern_p (pattern, !(flags & GLOB_NOESCAPE));
3010 - flags |= GLOB_MAGCHAR;
3016 - struct dirent *d = ((flags & GLOB_ALTDIRFUNC) ?
3017 - (*pglob->gl_readdir) (stream) :
3018 - readdir ((DIR *) stream));
3021 - if (! REAL_DIR_ENTRY (d))
3025 - /* If we shall match only directories use the information
3026 - provided by the dirent call if possible. */
3027 - if ((flags & GLOB_ONLYDIR)
3028 - && d->d_type != DT_UNKNOWN && d->d_type != DT_DIR)
3034 - if ((!meta && strcmp (pattern, name) == 0)
3035 - || pr_fnmatch (pattern, name,
3036 - (!(flags & GLOB_PERIOD) ? PR_FNM_PERIOD : 0) |
3037 - ((flags & GLOB_NOESCAPE) ? PR_FNM_NOESCAPE : 0)
3043 - struct globlink *new
3044 - = (struct globlink *) __alloca (sizeof (struct globlink));
3046 - new->name = (char *) malloc (len + 1);
3047 - if (new->name == NULL)
3048 - goto memory_error;
3049 -#ifdef HAVE_MEMPCPY
3050 - *((char *) mempcpy ((__ptr_t) new->name, name, len)) = '\0';
3052 - memcpy ((__ptr_t) new->name, name, len);
3053 - new->name[len] = '\0';
3055 - new->next = names;
3064 - if (nfound == 0 && (flags & GLOB_NOMAGIC) && !meta)
3065 - flags |= GLOB_NOCHECK;
3067 - if (nfound == 0 && (flags & GLOB_NOCHECK))
3069 - size_t len = strlen (pattern);
3071 - names = (struct globlink *) __alloca (sizeof (struct globlink));
3072 - names->next = NULL;
3073 - names->name = (char *) malloc (len + 1);
3074 - if (names->name == NULL)
3075 - goto memory_error;
3076 -#ifdef HAVE_MEMPCPY
3077 - *((char *) mempcpy (names->name, pattern, len)) = '\0';
3079 - memcpy (names->name, pattern, len);
3080 - names->name[len] = '\0';
3087 - = (char **) realloc (pglob->gl_pathv,
3088 - (pglob->gl_pathc +
3089 - ((flags & GLOB_DOOFFS) ? pglob->gl_offs : 0) +
3092 - if (pglob->gl_pathv == NULL)
3093 - goto memory_error;
3095 - if (flags & GLOB_DOOFFS)
3096 - while (pglob->gl_pathc < pglob->gl_offs)
3097 - pglob->gl_pathv[pglob->gl_pathc++] = NULL;
3099 - for (; names != NULL; names = names->next)
3100 - pglob->gl_pathv[pglob->gl_pathc++] = names->name;
3101 - pglob->gl_pathv[pglob->gl_pathc] = NULL;
3103 - pglob->gl_flags = flags;
3108 - if (flags & GLOB_ALTDIRFUNC)
3109 - (*pglob->gl_closedir) (stream);
3111 - closedir ((DIR *) stream);
3113 - __set_errno (save);
3115 - return nfound == 0 ? GLOB_NOMATCH : 0;
3120 - if (flags & GLOB_ALTDIRFUNC)
3121 - (*pglob->gl_closedir) (stream);
3123 - closedir ((DIR *) stream);
3124 - __set_errno (save);
3126 - while (names != NULL)
3128 - if (names->name != NULL)
3129 - free ((__ptr_t) names->name);
3130 - names = names->next;
3132 - return GLOB_NOSPACE;
3135 -#endif /* HAVE_GLOB */
3136 diff -urN proftpd-1.2.1/lib/glob.h proftpd-1.2/lib/glob.h
3137 --- proftpd-1.2.1/lib/glob.h Sun Oct 18 04:24:41 1998
3138 +++ proftpd-1.2/lib/glob.h Thu Jan 1 01:00:00 1970
3140 -/* Copyright (C) 1991, 1992, 1995, 1996, 1997 Free Software Foundation, Inc.
3142 - The GNU C Library is free software; you can redistribute it and/or
3143 - modify it under the terms of the GNU Library General Public License as
3144 - published by the Free Software Foundation; either version 2 of the
3145 - License, or (at your option) any later version.
3147 - The GNU C Library is distributed in the hope that it will be useful,
3148 - but WITHOUT ANY WARRANTY; without even the implied warranty of
3149 - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3150 - Library General Public License for more details.
3152 - You should have received a copy of the GNU Library General Public
3153 - License along with the GNU C Library; see the file COPYING.LIB. If not,
3154 - write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
3155 - Boston, MA 02111-1307, USA. */
3166 -#if (defined __cplusplus || (defined __STDC__ && __STDC__) \
3167 - || defined WINDOWS32)
3169 -# define __P(protos) protos
3170 -# define __ptr_t void *
3171 -# if !defined __GNUC__ || __GNUC__ < 2
3173 -# define __const const
3175 -#else /* Not C++ or ANSI C. */
3177 -# define __P(protos) ()
3180 -# define __ptr_t char *
3181 -#endif /* C++ or ANSI C. */
3183 -/* Bits set in the FLAGS argument to `glob'. */
3184 -#define GLOB_ERR (1 << 0)/* Return on read errors. */
3185 -#define GLOB_MARK (1 << 1)/* Append a slash to each name. */
3186 -#define GLOB_NOSORT (1 << 2)/* Don't sort the names. */
3187 -#define GLOB_DOOFFS (1 << 3)/* Insert PGLOB->gl_offs NULLs. */
3188 -#define GLOB_NOCHECK (1 << 4)/* If nothing matches, return the pattern. */
3189 -#define GLOB_APPEND (1 << 5)/* Append to results of a previous call. */
3190 -#define GLOB_NOESCAPE (1 << 6)/* Backslashes don't quote metacharacters. */
3191 -#define GLOB_PERIOD (1 << 7)/* Leading `.' can be matched by metachars. */
3193 -#if (!defined _POSIX_C_SOURCE || _POSIX_C_SOURCE < 2 || defined _BSD_SOURCE \
3194 - || defined _GNU_SOURCE)
3195 -# define GLOB_MAGCHAR (1 << 8)/* Set in gl_flags if any metachars seen. */
3196 -# define GLOB_ALTDIRFUNC (1 << 9)/* Use gl_opendir et al functions. */
3197 -# define GLOB_BRACE (1 << 10)/* Expand "{a,b}" to "a" "b". */
3198 -# define GLOB_NOMAGIC (1 << 11)/* If no magic chars, return the pattern. */
3199 -# define GLOB_TILDE (1 << 12)/* Expand ~user and ~ to home directories. */
3200 -# define GLOB_ONLYDIR (1 << 13)/* Match only directories. */
3201 -# define __GLOB_FLAGS (GLOB_ERR|GLOB_MARK|GLOB_NOSORT|GLOB_DOOFFS| \
3202 - GLOB_NOESCAPE|GLOB_NOCHECK|GLOB_APPEND| \
3203 - GLOB_PERIOD|GLOB_ALTDIRFUNC|GLOB_BRACE| \
3204 - GLOB_NOMAGIC|GLOB_TILDE|GLOB_ONLYDIR)
3206 -# define __GLOB_FLAGS (GLOB_ERR|GLOB_MARK|GLOB_NOSORT|GLOB_DOOFFS| \
3207 - GLOB_NOESCAPE|GLOB_NOCHECK|GLOB_APPEND| \
3211 -/* Error returns from `glob'. */
3212 -#define GLOB_NOSPACE 1 /* Ran out of memory. */
3213 -#define GLOB_ABORTED 2 /* Read error. */
3214 -#define GLOB_NOMATCH 3 /* No matches found. */
3217 -/* Previous versions of this file defined GLOB_ABEND instead of
3218 - GLOB_ABORTED. Provide a compatibility definition here. */
3219 -# define GLOB_ABEND GLOB_ABORTED
3222 -/* Structure describing a globbing run. */
3223 -#if !defined _AMIGA && !defined VMS /* Buggy compiler. */
3228 - int gl_pathc; /* Count of paths matched by the pattern. */
3229 - char **gl_pathv; /* List of matched pathnames. */
3230 - int gl_offs; /* Slots to reserve in `gl_pathv'. */
3231 - int gl_flags; /* Set to FLAGS, maybe | GLOB_MAGCHAR. */
3233 - /* If the GLOB_ALTDIRFUNC flag is set, the following functions
3234 - are used instead of the normal file access functions. */
3235 - void (*gl_closedir) __P ((void *));
3236 - struct dirent *(*gl_readdir) __P ((void *));
3237 - __ptr_t (*gl_opendir) __P ((__const char *));
3238 - int (*gl_lstat) __P ((__const char *, struct stat *));
3239 - int (*gl_stat) __P ((__const char *, struct stat *));
3242 -/* Do glob searching for PATTERN, placing results in PGLOB.
3243 - The bits defined above may be set in FLAGS.
3244 - If a directory cannot be opened or read and ERRFUNC is not nil,
3245 - it is called with the pathname that caused the error, and the
3246 - `errno' value from the failing call; if it returns non-zero
3247 - `glob' returns GLOB_ABEND; if it returns zero, the error is ignored.
3248 - If memory cannot be allocated for PGLOB, GLOB_NOSPACE is returned.
3249 - Otherwise, `glob' returns zero. */
3250 -extern int glob __P ((__const char *__pattern, int __flags,
3251 - int (*__errfunc) __P ((__const char *, int)),
3252 - glob_t *__pglob));
3254 -/* Free storage allocated in PGLOB by a previous `glob' call. */
3255 -extern void globfree __P ((glob_t *__pglob));
3259 -/* Return nonzero if PATTERN contains any metacharacters.
3260 - Metacharacters can be quoted with backslashes if QUOTE is nonzero.
3262 - This function is not part of the interface specified by POSIX.2
3263 - but several programs want to use it. */
3264 -extern int __glob_pattern_p __P ((__const char *__pattern, int __quote));
3265 -extern int glob_pattern_p __P ((__const char *__pattern, int __quote));
3272 -#endif /* glob.h */
3273 diff -urN proftpd-1.2.1/src/fs.c proftpd-1.2/src/fs.c
3274 --- proftpd-1.2.1/src/fs.c Sat Feb 3 00:09:26 2001
3275 +++ proftpd-1.2/src/fs.c Mon Mar 19 23:11:36 2001
3279 /* ProFTPD virtual/modular file-system support
3285 @@ -1132,10 +1132,10 @@
3286 flags |= GLOB_ALTDIRFUNC;
3288 pglob->gl_closedir = (void (*)(void*))fs_closedir;
3289 - pglob->gl_readdir = fs_readdir;
3290 + pglob->gl_readdir = (void*(*)(void*))fs_readdir;
3291 pglob->gl_opendir = fs_opendir;
3292 - pglob->gl_lstat = fs_lstat;
3293 - pglob->gl_stat = fs_stat;
3294 + pglob->gl_lstat = (int (*)(const char *,void*))fs_lstat;
3295 + pglob->gl_stat = (int (*)(const char *,void*))fs_stat;
3298 return glob(pattern,flags,errfunc,pglob);