]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
util-lib: split out globbing related calls into glob-util.[ch]
authorLennart Poettering <lennart@poettering.net>
Tue, 27 Oct 2015 00:48:17 +0000 (01:48 +0100)
committerLennart Poettering <lennart@poettering.net>
Tue, 27 Oct 2015 12:25:58 +0000 (13:25 +0100)
17 files changed:
Makefile.am
src/analyze/analyze.c
src/basic/glob-util.c [new file with mode: 0644]
src/basic/glob-util.h [new file with mode: 0644]
src/basic/macro.h
src/basic/util.c
src/basic/util.h
src/core/execute.c
src/core/path.c
src/journal-remote/journal-upload.c
src/journal/fsprg.h
src/journal/journalctl.c
src/shared/condition.c
src/systemctl/systemctl.c
src/test/test-util.c
src/tmpfiles/tmpfiles.c
src/udev/udev-rules.c

index c47ad240abdcfe08d29b0b55f393c0f2690a15ba..3c4250a144cbcb7adea2032604bbe51199b4732d 100644 (file)
@@ -812,6 +812,8 @@ libbasic_la_SOURCES = \
        src/basic/mount-util.h \
        src/basic/hexdecoct.c \
        src/basic/hexdecoct.h \
+       src/basic/glob-util.h \
+       src/basic/glob-util.c \
        src/basic/extract-word.c \
        src/basic/extract-word.h \
        src/basic/escape.c \
index a165152cb2c92d13f34cbd94c52e25a2a816e31a..7e63bfa8211254df3867a32157dab897b03bf836 100644 (file)
@@ -30,6 +30,7 @@
 #include "analyze-verify.h"
 #include "bus-error.h"
 #include "bus-util.h"
+#include "glob-util.h"
 #include "hashmap.h"
 #include "locale-util.h"
 #include "log.h"
