public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* fnmatch() doesn't work with character classes?
@ 2015-11-18  5:52 Dustin Boyd
  2015-11-18 18:00 ` Corinna Vinschen
  0 siblings, 1 reply; 2+ messages in thread
From: Dustin Boyd @ 2015-11-18  5:52 UTC (permalink / raw)
  To: cygwin

[-- Attachment #1: Type: text/plain, Size: 651 bytes --]

fnmatch() does not appear to work with character classes or character equivalents. regcomp(), however, does work with character classes, but not character equivalents. Is this behavior one should expect? I've tested with Debian, and it matches in both cases.

I sent this to the Cygwin ML rather than the Newlib ML just because of the fact that it may be locale-related, which is a problem on Cygwin's end, not Newlib's, if it's a problem at all.

The attached program will hopefully illustrate the trouble occurring on my Windows 10 machine:

regexec: 0 matched /[[:digit:]]/
fnmatch: 0 did not match /[[:digit:]]/
-- 
Sent using Mozilla Thunderbird

[-- Attachment #2: fnmatch_fail.c --]
[-- Type: text/plain, Size: 689 bytes --]

#define _XOPEN_SOURCE 700
#include <assert.h>
#include <fnmatch.h>
#include <regex.h>
#include <stdio.h>

int
main (void)
{
  regex_t reg;
  const char *pattern = "[[:digit:]]";
  const char *s = "0";
  int cflags = REG_NOSUB;

  assert(regcomp(&reg, pattern, cflags) == 0);
  if (regexec(&reg, s, 0, NULL, 0) == REG_NOMATCH)
    {
      printf("regexec: %s did not match /%s/\n", s, pattern);
    }
  else
    {
      printf("regexec: %s matched /%s/\n", s, pattern);
    }
  regfree(&reg);

  if (fnmatch(pattern, s, 0) == FNM_NOMATCH)
    {
      printf("fnmatch: %s did not match /%s/\n", s, pattern);
    }
  else
    {
      printf("fnmatch: %s matched /%s/\n", s, pattern);
    }
}

[-- Attachment #3: Type: text/plain, Size: 218 bytes --]

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: fnmatch() doesn't work with character classes?
  2015-11-18  5:52 fnmatch() doesn't work with character classes? Dustin Boyd
@ 2015-11-18 18:00 ` Corinna Vinschen
  0 siblings, 0 replies; 2+ messages in thread
From: Corinna Vinschen @ 2015-11-18 18:00 UTC (permalink / raw)
  To: cygwin

[-- Attachment #1: Type: text/plain, Size: 936 bytes --]

On Nov 18 05:52, Dustin Boyd wrote:
> fnmatch() does not appear to work with character classes or character
> equivalents. regcomp(), however, does work with character classes, but
> not character equivalents. Is this behavior one should expect? I've
> tested with Debian, and it matches in both cases.

The behaviour is expected.  Debian uses glibc, Cygwin doesn't.

> I sent this to the Cygwin ML rather than the Newlib ML just because of
> the fact that it may be locale-related, which is a problem on Cygwin's
> end, not Newlib's, if it's a problem at all.

That's right in this case because Cygwin has its own fnmatch and regcomp.
Both are taken from FreeBSD.  So the support for character classes and
character equivalents match what FreeBSD supports.


Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Maintainer                 cygwin AT cygwin DOT com
Red Hat

[-- Attachment #2: Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-11-18 18:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-18  5:52 fnmatch() doesn't work with character classes? Dustin Boyd
2015-11-18 18:00 ` Corinna Vinschen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).