Project

General

Profile

Bug #1097 » glob.c-sty.diff

Gary Mills, 2012-11-08 02:56 PM

View differences:

glob.c Tue Nov 6 11:32:41 2012
122 122
#define	M_MASK		0xffff
123 123
#define	M_ASCII		0x00ff
124 124

  
125
typedef u_short Char;
125
typedef ushort_t Char;
126 126

  
127 127
#else
128 128

  
......
152 152
#define	GLOB_LIMIT_READDIR	16384
153 153

  
154 154
/* Limit of recursion during matching attempts. */
155
#define GLOB_LIMIT_RECUR	64
155
#define	GLOB_LIMIT_RECUR	64
156 156

  
157 157
struct glob_lim {
158 158
	size_t	glim_malloc;
......
167 167

  
168 168
static int	 compare(const void *, const void *);
169 169
static int	 compare_gps(const void *, const void *);
170
static int	 g_Ctoc(const Char *, char *, u_int);
170
static int	 g_Ctoc(const Char *, char *, uint_t);
171 171
static int	 g_lstat(Char *, struct stat *, glob_t *);
172 172
static DIR	*g_opendir(Char *, glob_t *);
173 173
static Char	*g_strchr(const Char *, int);
174 174
static int	 g_strncmp(const Char *, const char *, size_t);
175 175
static int	 g_stat(Char *, struct stat *, glob_t *);
176 176
static int	 glob0(const Char *, glob_t *, struct glob_lim *,
177
		       int (*)(const char *, int));
177
			int (*)(const char *, int));
178 178
static int	 glob1(Char *, Char *, glob_t *, struct glob_lim *,
179
		       int (*)(const char *, int));
179
			int (*)(const char *, int));
180 180
static int	 glob2(Char *, Char *, Char *, Char *, Char *, Char *,
181
		       glob_t *, struct glob_lim *,
182
		       int (*)(const char *, int));
181
			glob_t *, struct glob_lim *,
182
			int (*)(const char *, int));
183 183
static int	 glob3(Char *, Char *, Char *, Char *, Char *,
184
		       Char *, Char *, glob_t *, struct glob_lim *,
185
		       int (*)(const char *, int));
184
			Char *, Char *, glob_t *, struct glob_lim *,
185
			int (*)(const char *, int));
186 186
static int	 globextend(const Char *, glob_t *, struct glob_lim *,
187 187
		    struct stat *);
188
static const Char *
189
		 globtilde(const Char *, Char *, size_t, glob_t *);
188
static
189
const Char	*globtilde(const Char *, Char *, size_t, glob_t *);
190 190
static int	 globexp1(const Char *, glob_t *, struct glob_lim *,
191
			  int (*)(const char *, int));
191
		    int (*)(const char *, int));
192 192
static int	 globexp2(const Char *, const Char *, glob_t *,
193
			  struct glob_lim *, int (*)(const char *, int));
193
		    struct glob_lim *, int (*)(const char *, int));
194 194
static int	 match(Char *, Char *, Char *, int);
195 195
#ifdef DEBUG
196 196
static void	 qprintf(const char *, Char *);
......
200 200
glob(const char *pattern, int flags, int (*errfunc)(const char *, int),
201 201
    glob_t *pglob)
202 202
{
203
	const u_char *patnext;
203
	const uchar_t *patnext;
204 204
	int c;
205 205
	Char *bufnext, *bufend, patbuf[MAXPATHLEN];
206 206
	struct glob_lim limit = { 0, 0, 0 };
207 207

  
208 208
	if (strnlen(pattern, PATH_MAX) == PATH_MAX)
209
		return(GLOB_NOMATCH);
209
		return (GLOB_NOMATCH);
210 210

  
211
	patnext = (u_char *) pattern;
211
	patnext = (uchar_t *)pattern;
212 212
	if (!(flags & GLOB_APPEND)) {
213 213
		pglob->gl_pathc = 0;
214 214
		pglob->gl_pathv = NULL;
215 215
		if ((flags & GLOB_KEEPSTAT) != 0)
216
		  pglob->gl_statv = NULL;
216
			pglob->gl_statv = NULL;
217 217
		if (!(flags & GLOB_DOOFFS))
218 218
			pglob->gl_offs = 0;
219 219
	}
......
223 223
	if (pglob->gl_offs < 0 || pglob->gl_pathc < 0 ||
224 224
	    pglob->gl_offs >= INT_MAX || pglob->gl_pathc >= INT_MAX ||
225 225
	    pglob->gl_pathc >= INT_MAX - pglob->gl_offs - 1)
226
		return GLOB_NOSPACE;
226
		return (GLOB_NOSPACE);
227 227

  
228 228
	bufnext = patbuf;
229 229
	bufend = bufnext + MAXPATHLEN - 1;
......
245 245
	*bufnext = EOS;
246 246

  
247 247
	if (flags & GLOB_BRACE)
248
	  return globexp1(patbuf, pglob, &limit, errfunc);
248
		return (globexp1(patbuf, pglob, &limit, errfunc));
249 249
	else
250
	  return glob0(patbuf, pglob, &limit, errfunc);
250
		return (glob0(patbuf, pglob, &limit, errfunc));
251 251
}
252 252

  
253 253
/*
......
257 257
 */
