Project

General

Profile

Bug #1097 » glob.c-sty.diff

Gary Mills, 2012-11-01 02:58 PM

View differences:

glob.c-sty Wed Oct 31 10:34:02 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;
......
735 738
	if ((dirp = g_opendir(pathbuf, pglob)) == NULL) {
736 739
		/* TODO: don't call for ENOENT or ENOTDIR? */
737 740
		if (errfunc) {
738
			if (g_Ctoc(pathbuf, buf, sizeof(buf)))
739
				return(GLOB_ABORTED);
741
			if (g_Ctoc(pathbuf, buf, sizeof (buf)))
742
				return (GLOB_ABORTED);
740 743
			if (errfunc(buf, errno) ||
741 744
			    pglob->gl_flags & GLOB_ERR)
742
				return(GLOB_ABORTED);
745
				return (GLOB_ABORTED);
743 746
		}
744
		return(0);
747
		return (0);
745 748
	}
746 749

  
747 750
	err = 0;
......
752 755
	else
753 756
		readdirfunc = readdir;
754 757
	while ((dp = (*readdirfunc)(dirp))) {
755
		u_char *sc;
758
		uchar_t *sc;
756 759
		Char *dc;
757 760

  
758 761
		if ((pglob->gl_flags & GLOB_LIMIT) &&
......
768 771
		if (dp->d_name[0] == DOT && *pattern != DOT)
769 772
			continue;
770 773
		dc = pathend;
771
		sc = (u_char *) dp->d_name;
774
		sc = (uchar_t *)dp->d_name;
772 775
		while (dc < pathend_last && (*dc++ = *sc++) != EOS)
773 776
			;
774 777
		if (dc >= pathend_last) {
......
782 785
			continue;
783 786
		}
784 787
		err = glob2(pathbuf, pathbuf_last, --dc, pathend_last,
785
			    restpattern, restpattern_last, pglob, limitp,
786
			    errfunc);
788
		    restpattern, restpattern_last, pglob, limitp,
789
		    errfunc);
787 790
		if (err)
788 791
			break;
789 792
	}
......
792 795
		(*pglob->gl_closedir)(dirp);
793 796
	else
794 797
		closedir(dirp);
795
	return(err);
798
	return (err);
796 799
}
797 800

  
798 801

  
......
825 828
	if (pglob->gl_offs >= INT_MAX ||
826 829
	    pglob->gl_pathc >= INT_MAX ||
827 830
	    newn >= INT_MAX ||
828
	    SIZE_MAX / sizeof(*pathv) <= newn ||
829
	    SIZE_MAX / sizeof(*statv) <= newn) {
830
 nospace:
831
	    SIZE_MAX / sizeof (*pathv) <= newn ||
832
	    SIZE_MAX / sizeof (*statv) <= newn) {
833
	nospace:
831 834
		for (i = pglob->gl_offs; i < (ssize_t)(newn - 2); i++) {
832 835
			if (pglob->gl_pathv && pglob->gl_pathv[i])
833 836
				free(pglob->gl_pathv[i]);
......
844 847
			free(pglob->gl_statv);
845 848
			pglob->gl_statv = NULL;
846 849
		}
847
		return(GLOB_NOSPACE);
850
		return (GLOB_NOSPACE);
848 851
	}
849 852

  
850
	pathv = realloc(pglob->gl_pathv, newn * sizeof(*pathv));
853
	pathv = realloc(pglob->gl_pathv, newn * sizeof (*pathv));
851 854
	if (pathv == NULL)
852 855
		goto nospace;
