diff options
author | Damien Miller <djm@cvs.openbsd.org> | 2010-09-24 13:32:56 +0000 |
---|---|---|
committer | Damien Miller <djm@cvs.openbsd.org> | 2010-09-24 13:32:56 +0000 |
commit | 898c385370762cd3fd1a6fa08058a30f7511fa79 (patch) | |
tree | c9c36ef54367699bdaf54b8bd9581c3f8736cb86 /regress/lib/libc | |
parent | 0df142c814e864e0da4dbc09c556d9632501d2ee (diff) |
add a GLOB_KEEPSTAT option that retains a copy of the struct stat
information that is looked up while matching glob(3)s
Keeping this information around can make a big difference when
fetching it is expensive, e.g. in sftp which uses GLOB_ALTDIRFUNC
feedback millert@ jmc@
"get it in before the libc crank" deraadt@
Diffstat (limited to 'regress/lib/libc')
-rw-r--r-- | regress/lib/libc/glob/Makefile | 5 | ||||
-rw-r--r-- | regress/lib/libc/glob/globtest.c | 39 | ||||
-rw-r--r-- | regress/lib/libc/glob/globtest.in | 52 |
3 files changed, 86 insertions, 10 deletions
diff --git a/regress/lib/libc/glob/Makefile b/regress/lib/libc/glob/Makefile index 6b93edfc386..ef209a3e189 100644 --- a/regress/lib/libc/glob/Makefile +++ b/regress/lib/libc/glob/Makefile @@ -1,10 +1,13 @@ -# $OpenBSD: Makefile,v 1.2 2009/02/18 15:17:55 millert Exp $ +# $OpenBSD: Makefile,v 1.3 2010/09/24 13:32:55 djm Exp $ PROG= globtest run-regress-${PROG}: mkdir -p `sed 's@/[^/]*$$@@' ${.CURDIR}/files | sort -u` touch `cat ${.CURDIR}/files` + chmod 0755 `grep '/r[^/]*$$' ${.CURDIR}/files` + chmod 0444 `grep '/s[^/]*$$' ${.CURDIR}/files` + chmod 0711 `grep '/t[^/]*$$' ${.CURDIR}/files` ./${PROG} ${.CURDIR}/${PROG}.in clean: diff --git a/regress/lib/libc/glob/globtest.c b/regress/lib/libc/glob/globtest.c index f8f93573c65..e47a728da81 100644 --- a/regress/lib/libc/glob/globtest.c +++ b/regress/lib/libc/glob/globtest.c @@ -1,4 +1,4 @@ -/* $OpenBSD: globtest.c,v 1.1 2008/10/01 23:04:36 millert Exp $ */ +/* $OpenBSD: globtest.c,v 1.2 2010/09/24 13:32:55 djm Exp $ */ /* * Public domain, 2008, Todd C. Miller <Todd.Miller@courtesan.com> @@ -17,6 +17,7 @@ struct gl_entry { int nresults; char pattern[1024]; char *results[MAX_RESULTS]; + long modes[MAX_RESULTS]; }; int test_glob(struct gl_entry *); @@ -27,7 +28,7 @@ main(int argc, char **argv) FILE *fp = stdin; char *buf, *cp, *want, *got, *last; const char *errstr; - int errors = 0, i, lineno; + int errors = 0, i, lineno, mode; struct gl_entry entry; size_t len; @@ -40,9 +41,9 @@ main(int argc, char **argv) * Read in test file, which is formatted thusly: * * [pattern] <flags> - * result1 - * result2 - * result3 + * result1 [mode] + * result2 [mode] + * result3 [mode] * ... * */ @@ -76,7 +77,7 @@ main(int argc, char **argv) if ((cp = strchr(buf, '>')) == NULL) errx(1, "invalid entry on line %d", lineno); entry.flags = (int)strtol(buf, &cp, 0); - if (*cp != '>' || entry.flags < 0 || entry.flags > 0x2000) + if (*cp != '>' || entry.flags < 0 || entry.flags > 0x4000) errx(1, "invalid flags: %s", buf); entry.nresults = 0; continue; @@ -88,6 +89,12 @@ main(int argc, char **argv) errx(1, "too many results for %s, max %d", entry.pattern, MAX_RESULTS); } + if ((cp = strchr(buf, ' ')) != NULL) { + *cp++ = '\0'; + mode = strtol(cp, NULL, 8); + } else + mode = -1; + entry.modes[entry.nresults] = mode; entry.results[entry.nresults++] = strdup(buf); } if (entry.pattern[0]) @@ -109,12 +116,26 @@ int test_glob(struct gl_entry *entry) for (i = 0; i < gl.gl_matchc; i++) { if (strcmp(gl.gl_pathv[i], entry->results[i]) != 0) goto mismatch; + if ((entry->flags & GLOB_KEEPSTAT) != 0) { + if (entry->modes[i] == -1 || + gl.gl_statv[i] == NULL || + entry->modes[i] != gl.gl_statv[i]->st_mode) + goto badmode; + } free(entry->results[i]); } return (0); -mismatch: - warnx("mismatch for pattern %s, flags 0x%x", entry->pattern, - entry->flags); + badmode: + warnx("mismatch mode for pattern %s, flags 0x%x, file \"%s\" " + "(found %07o, expected %07o)", entry->pattern, entry->flags, + gl.gl_pathv[i], gl.gl_statv[i] ? gl.gl_statv[i]->st_mode : 0, + entry->modes[i]); + goto cleanup; + mismatch: + warnx("mismatch for pattern %s, flags 0x%x " + "(found \"%s\", expected \"%s\")", entry->pattern, entry->flags, + gl.gl_pathv[i], entry->results[i]); + cleanup: while (i < gl.gl_matchc) { free(entry->results[i++]); } diff --git a/regress/lib/libc/glob/globtest.in b/regress/lib/libc/glob/globtest.in index 5995fa4b31d..2ae3b4dfb26 100644 --- a/regress/lib/libc/glob/globtest.in +++ b/regress/lib/libc/glob/globtest.in @@ -46,6 +46,54 @@ fake/bin/systrace fake/bin/tar fake/bin/test +[fake/bin/[[:alpha:]]*] <0x4000> +fake/bin/cat 0100644 +fake/bin/chgrp 0100644 +fake/bin/chio 0100644 +fake/bin/chmod 0100644 +fake/bin/cksum 0100644 +fake/bin/cp 0100644 +fake/bin/cpio 0100644 +fake/bin/csh 0100644 +fake/bin/date 0100644 +fake/bin/dd 0100644 +fake/bin/df 0100644 +fake/bin/domainname 0100644 +fake/bin/echo 0100644 +fake/bin/ed 0100644 +fake/bin/eject 0100644 +fake/bin/expr 0100644 +fake/bin/hostname 0100644 +fake/bin/kill 0100644 +fake/bin/ksh 0100644 +fake/bin/ln 0100644 +fake/bin/ls 0100644 +fake/bin/md5 0100644 +fake/bin/mkdir 0100644 +fake/bin/mt 0100644 +fake/bin/mv 0100644 +fake/bin/pax 0100644 +fake/bin/ps 0100644 +fake/bin/pwd 0100644 +fake/bin/rcp 0100755 +fake/bin/rksh 0100755 +fake/bin/rm 0100755 +fake/bin/rmail 0100755 +fake/bin/rmd160 0100755 +fake/bin/rmdir 0100755 +fake/bin/sh 0100444 +fake/bin/sha1 0100444 +fake/bin/sha256 0100444 +fake/bin/sha384 0100444 +fake/bin/sha512 0100444 +fake/bin/sleep 0100444 +fake/bin/stty 0100444 +fake/bin/sum 0100444 +fake/bin/sync 0100444 +fake/bin/systrace 0100444 +fake/bin/tar 0100711 +fake/bin/test 0100711 + [fake/bin/rm{,dir,ail}] <0x80> fake/bin/rm fake/bin/rmdir @@ -62,3 +110,7 @@ fake/bin/sha512 [fake/bin/ca[a-z]] <0x0> fake/bin/cat + +[fake/b[a-z]*] <0x4000> +fake/bin 0040755 + |