258 258
static int
259 259
globexp1(const Char *pattern, glob_t *pglob, struct glob_lim *limitp,
260
	 int (*errfunc)(const char *, int))
260
    int (*errfunc)(const char *, int))
261 261
{
262 262
	const Char* ptr = pattern;
263 263

  
264 264
	/* Protect a single {}, for find(1), like csh */
265 265
	if (pattern[0] == LBRACE && pattern[1] == RBRACE && pattern[2] == EOS)
266
	  return glob0(pattern, pglob, limitp, errfunc);
266
		return (glob0(pattern, pglob, limitp, errfunc));
267 267

  
268 268
	if ((ptr = (const Char *) g_strchr(ptr, LBRACE)) != NULL)
269
	  return globexp2(ptr, pattern, pglob, limitp, errfunc);
269
		return (globexp2(ptr, pattern, pglob, limitp, errfunc));
270 270

  
271
	return glob0(pattern, pglob, limitp, errfunc);
271
	return (glob0(pattern, pglob, limitp, errfunc));
272 272
}
273 273

  
274 274

  
......
279 279
 */
280 280
static int
281 281
globexp2(const Char *ptr, const Char *pattern, glob_t *pglob,
282
	 struct glob_lim *limitp, int (*errfunc)(const char *, int))
282
    struct glob_lim *limitp, int (*errfunc)(const char *, int))
283 283
{
284
	int     i, rv;
284
	int	i, rv;
285 285
	Char   *lm, *ls;
286 286
	const Char *pe, *pm, *pl;
287 287
	Char    patbuf[MAXPATHLEN];
......
315 315

  
316 316
	/* Non matching braces; just glob the pattern */
317 317
	if (i != 0 || *pe == EOS)
318
	  return glob0(patbuf, pglob, limitp, errfunc);
318
		return (glob0(patbuf, pglob, limitp, errfunc));
319 319

  
320 320
	for (i = 0, pl = pm = ptr; pm <= pe; pm++) {
321 321
		switch (*pm) {
......
363 363
#endif
364 364
				rv = globexp1(patbuf, pglob, limitp, errfunc);
365 365
				if (rv && rv != GLOB_NOMATCH)
366
					return rv;
366
					return (rv);
367 367

  
368 368
				/* move after the comma, to the next string */
369 369
				pl = pm + 1;
......
374 374
			break;
375 375
		}
376 376
	}
377
	return 0;
377
	return (0);
378 378
}
379 379

  
380 380

  
......
391 391
	Char *b, *eb;
392 392

  
393 393
	if (*pattern != TILDE || !(pglob->gl_flags & GLOB_TILDE))
394
		return pattern;
394
		return (pattern);
395 395

  
396 396
	/* Copy up to the end of the string or / */
397 397
	eb = &patbuf[patbuf_len - 1];
