* Makefile.in (clean): Remove non-existant regexp dir.
* collate.h: New header. (__collate_range_cmp): Declare. (__collate_load_error): Define. * glob.cc: Pull in latest version from FreeBSD. Simplify and reduce Cygwin-specific changes. * regex/regcomp.c: Include collate.h on Cygwin as well. (__collate_range_cmp): Move from here... * nlsfuncs.cc (__collate_range_cmp): ...to here. * miscfuncs.cc (thread_wrapper): Fix typo in comment. (CygwinCreateThread): Take dead zone of Windows stack into account. Change the way how the stack is commited and how to handle guardpages. Explain how and why. * thread.h (PTHREAD_DEFAULT_STACKSIZE): Change definition. Explain why.
This commit is contained in:
@@ -33,9 +33,8 @@
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char sccsid[] = "@(#)glob.c 8.3 (Berkeley) 10/13/93";
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
#ifdef __CYGWIN
|
||||
__FBSDID("$FreeBSD: /repoman/r/ncvs/src/lib/libc/gen/glob.c,v 1.25 2006/06/05 18:22:13 delphij Exp $");
|
||||
#endif
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD: src/lib/libc/gen/glob.c,v 1.28 2010/05/12 17:44:00 gordon Exp $");
|
||||
|
||||
/*
|
||||
* glob(3) -- a superset of the one defined in POSIX 1003.2.
|
||||
@@ -72,35 +71,45 @@ __FBSDID("$FreeBSD: /repoman/r/ncvs/src/lib/libc/gen/glob.c,v 1.25 2006/06/05 18
|
||||
* 3. State-dependent encodings are not currently supported.
|
||||
*/
|
||||
|
||||
#ifdef __CYGWIN__
|
||||
#include "winsup.h"
|
||||
#endif
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
#include <glob.h>
|
||||
#include <limits.h>
|
||||
#include <pwd.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <wchar.h>
|
||||
|
||||
//#include "collate.h"
|
||||
#include "collate.h"
|
||||
|
||||
#include "cygerrno.h"
|
||||
#include "security.h"
|
||||
#ifdef __CYGWIN__
|
||||
#include <wctype.h>
|
||||
#include "path.h"
|
||||
#include "fhandler.h"
|
||||
#include "dtable.h"
|
||||
|
||||
#include "cygheap.h"
|
||||
#include "perprocess.h"
|
||||
#include "cygwin/version.h"
|
||||
|
||||
#ifndef ARG_MAX
|
||||
#define ARG_MAX 32000 /* See CreateProcess */
|
||||
#endif
|
||||
#define getpwuid(uid) getpwuid32 (uid)
|
||||
#define getuid() getuid32 ()
|
||||
#define issetugid() (cygheap->user.issetuid ())
|
||||
|
||||
#undef MAXPATHLEN
|
||||
#define MAXPATHLEN 16384
|
||||
#define stat __stat64
|
||||
|
||||
#define CCHAR(c) (ignore_case_with_glob ? towlower (CHAR (c)) : CHAR (c))
|
||||
#define Cchar(c) (ignore_case_with_glob ? towlower (c) : (c))
|
||||
#endif
|
||||
|
||||
#define DOLLAR '$'
|
||||
#define DOT '.'
|
||||
@@ -154,19 +163,19 @@ typedef char Char;
|
||||
|
||||
static int compare(const void *, const void *);
|
||||
static int g_Ctoc(const Char *, char *, size_t);
|
||||
static int g_lstat(Char *, struct __stat64 *, glob_t *);
|
||||
static int g_lstat(Char *, struct stat *, glob_t *);
|
||||
static DIR *g_opendir(Char *, glob_t *);
|
||||
static Char *g_strchr(Char *, wchar_t);
|
||||
static const Char *g_strchr(const Char *, wchar_t);
|
||||
#ifdef notdef
|
||||
static Char *g_strcat(Char *, const Char *);
|
||||
#endif
|
||||
static int g_stat(Char *, struct __stat64 *, glob_t *);
|
||||
static int g_stat(Char *, struct stat *, glob_t *);
|
||||
static int glob0(const Char *, glob_t *, size_t *);
|
||||
static int glob1(Char *, glob_t *, size_t *);
|
||||
static int glob2(Char *, Char *, Char *, Char *, glob_t *, size_t *);
|
||||
static int glob3(Char *, Char *, Char *, Char *, Char *, glob_t *, size_t *);
|
||||
static int globextend(const Char *, glob_t *, size_t *);
|
||||
static const Char *
|
||||
static const Char *
|
||||
globtilde(const Char *, Char *, size_t, glob_t *);
|
||||
static int globexp1(const Char *, glob_t *, size_t *);
|
||||
static int globexp2(const Char *, const Char *, glob_t *, int *, size_t *);
|
||||
@@ -259,7 +268,7 @@ globexp1(const Char *pattern, glob_t *pglob, size_t *limit)
|
||||
if (pattern[0] == LBRACE && pattern[1] == RBRACE && pattern[2] == EOS)
|
||||
return glob0(pattern, pglob, limit);
|
||||
|
||||
while ((ptr = (const Char *) g_strchr((Char *) ptr, LBRACE)) != NULL)
|
||||
while ((ptr = g_strchr(ptr, LBRACE)) != NULL)
|
||||
if (!globexp2(ptr, pattern, pglob, &rv, limit))
|
||||
return rv;
|
||||
|
||||
@@ -387,8 +396,8 @@ globtilde(const Char *pattern, Char *patbuf, size_t patbuf_len, glob_t *pglob)
|
||||
if (*pattern != TILDE || !(pglob->gl_flags & GLOB_TILDE))
|
||||
return pattern;
|
||||
|
||||
/*
|
||||
* Copy up to the end of the string or /
|
||||
/*
|
||||
* Copy up to the end of the string or /
|
||||
*/
|
||||
eb = &patbuf[patbuf_len - 1];
|
||||
for (p = pattern + 1, h = (char *) patbuf;
|
||||
@@ -403,11 +412,11 @@ globtilde(const Char *pattern, Char *patbuf, size_t patbuf_len, glob_t *pglob)
|
||||
* we're not running setuid or setgid) and then trying
|
||||
* the password file
|
||||
*/
|
||||
if (cygheap->user.issetuid() != 0 ||
|
||||
if (issetugid() != 0 ||
|
||||
(h = getenv("HOME")) == NULL) {
|
||||
if (((h = getlogin()) != NULL &&
|
||||
(pwd = getpwnam(h)) != NULL) ||
|
||||
(pwd = getpwuid32(getuid32())) != NULL)
|
||||
(pwd = getpwuid(getuid())) != NULL)
|
||||
h = pwd->pw_dir;
|
||||
else
|
||||
return pattern;
|
||||
@@ -448,7 +457,7 @@ glob0(const Char *pattern, glob_t *pglob, size_t *limit)
|
||||
const Char *qpatnext;
|
||||
int err;
|
||||
size_t oldpathc;
|
||||
Char c, *bufnext, patbuf[MAXPATHLEN];
|
||||
Char *bufnext, c, patbuf[MAXPATHLEN];
|
||||
|
||||
qpatnext = globtilde(pattern, patbuf, MAXPATHLEN, pglob);
|
||||
oldpathc = pglob->gl_pathc;
|
||||
@@ -462,7 +471,7 @@ glob0(const Char *pattern, glob_t *pglob, size_t *limit)
|
||||
if (c == NOT)
|
||||
++qpatnext;
|
||||
if (*qpatnext == EOS ||
|
||||
g_strchr((Char *) qpatnext+1, RBRACKET) == NULL) {
|
||||
g_strchr(qpatnext+1, RBRACKET) == NULL) {
|
||||
*bufnext++ = LBRACKET;
|
||||
if (c == NOT)
|
||||
--qpatnext;
|
||||
@@ -556,7 +565,7 @@ static int
|
||||
glob2(Char *pathbuf, Char *pathend, Char *pathend_last, Char *pattern,
|
||||
glob_t *pglob, size_t *limit)
|
||||
{
|
||||
struct __stat64 sb;
|
||||
struct stat sb;
|
||||
Char *p, *q;
|
||||
int anymeta;
|
||||
|
||||
@@ -625,6 +634,8 @@ glob3(Char *pathbuf, Char *pathend, Char *pathend_last,
|
||||
* assigned, below, to two functions which are prototyped in glob.h
|
||||
* and dirent.h as taking pointers to differently typed opaque
|
||||
* structures.
|
||||
* CYGWIN: Needs prototype and subsequently wild casting to avoid
|
||||
* compiler error.
|
||||
*/
|
||||
struct dirent *(*readdirfunc)(void *);
|
||||
|
||||
@@ -642,7 +653,7 @@ glob3(Char *pathbuf, Char *pathend, Char *pathend_last,
|
||||
pglob->gl_flags & GLOB_ERR)
|
||||
return (GLOB_ABORTED);
|
||||
}
|
||||
return((pglob->gl_flags & GLOB_ERR) ? GLOB_ABORTED : 0);
|
||||
return(0);
|
||||
}
|
||||
|
||||
err = 0;
|
||||
@@ -786,41 +797,23 @@ match(Char *name, Char *pat, Char *patend)
|
||||
return(0);
|
||||
if ((negate_range = ((*pat & M_MASK) == M_NOT)) != EOS)
|
||||
++pat;
|
||||
if (ignore_case_with_glob)
|
||||
{
|
||||
while (((c = *pat++) & M_MASK) != M_END)
|
||||
while (((c = *pat++) & M_MASK) != M_END)
|
||||
if ((*pat & M_MASK) == M_RNG) {
|
||||
if (tolower(c) <= tolower(k) && tolower(k) <= tolower(pat[1]))
|
||||
ok = 1;
|
||||
pat += 2;
|
||||
} else if (tolower(c) == tolower(k))
|
||||
ok = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
while (((c = *pat++) & M_MASK) != M_END)
|
||||
if ((*pat & M_MASK) == M_RNG) {
|
||||
if (c <= k && k <= pat[1])
|
||||
ok = 1;
|
||||
pat += 2;
|
||||
if (__collate_load_error ?
|
||||
CCHAR(c) <= CCHAR(k) && CCHAR(k) <= CCHAR(pat[1]) :
|
||||
__collate_range_cmp(CCHAR(c), CCHAR(k)) <= 0
|
||||
&& __collate_range_cmp(CCHAR(k), CCHAR(pat[1])) <= 0
|
||||
)
|
||||
ok = 1;
|
||||
pat += 2;
|
||||
} else if (c == k)
|
||||
ok = 1;
|
||||
}
|
||||
ok = 1;
|
||||
if (ok == negate_range)
|
||||
return(0);
|
||||
break;
|
||||
default:
|
||||
if (ignore_case_with_glob)
|
||||
{
|
||||
if (tolower(*name) != tolower(c))
|
||||
return(0);
|
||||
++name;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (*name++ != c)
|
||||
if (Cchar(*name++) != Cchar(c))
|
||||
return(0);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -881,8 +874,18 @@ stat32_to_stat64 (struct __stat32 *src, struct __stat64 *dst)
|
||||
dst->st_blocks = src->st_blocks;
|
||||
}
|
||||
|
||||
#define CYGWIN_gl_stat(sfptr) \
|
||||
({ int ret; \
|
||||
struct __stat32 lsb; \
|
||||
if (CYGWIN_VERSION_CHECK_FOR_USING_BIG_TYPES) \
|
||||
ret = (*pglob->sfptr) (buf, sb); \
|
||||
else if (!(ret = (*pglob->sfptr) (buf, (struct __stat64 *) &lsb))) \
|
||||
stat32_to_stat64 (&lsb, sb); \
|
||||
ret; \
|
||||
})
|
||||
|
||||
static int
|
||||
g_lstat(Char *fn, struct __stat64 *sb, glob_t *pglob)
|
||||
g_lstat(Char *fn, struct stat *sb, glob_t *pglob)
|
||||
{
|
||||
char buf[MAXPATHLEN];
|
||||
|
||||
@@ -890,22 +893,13 @@ g_lstat(Char *fn, struct __stat64 *sb, glob_t *pglob)
|
||||
errno = ENAMETOOLONG;
|
||||
return (-1);
|
||||
}
|
||||
if (pglob->gl_flags & GLOB_ALTDIRFUNC) {
|
||||
struct __stat32 lsb;
|
||||
int ret;
|
||||
|
||||
if (CYGWIN_VERSION_CHECK_FOR_USING_BIG_TYPES)
|
||||
ret = (*pglob->gl_lstat)(buf, sb);
|
||||
else if (!(ret = (*pglob->gl_lstat)(buf,
|
||||
(struct __stat64 *)&lsb)))
|
||||
stat32_to_stat64 (&lsb, sb);
|
||||
return ret;
|
||||
}
|
||||
if (pglob->gl_flags & GLOB_ALTDIRFUNC)
|
||||
return CYGWIN_gl_stat (gl_lstat);
|
||||
return(lstat64(buf, sb));
|
||||
}
|
||||
|
||||
static int
|
||||
g_stat(Char *fn, struct __stat64 *sb, glob_t *pglob)
|
||||
g_stat(Char *fn, struct stat *sb, glob_t *pglob)
|
||||
{
|
||||
char buf[MAXPATHLEN];
|
||||
|
||||
@@ -913,22 +907,13 @@ g_stat(Char *fn, struct __stat64 *sb, glob_t *pglob)
|
||||
errno = ENAMETOOLONG;
|
||||
return (-1);
|
||||
}
|
||||
if (pglob->gl_flags & GLOB_ALTDIRFUNC) {
|
||||
struct __stat32 lsb;
|
||||
int ret;
|
||||
|
||||
if (CYGWIN_VERSION_CHECK_FOR_USING_BIG_TYPES)
|
||||
ret = (*pglob->gl_stat)(buf, sb);
|
||||
else if (!(ret = (*pglob->gl_stat)(buf,
|
||||
(struct __stat64 *)&lsb)))
|
||||
stat32_to_stat64 (&lsb, sb);
|
||||
return ret;
|
||||
}
|
||||
if (pglob->gl_flags & GLOB_ALTDIRFUNC)
|
||||
return CYGWIN_gl_stat (gl_stat);
|
||||
return(stat64(buf, sb));
|
||||
}
|
||||
|
||||
static Char *
|
||||
g_strchr(Char *str, wchar_t ch)
|
||||
static const Char *
|
||||
g_strchr(const Char *str, wchar_t ch)
|
||||
{
|
||||
|
||||
do {
|
||||
|
Reference in New Issue
Block a user