*BSD News Article 11250


Return to BSD News archive

Received: by minnie.vk1xwt.ampr.org with NNTP
	id AA1455 ; Tue, 23 Feb 93 14:42:29 EST
Newsgroups: comp.unix.bsd
Path: sserve!manuel.anu.edu.au!munnari.oz.au!news.Hawaii.Edu!ames!elroy.jpl.nasa.gov!sdd.hp.com!caen!batcomputer!cornell!uw-beaver!fluke!gtisqr!rick
From: rick@mav.com (Hendrik Groeneveld)
Subject: [386bsd] patch for /usr/src/lib/libc/gen/fnmatch.c (cvs import broken)
Message-ID: <1993Feb17.170113.10863@mav.com>
Keywords: libc bug
Reply-To: rick@mav.com
Organization: Maverick International, Inc.
Date: Wed, 17 Feb 93 17:01:13 GMT
Lines: 124

While trying to get "cvs import" to work, I found that fnmatch() returned
exactly the opposite of what the man page said it did (and cvs expected).
The patch follows.

*** fnmatch.BOGUS	Tue Apr 30 17:35:47 1991
--- fnmatch.c	Sat Feb 13 22:56:27 1993
***************
*** 87,97 ****
  	for (;;)
  		switch (c = *pattern++) {
  		case EOS:
! 			return(*string == EOS);
  		case '?':
! 			if ((test = *string++) == EOS ||
! 			    test == '/' && flags & FNM_PATHNAME)
! 				return(0);
  			break;
  		case '*':
  			c = *pattern;
--- 87,97 ----
  	for (;;)
  		switch (c = *pattern++) {
  		case EOS:
! 			return(!(*string == EOS));
  		case '?':
! 			if (((test = *string++) == EOS) ||
! 			    ((test == '/') && (flags & FNM_PATHNAME)))
! 				return(1);
  			break;
  		case '*':
  			c = *pattern;
***************
*** 102,131 ****
  			/* optimize for pattern with * at end or before / */
  			if (c == EOS)
  				if (flags & FNM_PATHNAME)
! 					return(!index(string, '/'));
  				else
- 					return(1);
- 			else if (c == '/' && flags & FNM_PATHNAME) {
- 				if ((string = index(string, '/')) == NULL)
  					return(0);
  				break;
  			}
  
  			/* general case, use recursion */
  			while ((test = *string) != EOS) {
! 				if (fnmatch(pattern, string, flags))
! 					return(1);
  				if (test == '/' && flags & FNM_PATHNAME)
  					break;
  				++string;
  			}
! 			return(0);
  		case '[':
  			if ((test = *string++) == EOS ||
  			    test == '/' && flags & FNM_PATHNAME)
! 				return(0);
  			if ((pattern = rangematch(pattern, test)) == NULL)
! 				return(0);
  			break;
  		case '\\':
  			if (flags & FNM_QUOTE) {
--- 102,131 ----
  			/* optimize for pattern with * at end or before / */
  			if (c == EOS)
  				if (flags & FNM_PATHNAME)
! 					return(index(string, '/') != NULL);
  				else
  					return(0);
+ 			else if ((c == '/') && (flags & FNM_PATHNAME)) {
+ 				if ((string = index(string, '/')) == NULL)
+ 					return(1);
  				break;
  			}
  
  			/* general case, use recursion */
  			while ((test = *string) != EOS) {
! 				if (!fnmatch(pattern, string, flags))
! 					return(0);
  				if (test == '/' && flags & FNM_PATHNAME)
  					break;
  				++string;
  			}
! 			return(1);
  		case '[':
  			if ((test = *string++) == EOS ||
  			    test == '/' && flags & FNM_PATHNAME)
! 				return(1);
  			if ((pattern = rangematch(pattern, test)) == NULL)
! 				return(1);
  			break;
  		case '\\':
  			if (flags & FNM_QUOTE) {
***************
*** 134,146 ****
  					--pattern;
  				}
  				if (c != *string++)
! 					return(0);
  				break;
  			}
  			/* FALLTHROUGH */
  		default:
  			if (c != *string++)
! 				return(0);
  			break;
  		}
  }
--- 134,146 ----
  					--pattern;
  				}
  				if (c != *string++)
! 					return(1);
  				break;
  			}
  			/* FALLTHROUGH */
  		default:
  			if (c != *string++)
! 				return(1);
  			break;
  		}
  }