398
	for (p = pattern + 1, h = (char *) patbuf;
398
	for (p = pattern + 1, h = (char *)patbuf;
399 399
	    h < (char *)eb && *p && *p != SLASH; *h++ = *p++)
400 400
		;
401 401

  
......
403 403

  
404 404
#if 0
405 405
	if (h == (char *)eb)
406
		return what;
406
		return (what);
407 407
#endif
408 408

  
409
	if (((char *) patbuf)[0] == EOS) {
409
	if (((char *)patbuf)[0] == EOS) {
410 410
		/*
411 411
		 * handle a plain ~ or ~/ by expanding $HOME
412 412
		 * first and then trying the password file
413 413
		 */
414 414
		if (issetugid() != 0 || (h = getenv("HOME")) == NULL) {
415 415
			if ((pwd = getpwuid(getuid())) == NULL)
416
				return pattern;
416
				return (pattern);
417 417
			else
418 418
				h = pwd->pw_dir;
419 419
		}
......
421 421
		/*
422 422
		 * Expand a ~user
423 423
		 */
424
		if ((pwd = getpwnam((char*) patbuf)) == NULL)
425
			return pattern;
424
		if ((pwd = getpwnam((char *)patbuf)) == NULL)
425
			return (pattern);
426 426
		else
427 427
			h = pwd->pw_dir;
428 428
	}
......
436 436
		;
437 437
	*b = EOS;
438 438

  
439
	return patbuf;
439
	return (patbuf);
440 440
}
441 441

  
442 442
static int
......
451 451
		if (*s1++ == '\0')
452 452
			break;
453 453
	}
454
	return rv;
454
	return (rv);
455 455
}
456 456

  
457 457
static int
......
464 464
	size_t len;
465 465

  
466 466
	if ((colon = g_strchr(pattern, ':')) == NULL || colon[1] != ']')
467
		return 1;	/* not a character class */
467
		return (1);	/* not a character class */
468 468

  
469 469
	len = (size_t)(colon - pattern);
470 470
	for (cc = cclasses; cc->name != NULL; cc++) {
......
472 472
			break;
473 473
	}
474 474
	if (cc->name == NULL)
475
		return -1;	/* invalid character class */
475
		return (-1);	/* invalid character class */
476 476
	*bufnext++ = M_CLASS;
477 477
	*bufnext++ = (Char)(cc - &cclasses[0]);
478 478
	*bufnextp = bufnext;
479 479
	*patternp += len + 3;
480 480

  
481
	return 0;
481
	return (0);
482 482
}
483 483

  
484 484
/*
......
490 490
 */
491 491
static int
492 492
glob0(const Char *pattern, glob_t *pglob, struct glob_lim *limitp,
493
      int (*errfunc)(const char *, int))
493
    int (*errfunc)(const char *, int))
494 494
{
495 495
	const Char *qpatnext;
496 496
	int c, err, oldpathc;
......
526 526
						if (err)
527 527
							break;
528 528
						c = *qpatnext++;
529
					} while (c == LBRACKET && *qpatnext == ':');
529
					} while (c == LBRACKET &&
530
					    *qpatnext == ':');
530 531
					if (err == -1 &&
531 532
					    !(pglob->gl_flags & GLOB_NOCHECK))
532
						return GLOB_NOMATCH;
533
						return (GLOB_NOMATCH);
533 534
					if (c == RBRACKET)
534 535
						break;
535 536
				}
......
550 551
			break;
551 552
		case STAR:
552 553
			pglob->gl_flags |= GLOB_MAGCHAR;
553
			/* collapse adjacent stars to one,
554
			/*
555
			 * collapse adjacent stars to one,
554 556
			 * to avoid exponential behavior
555 557
			 */
556 558
			if (bufnext == patbuf || bufnext[-1] != M_ALL)
......
568 570

  
569 571
	if ((err = glob1(patbuf, patbuf+MAXPATHLEN-1, pglob, limitp, errfunc))
570 572
	    != 0)
571
		return(err);
573
		return (err);
