Loading...
gen/FreeBSD/glob.c.patch Libc-391 Libc-498
--- Libc/Libc-391/gen/FreeBSD/glob.c.patch
+++ Libc/Libc-498/gen/FreeBSD/glob.c.patch
@@ -1,5 +1,5 @@
 --- glob.c.orig	2004-11-25 11:38:01.000000000 -0800
-+++ glob.c	2005-02-24 16:02:34.000000000 -0800
++++ glob.c	2006-07-04 12:47:05.000000000 -0700
 @@ -40,6 +40,8 @@
  #include <sys/cdefs.h>
  __FBSDID("$FreeBSD: src/lib/libc/gen/glob.c,v 1.22 2004/07/29 03:48:52 tjr Exp $");
@@ -9,15 +9,35 @@
  /*
   * glob(3) -- a superset of the one defined in POSIX 1003.2.
   *
-@@ -144,24 +146,24 @@
- 
+@@ -142,29 +144,42 @@
+ #define	M_SET		META('[')
+ #define	ismeta(c)	(((c)&M_QUOTE) != 0)
+ 
++static int	 g_lstat(Char *, struct stat *, glob_t *, locale_t);
++static int	 g_stat(Char *, struct stat *, glob_t *, locale_t);
++
++#define g_Ctoc		__gl_g_Ctoc
++#define glob0		__gl_glob0
++#define glob2_32	__gl_glob0_32
++#define glob2_64	__gl_glob0_64
++#define glob3		__gl_glob3
++#define globexp1	__gl_globexp1
++#define globextend	__gl_globextend
++__private_extern__ int g_Ctoc(const Char *, char *, u_int, locale_t);
++__private_extern__ int glob0(const Char *, glob_t *, int *, locale_t);
++__private_extern__ int glob2_32(Char *, Char *, Char *, Char *, glob_t *, int *, locale_t);
++__private_extern__ int glob2_64(Char *, Char *, Char *, Char *, glob_t *, int *, locale_t);
++__private_extern__ int glob3(Char *, Char *, Char *, Char *, Char *, glob_t *, int *, locale_t);
++__private_extern__ int globexp1(const Char *, glob_t *, int *, locale_t);
++__private_extern__ int globextend(const Char *, glob_t *, int *, locale_t);
++
++#ifndef BUILDING_VARIANT
++#define glob2(a,b,c,d,e,f,g)	(((e)->gl_flags & GLOB_INODE64) ? glob2_64((a),(b),(c),(d),(e),(f),(g)) : glob2_32((a),(b),(c),(d),(e),(f),(g)))
  
  static int	 compare(const void *, const void *);
 -static int	 g_Ctoc(const Char *, char *, u_int);
 -static int	 g_lstat(Char *, struct stat *, glob_t *);
 -static DIR	*g_opendir(Char *, glob_t *);
-+static int	 g_Ctoc(const Char *, char *, u_int, locale_t);
-+static int	 g_lstat(Char *, struct stat *, glob_t *, locale_t);
 +static DIR	*g_opendir(Char *, glob_t *, locale_t);
  static Char	*g_strchr(Char *, wchar_t);
  #ifdef notdef
@@ -29,24 +49,22 @@
 -static int	 glob2(Char *, Char *, Char *, Char *, glob_t *, int *);
 -static int	 glob3(Char *, Char *, Char *, Char *, Char *, glob_t *, int *);
 -static int	 globextend(const Char *, glob_t *, int *);
-+static int	 g_stat(Char *, struct stat *, glob_t *, locale_t);
-+static int	 glob0(const Char *, glob_t *, int *, locale_t);
 +static int	 glob1(Char *, glob_t *, int *, locale_t);
-+static int	 glob2(Char *, Char *, Char *, Char *, glob_t *, int *, locale_t);
-+static int	 glob3(Char *, Char *, Char *, Char *, Char *, glob_t *, int *, locale_t);
-+static int	 globextend(const Char *, glob_t *, int *, locale_t);
  static const Char *	
  		 globtilde(const Char *, Char *, size_t, glob_t *);
 -static int	 globexp1(const Char *, glob_t *, int *);
 -static int	 globexp2(const Char *, const Char *, glob_t *, int *, int *);
 -static int	 match(Char *, Char *, Char *);
-+static int	 globexp1(const Char *, glob_t *, int *, locale_t);
 +static int	 globexp2(const Char *, const Char *, glob_t *, int *, int *, locale_t);
 +static int	 match(Char *, Char *, Char *, locale_t);
  #ifdef DEBUG
  static void	 qprintf(const char *, Char *);
  #endif
-@@ -178,6 +180,8 @@
++#endif /* !BUILDING_VARIANT */
+ 
+ int
+ glob(pattern, flags, errfunc, pglob)
+@@ -178,6 +193,8 @@
  	mbstate_t mbs;
  	wchar_t wc;
  	size_t clen;
