mailing list of musl libc
 help / color / mirror / Atom feed
* [PATCH] glob: implement GLOB_NOMAGIC
@ 2019-07-26 23:48 Ismael Luceno
  2019-07-27  2:39 ` Rich Felker
  0 siblings, 1 reply; 4+ messages in thread
From: Ismael Luceno @ 2019-07-26 23:48 UTC (permalink / raw)
  To: musl; +Cc: Ismael Luceno

Signed-off-by: Ismael Luceno <ismael@iodev.co.uk>
---
 include/glob.h   |  1 +
 src/regex/glob.c | 13 +++++++++----
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/include/glob.h b/include/glob.h
index 4a562a206d52..0ff70bdfeef2 100644
--- a/include/glob.h
+++ b/include/glob.h
@@ -31,6 +31,7 @@ void globfree(glob_t *);
 #define GLOB_NOESCAPE 0x40
 #define	GLOB_PERIOD   0x80
 
+#define GLOB_NOMAGIC     0x0800
 #define GLOB_TILDE       0x1000
 #define GLOB_TILDE_CHECK 0x4000
 
diff --git a/src/regex/glob.c b/src/regex/glob.c
index 58248675c203..0ccd9759c5e7 100644
--- a/src/regex/glob.c
+++ b/src/regex/glob.c
@@ -253,13 +253,18 @@ int glob(const char *restrict pat, int flags, int (*errfunc)(const char *path, i
 	
 	for (cnt=0, tail=head.next; tail; tail=tail->next, cnt++);
 	if (!cnt) {
+		size_t len;
 		if (flags & GLOB_NOCHECK) {
-			tail = &head;
-			if (append(&tail, pat, strlen(pat), 0))
-				return GLOB_NOSPACE;
-			cnt++;
+			len = strlen(pat);
+		} else if (flags & GLOB_NOMAGIC) {
+			len = strcspn(pat, "*?[");
+			if (pat[len]) return GLOB_NOMATCH;
 		} else
 			return GLOB_NOMATCH;
+		tail = &head;
+		if (append(&tail, pat, len, 0))
+			return GLOB_NOSPACE;
+		cnt++;
 	}
 
 	if (flags & GLOB_APPEND) {
-- 
2.22.0



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

* Re: [PATCH] glob: implement GLOB_NOMAGIC
  2019-07-26 23:48 [PATCH] glob: implement GLOB_NOMAGIC Ismael Luceno
@ 2019-07-27  2:39 ` Rich Felker
  2019-07-27 13:59   ` Ismael Luceno
  0 siblings, 1 reply; 4+ messages in thread
From: Rich Felker @ 2019-07-27  2:39 UTC (permalink / raw)
  To: musl

On Sat, Jul 27, 2019 at 01:48:47AM +0200, Ismael Luceno wrote:
> Signed-off-by: Ismael Luceno <ismael@iodev.co.uk>
> ---
>  include/glob.h   |  1 +
>  src/regex/glob.c | 13 +++++++++----
>  2 files changed, 10 insertions(+), 4 deletions(-)
> 
> diff --git a/include/glob.h b/include/glob.h
> index 4a562a206d52..0ff70bdfeef2 100644
> --- a/include/glob.h
> +++ b/include/glob.h
> @@ -31,6 +31,7 @@ void globfree(glob_t *);
>  #define GLOB_NOESCAPE 0x40
>  #define	GLOB_PERIOD   0x80
>  
> +#define GLOB_NOMAGIC     0x0800
>  #define GLOB_TILDE       0x1000
>  #define GLOB_TILDE_CHECK 0x4000
>  
> diff --git a/src/regex/glob.c b/src/regex/glob.c
> index 58248675c203..0ccd9759c5e7 100644
> --- a/src/regex/glob.c
> +++ b/src/regex/glob.c
> @@ -253,13 +253,18 @@ int glob(const char *restrict pat, int flags, int (*errfunc)(const char *path, i
>  	
>  	for (cnt=0, tail=head.next; tail; tail=tail->next, cnt++);
>  	if (!cnt) {
> +		size_t len;
>  		if (flags & GLOB_NOCHECK) {
> -			tail = &head;
> -			if (append(&tail, pat, strlen(pat), 0))
> -				return GLOB_NOSPACE;
> -			cnt++;
> +			len = strlen(pat);
> +		} else if (flags & GLOB_NOMAGIC) {
> +			len = strcspn(pat, "*?[");
> +			if (pat[len]) return GLOB_NOMATCH;
>  		} else
>  			return GLOB_NOMATCH;
> +		tail = &head;
> +		if (append(&tail, pat, len, 0))
> +			return GLOB_NOSPACE;
> +		cnt++;
>  	}
>  
>  	if (flags & GLOB_APPEND) {

The documentation for this flag is really poor. Do you know how it's
supposed to interact with escaped characters? Is it really supposed to
refuse to expand to the literal pattern when the literal pattern
contains an escaped *, ?, or [ but not a special one?

Otherwise I think this looks ok. Nice use of strcspn.

Rich


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

* Re: [PATCH] glob: implement GLOB_NOMAGIC
  2019-07-27  2:39 ` Rich Felker
