263 lines
6.5 KiB
Diff
263 lines
6.5 KiB
Diff
diff -uNr src/CMakeLists.txt src.mod/CMakeLists.txt
|
|
--- src/CMakeLists.txt 2021-05-21 08:58:40.268102000 +0000
|
|
+++ src.mod/CMakeLists.txt 2021-05-21 08:46:53.277571000 +0000
|
|
@@ -142,6 +142,8 @@
|
|
lxqtrotatedwidget.cpp
|
|
lxqtbacklight.cpp
|
|
lxqtbacklight/virtual_backend.cpp
|
|
+
|
|
+ wordexp.c
|
|
)
|
|
|
|
if (NOT APPLE)
|
|
diff -uNr src/wordexp.c src.mod/wordexp.c
|
|
--- src/wordexp.c 1970-01-01 00:00:00.000000000 +0000
|
|
+++ src.mod/wordexp.c 2021-05-21 08:58:23.662102000 +0000
|
|
@@ -0,0 +1,184 @@
|
|
+// Copied from http://git.musl-libc.org/cgit/musl/plain/src/misc/wordexp.c
|
|
+// pthread-related lines are removed because they're missing on Android
|
|
+#include <wordexp.h>
|
|
+#include <unistd.h>
|
|
+#include <stdio.h>
|
|
+#include <string.h>
|
|
+#include <limits.h>
|
|
+#include <stdint.h>
|
|
+#include <stdlib.h>
|
|
+#include <sys/wait.h>
|
|
+#include <signal.h>
|
|
+#include <errno.h>
|
|
+#include <fcntl.h>
|
|
+
|
|
+static void reap(pid_t pid)
|
|
+{
|
|
+ int status;
|
|
+ while (waitpid(pid, &status, 0) < 0 && errno == EINTR);
|
|
+}
|
|
+
|
|
+static char *getword(FILE *f)
|
|
+{
|
|
+ char *s = 0;
|
|
+ return getdelim(&s, (size_t [1]){0}, 0, f) < 0 ? 0 : s;
|
|
+}
|
|
+
|
|
+static int do_wordexp(const char *s, wordexp_t *we, int flags)
|
|
+{
|
|
+ size_t i, l;
|
|
+ int sq=0, dq=0;
|
|
+ size_t np=0;
|
|
+ char *w, **tmp;
|
|
+ char *redir = (flags & WRDE_SHOWERR) ? "" : "2>/dev/null";
|
|
+ int err = 0;
|
|
+ FILE *f;
|
|
+ size_t wc = 0;
|
|
+ char **wv = 0;
|
|
+ int p[2];
|
|
+ pid_t pid;
|
|
+ sigset_t set;
|
|
+
|
|
+ if (flags & WRDE_REUSE) wordfree(we);
|
|
+
|
|
+ if (flags & WRDE_NOCMD) for (i=0; s[i]; i++) switch (s[i]) {
|
|
+ case '\\':
|
|
+ if (!sq && !s[++i]) return WRDE_SYNTAX;
|
|
+ break;
|
|
+ case '\'':
|
|
+ if (!dq) sq^=1;
|
|
+ break;
|
|
+ case '"':
|
|
+ if (!sq) dq^=1;
|
|
+ break;
|
|
+ case '(':
|
|
+ if (np) {
|
|
+ np++;
|
|
+ break;
|
|
+ }
|
|
+ case ')':
|
|
+ if (np) {
|
|
+ np--;
|
|
+ break;
|
|
+ }
|
|
+ case '\n':
|
|
+ case '|':
|
|
+ case '&':
|
|
+ case ';':
|
|
+ case '<':
|
|
+ case '>':
|
|
+ case '{':
|
|
+ case '}':
|
|
+ if (!(sq|dq|np)) return WRDE_BADCHAR;
|
|
+ break;
|
|
+ case '$':
|
|
+ if (sq) break;
|
|
+ if (s[i+1]=='(' && s[i+2]=='(') {
|
|
+ i += 2;
|
|
+ np += 2;
|
|
+ break;
|
|
+ } else if (s[i+1] != '(') break;
|
|
+ case '`':
|
|
+ if (sq) break;
|
|
+ return WRDE_CMDSUB;
|
|
+ }
|
|
+
|
|
+ if (flags & WRDE_APPEND) {
|
|
+ wc = we->we_wordc;
|
|
+ wv = we->we_wordv;
|
|
+ }
|
|
+
|
|
+ i = wc;
|
|
+ if (flags & WRDE_DOOFFS) {
|
|
+ if (we->we_offs > SIZE_MAX/sizeof(void *)/4)
|
|
+ goto nospace;
|
|
+ i += we->we_offs;
|
|
+ } else {
|
|
+ we->we_offs = 0;
|
|
+ }
|
|
+
|
|
+ if (pipe2(p, O_CLOEXEC) < 0) goto nospace;
|
|
+ pid = fork();
|
|
+ if (pid < 0) {
|
|
+ close(p[0]);
|
|
+ close(p[1]);
|
|
+ goto nospace;
|
|
+ }
|
|
+ if (!pid) {
|
|
+ if (p[1] == 1) fcntl(1, F_SETFD, 0);
|
|
+ else dup2(p[1], 1);
|
|
+ execl("/bin/sh", "sh", "-c",
|
|
+ "eval \"printf %s\\\\\\\\0 x $1 $2\"",
|
|
+ "sh", s, redir, (char *)0);
|
|
+ _exit(1);
|
|
+ }
|
|
+ close(p[1]);
|
|
+
|
|
+ f = fdopen(p[0], "r");
|
|
+ if (!f) {
|
|
+ close(p[0]);
|
|
+ kill(pid, SIGKILL);
|
|
+ reap(pid);
|
|
+ goto nospace;
|
|
+ }
|
|
+
|
|
+ l = wv ? i+1 : 0;
|
|
+
|
|
+ free(getword(f));
|
|
+ if (feof(f)) {
|
|
+ fclose(f);
|
|
+ reap(pid);
|
|
+ return WRDE_SYNTAX;
|
|
+ }
|
|
+
|
|
+ while ((w = getword(f))) {
|
|
+ if (i+1 >= l) {
|
|
+ l += l/2+10;
|
|
+ tmp = realloc(wv, l*sizeof(char *));
|
|
+ if (!tmp) break;
|
|
+ wv = tmp;
|
|
+ }
|
|
+ wv[i++] = w;
|
|
+ wv[i] = 0;
|
|
+ }
|
|
+ if (!feof(f)) err = WRDE_NOSPACE;
|
|
+
|
|
+ fclose(f);
|
|
+ reap(pid);
|
|
+
|
|
+ if (!wv) wv = calloc(i+1, sizeof *wv);
|
|
+
|
|
+ we->we_wordv = wv;
|
|
+ we->we_wordc = i;
|
|
+
|
|
+ if (flags & WRDE_DOOFFS) {
|
|
+ if (wv) for (i=we->we_offs; i; i--)
|
|
+ we->we_wordv[i-1] = 0;
|
|
+ we->we_wordc -= we->we_offs;
|
|
+ }
|
|
+ return err;
|
|
+
|
|
+nospace:
|
|
+ if (!(flags & WRDE_APPEND)) {
|
|
+ we->we_wordc = 0;
|
|
+ we->we_wordv = 0;
|
|
+ }
|
|
+ return WRDE_NOSPACE;
|
|
+}
|
|
+
|
|
+int wordexp(const char *restrict s, wordexp_t *restrict we, int flags)
|
|
+{
|
|
+ int r, cs;
|
|
+ r = do_wordexp(s, we, flags);
|
|
+ return r;
|
|
+}
|
|
+
|
|
+void wordfree(wordexp_t *we)
|
|
+{
|
|
+ size_t i;
|
|
+ if (!we->we_wordv) return;
|
|
+ for (i=0; i<we->we_wordc; i++) free(we->we_wordv[we->we_offs+i]);
|
|
+ free(we->we_wordv);
|
|
+ we->we_wordv = 0;
|
|
+ we->we_wordc = 0;
|
|
+}
|
|
diff -uNr src/wordexp.h src.mod/wordexp.h
|
|
--- src/wordexp.h 1970-01-01 00:00:00.000000000 +0000
|
|
+++ src.mod/wordexp.h 2021-05-21 08:58:53.085923000 +0000
|
|
@@ -0,0 +1,58 @@
|
|
+/* Copyright (C) 1991, 92, 1996-1999, 2001, 2003 Free Software Foundation, Inc.
|
|
+ This file is part of the GNU C Library.
|
|
+ The GNU C Library is free software; you can redistribute it and/or
|
|
+ modify it under the terms of the GNU Lesser General Public
|
|
+ License as published by the Free Software Foundation; either
|
|
+ version 2.1 of the License, or (at your option) any later version.
|
|
+ The GNU C Library is distributed in the hope that it will be useful,
|
|
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
+ Lesser General Public License for more details.
|
|
+ You should have received a copy of the GNU Lesser General Public
|
|
+ License along with the GNU C Library; if not, write to the Free
|
|
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
|
+ 02111-1307 USA. */
|
|
+#ifndef _WORDEXP_H
|
|
+#define _WORDEXP_H 1
|
|
+#include <features.h>
|
|
+#define __need_size_t
|
|
+#include <stddef.h>
|
|
+__BEGIN_DECLS
|
|
+/* Bits set in the FLAGS argument to `wordexp'. */
|
|
+enum
|
|
+ {
|
|
+ WRDE_DOOFFS = (1 << 0), /* Insert PWORDEXP->we_offs NULLs. */
|
|
+ WRDE_APPEND = (1 << 1), /* Append to results of a previous call. */
|
|
+ WRDE_NOCMD = (1 << 2), /* Don't do command substitution. */
|
|
+ WRDE_REUSE = (1 << 3), /* Reuse storage in PWORDEXP. */
|
|
+ WRDE_SHOWERR = (1 << 4), /* Don't redirect stderr to /dev/null. */
|
|
+ WRDE_UNDEF = (1 << 5), /* Error for expanding undefined variables. */
|
|
+ __WRDE_FLAGS = (WRDE_DOOFFS | WRDE_APPEND | WRDE_NOCMD |
|
|
+ WRDE_REUSE | WRDE_SHOWERR | WRDE_UNDEF)
|
|
+ };
|
|
+/* Structure describing a word-expansion run. */
|
|
+typedef struct
|
|
+ {
|
|
+ size_t we_wordc; /* Count of words matched. */
|
|
+ char **we_wordv; /* List of expanded words. */
|
|
+ size_t we_offs; /* Slots to reserve in `we_wordv'. */
|
|
+ } wordexp_t;
|
|
+/* Possible nonzero return values from `wordexp'. */
|
|
+enum
|
|
+ {
|
|
+#ifdef __USE_XOPEN
|
|
+ WRDE_NOSYS = -1, /* Never used since we support `wordexp'. */
|
|
+#endif
|
|
+ WRDE_NOSPACE = 1, /* Ran out of memory. */
|
|
+ WRDE_BADCHAR, /* A metachar appears in the wrong place. */
|
|
+ WRDE_BADVAL, /* Undefined var reference with WRDE_UNDEF. */
|
|
+ WRDE_CMDSUB, /* Command substitution with WRDE_NOCMD. */
|
|
+ WRDE_SYNTAX /* Shell syntax error. */
|
|
+ };
|
|
+/* Do word expansion of WORDS into PWORDEXP. */
|
|
+extern int wordexp (__const char *__restrict __words,
|
|
+ wordexp_t *__restrict __pwordexp, int __flags);
|
|
+/* Free the storage allocated by a `wordexp' call. */
|
|
+extern void wordfree (wordexp_t *__wordexp);
|
|
+__END_DECLS
|
|
+#endif /* wordexp.h */
|