+/* If we want to use glob() from libc... */
+#if 1
+
+/* Add the result of glob() to the list */
+static void
+addglob(const glob_t *pglob)
+{
+ char **p = pglob->gl_pathv;
+
+ do {
+ addfname(*p);
+ } while (*++p);
+}
+static void
+expandmeta(struct strlist *str /*, int flag*/)
+{
+ /* TODO - EXP_REDIR */
+
+ while (str) {
+ char *p;
+ glob_t pglob;
+ int i;
+
+ if (fflag)
+ goto nometa;
+ INT_OFF;
+ p = preglob(str->text, RMESCAPE_ALLOC | RMESCAPE_HEAP);
+ /*
+ * GLOB_NOMAGIC (GNU): if no *?[ chars in pattern, return it even if no match
+ * TODO?: GLOB_NOCHECK: if no match, return unchanged pattern (sans \* escapes?)
+ */
+ i = glob(p, GLOB_NOMAGIC, NULL, &pglob);
+ if (p != str->text)
+ free(p);
+ switch (i) {
+ case 0:
+ /* GLOB_MAGCHAR is set if *?[ chars were seen (GNU) */
+ if (!(pglob.gl_flags & GLOB_MAGCHAR))
+ goto nometa2;
+ addglob(&pglob);
+ globfree(&pglob);
+ INT_ON;
+ break;
+ case GLOB_NOMATCH:
+nometa2:
+ globfree(&pglob);
+ INT_ON;
+nometa:
+ *exparg.lastp = str;
+ rmescapes(str->text, 0);
+ exparg.lastp = &str->next;
+ break;
+ default: /* GLOB_NOSPACE */
+ globfree(&pglob);
+ INT_ON;
+ ash_msg_and_raise_error(bb_msg_memory_exhausted);
+ }
+ str = str->next;
+ }
+}
+
+#else
+/* Homegrown globbing code. (dash also has both, uses homegrown one.) */
+