Opened 12 years ago

Closed 8 years ago

#193 closed defect (fixed)

fnmatch() implementation is broken

Reported by: guest Owned by: bird
Priority: normal Milestone: libc-0.6.5
Component: libc Version: 0.6
Severity: normal Keywords:
Cc:

Description

According to http://www.opengroup.org/onlinepubs/000095399/functions/fnmatch.html[[BR]]

If string matches the pattern specified by pattern, then fnmatch() shall return 0. If there is no match, fnmatch() shall return FNM_NOMATCH, which is defined in <fnmatch.h>. If an error occurs, fnmatch() shall return another non-zero value.

FNM_NOMATCH is defined in fnmatch.h as

#define	FNM_NOMATCH	1

but fnmatch() return 2 in case of string is not match to pattern.
Testcase attached here


#include <stdio.h>
#include <fnmatch.h>

int main()
{
	const char pat[]= "a";
	const char string[]= "__nargin__";
	int flags= FNM_PATHNAME|FNM_NOESCAPE|FNM_PERIOD;

	printf("fnmatch(\"%s\", \"%s\", %d) return %d\n", pat, string, flags,
		fnmatch(pat, string, flags) );
	
}



Output should be like

fnmatch("a", "__nargin__", 7) return 1

While with current libc implementation it is

fnmatch("a", "__nargin__", 7) return 2

Working implementation can be taken here http://www.koders.com/c/fid9017D6D4B610AB3B4FB492C9229D41676C2FAA78.aspx?s=md5

Change History (6)

comment:1 Changed 12 years ago by guest

Was tested with libc05 and libc063 versions

comment:2 Changed 12 years ago by guest

  • Milestone set to libc-0.6.4
  • Version set to 0.6

comment:3 Changed 9 years ago by bird

  • Status changed from new to assigned

comment:4 Changed 8 years ago by bird

The problem here is header confusion. For some reason I don't recall/know, fnmatch.h and emx/fnmatch.h differs constant wise but ends up in the same EMX code. So, when using the GNU liberty header the EMX code will choke and return _FNM_ERR (2).

comment:5 Changed 8 years ago by bird

Fixed in r3779. (Hope it doesn't mess up the gcc and binutils buils...)

comment:6 Changed 8 years ago by bird

  • Resolution set to fixed
  • Status changed from assigned to closed
Note: See TracTickets for help on using tickets.