diff --git a/src/basic/glob-util.c b/src/basic/glob-util.c
new file mode 100644 (file)
index 0000000..112c639
--- /dev/null
@@ -0,0 +1,71 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+/***
+  This file is part of systemd.
+
+  Copyright 2010 Lennart Poettering
+
+  systemd 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.
+
+  systemd 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 systemd; If not, see <http://www.gnu.org/licenses/>.
+***/
+
+#include <glob.h>
+
+#include "glob-util.h"
+#include "strv.h"
+#include "util.h"
+
+int glob_exists(const char *path) {
+        _cleanup_globfree_ glob_t g = {};
+        int k;
+
+        assert(path);
+
+        errno = 0;
+        k = glob(path, GLOB_NOSORT|GLOB_BRACE, NULL, &g);
+
+        if (k == GLOB_NOMATCH)
+                return 0;
+        if (k == GLOB_NOSPACE)
+                return -ENOMEM;
+        if (k != 0)
+                return errno ? -errno : -EIO;
+
+        return !strv_isempty(g.gl_pathv);
+}
+
+int glob_extend(char ***strv, const char *path) {
+        _cleanup_globfree_ glob_t g = {};
+        int k;
+        char **p;
+
+        errno = 0;
+        k = glob(path, GLOB_NOSORT|GLOB_BRACE, NULL, &g);
+
+        if (k == GLOB_NOMATCH)
+                return -ENOENT;
+        if (k == GLOB_NOSPACE)
+                return -ENOMEM;
+        if (k != 0)
+                return errno ? -errno : -EIO;
+        if (strv_isempty(g.gl_pathv))
+                return -ENOENT;
+
+        STRV_FOREACH(p, g.gl_pathv) {
+                k = strv_extend(strv, *p);
+                if (k < 0)
+                        return k;
+        }
+
+        return 0;
+}
diff --git a/src/basic/glob-util.h b/src/basic/glob-util.h
new file mode 100644 (file)
index 0000000..8817df1
--- /dev/null
@@ -0,0 +1,37 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+#pragma once
+
+/***
+  This file is part of systemd.
+
+  Copyright 2010 Lennart Poettering
+
+  systemd 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.
+
+  systemd 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 systemd; If not, see <http://www.gnu.org/licenses/>.
+***/
+
+#include <string.h>
+
+#include "macro.h"
+#include "util.h"
+
+int glob_exists(const char *path);
+int glob_extend(char ***strv, const char *path);
+
+#define _cleanup_globfree_ _cleanup_(globfree)
+
+_pure_ static inline bool string_is_glob(const char *p) {
+        /* Check if a string contains any glob patterns. */
+        return !!strpbrk(p, GLOB_CHARS);
+}
index 975714da2baa50248cb64aae55ecbe4f0b4499b2..daa7c416f71a749045ff0b8d2980443ecd0efdaf 100644 (file)
@@ -294,9 +294,6 @@ static inline unsigned long ALIGN_POWER2(unsigned long u) {
 #define PTR_TO_SIZE(p) ((size_t) ((uintptr_t) (p)))
 #define SIZE_TO_PTR(u) ((void *) ((uintptr_t) (u)))
 
-#define memzero(x,l) (memset((x), 0, (l)))
-#define zero(x) (memzero(&(x), sizeof(x)))
-
 #define CHAR_TO_STR(x) ((char[2]) { x, 0 })
 
 #define char_array_0(x) x[sizeof(x)-1] = 0;
index 412ea50b9684d10cb98691306f0eac684559eb0f..6da311ad1e17cf3b08650330826d6544f8949537 100644 (file)
@@ -23,7 +23,6 @@
 #include <dirent.h>
 #include <errno.h>
 #include <fcntl.h>
-#include <glob.h>
 #include <grp.h>
 #include <langinfo.h>
 #include <libintl.h>
@@ -368,49 +367,6 @@ int socket_from_display(const char *display, char **path) {
         return 0;
 }
 
-int glob_exists(const char *path) {
-        _cleanup_globfree_ glob_t g = {};
-        int k;
-
-        assert(path);
-
-        errno = 0;
-        k = glob(path, GLOB_NOSORT|GLOB_BRACE, NULL, &g);
-
-        if (k == GLOB_NOMATCH)
-                return 0;
-        else if (k == GLOB_NOSPACE)
-                return -ENOMEM;
-        else if (k == 0)
-                return !strv_isempty(g.gl_pathv);
-        else
-                return errno ? -errno : -EIO;
-}
-
-int glob_extend(char ***strv, const char *path) {
-        _cleanup_globfree_ glob_t g = {};
-        int k;
-        char **p;
-
-        errno = 0;
-        k = glob(path, GLOB_NOSORT|GLOB_BRACE, NULL, &g);
-
-        if (k == GLOB_NOMATCH)
-                return -ENOENT;
-        else if (k == GLOB_NOSPACE)
-                return -ENOMEM;
-        else if (k != 0 || strv_isempty(g.gl_pathv))
-                return errno ? -errno : -EIO;
-
-        STRV_FOREACH(p, g.gl_pathv) {
-                k = strv_extend(strv, *p);
-                if (k < 0)
-                        break;
-        }
-
-        return k;
-}
-
 int block_get_whole_disk(dev_t d, dev_t *ret) {
         char *p, *s;
         int r;
index 95c7c75b9c4fdc198ce9f3a7a38784df88c5d018..3074029f38b6a2e513a6704a0230bf3c52a218c7 100644 (file)
@@ -94,9 +94,6 @@ bool plymouth_running(void);
 bool display_is_local(const char *display) _pure_;
 int socket_from_display(const char *display, char **path);
 
-int glob_exists(const char *path);
-int glob_extend(char ***strv, const char *path);
-
 int block_get_whole_disk(dev_t d, dev_t *ret);
 
 #define NULSTR_FOREACH(i, l)                                    \
@@ -132,7 +129,6 @@ static inline void freep(void *p) {
 }
 
 #define _cleanup_free_ _cleanup_(freep)
-#define _cleanup_globfree_ _cleanup_(globfree)
 
 _malloc_  _alloc_(1, 2) static inline void *malloc_multiply(size_t a, size_t b) {
         if (_unlikely_(b != 0 && a > ((size_t) -1) / b))
@@ -155,13 +151,6 @@ _alloc_(2, 3) static inline void *memdup_multiply(const void *p, size_t a, size_
         return memdup(p, a * b);
 }
 
-/**
- * Check if a string contains any glob patterns.
- */
-_pure_ static inline bool string_is_glob(const char *p) {
-        return !!strpbrk(p, GLOB_CHARS);
-}
-
 void *xbsearch_r(const void *key, const void *base, size_t nmemb, size_t size,
                  int (*compar) (const void *, const void *, void *),
                  void *arg);
@@ -173,6 +162,9 @@ static inline void *mempset(void *s, int c, size_t n) {
         return (uint8_t*)s + n;
 }
 
+#define memzero(x,l) (memset((x), 0, (l)))
+#define zero(x) (memzero(&(x), sizeof(x)))
+
 void* greedy_realloc(void **p, size_t *allocated, size_t need, size_t size);
 void* greedy_realloc0(void **p, size_t *allocated, size_t need, size_t size);
 #define GREEDY_REALLOC(array, allocated, need)                          \
index 3814fd438189526b0ff81eed3656ce3029868eef..bf13e29bd9bb12e02d5736cbdd96aac7042f4b85 100644 (file)
@@ -70,6 +70,7 @@
 #include "fileio.h"
 #include "formats-util.h"
 #include "fs-util.h"
+#include "glob-util.h"
 #include "io-util.h"
 #include "ioprio.h"
 #include "log.h"
index 761ec265b485e6c2b184652a8ce30ef7350ed8bc..9c5309a58a6f72c5dc04a98c800f25272403e4dd 100644 (file)
@@ -28,6 +28,7 @@
 #include "bus-util.h"
 #include "dbus-path.h"
 #include "fd-util.h"
+#include "glob-util.h"
 #include "macro.h"
 #include "mkdir.h"
 #include "path.h"
index 20e2a2f73bdde82037da4a59b5eeeb1f088e9cfb..1925475db8be84e604c88ab29b0067b65ef05e2f 100644 (file)
@@ -31,6 +31,7 @@
 #include "fd-util.h"
 #include "fileio.h"
 #include "formats-util.h"
+#include "glob-util.h"
 #include "journal-upload.h"
 #include "log.h"
 #include "mkdir.h"
index 150d034828f329ab2b5672f4c75c1ba3b6d7b8ec..5959b1fed2f8e6a83d21567faf7afc26325801b4 100644 (file)
@@ -29,6 +29,7 @@
 #include <inttypes.h>
 
 #include "macro.h"
+#include "util.h"
 
 #ifdef __cplusplus
 extern "C" {
index 1965522dfd16ba56113c31db6e5f0aeccfccefdf..2782ac032945e217b83e3001fd205fcaff3e93b5 100644 (file)
@@ -47,6 +47,7 @@
 #include "fileio.h"
 #include "fs-util.h"
 #include "fsprg.h"
+#include "glob-util.h"
 #include "hostname-util.h"
 #include "io-util.h"
 #include "journal-def.h"
index d06120f0d754d23532575cb51d3c7a48f32f6407..2929e3e821048bb97fd4a905f782f8eb8af41e64 100644 (file)
@@ -34,6 +34,7 @@
 #include "condition.h"
 #include "extract-word.h"
 #include "fd-util.h"
+#include "glob-util.h"
 #include "hostname-util.h"
 #include "ima-util.h"
 #include "mount-util.h"
index 2166554f4d2736c63ffef0f8e9bb6dcc7ff1d686..2faa93ef8817860b910c7874aee4afa81432aebf 100644 (file)
@@ -52,6 +52,7 @@
 #include "fileio.h"
 #include "formats-util.h"
 #include "fs-util.h"
+#include "glob-util.h"
 #include "hostname-util.h"
 #include "initreq.h"
 #include "install.h"
index 6c6fce2d6a1adf5bbb475fd88b10ca0a8d85ac24..647eff0496e615f2417e184bd26f493140359e37 100644 (file)
@@ -39,6 +39,7 @@
 #include "fileio.h"
 #include "fs-util.h"
 #include "fstab-util.h"
+#include "glob-util.h"
 #include "hexdecoct.h"
 #include "io-util.h"
 #include "mkdir.h"
@@ -54,8 +55,8 @@
 #include "user-util.h"
 #include "util.h"
 #include "virt.h"
-#include "xattr-util.h"
 #include "web-util.h"
+#include "xattr-util.h"
 
 static void test_streq_ptr(void) {
         assert_se(streq_ptr(NULL, NULL));
index 41deea70fbd57ab1af6428c2b90bd22a4da89e8a..5196447963a0dc8f4b6046b4f59badb7304d5f6f 100644 (file)
@@ -49,6 +49,7 @@
 #include "fileio.h"
 #include "formats-util.h"
 #include "fs-util.h"
+#include "glob-util.h"
 #include "io-util.h"
 #include "label.h"
 #include "log.h"
index b87c14efb284f798491e7a31f48e0807099a022e..7d5f473d457b810aa03112c61a690fb967b8cde7 100644 (file)
@@ -32,6 +32,7 @@
 #include "conf-files.h"
 #include "escape.h"
 #include "fd-util.h"
+#include "glob-util.h"
 #include "path-util.h"
 #include "stat-util.h"
 #include "strbuf.h"