572 574

  
573 575
	/*
574 576
	 * If there was no match we are going to append the pattern
......
580 582
		if ((pglob->gl_flags & GLOB_NOCHECK) ||
581 583
		    ((pglob->gl_flags & GLOB_NOMAGIC) &&
582 584
		    !(pglob->gl_flags & GLOB_MAGCHAR)))
583
			return(globextend(pattern, pglob, limitp, NULL));
585
			return (globextend(pattern, pglob, limitp, NULL));
584 586
		else
585
			return(GLOB_NOMATCH);
587
			return (GLOB_NOMATCH);
586 588
	}
587 589
	if (!(pglob->gl_flags & GLOB_NOSORT)) {
588 590
		if ((pglob->gl_flags & GLOB_KEEPSTAT)) {
......
592 594
			int n = pglob->gl_pathc - oldpathc;
593 595
			int o = pglob->gl_offs + oldpathc;
594 596

  
595
			if ((path_stat = calloc(n, sizeof(*path_stat))) == NULL)
596
				return GLOB_NOSPACE;
597
			if ((path_stat = calloc(n, sizeof (*path_stat))) ==
598
			    NULL)
599
				return (GLOB_NOSPACE);
597 600
			for (i = 0; i < n; i++) {
598 601
				path_stat[i].gps_path = pglob->gl_pathv[o + i];
599 602
				path_stat[i].gps_stat = pglob->gl_statv[o + i];
600 603
			}
601
			qsort(path_stat, n, sizeof(*path_stat), compare_gps);
604
			qsort(path_stat, n, sizeof (*path_stat), compare_gps);
602 605
			for (i = 0; i < n; i++) {
603 606
				pglob->gl_pathv[o + i] = path_stat[i].gps_path;
604 607
				pglob->gl_statv[o + i] = path_stat[i].gps_stat;
......
606 609
			free(path_stat);
607 610
		} else {
608 611
			qsort(pglob->gl_pathv + pglob->gl_offs + oldpathc,
609
			    pglob->gl_pathc - oldpathc, sizeof(char *),
612
			    pglob->gl_pathc - oldpathc, sizeof (char *),
610 613
			    compare);
611 614
		}
612 615
	}
613
	return(0);
616
	return (0);
614 617
}
615 618

  
616 619
static int
617 620
compare(const void *p, const void *q)
618 621
{
619
	return(strcmp(*(char **)p, *(char **)q));
622
	return (strcmp(*(char **)p, *(char **)q));
620 623
}
621 624

  
622 625
static int
......
625 628
	const struct glob_path_stat *p = (const struct glob_path_stat *)_p;
626 629
	const struct glob_path_stat *q = (const struct glob_path_stat *)_q;
627 630

  
628
	return(strcmp(p->gps_path, q->gps_path));
631
	return (strcmp(p->gps_path, q->gps_path));
629 632
}
630 633

  
631 634
static int
632 635
glob1(Char *pattern, Char *pattern_last, glob_t *pglob,
633
      struct glob_lim *limitp, int (*errfunc)(const char *, int))
636
    struct glob_lim *limitp, int (*errfunc)(const char *, int))
634 637
{
635 638
	Char pathbuf[MAXPATHLEN];
636 639

  
637 640
	/* A null pathname is invalid -- POSIX 1003.1 sect. 2.4. */
638 641
	if (*pattern == EOS)
639
		return(0);
640
	return(glob2(pathbuf, pathbuf+MAXPATHLEN-1,
642
		return (0);
643
	return (glob2(pathbuf, pathbuf+MAXPATHLEN-1,
641 644
	    pathbuf, pathbuf+MAXPATHLEN-1,
642
		     pattern, pattern_last, pglob, limitp, errfunc));
645
	    pattern, pattern_last, pglob, limitp, errfunc));
643 646
}
644 647

  
645 648
/*
......
650 653
static int
651 654
glob2(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend_last,
652 655
    Char *pattern, Char *pattern_last, glob_t *pglob,
653
      struct glob_lim *limitp, int (*errfunc)(const char *, int))
656
    struct glob_lim *limitp, int (*errfunc)(const char *, int))
654 657
{
655 658
	struct stat sb;
656 659
	Char *p, *q;
......
660 663
	 * Loop over pattern segments until end of pattern or until
661 664
	 * segment with meta character found.
662 665
	 */
663
	for (anymeta = 0;;) {
666
	for (anymeta = 0; ; ) {
664 667
		if (*pattern == EOS) {		/* End of pattern? */
665 668
			*pathend = EOS;
666 669

  
......
669 672
				errno = 0;
670 673
				*pathend++ = SEP;
671 674
				*pathend = EOS;
672
				return(GLOB_NOSPACE);
675
				return (GLOB_NOSPACE);
673 676
			}
674 677
			if (g_lstat(pathbuf, &sb, pglob))
675
				return(0);
678
				return (0);
676 679

  
677 680
			if (((pglob->gl_flags & GLOB_MARK) &&
678 681
			    pathend[-1] != SEP) && (S_ISDIR(sb.st_mode) ||
......
685 688
				*pathend = EOS;
686 689
			}
687 690
			++pglob->gl_matchc;
688
			return(globextend(pathbuf, pglob, limitp, &sb));
691
			return (globextend(pathbuf, pglob, limitp, &sb));
689 692
		}
690 693

  
691 694
		/* Find end of next segment, copy tentatively to pathend. */
......
709 712
			}
710 713
		} else