@@ -55,7 +73,20 @@
  
  	patnext = (u_char *) pattern;
  	if (!(flags & GLOB_APPEND)) {
-@@ -200,8 +204,8 @@
+@@ -192,7 +209,12 @@
+ 			limit = ARG_MAX;
+ 	} else
+ 		limit = 0;
++#if __DARWIN_64_BIT_INO_T
+ 	pglob->gl_flags = flags & ~GLOB_MAGCHAR;
++	pglob->gl_flags |= GLOB_INODE64;
++#else /* !__DARWIN_64_BIT_INO_T */
++	pglob->gl_flags = flags & ~(GLOB_MAGCHAR | GLOB_INODE64);
++#endif /* __DARWIN_64_BIT_INO_T */
+ 	pglob->gl_errfunc = errfunc;
+ 	pglob->gl_matchc = 0;
+ 
+@@ -200,8 +222,8 @@
  	bufend = bufnext + MAXPATHLEN - 1;
  	if (flags & GLOB_NOESCAPE) {
  		memset(&mbs, 0, sizeof(mbs));
@@ -66,7 +97,7 @@
  			if (clen == (size_t)-1 || clen == (size_t)-2)
  				return (GLOB_NOMATCH);
  			else if (clen == 0)
-@@ -212,7 +216,7 @@
+@@ -212,7 +234,7 @@
  	} else {
  		/* Protect the quoted characters. */
  		memset(&mbs, 0, sizeof(mbs));
@@ -75,7 +106,7 @@
  			if (*patnext == QUOTE) {
  				if (*++patnext == EOS) {
  					*bufnext++ = QUOTE | M_PROTECT;
-@@ -221,7 +225,7 @@
+@@ -221,7 +243,7 @@
  				prot = M_PROTECT;
  			} else
  				prot = 0;
@@ -84,7 +115,7 @@
  			if (clen == (size_t)-1 || clen == (size_t)-2)
  				return (GLOB_NOMATCH);
  			else if (clen == 0)
-@@ -233,9 +237,9 @@
+@@ -233,34 +255,36 @@
  	*bufnext = EOS;
  
  	if (flags & GLOB_BRACE)
@@ -95,12 +126,15 @@
 +	    return glob0(patbuf, pglob, &limit, loc);
  }
  
++#ifndef BUILDING_VARIANT
  /*
-@@ -244,23 +248,24 @@
+  * Expand recursively a glob {} pattern. When there is no more expansion
+  * invoke the standard globbing routine to glob the rest of the magic
   * characters
   */
- static int
+-static int
 -globexp1(pattern, pglob, limit)
++__private_extern__ int
 +globexp1(pattern, pglob, limit, loc)
  	const Char *pattern;
  	glob_t *pglob;
@@ -125,7 +159,7 @@
  }
  
  
-@@ -270,10 +275,11 @@
+@@ -270,10 +294,11 @@
   * If it fails then it tries to glob the rest of the pattern and returns.
   */
  static int
