public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Dustin Boyd <chronokitsune3233@gmail.com>
To: cygwin@cygwin.com
Subject: fnmatch() doesn't work with character classes?
Date: Wed, 18 Nov 2015 05:52:00 -0000	[thread overview]
Message-ID: <564C122C.7080608@gmail.com> (raw)

[-- 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

             reply	other threads:[~2015-11-18  5:52 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-18  5:52 Dustin Boyd [this message]
2015-11-18 18:00 ` Corinna Vinschen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=564C122C.7080608@gmail.com \
    --to=chronokitsune3233@gmail.com \
    --cc=cygwin@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).