711 714
			/* Need expansion, recurse. */
712
			return(glob3(pathbuf, pathbuf_last, pathend,
715
			return (glob3(pathbuf, pathbuf_last, pathend,
713 716
			    pathend_last, pattern, p, pattern_last,
714
				     pglob, limitp, errfunc));
717
			    pglob, limitp, errfunc));
715 718
	}
716 719
	/* NOTREACHED */
717 720
}
......
719 722
static int
720 723
glob3(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend_last,
721 724
    Char *pattern, Char *restpattern, Char *restpattern_last, glob_t *pglob,
722
      struct glob_lim *limitp, int (*errfunc)(const char *, int))
725
    struct glob_lim *limitp, int (*errfunc)(const char *, int))
723 726
{
724 727
	struct dirent *dp;
725 728
	DIR *dirp;
......
742 745
	if ((dirp = g_opendir(pathbuf, pglob)) == NULL) {
743 746
		/* TODO: don't call for ENOENT or ENOTDIR? */
744 747
		if (errfunc) {
745
			if (g_Ctoc(pathbuf, buf, sizeof(buf)))
746
				return(GLOB_ABORTED);
748
			if (g_Ctoc(pathbuf, buf, sizeof (buf)))
749
				return (GLOB_ABORTED);
747 750
			if (errfunc(buf, errno) ||
748 751
			    pglob->gl_flags & GLOB_ERR)
749
				return(GLOB_ABORTED);
752
				return (GLOB_ABORTED);
750 753
		}
751
		return(0);
754
		return (0);
752 755
	}
753 756

  
754 757
	err = 0;
......
759 762
	else
760 763
		readdirfunc = (struct dirent *(*)(void *))readdir;
761 764
	while ((dp = (*readdirfunc)(dirp))) {
762
		u_char *sc;
765
		uchar_t *sc;
763 766
		Char *dc;
764 767

  
765 768
		if ((pglob->gl_flags & GLOB_LIMIT) &&
......
775 778
		if (dp->d_name[0] == DOT && *pattern != DOT)
776 779
			continue;
777 780
		dc = pathend;
778
		sc = (u_char *) dp->d_name;
781
		sc = (uchar_t *)dp->d_name;
779 782
		while (dc < pathend_last && (*dc++ = *sc++) != EOS)
780 783
			;
781 784
		if (dc >= pathend_last) {
......
789 792
			continue;
790 793
		}
791 794
		err = glob2(pathbuf, pathbuf_last, --dc, pathend_last,
792
			    restpattern, restpattern_last, pglob, limitp,
793
			    errfunc);
795
		    restpattern, restpattern_last, pglob, limitp,
796
		    errfunc);
794 797
		if (err)
795 798
			break;
796 799
	}
......
799 802
		(*pglob->gl_closedir)(dirp);
800 803
	else
801 804
		closedir(dirp);
802
	return(err);
805
	return (err);
803 806
}
804 807

  
805 808

  
......
832 835
	if (pglob->gl_offs >= INT_MAX ||
833 836
	    pglob->gl_pathc >= INT_MAX ||
834 837
	    newn >= INT_MAX ||
835
	    SIZE_MAX / sizeof(*pathv) <= newn ||
836
	    SIZE_MAX / sizeof(*statv) <= newn) {
837
 nospace:
838
	    SIZE_MAX / sizeof (*pathv) <= newn ||
839
	    SIZE_MAX / sizeof (*statv) <= newn) {
840
	nospace:
838 841
		for (i = pglob->gl_offs; i < (ssize_t)(newn - 2); i++) {
839 842
			if (pglob->gl_pathv && pglob->gl_pathv[i])
840 843
				free(pglob->gl_pathv[i]);
......
851 854
			free(pglob->gl_statv);
852 855
			pglob->gl_statv = NULL;
853 856
		}
854
		return(GLOB_NOSPACE);
857
		return (GLOB_NOSPACE);
855 858
	}
856 859

  
857
	pathv = realloc(pglob->gl_pathv, newn * sizeof(*pathv));
860
	pathv = realloc(pglob->gl_pathv, newn * sizeof (*pathv));
858 861
	if (pathv == NULL)
859 862
		goto nospace;