@@ -138,7 +172,7 @@
  {
  	int     i;
  	Char   *lm, *ls;
-@@ -310,7 +316,7 @@
+@@ -310,7 +335,7 @@
  
  	/* Non matching braces; just glob the pattern */
  	if (i != 0 || *pe == EOS) {
@@ -147,7 +181,7 @@
  		return 0;
  	}
  
-@@ -357,7 +363,7 @@
+@@ -357,7 +382,7 @@
  #ifdef DEBUG
  				qprintf("globexp2:", patbuf);
  #endif
@@ -156,11 +190,13 @@
  
  				/* move after the comma, to the next string */
  				pl = pm + 1;
-@@ -447,10 +453,11 @@
+@@ -446,14 +471,16 @@
+  * sorts the list (unless unsorted operation is requested).  Returns 0
   * if things went well, nonzero if errors occurred.
   */
- static int
+-static int
 -glob0(pattern, pglob, limit)
++__private_extern__ int
 +glob0(pattern, pglob, limit, loc)
  	const Char *pattern;
  	glob_t *pglob;
@@ -168,8 +204,24 @@
 +	locale_t loc;
  {
  	const Char *qpatnext;
- 	int c, err, oldpathc;
-@@ -512,7 +519,7 @@
+-	int c, err, oldpathc;
++	Char c;
++	int err, oldpathc;
+ 	Char *bufnext, patbuf[MAXPATHLEN];
+ 
+ 	qpatnext = globtilde(pattern, patbuf, MAXPATHLEN, pglob);
+@@ -462,6 +489,10 @@
+ 
+ 	/* We don't need to check for buffer overflow any more. */
+ 	while ((c = *qpatnext++) != EOS) {
++		if (c & M_PROTECT) {
++			*bufnext++ = CHAR(c);
++			continue;
++		} /* else */
+ 		switch (c) {
+ 		case LBRACKET:
+ 			c = *qpatnext;
+@@ -512,7 +543,7 @@
  	qprintf("glob0:", patbuf);
  #endif
  
@@ -178,7 +230,7 @@
  		return(err);
  
  	/*
-@@ -525,7 +532,7 @@
+@@ -525,7 +556,7 @@
  		if (((pglob->gl_flags & GLOB_NOCHECK) ||
  		    ((pglob->gl_flags & GLOB_NOMAGIC) &&
  			!(pglob->gl_flags & GLOB_MAGCHAR))))
@@ -187,7 +239,12 @@
  		else
  			return(GLOB_NOMATCH);
  	}
-@@ -543,10 +550,11 @@
+@@ -539,14 +570,15 @@
+ compare(p, q)
+ 	const void *p, *q;
+ {
+-	return(strcmp(*(char **)p, *(char **)q));
++	return(strcoll(*(char **)p, *(char **)q));
  }
  
  static int
@@ -200,21 +257,28 @@
  {
  	Char pathbuf[MAXPATHLEN];
  
-@@ -554,7 +562,7 @@
+@@ -554,19 +586,25 @@
  	if (*pattern == EOS)
  		return(0);
  	return(glob2(pathbuf, pathbuf, pathbuf + MAXPATHLEN - 1,
 -	    pattern, pglob, limit));
 +	    pattern, pglob, limit, loc));
  }
++#endif /* !BUILDING_VARIANT */
  
  /*
-@@ -563,10 +571,11 @@
+  * The functions glob2 and glob3 are mutually recursive; there is one level
+  * of recursion for each segment in the pattern that contains one or more
   * meta characters.
   */
- static int
+-static int
 -glob2(pathbuf, pathend, pathend_last, pattern, pglob, limit)
-+glob2(pathbuf, pathend, pathend_last, pattern, pglob, limit, loc)
++__private_extern__ int
++#if __DARWIN_64_BIT_INO_T
++glob2_64(pathbuf, pathend, pathend_last, pattern, pglob, limit, loc)
++#else /* !__DARWIN_64_BIT_INO_T */
++glob2_32(pathbuf, pathend, pathend_last, pattern, pglob, limit, loc)
++#endif /* __DARWIN_64_BIT_INO_T */
  	Char *pathbuf, *pathend, *pathend_last, *pattern;
  	glob_t *pglob;
  	int *limit;
@@ -222,7 +286,7 @@
  {
  	struct stat sb;
  	Char *p, *q;
-@@ -579,13 +588,13 @@
+@@ -579,13 +617,13 @@
  	for (anymeta = 0;;) {
  		if (*pattern == EOS) {		/* End of pattern? */
  			*pathend = EOS;
@@ -238,7 +302,7 @@
  			    S_ISDIR(sb.st_mode)))) {
  				if (pathend + 1 > pathend_last)
  					return (GLOB_ABORTED);
-@@ -593,7 +602,7 @@
+@@ -593,7 +631,7 @@
  				*pathend = EOS;
  			}
  			++pglob->gl_matchc;
@@ -247,7 +311,7 @@
  		}
  
  		/* Find end of next segment, copy tentatively to pathend. */
-@@ -617,16 +626,17 @@
+@@ -617,16 +655,18 @@
  			}
  		} else			/* Need expansion, recurse. */
  			return(glob3(pathbuf, pathend, pathend_last, pattern, p,
@@ -257,8 +321,10 @@
  	/* NOTREACHED */
  }
  
- static int
+-static int
 -glob3(pathbuf, pathend, pathend_last, pattern, restpattern, pglob, limit)
++#ifndef BUILDING_VARIANT
++__private_extern__ int
 +glob3(pathbuf, pathend, pathend_last, pattern, restpattern, pglob, limit, loc)
  	Char *pathbuf, *pathend, *pathend_last, *pattern, *restpattern;
  	glob_t *pglob;
@@ -267,7 +333,7 @@
  {
  	struct dirent *dp;
  	DIR *dirp;
-@@ -646,10 +656,10 @@
+@@ -646,15 +686,16 @@
  	*pathend = EOS;
  	errno = 0;
  
@@ -278,9 +344,17 @@
 -			if (g_Ctoc(pathbuf, buf, sizeof(buf)))
 +			if (g_Ctoc(pathbuf, buf, sizeof(buf), loc))
  				return (GLOB_ABORTED);
- 			if (pglob->gl_errfunc(buf, errno) ||
- 			    pglob->gl_flags & GLOB_ERR)
-@@ -679,7 +689,7 @@
+-			if (pglob->gl_errfunc(buf, errno) ||
+-			    pglob->gl_flags & GLOB_ERR)
++			if (pglob->gl_errfunc(buf, errno))
+ 				return (GLOB_ABORTED);
+ 		}
++		if (pglob->gl_flags & GLOB_ERR)
++			return (GLOB_ABORTED);
+ 		return(0);
+ 	}
+ 
+@@ -679,7 +720,7 @@
  		dc = pathend;
  		sc = (u_char *) dp->d_name;
  		while (dc < pathend_last) {
@@ -289,7 +363,7 @@
  			if (clen == (size_t)-1 || clen == (size_t)-2) {
  				wc = *sc;
  				clen = 1;
-@@ -689,12 +699,12 @@
+@@ -689,12 +730,12 @@
  				break;
  			sc += clen;
  		}
@@ -304,11 +378,13 @@
  		if (err)
  			break;
  	}
-@@ -722,10 +732,11 @@
+@@ -721,11 +762,12 @@
+  *	Either gl_pathc is zero and gl_pathv is NULL; or gl_pathc > 0 and
   *	gl_pathv points to (gl_offs + gl_pathc + 1) items.
   */
- static int
+-static int
 -globextend(path, pglob, limit)
++__private_extern__ int
 +globextend(path, pglob, limit, loc)
  	const Char *path;
  	glob_t *pglob;
@@ -317,7 +393,7 @@
  {
  	char **pathv;
  	int i;
-@@ -760,9 +771,9 @@
+@@ -760,9 +802,9 @@
  
  	for (p = path; *p++;)
  		continue;
@@ -329,7 +405,7 @@
  			free(copy);
  			return (GLOB_NOSPACE);
  		}
-@@ -777,8 +788,9 @@
+@@ -777,8 +819,9 @@
   * pattern causes a recursion level.
   */
  static int
@@ -340,7 +416,7 @@
  {
  	int ok, negate_range;
  	Char c, k;
-@@ -790,7 +802,7 @@
+@@ -790,7 +833,7 @@
  			if (pat == patend)
  				return(1);
  			do
@@ -349,7 +425,7 @@
  				    return(1);
  			while (*name++ != EOS);
  			return(0);
-@@ -806,10 +818,10 @@
+@@ -806,10 +849,10 @@
  				++pat;
  			while (((c = *pat++) & M_MASK) != M_END)
  				if ((*pat & M_MASK) == M_RNG) {
@@ -363,7 +439,7 @@
  					   )
  						ok = 1;
  					pat += 2;
-@@ -846,16 +858,17 @@
+@@ -846,16 +889,17 @@
  }
  
  static DIR *
@@ -383,8 +459,11 @@
  			return (NULL);
  	}
  