853 856
	if (pglob->gl_pathv == NULL && pglob->gl_offs > 0) {
......
859 862
	pglob->gl_pathv = pathv;
860 863

  
861 864
	if ((pglob->gl_flags & GLOB_KEEPSTAT) != 0) {
862
		statv = realloc(pglob->gl_statv, newn * sizeof(*statv));
865
		statv = realloc(pglob->gl_statv, newn * sizeof (*statv));
863 866
		if (statv == NULL)
864 867
			goto nospace;
865 868
		if (pglob->gl_statv == NULL && pglob->gl_offs > 0) {
......
872 875
		if (sb == NULL)
873 876
			statv[pglob->gl_offs + pglob->gl_pathc] = NULL;
874 877
		else {
875
			limitp->glim_malloc += sizeof(**statv);
878
			limitp->glim_malloc += sizeof (**statv);
876 879
			if ((pglob->gl_flags & GLOB_LIMIT) &&
877 880
			    limitp->glim_malloc >= GLOB_LIMIT_MALLOC) {
878 881
				errno = 0;
879
				return(GLOB_NOSPACE);
882
				return (GLOB_NOSPACE);
880 883
			}
881 884
			if ((statv[pglob->gl_offs + pglob->gl_pathc] =
882
			    malloc(sizeof(**statv))) == NULL)
885
			    malloc(sizeof (**statv))) == NULL)
883 886
				goto copy_error;
884 887
			memcpy(statv[pglob->gl_offs + pglob->gl_pathc], sb,
885
			    sizeof(*sb));
888
			    sizeof (*sb));
886 889
		}
887 890
		statv[pglob->gl_offs + pglob->gl_pathc + 1] = NULL;
888 891
	}
889 892

  
890
	for (p = path; *p++;)
893
	for (p = path; *p++; )
891 894
		;
892 895
	len = (size_t)(p - path);
893 896
	limitp->glim_malloc += len;
894 897
	if ((copy = malloc(len)) != NULL) {
895 898
		if (g_Ctoc(path, copy, len)) {
896 899
			free(copy);
897
			return(GLOB_NOSPACE);
900
			return (GLOB_NOSPACE);
898 901
		}
899 902
		pathv[pglob->gl_offs + pglob->gl_pathc++] = copy;
900 903
	}
901 904
	pathv[pglob->gl_offs + pglob->gl_pathc] = NULL;
902 905

  
903 906
	if ((pglob->gl_flags & GLOB_LIMIT) &&
904
	    (newn * sizeof(*pathv)) + limitp->glim_malloc >
907
	    (newn * sizeof (*pathv)) + limitp->glim_malloc >
905 908
	    GLOB_LIMIT_MALLOC) {
906 909
		errno = 0;
907
		return(GLOB_NOSPACE);
910
		return (GLOB_NOSPACE);
908 911
	}
909
 copy_error:
910
	return(copy == NULL ? GLOB_NOSPACE : 0);
912
	copy_error:
913
	return (copy == NULL ? GLOB_NOSPACE : 0);
911 914
}
912 915

  
913 916

  
......
922 925
	Char c, k;
923 926

  
924 927
	if (recur-- == 0)
925
		return(GLOB_NOSPACE);
928
		return (GLOB_NOSPACE);
926 929

  
927 930
	while (pat < patend) {
928 931
		c = *pat++;
......
931 934
			while (pat < patend && (*pat & M_MASK) == M_ALL)
932 935
				pat++;	/* eat consecutive '*' */
933 936
			if (pat == patend)
934
				return(1);
937
				return (1);
935 938
			do {
936
			    if (match(name, pat, patend, recur))
937
				    return(1);
939
				if (match(name, pat, patend, recur))
940
					return (1);
938 941
			} while (*name++ != EOS);
939
			return(0);
942
			return (0);
940 943
		case M_ONE:
941 944
			if (*name++ == EOS)
942
				return(0);
945
				return (0);
943 946
			break;
944 947
		case M_SET:
945 948
			ok = 0;
946 949
			if ((k = *name++) == EOS)
947
				return(0);
950
				return (0);
948 951
			if ((negate_range = ((*pat & M_MASK) == M_NOT)) != EOS)
949 952
				++pat;
950 953
			while (((c = *pat++) & M_MASK) != M_END) {
......
963 966
					ok = 1;
964 967
			}
965 968
			if (ok == negate_range)
966
				return(0);
969
				return (0);
967 970
			break;
968 971
		default:
969 972
			if (*name++ != c)
970
				return(0);
973
				return (0);
971 974
			break;
972 975
		}
973 976
	}
974
	return(*name == EOS);
977
	return (*name == EOS);