860 863
	if (pglob->gl_pathv == NULL && pglob->gl_offs > 0) {
......
866 869
	pglob->gl_pathv = pathv;
867 870

  
868 871
	if ((pglob->gl_flags & GLOB_KEEPSTAT) != 0) {
869
		statv = realloc(pglob->gl_statv, newn * sizeof(*statv));
872
		statv = realloc(pglob->gl_statv, newn * sizeof (*statv));
870 873
		if (statv == NULL)
871 874
			goto nospace;
872 875
		if (pglob->gl_statv == NULL && pglob->gl_offs > 0) {
......
879 882
		if (sb == NULL)
880 883
			statv[pglob->gl_offs + pglob->gl_pathc] = NULL;
881 884
		else {
882
			limitp->glim_malloc += sizeof(**statv);
885
			limitp->glim_malloc += sizeof (**statv);
883 886
			if ((pglob->gl_flags & GLOB_LIMIT) &&
884 887
			    limitp->glim_malloc >= GLOB_LIMIT_MALLOC) {
885 888
				errno = 0;
886
				return(GLOB_NOSPACE);
889
				return (GLOB_NOSPACE);
887 890
			}
888 891
			if ((statv[pglob->gl_offs + pglob->gl_pathc] =
889
			    malloc(sizeof(**statv))) == NULL)
892
			    malloc(sizeof (**statv))) == NULL)
890 893
				goto copy_error;
891 894
			memcpy(statv[pglob->gl_offs + pglob->gl_pathc], sb,
892
			    sizeof(*sb));
895
			    sizeof (*sb));
893 896
		}
894 897
		statv[pglob->gl_offs + pglob->gl_pathc + 1] = NULL;
895 898
	}
896 899

  
897
	for (p = path; *p++;)
900
	for (p = path; *p++; )
898 901
		;
899 902
	len = (size_t)(p - path);
900 903
	limitp->glim_malloc += len;
901 904
	if ((copy = malloc(len)) != NULL) {
902 905
		if (g_Ctoc(path, copy, len)) {
903 906
			free(copy);
904
			return(GLOB_NOSPACE);
907
			return (GLOB_NOSPACE);
905 908
		}
906 909
		pathv[pglob->gl_offs + pglob->gl_pathc++] = copy;
907 910
	}
908 911
	pathv[pglob->gl_offs + pglob->gl_pathc] = NULL;
909 912

  
910 913
	if ((pglob->gl_flags & GLOB_LIMIT) &&
911
	    (newn * sizeof(*pathv)) + limitp->glim_malloc >
914
	    (newn * sizeof (*pathv)) + limitp->glim_malloc >
912 915
	    GLOB_LIMIT_MALLOC) {
913 916
		errno = 0;
914
		return(GLOB_NOSPACE);
917
		return (GLOB_NOSPACE);
915 918
	}
916
 copy_error:
917
	return(copy == NULL ? GLOB_NOSPACE : 0);
919
	copy_error:
920
	return (copy == NULL ? GLOB_NOSPACE : 0);
918 921
}
919 922

  
920 923

  
......
929 932
	Char c, k;
930 933

  
931 934
	if (recur-- == 0)
932
		return(GLOB_NOSPACE);
935
		return (GLOB_NOSPACE);
933 936

  
934 937
	while (pat < patend) {
935 938
		c = *pat++;
......
938 941
			while (pat < patend && (*pat & M_MASK) == M_ALL)
939 942
				pat++;	/* eat consecutive '*' */
940 943
			if (pat == patend)
941
				return(1);
944
				return (1);
942 945
			do {
943
			    if (match(name, pat, patend, recur))
944
				    return(1);
946
				if (match(name, pat, patend, recur))
947
					return (1);
945 948
			} while (*name++ != EOS);
946
			return(0);
949
			return (0);
947 950
		case M_ONE:
948 951
			if (*name++ == EOS)
949
				return(0);
952
				return (0);
950 953
			break;
951 954
		case M_SET:
952 955
			ok = 0;
953 956
			if ((k = *name++) == EOS)
954
				return(0);
957
				return (0);
955 958
			if ((negate_range = ((*pat & M_MASK) == M_NOT)) != EOS)
956 959
				++pat;
957 960
			while (((c = *pat++) & M_MASK) != M_END) {
......
970 973
					ok = 1;
971 974
			}
972 975
			if (ok == negate_range)
973
				return(0);
976
				return (0);
974 977
			break;
975 978
		default:
976 979
			if (*name++ != c)
977
				return(0);
980
				return (0);
978 981
			break;
979 982
		}
