mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Ismael Luceno <ismael@iodev.co.uk>
To: musl@lists.openwall.com
Cc: Ismael Luceno <ismael@iodev.co.uk>
Subject: [PATCH] glob: implement GLOB_NOMAGIC
Date: Sat, 27 Jul 2019 01:48:47 +0200	[thread overview]
Message-ID: <20190726234847.12321-1-ismael@iodev.co.uk> (raw)

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



             reply	other threads:[~2019-07-26 23:48 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-26 23:48 Ismael Luceno [this message]
2019-07-27  2:39 ` Rich Felker
2019-07-27 13:59   ` Ismael Luceno
2021-08-15 17:36     ` [musl] " Ismael Luceno

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=20190726234847.12321-1-ismael@iodev.co.uk \
    --to=ismael@iodev.co.uk \
    --cc=musl@lists.openwall.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.
Code repositories for project(s) associated with this public inbox

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

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 NNTP newsgroup(s).