Subject: [PATCH] GLOB_PERIOD support for glob(3)
To: None <tech-userlevel@netbsd.org>
From: Richard M Kreuter <kreuter@progn.net>
List: tech-userlevel
Date: 12/04/2007 18:28:18
--=-=-=

Hello,

(Apologies if this is the wrong list to send to.)

Attached are three tiny patches that add to glob(3) a flag which, if
set, allows glob metacharacters to match an inital dot in a filename.
I've copied the name of the option, GLOB_PERIOD, from GNU glob.

Please let me know if there's further work I should do to get this
change incorporated.

Thanks,
Richard Kreuter


--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment; filename=glob.c.diff
Content-Description: GLOB_PERIOD in glob.c

--- /home/alex/build/NetBSD/current/src/lib/libc/gen/glob.c	2007-08-19 19:38:26.000000000 -0400
+++ glob.c	2007-12-04 15:51:14.000000000 -0500
@@ -696,8 +696,9 @@
 		Char *dc;
 
 		/* Initial DOT must be matched literally. */
-		if (dp->d_name[0] == DOT && *pattern != DOT)
-			continue;
+		if (!(pglob->gl_flags & GLOB_PERIOD))
+		    if (dp->d_name[0] == DOT && (*pattern != DOT))
+		        continue;
 		/*
 		 * The resulting string contains EOS, so we can
 		 * use the pathlim character, if it is the nul

--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment; filename=glob.h.diff
Content-Description: GLOB_PERIOD in glob.h

--- /usr/include/glob.h	2006-06-30 11:48:30.000000000 -0400
+++ glob.h	2007-12-04 15:48:20.000000000 -0500
@@ -90,6 +90,7 @@
 #define	GLOB_NOMAGIC	0x0200	/* GLOB_NOCHECK without magic chars (csh). */
 #define GLOB_LIMIT	0x0400	/* Limit memory used by matches to ARG_MAX */
 #define	GLOB_TILDE	0x0800	/* Expand tilde names from the passwd file. */
+#define GLOB_PERIOD	0x1600  /* Allow metachars to match leading periods. */
 #define	GLOB_QUOTE	0		/* source compatibility */
 
 #define	GLOB_ABEND	GLOB_ABORTED	/* source compatibility */

--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment; filename=glob.3.diff
Content-Description: GLOB_PERIOD in glob.3

--- /home/alex/build/NetBSD/current/src/lib/libc/gen/glob.3	2006-06-30 11:48:33.000000000 -0400
+++ glob.3	2007-12-04 15:54:08.000000000 -0500
@@ -248,6 +248,8 @@
 Disable the use of the backslash
 .Pq Ql \e
 character for quoting.
+.It Dv GLOB_PERIOD
+Allow metacharacters to match a dot at the beginning of a directory entry.
 .It Dv GLOB_TILDE
 Expand patterns that start with
 .Ql ~

--=-=-=--