diff options
author | Darren Tucker <dtucker@zip.com.au> | 2005-11-10 17:02:21 +1100 |
---|---|---|
committer | Darren Tucker <dtucker@zip.com.au> | 2005-11-10 17:02:21 +1100 |
commit | 6524d4f161d0505af2926c34e19032e1fcd102fd (patch) | |
tree | 7c84af7db98da84389d6ec7ada0cd2caadb2a2cf /openbsd-compat/glob.c | |
parent | d76b4c74f808d356ac620fa18ee9e3c3ab75dd0c (diff) |
- (dtucker) [openbsd-compat/glob.c] Update from OpenBSD 1.22 -> 1.25.
Diffstat (limited to 'openbsd-compat/glob.c')
-rw-r--r-- | openbsd-compat/glob.c | 118 |
1 files changed, 33 insertions, 85 deletions
diff --git a/openbsd-compat/glob.c b/openbsd-compat/glob.c index e00db7079..f6a04ea3f 100644 --- a/openbsd-compat/glob.c +++ b/openbsd-compat/glob.c | |||
@@ -1,3 +1,4 @@ | |||
1 | /* $OpenBSD: glob.c,v 1.25 2005/08/08 08:05:34 espie Exp $ */ | ||
1 | /* | 2 | /* |
2 | * Copyright (c) 1989, 1993 | 3 | * Copyright (c) 1989, 1993 |
3 | * The Regents of the University of California. All rights reserved. | 4 | * The Regents of the University of California. All rights reserved. |
@@ -50,14 +51,6 @@ get_arg_max(void) | |||
50 | #if !defined(HAVE_GLOB) || !defined(GLOB_HAS_ALTDIRFUNC) || \ | 51 | #if !defined(HAVE_GLOB) || !defined(GLOB_HAS_ALTDIRFUNC) || \ |
51 | !defined(GLOB_HAS_GL_MATCHC) | 52 | !defined(GLOB_HAS_GL_MATCHC) |
52 | 53 | ||
53 | #if defined(LIBC_SCCS) && !defined(lint) | ||
54 | #if 0 | ||
55 | static char sccsid[] = "@(#)glob.c 8.3 (Berkeley) 10/13/93"; | ||
56 | #else | ||
57 | static char rcsid[] = "$OpenBSD: glob.c,v 1.22 2003/06/25 21:16:47 deraadt Exp $"; | ||
58 | #endif | ||
59 | #endif /* LIBC_SCCS and not lint */ | ||
60 | |||
61 | /* | 54 | /* |
62 | * glob(3) -- a superset of the one defined in POSIX 1003.2. | 55 | * glob(3) -- a superset of the one defined in POSIX 1003.2. |
63 | * | 56 | * |
@@ -158,10 +151,8 @@ static void qprintf(const char *, Char *); | |||
158 | #endif | 151 | #endif |
159 | 152 | ||
160 | int | 153 | int |
161 | glob(pattern, flags, errfunc, pglob) | 154 | glob(const char *pattern, int flags, int (*errfunc)(const char *, int), |
162 | const char *pattern; | 155 | glob_t *pglob) |
163 | int flags, (*errfunc)(const char *, int); | ||
164 | glob_t *pglob; | ||
165 | { | 156 | { |
166 | const u_char *patnext; | 157 | const u_char *patnext; |
167 | int c; | 158 | int c; |
@@ -209,9 +200,7 @@ glob(pattern, flags, errfunc, pglob) | |||
209 | * characters | 200 | * characters |
210 | */ | 201 | */ |
211 | static int | 202 | static int |
212 | globexp1(pattern, pglob) | 203 | globexp1(const Char *pattern, glob_t *pglob) |
213 | const Char *pattern; | ||
214 | glob_t *pglob; | ||
215 | { | 204 | { |
216 | const Char* ptr = pattern; | 205 | const Char* ptr = pattern; |
217 | int rv; | 206 | int rv; |
@@ -234,10 +223,7 @@ globexp1(pattern, pglob) | |||
234 | * If it fails then it tries to glob the rest of the pattern and returns. | 223 | * If it fails then it tries to glob the rest of the pattern and returns. |
235 | */ | 224 | */ |
236 | static int | 225 | static int |
237 | globexp2(ptr, pattern, pglob, rv) | 226 | globexp2(const Char *ptr, const Char *pattern, glob_t *pglob, int *rv) |
238 | const Char *ptr, *pattern; | ||
239 | glob_t *pglob; | ||
240 | int *rv; | ||
241 | { | 227 | { |
242 | int i; | 228 | int i; |
243 | Char *lm, *ls; | 229 | Char *lm, *ls; |
@@ -342,11 +328,7 @@ globexp2(ptr, pattern, pglob, rv) | |||
342 | * expand tilde from the passwd file. | 328 | * expand tilde from the passwd file. |
343 | */ | 329 | */ |
344 | static const Char * | 330 | static const Char * |
345 | globtilde(pattern, patbuf, patbuf_len, pglob) | 331 | globtilde(const Char *pattern, Char *patbuf, size_t patbuf_len, glob_t *pglob) |
346 | const Char *pattern; | ||
347 | Char *patbuf; | ||
348 | size_t patbuf_len; | ||
349 | glob_t *pglob; | ||
350 | { | 332 | { |
351 | struct passwd *pwd; | 333 | struct passwd *pwd; |
352 | char *h; | 334 | char *h; |
@@ -414,9 +396,7 @@ globtilde(pattern, patbuf, patbuf_len, pglob) | |||
414 | * to find no matches. | 396 | * to find no matches. |
415 | */ | 397 | */ |
416 | static int | 398 | static int |
417 | glob0(pattern, pglob) | 399 | glob0(const Char *pattern, glob_t *pglob) |
418 | const Char *pattern; | ||
419 | glob_t *pglob; | ||
420 | { | 400 | { |
421 | const Char *qpatnext; | 401 | const Char *qpatnext; |
422 | int c, err, oldpathc; | 402 | int c, err, oldpathc; |
@@ -503,17 +483,13 @@ glob0(pattern, pglob) | |||
503 | } | 483 | } |
504 | 484 | ||
505 | static int | 485 | static int |
506 | compare(p, q) | 486 | compare(const void *p, const void *q) |
507 | const void *p, *q; | ||
508 | { | 487 | { |
509 | return(strcmp(*(char **)p, *(char **)q)); | 488 | return(strcmp(*(char **)p, *(char **)q)); |
510 | } | 489 | } |
511 | 490 | ||
512 | static int | 491 | static int |
513 | glob1(pattern, pattern_last, pglob, limitp) | 492 | glob1(Char *pattern, Char *pattern_last, glob_t *pglob, size_t *limitp) |
514 | Char *pattern, *pattern_last; | ||
515 | glob_t *pglob; | ||
516 | size_t *limitp; | ||
517 | { | 493 | { |
518 | Char pathbuf[MAXPATHLEN]; | 494 | Char pathbuf[MAXPATHLEN]; |
519 | 495 | ||
@@ -531,12 +507,8 @@ glob1(pattern, pattern_last, pglob, limitp) | |||
531 | * meta characters. | 507 | * meta characters. |
532 | */ | 508 | */ |
533 | static int | 509 | static int |
534 | glob2(pathbuf, pathbuf_last, pathend, pathend_last, pattern, | 510 | glob2(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend_last, |
535 | pattern_last, pglob, limitp) | 511 | Char *pattern, Char *pattern_last, glob_t *pglob, size_t *limitp) |
536 | Char *pathbuf, *pathbuf_last, *pathend, *pathend_last; | ||
537 | Char *pattern, *pattern_last; | ||
538 | glob_t *pglob; | ||
539 | size_t *limitp; | ||
540 | { | 512 | { |
541 | struct stat sb; | 513 | struct stat sb; |
542 | Char *p, *q; | 514 | Char *p, *q; |
@@ -595,14 +567,11 @@ glob2(pathbuf, pathbuf_last, pathend, pathend_last, pattern, | |||
595 | } | 567 | } |
596 | 568 | ||
597 | static int | 569 | static int |
598 | glob3(pathbuf, pathbuf_last, pathend, pathend_last, pattern, pattern_last, | 570 | glob3(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend_last, |
599 | restpattern, restpattern_last, pglob, limitp) | 571 | Char *pattern, Char *pattern_last, Char *restpattern, |
600 | Char *pathbuf, *pathbuf_last, *pathend, *pathend_last; | 572 | Char *restpattern_last, glob_t *pglob, size_t *limitp) |
601 | Char *pattern, *pattern_last, *restpattern, *restpattern_last; | ||
602 | glob_t *pglob; | ||
603 | size_t *limitp; | ||
604 | { | 573 | { |
605 | register struct dirent *dp; | 574 | struct dirent *dp; |
606 | DIR *dirp; | 575 | DIR *dirp; |
607 | int err; | 576 | int err; |
608 | char buf[MAXPATHLEN]; | 577 | char buf[MAXPATHLEN]; |
@@ -640,8 +609,8 @@ glob3(pathbuf, pathbuf_last, pathend, pathend_last, pattern, pattern_last, | |||
640 | else | 609 | else |
641 | readdirfunc = (struct dirent *(*)(void *))readdir; | 610 | readdirfunc = (struct dirent *(*)(void *))readdir; |
642 | while ((dp = (*readdirfunc)(dirp))) { | 611 | while ((dp = (*readdirfunc)(dirp))) { |
643 | register u_char *sc; | 612 | u_char *sc; |
644 | register Char *dc; | 613 | Char *dc; |
645 | 614 | ||
646 | /* Initial DOT must be matched literally. */ | 615 | /* Initial DOT must be matched literally. */ |
647 | if (dp->d_name[0] == DOT && *pattern != DOT) | 616 | if (dp->d_name[0] == DOT && *pattern != DOT) |
@@ -689,13 +658,10 @@ glob3(pathbuf, pathbuf_last, pathend, pathend_last, pattern, pattern_last, | |||
689 | * gl_pathv points to (gl_offs + gl_pathc + 1) items. | 658 | * gl_pathv points to (gl_offs + gl_pathc + 1) items. |
690 | */ | 659 | */ |
691 | static int | 660 | static int |
692 | globextend(path, pglob, limitp) | 661 | globextend(const Char *path, glob_t *pglob, size_t *limitp) |
693 | const Char *path; | ||
694 | glob_t *pglob; | ||
695 | size_t *limitp; | ||
696 | { | 662 | { |
697 | register char **pathv; | 663 | char **pathv; |
698 | register int i; | 664 | int i; |
699 | u_int newsize, len; | 665 | u_int newsize, len; |
700 | char *copy; | 666 | char *copy; |
701 | const Char *p; | 667 | const Char *p; |
@@ -747,8 +713,7 @@ globextend(path, pglob, limitp) | |||
747 | * pattern causes a recursion level. | 713 | * pattern causes a recursion level. |
748 | */ | 714 | */ |
749 | static int | 715 | static int |
750 | match(name, pat, patend) | 716 | match(Char *name, Char *pat, Char *patend) |
751 | register Char *name, *pat, *patend; | ||
752 | { | 717 | { |
753 | int ok, negate_range; | 718 | int ok, negate_range; |
754 | Char c, k; | 719 | Char c, k; |
@@ -759,11 +724,10 @@ match(name, pat, patend) | |||
759 | case M_ALL: | 724 | case M_ALL: |
760 | if (pat == patend) | 725 | if (pat == patend) |
761 | return(1); | 726 | return(1); |
762 | do | 727 | do { |
763 | if (match(name, pat, patend)) | 728 | if (match(name, pat, patend)) |
764 | return(1); | 729 | return(1); |
765 | while (*name++ != EOS) | 730 | } while (*name++ != EOS); |
766 | ; | ||
767 | return(0); | 731 | return(0); |
768 | case M_ONE: | 732 | case M_ONE: |
769 | if (*name++ == EOS) | 733 | if (*name++ == EOS) |
@@ -796,11 +760,10 @@ match(name, pat, patend) | |||
796 | 760 | ||
797 | /* Free allocated data belonging to a glob_t structure. */ | 761 | /* Free allocated data belonging to a glob_t structure. */ |
798 | void | 762 | void |
799 | globfree(pglob) | 763 | globfree(glob_t *pglob) |
800 | glob_t *pglob; | ||
801 | { | 764 | { |
802 | register int i; | 765 | int i; |
803 | register char **pp; | 766 | char **pp; |
804 | 767 | ||
805 | if (pglob->gl_pathv != NULL) { | 768 | if (pglob->gl_pathv != NULL) { |
806 | pp = pglob->gl_pathv + pglob->gl_offs; | 769 | pp = pglob->gl_pathv + pglob->gl_offs; |
@@ -813,9 +776,7 @@ globfree(pglob) | |||
813 | } | 776 | } |
814 | 777 | ||
815 | static DIR * | 778 | static DIR * |
816 | g_opendir(str, pglob) | 779 | g_opendir(Char *str, glob_t *pglob) |
817 | register Char *str; | ||
818 | glob_t *pglob; | ||
819 | { | 780 | { |
820 | char buf[MAXPATHLEN]; | 781 | char buf[MAXPATHLEN]; |
821 | 782 | ||
@@ -833,10 +794,7 @@ g_opendir(str, pglob) | |||
833 | } | 794 | } |
834 | 795 | ||
835 | static int | 796 | static int |
836 | g_lstat(fn, sb, pglob) | 797 | g_lstat(Char *fn, struct stat *sb, glob_t *pglob) |
837 | register Char *fn; | ||
838 | struct stat *sb; | ||
839 | glob_t *pglob; | ||
840 | { | 798 | { |
841 | char buf[MAXPATHLEN]; | 799 | char buf[MAXPATHLEN]; |
842 | 800 | ||
@@ -848,10 +806,7 @@ g_lstat(fn, sb, pglob) | |||
848 | } | 806 | } |
849 | 807 | ||
850 | static int | 808 | static int |
851 | g_stat(fn, sb, pglob) | 809 | g_stat(Char *fn, struct stat *sb, glob_t *pglob) |
852 | register Char *fn; | ||
853 | struct stat *sb; | ||
854 | glob_t *pglob; | ||
855 | { | 810 | { |
856 | char buf[MAXPATHLEN]; | 811 | char buf[MAXPATHLEN]; |
857 | 812 | ||
@@ -863,9 +818,7 @@ g_stat(fn, sb, pglob) | |||
863 | } | 818 | } |
864 | 819 | ||
865 | static Char * | 820 | static Char * |
866 | g_strchr(str, ch) | 821 | g_strchr(Char *str, int ch) |
867 | Char *str; | ||
868 | int ch; | ||
869 | { | 822 | { |
870 | do { | 823 | do { |
871 | if (*str == ch) | 824 | if (*str == ch) |
@@ -875,10 +828,7 @@ g_strchr(str, ch) | |||
875 | } | 828 | } |
876 | 829 | ||
877 | static int | 830 | static int |
878 | g_Ctoc(str, buf, len) | 831 | g_Ctoc(const Char *str, char *buf, u_int len) |
879 | register const Char *str; | ||
880 | char *buf; | ||
881 | u_int len; | ||
882 | { | 832 | { |
883 | 833 | ||
884 | while (len--) { | 834 | while (len--) { |
@@ -890,11 +840,9 @@ g_Ctoc(str, buf, len) | |||
890 | 840 | ||
891 | #ifdef DEBUG | 841 | #ifdef DEBUG |
892 | static void | 842 | static void |
893 | qprintf(str, s) | 843 | qprintf(const char *str, Char *s) |
894 | const char *str; | ||
895 | register Char *s; | ||
896 | { | 844 | { |
897 | register Char *p; | 845 | Char *p; |
898 | 846 | ||
899 | (void)printf("%s:\n", str); | 847 | (void)printf("%s:\n", str); |
900 | for (p = s; *p; p++) | 848 | for (p = s; *p; p++) |