975 978
}
976 979

  
977 980
/* Free allocated data belonging to a glob_t structure. */
......
990 993
		pglob->gl_pathv = NULL;
991 994
	}
992 995
	if ((pglob->gl_flags & GLOB_KEEPSTAT) != 0 &&
993
	  pglob->gl_statv != NULL) {
996
	    pglob->gl_statv != NULL) {
994 997
		for (i = 0; i < pglob->gl_pathc; i++) {
995 998
			if (pglob->gl_statv[i] != NULL)
996 999
				free(pglob->gl_statv[i]);
......
1006 1009
	char buf[MAXPATHLEN];
1007 1010

  
1008 1011
	if (!*str)
1009
		strlcpy(buf, ".", sizeof buf);
1012
		strlcpy(buf, ".", sizeof (buf));
1010 1013
	else {
1011
		if (g_Ctoc(str, buf, sizeof(buf)))
1012
			return(NULL);
1014
		if (g_Ctoc(str, buf, sizeof (buf)))
1015
			return (NULL);
1013 1016
	}
1014 1017

  
1015 1018
	if (pglob->gl_flags & GLOB_ALTDIRFUNC)
1016
		return((*pglob->gl_opendir)(buf));
1019
		return ((*pglob->gl_opendir)(buf));
1017 1020

  
1018
	return(opendir(buf));
1021
	return (opendir(buf));
1019 1022
}
1020 1023

  
1021 1024
static int
......
1023 1026
{
1024 1027
	char buf[MAXPATHLEN];
1025 1028

  
1026
	if (g_Ctoc(fn, buf, sizeof(buf)))
1027
		return(-1);
1029
	if (g_Ctoc(fn, buf, sizeof (buf)))
1030
		return (-1);
1028 1031
	if (pglob->gl_flags & GLOB_ALTDIRFUNC)
1029
		return((*pglob->gl_lstat)(buf, sb));
1030
	return(lstat(buf, sb));
1032
		return ((*pglob->gl_lstat)(buf, sb));
1033
	return (lstat(buf, sb));
1031 1034
}
1032 1035

  
1033 1036
static int
......
1035 1038
{
1036 1039
	char buf[MAXPATHLEN];
1037 1040

  
1038
	if (g_Ctoc(fn, buf, sizeof(buf)))
1039
		return(-1);
1041
	if (g_Ctoc(fn, buf, sizeof (buf)))
1042
		return (-1);
1040 1043
	if (pglob->gl_flags & GLOB_ALTDIRFUNC)
1041
		return((*pglob->gl_stat)(buf, sb));
1042
	return(stat(buf, sb));
1044
		return ((*pglob->gl_stat)(buf, sb));
1045
	return (stat(buf, sb));
1043 1046
}
1044 1047

  
1045 1048
static Char *
......
1053 1056
}
1054 1057

  
1055 1058
static int
1056
g_Ctoc(const Char *str, char *buf, u_int len)
1059
g_Ctoc(const Char *str, char *buf, uint_t len)
1057 1060
{
1058 1061

  
1059 1062
	while (len--) {
......
1069 1072
{
1070 1073
	Char *p;
1071 1074

  
1072
	(void)printf("%s:\n", str);
1075
	(void) printf("%s:\n", str);
1073 1076
	for (p = s; *p; p++)
1074
		(void)printf("%c", CHAR(*p));
1075
	(void)printf("\n");
1077
		(void) printf("%c", CHAR(*p));
1078
	(void) printf("\n");
1076 1079
	for (p = s; *p; p++)
1077
		(void)printf("%c", *p & M_PROTECT ? '"' : ' ');
1078
	(void)printf("\n");
1080
		(void) printf("%c", *p & M_PROTECT ? '"' : ' ');
1081
	(void) printf("\n");
1079 1082
	for (p = s; *p; p++)
1080
		(void)printf("%c", ismeta(*p) ? '_' : ' ');
1081
	(void)printf("\n");
1083
		(void) printf("%c", ismeta(*p) ? '_' : ' ');
1084
	(void) printf("\n");
1082 1085
}
1083 1086
#endif
(2-2/11)