@ 2019-07-27 13:59   ` Ismael Luceno
  2021-08-15 17:36     ` [musl] " Ismael Luceno
  0 siblings, 1 reply; 4+ messages in thread
From: Ismael Luceno @ 2019-07-27 13:59 UTC (permalink / raw)
  To: musl

On 26/Jul/2019 22:39, Rich Felker wrote:
<...>
> The documentation for this flag is really poor. Do you know how it's
> supposed to interact with escaped characters? Is it really supposed to
> refuse to expand to the literal pattern when the literal pattern
> contains an escaped *, ?, or [ but not a special one?

It's intended for implementing csh-style globbing, which doesn't
recognize escaping.

I don't see any reason to enforce GLOB_NOESCAPE, though.

> Otherwise I think this looks ok. Nice use of strcspn.

:-).


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

* Re: [musl] [PATCH] glob: implement GLOB_NOMAGIC
  2019-07-27 13:59   ` Ismael Luceno
@ 2021-08-15 17:36     ` Ismael Luceno
  0 siblings, 0 replies; 4+ messages in thread
From: Ismael Luceno @ 2021-08-15 17:36 UTC (permalink / raw)
  To: musl; +Cc: Rich Felker

On 27/Jul/2019 15:59, Ismael Luceno wrote:
> On 26/Jul/2019 22:39, Rich Felker wrote:
> <...>
> > The documentation for this flag is really poor. Do you know how it's
> > supposed to interact with escaped characters? Is it really supposed to
> > refuse to expand to the literal pattern when the literal pattern
> > contains an escaped *, ?, or [ but not a special one?
> 
> It's intended for implementing csh-style globbing, which doesn't
> recognize escaping.
> 
> I don't see any reason to enforce GLOB_NOESCAPE, though.
> 
> > Otherwise I think this looks ok. Nice use of strcspn.
> 
> :-).

Ping.

This is used in combination with GLOB_NOESCAPE by csh implementations
to implement their globbing behavior; I added it for completeness,
it's very small, and it saves quite some disk space in the csh binary,
by not having to bundle another glob implementation.

While AFAIK it's always used in combination with GLOB_NOESCAPE, I see
no reason to enforce that.

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

end of thread, other threads:[~2021-08-15 17:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-26 23:48 [PATCH] glob: implement GLOB_NOMAGIC Ismael Luceno
2019-07-27  2:39 ` Rich Felker
2019-07-27 13:59   ` Ismael Luceno
2021-08-15 17:36     ` [musl] " Ismael Luceno

mailing list of musl libc

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://inbox.vuxu.org/musl

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 musl musl/ https://inbox.vuxu.org/musl \
		musl@inbox.vuxu.org
	public-inbox-index musl

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://inbox.vuxu.org/vuxu.archive.musl


code repositories for the project(s) associated with this inbox:

	https://git.vuxu.org/mirror/musl/

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git