• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

systemd / systemd / 14554080340

19 Apr 2025 11:46AM UTC coverage: 72.101% (-0.03%) from 72.13%
14554080340

push

github

web-flow
Add two new paragraphs to coding style about header files (#37188)

296880 of 411754 relevant lines covered (72.1%)

687547.52 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

94.55
/src/basic/glob-util.c
1
/* SPDX-License-Identifier: LGPL-2.1-or-later */
2

3
#include <errno.h>
4
#include <sys/types.h>
5
#include <sys/stat.h>
6
#include <unistd.h>
7

8
#include "dirent-util.h"
9
#include "errno-util.h"
10
#include "glob-util.h"
11
#include "log.h"
12
#include "macro.h"
13
#include "path-util.h"
14
#include "strv.h"
15

16
static void closedir_wrapper(void* v) {
11,142✔
17
        (void) closedir(v);
11,142✔
18
}
11,142✔
19

20
int safe_glob(const char *path, int flags, glob_t *pglob) {
42,675✔
21
        int k;
42,675✔
22

23
        /* We want to set GLOB_ALTDIRFUNC ourselves, don't allow it to be set. */
24
        assert(!(flags & GLOB_ALTDIRFUNC));
42,675✔
25

26
        if (!pglob->gl_closedir)
42,675✔
27
                pglob->gl_closedir = closedir_wrapper;
42,672✔
28
        if (!pglob->gl_readdir)
42,675✔
29
                pglob->gl_readdir = (struct dirent *(*)(void *)) readdir_no_dot;
42,672✔
30
        if (!pglob->gl_opendir)
42,675✔
31
                pglob->gl_opendir = (void *(*)(const char *)) opendir;
36,171✔
32
        if (!pglob->gl_lstat)
42,675✔
33
                pglob->gl_lstat = lstat;
42,672✔
34
        if (!pglob->gl_stat)
42,675✔
35
                pglob->gl_stat = stat;
42,672✔
36

37
        errno = 0;
42,675✔
38
        k = glob(path, flags | GLOB_ALTDIRFUNC, NULL, pglob);
42,675✔
39
        if (k == GLOB_NOMATCH)
42,675✔
40
                return -ENOENT;
41
        if (k == GLOB_NOSPACE)
8,275✔
42
                return -ENOMEM;
43
        if (k != 0)
8,275✔
44
                return errno_or_else(EIO);
×
45
        if (strv_isempty(pglob->gl_pathv))
8,275✔
46
                return -ENOENT;
×
47

48
        return 0;
49
}
50

51
int glob_first(const char *path, char **ret_first) {
12✔
52
        _cleanup_globfree_ glob_t g = {};
12✔
53
        int k;
12✔
54

55
        assert(path);
12✔
56

57
        k = safe_glob(path, GLOB_NOSORT|GLOB_BRACE, &g);
12✔
58
        if (k == -ENOENT) {
12✔
59
                if (ret_first)
6✔
60
                        *ret_first = NULL;
5✔
61
                return false;
6✔
62
        }
63
        if (k < 0)
6✔
64
                return k;
65

66
        if (ret_first) {
6✔
67
                assert(g.gl_pathv && g.gl_pathv[0]);
3✔
68

69
                char *first = strdup(g.gl_pathv[0]);
3✔
70
                if (!first)
3✔
71
                        return log_oom_debug();
×
72
                *ret_first = first;
3✔
73
        }
74

75
        return true;
76
}
77

78
int glob_extend(char ***strv, const char *path, int flags) {
4,137✔
79
        _cleanup_globfree_ glob_t g = {};
4,137✔
80
        int k;
4,137✔
81

82
        k = safe_glob(path, GLOB_NOSORT|GLOB_BRACE|flags, &g);
4,137✔
83
        if (k < 0)
4,137✔
84
                return k;
85

86
        return strv_extend_strv(strv, g.gl_pathv, false);
4,137✔
87
}
88

89
int glob_non_glob_prefix(const char *path, char **ret) {
3,648✔
90
        /* Return the path of the path that has no glob characters. */
91

92
        size_t n = strcspn(path, GLOB_CHARS);
3,648✔
93

94
        if (path[n] != '\0')
3,648✔
95
                while (n > 0 && path[n-1] != '/')
66,778✔
96
                        n--;
97

98
        if (n == 0)
3,648✔
99
                return -ENOENT;
100

101
        char *ans = strndup(path, n);
3,647✔
102
        if (!ans)
3,647✔
103
                return -ENOMEM;
104
        *ret = ans;
3,647✔
105
        return 0;
3,647✔
106
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc