After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 735689 - GLib has no g_fnmatch() function
GLib has no g_fnmatch() function
Status: RESOLVED WONTFIX
Product: glib
Classification: Platform
Component: general
unspecified
Other All
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks: 735696
 
 
Reported: 2014-08-29 19:11 UTC by LRN
Modified: 2014-09-10 16:20 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Add g_fnmatch() implementation (50.39 KB, patch)
2014-08-29 19:11 UTC, LRN
none Details | Review
Add g_fnmatch() implementation (15.82 KB, patch)
2014-09-08 09:57 UTC, LRN
needs-work Details | Review
Add g_fnmatch() implementation (15.92 KB, patch)
2014-09-08 11:26 UTC, LRN
needs-work Details | Review
Add g_fnmatch() implementation (16.08 KB, patch)
2014-09-08 15:12 UTC, LRN
none Details | Review

Description LRN 2014-08-29 19:11:24 UTC
It's useful, and at some point was asked for in the ML.

Without this function it won't be possible to make xdgmime compile on W32.
Comment 1 LRN 2014-08-29 19:11:29 UTC
Created attachment 284832 [details] [review]
Add g_fnmatch() implementation
Comment 2 Matthias Clasen 2014-08-29 19:31:13 UTC
If we were to take on an fnmatch, we would probably start from the version that is already in gtk, which is a stripped-down utf8-only version
Comment 3 LRN 2014-09-08 09:57:21 UTC
Created attachment 285638 [details] [review]
Add g_fnmatch() implementation

v2:
 - Use the implementation from GTK:
   - Use fnmatch() interface (with flags and integer result)
   - Fail when unsupported flags are used
   - Fix G_DIR_SEPARATOR checks to correctly cover '/' on W32
   - Put the tests into the testsuite
Comment 4 LRN 2014-09-08 10:02:17 UTC
Here it is. The question is: can xdgmime work with *this* implementation? xdgmime calls fnmatch() with flags == 0, which means that it has G_FNM_FILE_NAME unset. I'm not worried about G_FNM_NOESCAPE and G_FNM_CASEFOLD, these should be orthogonal, but G_FNM_FILE_NAME is another matter. I don't know xdgmime needs well enough to judge.
Comment 5 Ignacio Casal Quinteiro (nacho) 2014-09-08 10:02:29 UTC
Review of attachment 285638 [details] [review]:

See initial comments. A better person to review this would be owen though.

::: glib/gfnmatch.c
@@ +139,3 @@
+	    if (c == '\0')
+	      {
+                if (strchr (last_n, G_DIR_SEPARATOR) != NULL)

do we need this codepath on windows?

::: glib/gfnmatch.h
@@ +43,3 @@
+#define G_FNM_LEADING_DIR (1 << 3)	/* Ignore `/...' after a match.  */
+#define G_FNM_CASEFOLD	 (1 << 4)	/* Compare without regard to case.  */
+#define G_FNM_EXTMATCH	 (1 << 5)	/* Use ksh-like extended matching. */

I think we should typedef these flags

@@ +54,3 @@
+
+GLIB_AVAILABLE_IN_2_42
+gint g_fnmatch (const gchar *pattern, const gchar *name, gint flags);

one param per line

::: glib/tests/gfnmatch.c
@@ +1,1 @@
+#include "config.h"

missing copyright, do other tests have it?
Comment 6 LRN 2014-09-08 10:20:43 UTC
(In reply to comment #5)
> Review of attachment 285638 [details] [review]:
> 
> See initial comments. A better person to review this would be owen though.
> 
> ::: glib/gfnmatch.c
> @@ +139,3 @@
> +        if (c == '\0')
> +          {
> +                if (strchr (last_n, G_DIR_SEPARATOR) != NULL)
> 
> do we need this codepath on windows?

Yes, we need to check for both separators (on W32).

> ::: glib/tests/gfnmatch.c
> @@ +1,1 @@
> +#include "config.h"
> 
> missing copyright, do other tests have it?

Some tests have no copyright.
Comment 7 LRN 2014-09-08 11:26:18 UTC
Created attachment 285641 [details] [review]
Add g_fnmatch() implementation

v2:
 - Use the implementation from GTK:
   - Use fnmatch() interface (with flags and integer result)
   - Fail when unsupported flags are used
   - Fix G_DIR_SEPARATOR checks to correctly cover '/' on W32
   - Put the tests into the testsuite
v3:
 - Put constants (flags and return values) into enums
 - Formatting fixes
 - Make use NO_LEADING_PERIOD macro, since it's there
Comment 8 Ignacio Casal Quinteiro (nacho) 2014-09-08 13:26:08 UTC
Review of attachment 285641 [details] [review]:

See other nitpicks

::: glib/gfnmatch.c
@@ +267,3 @@
+{
+  gboolean no_leading_period = FALSE;
+

missing g_return_val_if_fail stuff

::: glib/gfnmatch.h
@@ +45,3 @@
+  G_FNM_CASEFOLD    = 1 << 4, /* Compare without regard to case.  */
+  G_FNM_EXTMATCH    = 1 << 5, /* Use ksh-like extended matching. */
+  G_FNM_FILE_NAME   = G_FNM_PATHNAME, /* Preferred GNU name.  */

last one should not have ,

@@ +52,3 @@
+  G_FNM_NOSYS       = -1, /* Unsupported combination of flags. */
+  G_FNM_MATCH       =  0, /* Match */
+  G_FNM_NOMATCH     =  1, /* STRING does not match PATTERN. */

same here
Comment 9 LRN 2014-09-08 15:12:57 UTC
Created attachment 285652 [details] [review]
Add g_fnmatch() implementation

v2:
 - Use the implementation from GTK:
   - Use fnmatch() interface (with flags and integer result)
   - Fail when unsupported flags are used
   - Fix G_DIR_SEPARATOR checks to correctly cover '/' on W32
   - Put the tests into the testsuite
v3:
 - Put constants (flags and return values) into enums
 - Formatting fixes
 - Make use NO_LEADING_PERIOD macro, since it's there
v4:
 - Check arguments for NULL
 - Remove unneeded commas after last enum elements
 - Rename to g_utf8_fnmatch()
Comment 10 Allison Karlitskaya (desrt) 2014-09-10 16:20:27 UTC
As discussed on IRC, I think we will not take this.

The reasons, more or less:

 - we don't need a utf8-safe fnmatch to implement the mimespec since it
   only uses * globbing and [0-9]

 - in fact, we could implement the xdgmime spec without using fnmatch at
   all because of the extremely simple cases of globs it contains

 - it may not even be desirable to have xdgmime on windows at all

Sorry :(