-@@ -866,14 +879,15 @@
- }
+@@ -864,16 +908,18 @@
+ 
+ 	return(opendir(buf));
+ }
++#endif /* !BUILDING_VARIANT */
  
  static int
 -g_lstat(fn, sb, pglob)
@@ -401,7 +480,7 @@
  		errno = ENAMETOOLONG;
  		return (-1);
  	}
-@@ -883,14 +897,15 @@
+@@ -883,14 +929,15 @@
  }
  
  static int
@@ -419,11 +498,21 @@
  		errno = ENAMETOOLONG;
  		return (-1);
  	}
-@@ -912,17 +927,19 @@
- }
- 
- static int
+@@ -899,6 +946,7 @@
+ 	return(stat(buf, sb));
+ }
+ 
++#ifndef BUILDING_VARIANT
+ static Char *
+ g_strchr(str, ch)
+ 	Char *str;
+@@ -911,18 +959,20 @@
+ 	return (NULL);
+ }
+ 
+-static int
 -g_Ctoc(str, buf, len)
++__private_extern__ int
 +g_Ctoc(str, buf, len, loc)
  	const Char *str;
  	char *buf;
@@ -442,3 +531,8 @@
  		if (clen == (size_t)-1)
  			return (1);
  		if (*str == L'\0')
+@@ -954,3 +1004,4 @@
+ 	(void)printf("\n");
+ }
+ #endif
++#endif /* !BUILDING_VARIANT */