Bugzilla – Attachment 2704 Details for
Bug 2463
Conflict with openbsd compat glob() function in shared libraries
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
reworked patch in cleaner way
glob_compat.patch (text/plain), 26.94 KB, created by
Jakub Jelen
on 2015-09-14 21:26:53 AEST
(
hide
)
Description:
reworked patch in cleaner way
Filename:
MIME Type:
Creator:
Jakub Jelen
Created:
2015-09-14 21:26:53 AEST
Size:
26.94 KB
patch
obsolete
>From b31e3dd0a0938ec6a2130fefd33286457f43f569 Mon Sep 17 00:00:00 2001 >From: Jakub Jelen <jjelen@redhat.com> >Date: Fri, 11 Sep 2015 16:26:10 +0200 >Subject: [PATCH] Compat glob() > >Move glob fuciton into its own "namespace" so it will not colide with dynamically linked libraries and other useage in code. > >Introduces macro GLOB_COMPAT(name), which translates types, constants and functions from <glob.h> to work with system library or compat library, depending on the usability. > >All the public API (functions, type, constatns) is namespaced so there is no conflict with system library. > >Signed-off-by: Jakub Jelen <jjelen@redhat.com> >--- > includes.h | 3 ++ > openbsd-compat/glob.c | 138 +++++++++++++++++++++++++------------------------- > openbsd-compat/glob.h | 52 +++++++++---------- > sftp-glob.c | 6 +-- > sftp.c | 51 ++++++++++--------- > 5 files changed, 128 insertions(+), 122 deletions(-) > >diff --git a/includes.h b/includes.h >index 2893a54..556ff46 100644 >--- a/includes.h >+++ b/includes.h >@@ -37,6 +37,9 @@ > defined(HAVE_DECL_GLOB_NOMATCH) && HAVE_DECL_GLOB_NOMATCH != 0 && \ > !defined(BROKEN_GLOB) > # include <glob.h> >+# define GLOB_COMPAT(NAME) NAME >+#else >+# define GLOB_COMPAT(NAME) compat_ ## NAME > #endif > #ifdef HAVE_ENDIAN_H > # include <endian.h> >diff --git a/openbsd-compat/glob.c b/openbsd-compat/glob.c >index 742b4b9..653115a 100644 >--- a/openbsd-compat/glob.c >+++ b/openbsd-compat/glob.c >@@ -150,23 +150,23 @@ struct glob_path_stat { > static int compare(const void *, const void *); > static int compare_gps(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_lstat(Char *, struct stat *, compat_glob_t *); >+static DIR *g_opendir(Char *, compat_glob_t *); > static Char *g_strchr(const Char *, int); > static int g_strncmp(const Char *, const char *, size_t); >-static int g_stat(Char *, struct stat *, glob_t *); >-static int glob0(const Char *, glob_t *, struct glob_lim *); >-static int glob1(Char *, Char *, glob_t *, struct glob_lim *); >+static int g_stat(Char *, struct stat *, compat_glob_t *); >+static int glob0(const Char *, compat_glob_t *, struct glob_lim *); >+static int glob1(Char *, Char *, compat_glob_t *, struct glob_lim *); > static int glob2(Char *, Char *, Char *, Char *, Char *, Char *, >- glob_t *, struct glob_lim *); >+ compat_glob_t *, struct glob_lim *); > static int glob3(Char *, Char *, Char *, Char *, Char *, >- Char *, Char *, glob_t *, struct glob_lim *); >-static int globextend(const Char *, glob_t *, struct glob_lim *, >+ Char *, Char *, compat_glob_t *, struct glob_lim *); >+static int globextend(const Char *, compat_glob_t *, struct glob_lim *, > struct stat *); > static const Char * >- globtilde(const Char *, Char *, size_t, glob_t *); >-static int globexp1(const Char *, glob_t *, struct glob_lim *); >-static int globexp2(const Char *, const Char *, glob_t *, >+ globtilde(const Char *, Char *, size_t, compat_glob_t *); >+static int globexp1(const Char *, compat_glob_t *, struct glob_lim *); >+static int globexp2(const Char *, const Char *, compat_glob_t *, > struct glob_lim *); > static int match(Char *, Char *, Char *, int); > #ifdef DEBUG >@@ -174,8 +174,8 @@ static void qprintf(const char *, Char *); > #endif > > int >-glob(const char *pattern, int flags, int (*errfunc)(const char *, int), >- glob_t *pglob) >+compat_glob(const char *pattern, int flags, int (*errfunc)(const char *, int), >+ compat_glob_t *pglob) > { > const u_char *patnext; > int c; >@@ -183,28 +183,28 @@ glob(const char *pattern, int flags, int (*errfunc)(const char *, int), > struct glob_lim limit = { 0, 0, 0 }; > > if (strnlen(pattern, PATH_MAX) == PATH_MAX) >- return(GLOB_NOMATCH); >+ return(compat_GLOB_NOMATCH); > > patnext = (u_char *) pattern; >- if (!(flags & GLOB_APPEND)) { >+ if (!(flags & compat_GLOB_APPEND)) { > pglob->gl_pathc = 0; > pglob->gl_pathv = NULL; > pglob->gl_statv = NULL; >- if (!(flags & GLOB_DOOFFS)) >+ if (!(flags & compat_GLOB_DOOFFS)) > pglob->gl_offs = 0; > } >- pglob->gl_flags = flags & ~GLOB_MAGCHAR; >+ pglob->gl_flags = flags & ~compat_GLOB_MAGCHAR; > pglob->gl_errfunc = errfunc; > pglob->gl_matchc = 0; > > if (pglob->gl_offs < 0 || pglob->gl_pathc < 0 || > pglob->gl_offs >= INT_MAX || pglob->gl_pathc >= INT_MAX || > pglob->gl_pathc >= INT_MAX - pglob->gl_offs - 1) >- return GLOB_NOSPACE; >+ return compat_GLOB_NOSPACE; > > bufnext = patbuf; > bufend = bufnext + MAXPATHLEN - 1; >- if (flags & GLOB_NOESCAPE) >+ if (flags & compat_GLOB_NOESCAPE) > while (bufnext < bufend && (c = *patnext++) != EOS) > *bufnext++ = c; > else { >@@ -221,7 +221,7 @@ glob(const char *pattern, int flags, int (*errfunc)(const char *, int), > } > *bufnext = EOS; > >- if (flags & GLOB_BRACE) >+ if (flags & compat_GLOB_BRACE) > return globexp1(patbuf, pglob, &limit); > else > return glob0(patbuf, pglob, &limit); >@@ -233,7 +233,7 @@ glob(const char *pattern, int flags, int (*errfunc)(const char *, int), > * characters > */ > static int >-globexp1(const Char *pattern, glob_t *pglob, struct glob_lim *limitp) >+globexp1(const Char *pattern, compat_glob_t *pglob, struct glob_lim *limitp) > { > const Char* ptr = pattern; > >@@ -254,7 +254,7 @@ globexp1(const Char *pattern, glob_t *pglob, struct glob_lim *limitp) > * If it fails then it tries to glob the rest of the pattern and returns. > */ > static int >-globexp2(const Char *ptr, const Char *pattern, glob_t *pglob, >+globexp2(const Char *ptr, const Char *pattern, compat_glob_t *pglob, > struct glob_lim *limitp) > { > int i, rv; >@@ -338,7 +338,7 @@ globexp2(const Char *ptr, const Char *pattern, glob_t *pglob, > qprintf("globexp2:", patbuf); > #endif > rv = globexp1(patbuf, pglob, limitp); >- if (rv && rv != GLOB_NOMATCH) >+ if (rv && rv != compat_GLOB_NOMATCH) > return rv; > > /* move after the comma, to the next string */ >@@ -359,14 +359,14 @@ globexp2(const Char *ptr, const Char *pattern, glob_t *pglob, > * expand tilde from the passwd file. > */ > static const Char * >-globtilde(const Char *pattern, Char *patbuf, size_t patbuf_len, glob_t *pglob) >+globtilde(const Char *pattern, Char *patbuf, size_t patbuf_len, compat_glob_t *pglob) > { > struct passwd *pwd; > char *h; > const Char *p; > Char *b, *eb; > >- if (*pattern != TILDE || !(pglob->gl_flags & GLOB_TILDE)) >+ if (*pattern != TILDE || !(pglob->gl_flags & compat_GLOB_TILDE)) > return pattern; > > /* Copy up to the end of the string or / */ >@@ -468,7 +468,7 @@ g_charclass(const Char **patternp, Char **bufnextp) > * to find no matches. > */ > static int >-glob0(const Char *pattern, glob_t *pglob, struct glob_lim *limitp) >+glob0(const Char *pattern, compat_glob_t *pglob, struct glob_lim *limitp) > { > const Char *qpatnext; > int c, err, oldpathc; >@@ -506,8 +506,8 @@ glob0(const Char *pattern, glob_t *pglob, struct glob_lim *limitp) > c = *qpatnext++; > } while (c == LBRACKET && *qpatnext == ':'); > if (err == -1 && >- !(pglob->gl_flags & GLOB_NOCHECK)) >- return GLOB_NOMATCH; >+ !(pglob->gl_flags & compat_GLOB_NOCHECK)) >+ return compat_GLOB_NOMATCH; > if (c == RBRACKET) > break; > } >@@ -519,15 +519,15 @@ glob0(const Char *pattern, glob_t *pglob, struct glob_lim *limitp) > qpatnext += 2; > } > } while ((c = *qpatnext++) != RBRACKET); >- pglob->gl_flags |= GLOB_MAGCHAR; >+ pglob->gl_flags |= compat_GLOB_MAGCHAR; > *bufnext++ = M_END; > break; > case QUESTION: >- pglob->gl_flags |= GLOB_MAGCHAR; >+ pglob->gl_flags |= compat_GLOB_MAGCHAR; > *bufnext++ = M_ONE; > break; > case STAR: >- pglob->gl_flags |= GLOB_MAGCHAR; >+ pglob->gl_flags |= compat_GLOB_MAGCHAR; > /* collapse adjacent stars to one, > * to avoid exponential behavior > */ >@@ -554,15 +554,15 @@ glob0(const Char *pattern, glob_t *pglob, struct glob_lim *limitp) > * GLOB_NOMAGIC is there just for compatibility with csh. > */ > if (pglob->gl_pathc == oldpathc) { >- if ((pglob->gl_flags & GLOB_NOCHECK) || >- ((pglob->gl_flags & GLOB_NOMAGIC) && >- !(pglob->gl_flags & GLOB_MAGCHAR))) >+ if ((pglob->gl_flags & compat_GLOB_NOCHECK) || >+ ((pglob->gl_flags & compat_GLOB_NOMAGIC) && >+ !(pglob->gl_flags & compat_GLOB_MAGCHAR))) > return(globextend(pattern, pglob, limitp, NULL)); > else >- return(GLOB_NOMATCH); >+ return(compat_GLOB_NOMATCH); > } >- if (!(pglob->gl_flags & GLOB_NOSORT)) { >- if ((pglob->gl_flags & GLOB_KEEPSTAT)) { >+ if (!(pglob->gl_flags & compat_GLOB_NOSORT)) { >+ if ((pglob->gl_flags & compat_GLOB_KEEPSTAT)) { > /* Keep the paths and stat info synced during sort */ > struct glob_path_stat *path_stat; > int i; >@@ -570,7 +570,7 @@ glob0(const Char *pattern, glob_t *pglob, struct glob_lim *limitp) > int o = pglob->gl_offs + oldpathc; > > if ((path_stat = calloc(n, sizeof(*path_stat))) == NULL) >- return GLOB_NOSPACE; >+ return compat_GLOB_NOSPACE; > for (i = 0; i < n; i++) { > path_stat[i].gps_path = pglob->gl_pathv[o + i]; > path_stat[i].gps_stat = pglob->gl_statv[o + i]; >@@ -606,7 +606,7 @@ compare_gps(const void *_p, const void *_q) > } > > static int >-glob1(Char *pattern, Char *pattern_last, glob_t *pglob, struct glob_lim *limitp) >+glob1(Char *pattern, Char *pattern_last, compat_glob_t *pglob, struct glob_lim *limitp) > { > Char pathbuf[MAXPATHLEN]; > >@@ -625,7 +625,7 @@ glob1(Char *pattern, Char *pattern_last, glob_t *pglob, struct glob_lim *limitp) > */ > static int > glob2(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend_last, >- Char *pattern, Char *pattern_last, glob_t *pglob, struct glob_lim *limitp) >+ Char *pattern, Char *pattern_last, compat_glob_t *pglob, struct glob_lim *limitp) > { > struct stat sb; > Char *p, *q; >@@ -641,15 +641,15 @@ glob2(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend_last, > if (g_lstat(pathbuf, &sb, pglob)) > return(0); > >- if ((pglob->gl_flags & GLOB_LIMIT) && >+ if ((pglob->gl_flags & compat_GLOB_LIMIT) && > limitp->glim_stat++ >= GLOB_LIMIT_STAT) { > errno = 0; > *pathend++ = SEP; > *pathend = EOS; >- return(GLOB_NOSPACE); >+ return(compat_GLOB_NOSPACE); > } > >- if (((pglob->gl_flags & GLOB_MARK) && >+ if (((pglob->gl_flags & compat_GLOB_MARK) && > pathend[-1] != SEP) && (S_ISDIR(sb.st_mode) || > (S_ISLNK(sb.st_mode) && > (g_stat(pathbuf, &sb, pglob) == 0) && >@@ -693,7 +693,7 @@ glob2(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend_last, > > static int > glob3(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend_last, >- Char *pattern, Char *restpattern, Char *restpattern_last, glob_t *pglob, >+ Char *pattern, Char *restpattern, Char *restpattern_last, compat_glob_t *pglob, > struct glob_lim *limitp) > { > struct dirent *dp; >@@ -718,10 +718,10 @@ glob3(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend_last, > /* TODO: don't call for ENOENT or ENOTDIR? */ > if (pglob->gl_errfunc) { > if (g_Ctoc(pathbuf, buf, sizeof(buf))) >- return(GLOB_ABORTED); >+ return(compat_GLOB_ABORTED); > if (pglob->gl_errfunc(buf, errno) || >- pglob->gl_flags & GLOB_ERR) >- return(GLOB_ABORTED); >+ pglob->gl_flags & compat_GLOB_ERR) >+ return(compat_GLOB_ABORTED); > } > return(0); > } >@@ -729,7 +729,7 @@ glob3(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend_last, > err = 0; > > /* Search directory for matching names. */ >- if (pglob->gl_flags & GLOB_ALTDIRFUNC) >+ if (pglob->gl_flags & compat_GLOB_ALTDIRFUNC) > readdirfunc = pglob->gl_readdir; > else > readdirfunc = (struct dirent *(*)(void *))readdir; >@@ -737,12 +737,12 @@ glob3(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend_last, > u_char *sc; > Char *dc; > >- if ((pglob->gl_flags & GLOB_LIMIT) && >+ if ((pglob->gl_flags & compat_GLOB_LIMIT) && > limitp->glim_readdir++ >= GLOB_LIMIT_READDIR) { > errno = 0; > *pathend++ = SEP; > *pathend = EOS; >- err = GLOB_NOSPACE; >+ err = compat_GLOB_NOSPACE; > break; > } > >@@ -769,7 +769,7 @@ glob3(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend_last, > break; > } > >- if (pglob->gl_flags & GLOB_ALTDIRFUNC) >+ if (pglob->gl_flags & compat_GLOB_ALTDIRFUNC) > (*pglob->gl_closedir)(dirp); > else > closedir(dirp); >@@ -792,7 +792,7 @@ glob3(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend_last, > * gl_pathv points to (gl_offs + gl_pathc + 1) items. > */ > static int >-globextend(const Char *path, glob_t *pglob, struct glob_lim *limitp, >+globextend(const Char *path, compat_glob_t *pglob, struct glob_lim *limitp, > struct stat *sb) > { > char **pathv; >@@ -812,7 +812,7 @@ globextend(const Char *path, glob_t *pglob, struct glob_lim *limitp, > for (i = pglob->gl_offs; i < (ssize_t)(newn - 2); i++) { > if (pglob->gl_pathv && pglob->gl_pathv[i]) > free(pglob->gl_pathv[i]); >- if ((pglob->gl_flags & GLOB_KEEPSTAT) != 0 && >+ if ((pglob->gl_flags & compat_GLOB_KEEPSTAT) != 0 && > pglob->gl_pathv && pglob->gl_pathv[i]) > free(pglob->gl_statv[i]); > } >@@ -824,7 +824,7 @@ globextend(const Char *path, glob_t *pglob, struct glob_lim *limitp, > free(pglob->gl_statv); > pglob->gl_statv = NULL; > } >- return(GLOB_NOSPACE); >+ return(compat_GLOB_NOSPACE); > } > > pathv = realloc(pglob->gl_pathv, newn * sizeof(*pathv)); >@@ -838,7 +838,7 @@ globextend(const Char *path, glob_t *pglob, struct glob_lim *limitp, > } > pglob->gl_pathv = pathv; > >- if ((pglob->gl_flags & GLOB_KEEPSTAT) != 0) { >+ if ((pglob->gl_flags & compat_GLOB_KEEPSTAT) != 0) { > statv = realloc(pglob->gl_statv, newn * sizeof(*statv)); > if (statv == NULL) > goto nospace; >@@ -853,10 +853,10 @@ globextend(const Char *path, glob_t *pglob, struct glob_lim *limitp, > statv[pglob->gl_offs + pglob->gl_pathc] = NULL; > else { > limitp->glim_malloc += sizeof(**statv); >- if ((pglob->gl_flags & GLOB_LIMIT) && >+ if ((pglob->gl_flags & compat_GLOB_LIMIT) && > limitp->glim_malloc >= GLOB_LIMIT_MALLOC) { > errno = 0; >- return(GLOB_NOSPACE); >+ return(compat_GLOB_NOSPACE); > } > if ((statv[pglob->gl_offs + pglob->gl_pathc] = > malloc(sizeof(**statv))) == NULL) >@@ -874,20 +874,20 @@ globextend(const Char *path, glob_t *pglob, struct glob_lim *limitp, > if ((copy = malloc(len)) != NULL) { > if (g_Ctoc(path, copy, len)) { > free(copy); >- return(GLOB_NOSPACE); >+ return(compat_GLOB_NOSPACE); > } > pathv[pglob->gl_offs + pglob->gl_pathc++] = copy; > } > pathv[pglob->gl_offs + pglob->gl_pathc] = NULL; > >- if ((pglob->gl_flags & GLOB_LIMIT) && >+ if ((pglob->gl_flags & compat_GLOB_LIMIT) && > (newn * sizeof(*pathv)) + limitp->glim_malloc > > GLOB_LIMIT_MALLOC) { > errno = 0; >- return(GLOB_NOSPACE); >+ return(compat_GLOB_NOSPACE); > } > copy_error: >- return(copy == NULL ? GLOB_NOSPACE : 0); >+ return(copy == NULL ? compat_GLOB_NOSPACE : 0); > } > > >@@ -902,7 +902,7 @@ match(Char *name, Char *pat, Char *patend, int recur) > Char c, k; > > if (recur-- == 0) >- return(GLOB_NOSPACE); >+ return(compat_GLOB_NOSPACE); > > while (pat < patend) { > c = *pat++; >@@ -956,7 +956,7 @@ match(Char *name, Char *pat, Char *patend, int recur) > > /* Free allocated data belonging to a glob_t structure. */ > void >-globfree(glob_t *pglob) >+compat_globfree(compat_glob_t *pglob) > { > int i; > char **pp; >@@ -980,7 +980,7 @@ globfree(glob_t *pglob) > } > > static DIR * >-g_opendir(Char *str, glob_t *pglob) >+g_opendir(Char *str, compat_glob_t *pglob) > { > char buf[MAXPATHLEN]; > >@@ -991,32 +991,32 @@ g_opendir(Char *str, glob_t *pglob) > return(NULL); > } > >- if (pglob->gl_flags & GLOB_ALTDIRFUNC) >+ if (pglob->gl_flags & compat_GLOB_ALTDIRFUNC) > return((*pglob->gl_opendir)(buf)); > > return(opendir(buf)); > } > > static int >-g_lstat(Char *fn, struct stat *sb, glob_t *pglob) >+g_lstat(Char *fn, struct stat *sb, compat_glob_t *pglob) > { > char buf[MAXPATHLEN]; > > if (g_Ctoc(fn, buf, sizeof(buf))) > return(-1); >- if (pglob->gl_flags & GLOB_ALTDIRFUNC) >+ if (pglob->gl_flags & compat_GLOB_ALTDIRFUNC) > return((*pglob->gl_lstat)(buf, sb)); > return(lstat(buf, sb)); > } > > static int >-g_stat(Char *fn, struct stat *sb, glob_t *pglob) >+g_stat(Char *fn, struct stat *sb, compat_glob_t *pglob) > { > char buf[MAXPATHLEN]; > > if (g_Ctoc(fn, buf, sizeof(buf))) > return(-1); >- if (pglob->gl_flags & GLOB_ALTDIRFUNC) >+ if (pglob->gl_flags & compat_GLOB_ALTDIRFUNC) > return((*pglob->gl_stat)(buf, sb)); > return(stat(buf, sb)); > } >diff --git a/openbsd-compat/glob.h b/openbsd-compat/glob.h >index f8a7fa5..66d7845 100644 >--- a/openbsd-compat/glob.h >+++ b/openbsd-compat/glob.h >@@ -42,8 +42,8 @@ > !defined(HAVE_DECL_GLOB_NOMATCH) || HAVE_DECL_GLOB_NOMATCH == 0 || \ > defined(BROKEN_GLOB) > >-#ifndef _GLOB_H_ >-#define _GLOB_H_ >+#ifndef _COMPAT_GLOB_H_ >+#define _COMPAT_GLOB_H_ > > #include <sys/stat.h> > >@@ -68,35 +68,35 @@ typedef struct { > void *(*gl_opendir)(const char *); > int (*gl_lstat)(const char *, struct stat *); > int (*gl_stat)(const char *, struct stat *); >-} glob_t; >+} compat_glob_t; > >-#define GLOB_APPEND 0x0001 /* Append to output from previous call. */ >-#define GLOB_DOOFFS 0x0002 /* Use gl_offs. */ >-#define GLOB_ERR 0x0004 /* Return on error. */ >-#define GLOB_MARK 0x0008 /* Append / to matching directories. */ >-#define GLOB_NOCHECK 0x0010 /* Return pattern itself if nothing matches. */ >-#define GLOB_NOSORT 0x0020 /* Don't sort. */ >-#define GLOB_NOESCAPE 0x1000 /* Disable backslash escaping. */ >+#define compat_GLOB_APPEND 0x0001 /* Append to output from previous call. */ >+#define compat_GLOB_DOOFFS 0x0002 /* Use gl_offs. */ >+#define compat_GLOB_ERR 0x0004 /* Return on error. */ >+#define compat_GLOB_MARK 0x0008 /* Append / to matching directories. */ >+#define compat_GLOB_NOCHECK 0x0010 /* Return pattern itself if nothing matches. */ >+#define compat_GLOB_NOSORT 0x0020 /* Don't sort. */ >+#define compat_GLOB_NOESCAPE 0x1000 /* Disable backslash escaping. */ > >-#define GLOB_NOSPACE (-1) /* Malloc call failed. */ >-#define GLOB_ABORTED (-2) /* Unignored error. */ >-#define GLOB_NOMATCH (-3) /* No match and GLOB_NOCHECK not set. */ >-#define GLOB_NOSYS (-4) /* Function not supported. */ >+#define compat_GLOB_NOSPACE (-1) /* Malloc call failed. */ >+#define compat_GLOB_ABORTED (-2) /* Unignored error. */ >+#define compat_GLOB_NOMATCH (-3) /* No match and GLOB_NOCHECK not set. */ >+#define compat_GLOB_NOSYS (-4) /* Function not supported. */ > >-#define GLOB_ALTDIRFUNC 0x0040 /* Use alternately specified directory funcs. */ >-#define GLOB_BRACE 0x0080 /* Expand braces ala csh. */ >-#define GLOB_MAGCHAR 0x0100 /* Pattern had globbing characters. */ >-#define GLOB_NOMAGIC 0x0200 /* GLOB_NOCHECK without magic chars (csh). */ >-#define GLOB_QUOTE 0x0400 /* Quote special chars with \. */ >-#define GLOB_TILDE 0x0800 /* Expand tilde names from the passwd file. */ >-#define GLOB_LIMIT 0x2000 /* Limit pattern match output to ARG_MAX */ >-#define GLOB_KEEPSTAT 0x4000 /* Retain stat data for paths in gl_statv. */ >-#define GLOB_ABEND GLOB_ABORTED /* backward compatibility */ >+#define compat_GLOB_ALTDIRFUNC 0x0040 /* Use alternately specified directory funcs. */ >+#define compat_GLOB_BRACE 0x0080 /* Expand braces ala csh. */ >+#define compat_GLOB_MAGCHAR 0x0100 /* Pattern had globbing characters. */ >+#define compat_GLOB_NOMAGIC 0x0200 /* GLOB_NOCHECK without magic chars (csh). */ >+#define compat_GLOB_QUOTE 0x0400 /* Quote special chars with \. */ >+#define compat_GLOB_TILDE 0x0800 /* Expand tilde names from the passwd file. */ >+#define compat_GLOB_LIMIT 0x2000 /* Limit pattern match output to ARG_MAX */ >+#define compat_GLOB_KEEPSTAT 0x4000 /* Retain stat data for paths in gl_statv. */ >+#define compat_GLOB_ABEND compat_GLOB_ABORTED /* backward compatibility */ > >-int glob(const char *, int, int (*)(const char *, int), glob_t *); >-void globfree(glob_t *); >+int compat_glob(const char *, int, int (*)(const char *, int), compat_glob_t *); >+void compat_globfree(compat_glob_t *); > >-#endif /* !_GLOB_H_ */ >+#endif /* !_COMPAT_GLOB_H_ */ > > #endif /* !defined(HAVE_GLOB_H) || !defined(GLOB_HAS_ALTDIRFUNC) || > !defined(GLOB_HAS_GL_MATCHC) || !defined(GLOH_HAS_GL_STATV) */ >diff --git a/sftp-glob.c b/sftp-glob.c >index 43a1beb..4ebb027 100644 >--- a/sftp-glob.c >+++ b/sftp-glob.c >@@ -33,7 +33,7 @@ > #include "sftp-client.h" > > int remote_glob(struct sftp_conn *, const char *, int, >- int (*)(const char *, int), glob_t *); >+ int (*)(const char *, int), GLOB_COMPAT(glob_t) *); > > struct SFTP_OPENDIR { > SFTP_DIRENT **dir; >@@ -135,7 +135,7 @@ fudge_stat(const char *path, struct stat *st) > > int > remote_glob(struct sftp_conn *conn, const char *pattern, int flags, >- int (*errfunc)(const char *, int), glob_t *pglob) >+ int (*errfunc)(const char *, int), GLOB_COMPAT(glob_t) *pglob) > { > pglob->gl_opendir = fudge_opendir; > pglob->gl_readdir = (struct dirent *(*)(void *))fudge_readdir; >@@ -146,5 +146,5 @@ remote_glob(struct sftp_conn *conn, const char *pattern, int flags, > memset(&cur, 0, sizeof(cur)); > cur.conn = conn; > >- return(glob(pattern, flags | GLOB_ALTDIRFUNC, errfunc, pglob)); >+ return(GLOB_COMPAT(glob)(pattern, flags | GLOB_COMPAT(GLOB_ALTDIRFUNC), errfunc, pglob)); > } >diff --git a/sftp.c b/sftp.c >index 788601a..3d06187 100644 >--- a/sftp.c >+++ b/sftp.c >@@ -113,7 +113,7 @@ struct complete_ctx { > }; > > int remote_glob(struct sftp_conn *, const char *, int, >- int (*)(const char *, int), glob_t *); /* proto for sftp-glob.c */ >+ int (*)(const char *, int), GLOB_COMPAT(glob_t) *); /* proto for sftp-glob.c */ > > extern char *__progname; > >@@ -590,7 +590,7 @@ process_get(struct sftp_conn *conn, char *src, char *dst, char *pwd, > { > char *abs_src = NULL; > char *abs_dst = NULL; >- glob_t g; >+ GLOB_COMPAT(glob_t) g; > char *filename, *tmp=NULL; > int i, r, err = 0; > >@@ -599,8 +599,8 @@ process_get(struct sftp_conn *conn, char *src, char *dst, char *pwd, > memset(&g, 0, sizeof(g)); > > debug3("Looking up %s", abs_src); >- if ((r = remote_glob(conn, abs_src, GLOB_MARK, NULL, &g)) != 0) { >- if (r == GLOB_NOSPACE) { >+ if ((r = remote_glob(conn, abs_src, GLOB_COMPAT(GLOB_MARK), NULL, &g)) != 0) { >+ if (r == GLOB_COMPAT(GLOB_NOSPACE)) { > error("Too many matches for \"%s\".", abs_src); > } else { > error("File \"%s\" not found.", abs_src); >@@ -664,7 +664,7 @@ process_get(struct sftp_conn *conn, char *src, char *dst, char *pwd, > > out: > free(abs_src); >- globfree(&g); >+ GLOB_COMPAT(globfree)(&g); > return(err); > } > >@@ -675,7 +675,7 @@ process_put(struct sftp_conn *conn, char *src, char *dst, char *pwd, > char *tmp_dst = NULL; > char *abs_dst = NULL; > char *tmp = NULL, *filename = NULL; >- glob_t g; >+ GLOB_COMPAT(glob_t) g; > int err = 0; > int i, dst_is_dir = 1; > struct stat sb; >@@ -687,7 +687,7 @@ process_put(struct sftp_conn *conn, char *src, char *dst, char *pwd, > > memset(&g, 0, sizeof(g)); > debug3("Looking up %s", src); >- if (glob(src, GLOB_NOCHECK | GLOB_MARK, NULL, &g)) { >+ if (GLOB_COMPAT(glob)(src, GLOB_COMPAT(GLOB_NOCHECK) | GLOB_COMPAT(GLOB_MARK), NULL, &g)) { > error("File \"%s\" not found.", src); > err = -1; > goto out; >@@ -755,7 +755,7 @@ process_put(struct sftp_conn *conn, char *src, char *dst, char *pwd, > out: > free(abs_dst); > free(tmp_dst); >- globfree(&g); >+ GLOB_COMPAT(globfree)(&g); > return(err); > } > >@@ -868,20 +868,21 @@ do_globbed_ls(struct sftp_conn *conn, char *path, char *strip_path, > int lflag) > { > char *fname, *lname; >- glob_t g; >+ compat_glob_t g; > int err, r; > struct winsize ws; > u_int i, c = 1, colspace = 0, columns = 1, m = 0, width = 80; > > memset(&g, 0, sizeof(g)); > >- if ((r = remote_glob(conn, path, >- GLOB_MARK|GLOB_NOCHECK|GLOB_BRACE|GLOB_KEEPSTAT|GLOB_NOSORT, >+ if ((r = remote_glob(conn, path,GLOB_COMPAT(GLOB_MARK)| >+ GLOB_COMPAT(GLOB_NOCHECK)| GLOB_COMPAT(GLOB_BRACE)| >+ GLOB_COMPAT(GLOB_KEEPSTAT)|GLOB_COMPAT(GLOB_NOSORT), > NULL, &g)) != 0 || > (g.gl_pathc && !g.gl_matchc)) { > if (g.gl_pathc) >- globfree(&g); >- if (r == GLOB_NOSPACE) { >+ GLOB_COMPAT(globfree)(&g); >+ if (r == GLOB_COMPAT(GLOB_NOSPACE)) { > error("Can't ls: Too many matches for \"%s\"", path); > } else { > error("Can't ls: \"%s\" not found", path); >@@ -899,7 +900,7 @@ do_globbed_ls(struct sftp_conn *conn, char *path, char *strip_path, > if (g.gl_matchc == 1 && g.gl_statv[0] != NULL && > S_ISDIR(g.gl_statv[0]->st_mode)) { > err = do_ls_dir(conn, g.gl_pathv[0], strip_path, lflag); >- globfree(&g); >+ GLOB_COMPAT(globfree)(&g); > return err; > } > >@@ -943,7 +944,7 @@ do_globbed_ls(struct sftp_conn *conn, char *path, char *strip_path, > > out: > if (g.gl_pathc) >- globfree(&g); >+ GLOB_COMPAT(globfree)(&g); > > return 0; > } >@@ -1405,7 +1406,7 @@ parse_dispatch_command(struct sftp_conn *conn, const char *cmd, char **pwd, > Attrib a, *aa; > char path_buf[PATH_MAX]; > int err = 0; >- glob_t g; >+ GLOB_COMPAT(glob_t) g; > > path1 = path2 = NULL; > cmdnum = parse_args(&cmd, &ignore_errors, &aflag, &fflag, &hflag, >@@ -1453,7 +1454,7 @@ parse_dispatch_command(struct sftp_conn *conn, const char *cmd, char **pwd, > break; > case I_RM: > path1 = make_absolute(path1, *pwd); >- remote_glob(conn, path1, GLOB_NOCHECK, NULL, &g); >+ remote_glob(conn, path1, GLOB_COMPAT(GLOB_NOCHECK), NULL, &g); > for (i = 0; g.gl_pathv[i] && !interrupted; i++) { > if (!quiet) > printf("Removing %s\n", g.gl_pathv[i]); >@@ -1553,7 +1554,7 @@ parse_dispatch_command(struct sftp_conn *conn, const char *cmd, char **pwd, > attrib_clear(&a); > a.flags |= SSH2_FILEXFER_ATTR_PERMISSIONS; > a.perm = n_arg; >- remote_glob(conn, path1, GLOB_NOCHECK, NULL, &g); >+ remote_glob(conn, path1, GLOB_COMPAT(GLOB_NOCHECK), NULL, &g); > for (i = 0; g.gl_pathv[i] && !interrupted; i++) { > if (!quiet) > printf("Changing mode on %s\n", g.gl_pathv[i]); >@@ -1565,7 +1566,7 @@ parse_dispatch_command(struct sftp_conn *conn, const char *cmd, char **pwd, > case I_CHOWN: > case I_CHGRP: > path1 = make_absolute(path1, *pwd); >- remote_glob(conn, path1, GLOB_NOCHECK, NULL, &g); >+ remote_glob(conn, path1, GLOB_COMPAT(GLOB_NOCHECK), NULL, &g); > for (i = 0; g.gl_pathv[i] && !interrupted; i++) { > if (!(aa = do_stat(conn, g.gl_pathv[i], 0))) { > if (err_abort) { >@@ -1632,7 +1633,7 @@ parse_dispatch_command(struct sftp_conn *conn, const char *cmd, char **pwd, > } > > if (g.gl_pathc) >- globfree(&g); >+ GLOB_COMPAT(globfree)(&g); > free(path1); > free(path2); > >@@ -1820,7 +1821,7 @@ static int > complete_match(EditLine *el, struct sftp_conn *conn, char *remote_path, > char *file, int remote, int lastarg, char quote, int terminated) > { >- glob_t g; >+ GLOB_COMPAT(glob_t) g; > char *tmp, *tmp2, ins[8]; > u_int i, hadglob, pwdlen, len, tmplen, filelen, cesc, isesc, isabs; > int clen; >@@ -1838,9 +1839,11 @@ complete_match(EditLine *el, struct sftp_conn *conn, char *remote_path, > memset(&g, 0, sizeof(g)); > if (remote != LOCAL) { > tmp = make_absolute(tmp, remote_path); >- remote_glob(conn, tmp, GLOB_DOOFFS|GLOB_MARK, NULL, &g); >+ remote_glob(conn, tmp, GLOB_COMPAT(GLOB_DOOFFS)| >+ GLOB_COMPAT(GLOB_MARK), NULL, &g); > } else >- glob(tmp, GLOB_DOOFFS|GLOB_MARK, NULL, &g); >+ GLOB_COMPAT(glob)(tmp, GLOB_COMPAT(GLOB_DOOFFS)| >+ GLOB_COMPAT(GLOB_MARK), NULL, &g); > > /* Determine length of pwd so we can trim completion display */ > for (hadglob = tmplen = pwdlen = 0; tmp[tmplen] != 0; tmplen++) { >@@ -1938,7 +1941,7 @@ complete_match(EditLine *el, struct sftp_conn *conn, char *remote_path, > free(tmp); > > out: >- globfree(&g); >+ GLOB_COMPAT(globfree)(&g); > return g.gl_matchc; > } > >-- >2.1.0 >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Flags:
dtucker
:
ok-
Actions:
View
|
Diff
Attachments on
bug 2463
:
2701
|
2704
|
2707
|
2708
|
2709