980 983
	}
981
	return(*name == EOS);
984
	return (*name == EOS);
982 985
}
983 986

  
984 987
/* Free allocated data belonging to a glob_t structure. */
......
997 1000
		pglob->gl_pathv = NULL;
998 1001
	}
999 1002
	if ((pglob->gl_flags & GLOB_KEEPSTAT) != 0 &&
1000
	  pglob->gl_statv != NULL) {
1003
	    pglob->gl_statv != NULL) {
1001 1004
		for (i = 0; i < pglob->gl_pathc; i++) {
1002 1005
			if (pglob->gl_statv[i] != NULL)
1003 1006
				free(pglob->gl_statv[i]);
......
1013 1016
	char buf[MAXPATHLEN];
1014 1017

  
1015 1018
	if (!*str)
1016
		strlcpy(buf, ".", sizeof buf);
1019
		strlcpy(buf, ".", sizeof (buf));
1017 1020
	else {
1018
		if (g_Ctoc(str, buf, sizeof(buf)))
1019
			return(NULL);
1021
		if (g_Ctoc(str, buf, sizeof (buf)))
1022
			return (NULL);
1020 1023
	}
1021 1024

  
1022 1025
	if (pglob->gl_flags & GLOB_ALTDIRFUNC)
1023
		return((*pglob->gl_opendir)(buf));
1026
		return ((*pglob->gl_opendir)(buf));
1024 1027

  
1025
	return(opendir(buf));
1028
	return (opendir(buf));
1026 1029
}
1027 1030

  
1028 1031
static int
......
1030 1033
{
1031 1034
	char buf[MAXPATHLEN];
1032 1035

  
1033
	if (g_Ctoc(fn, buf, sizeof(buf)))
1034
		return(-1);
1036
	if (g_Ctoc(fn, buf, sizeof (buf)))
1037
		return (-1);
1035 1038
	if (pglob->gl_flags & GLOB_ALTDIRFUNC)
1036
		return((*pglob->gl_lstat)(buf, sb));
1037
	return(lstat(buf, sb));
1039
		return ((*pglob->gl_lstat)(buf, sb));
1040
	return (lstat(buf, sb));
1038 1041
}
1039 1042

  
1040 1043
static int
......
1042 1045
{
1043 1046
	char buf[MAXPATHLEN];
1044 1047

  
1045
	if (g_Ctoc(fn, buf, sizeof(buf)))
1046
		return(-1);
1048
	if (g_Ctoc(fn, buf, sizeof (buf)))
1049
		return (-1);
1047 1050
	if (pglob->gl_flags & GLOB_ALTDIRFUNC)
1048
		return((*pglob->gl_stat)(buf, sb));
1049
	return(stat(buf, sb));
1051
		return ((*pglob->gl_stat)(buf, sb));
1052
	return (stat(buf, sb));
1050 1053
}
1051 1054

  
1052 1055
static Char *
......
1060 1063
}
1061 1064

  
1062 1065
static int
1063
g_Ctoc(const Char *str, char *buf, u_int len)
1066
g_Ctoc(const Char *str, char *buf, uint_t len)
1064 1067
{
1065 1068

  
1066 1069
	while (len--) {
......
1076 1079
{
1077 1080
	Char *p;
1078 1081

  
1079
	(void)printf("%s:\n", str);
1082
	(void) printf("%s:\n", str);
1080 1083
	for (p = s; *p; p++)
1081
		(void)printf("%c", CHAR(*p));
1082
	(void)printf("\n");
1084
		(void) printf("%c", CHAR(*p));
1085
	(void) printf("\n");
1083 1086
	for (p = s; *p; p++)
1084
		(void)printf("%c", *p & M_PROTECT ? '"' : ' ');
1085
	(void)printf("\n");
1087
		(void) printf("%c", *p & M_PROTECT ? '"' : ' ');
1088
	(void) printf("\n");
1086 1089
	for (p = s; *p; p++)
1087
		(void)printf("%c", ismeta(*p) ? '_' : ' ');
1088
	(void)printf("\n");
1090
		(void) printf("%c", ismeta(*p) ? '_' : ' ');
1091
	(void) printf("\n");
1089 1092
}
1090 1093
#endif
(4-4/11)