Coverage Report

Created: 2025-10-10 06:52

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/unit/src/nxt_fs.c
Line
Count
Source
1
/*
2
 * Copyright (C) NGINX, Inc.
3
 * Copyright 2024, Alejandro Colomar <alx@kernel.org>
4
 */
5
6
#include <nxt_main.h>
7
8
9
static nxt_int_t nxt_fs_mkdir(const u_char *dir, mode_t mode);
10
11
12
nxt_int_t
13
nxt_fs_mkdir_p(const u_char *dir, mode_t mode)
14
0
{
15
0
    char       *start, *end, *dst;
16
0
    size_t     dirlen;
17
0
    nxt_int_t  ret;
18
0
    char       path[PATH_MAX];
19
20
0
    dirlen = nxt_strlen(dir);
21
22
0
    nxt_assert(dirlen < PATH_MAX && dirlen > 0);
23
24
0
    dst = path;
25
0
    start = (char *) dir;
26
27
0
    while (*start != '\0') {
28
0
        end = strchr(start + 1, '/');
29
0
        if (end == NULL) {
30
0
            end = ((char *)dir + dirlen);
31
0
        }
32
33
0
        dst = nxt_cpymem(dst, start, end - start);
34
0
        *dst = '\0';
35
36
0
        ret = nxt_fs_mkdir((u_char *) path, mode);
37
0
        if (nxt_slow_path(ret != NXT_OK && nxt_errno != EEXIST)) {
38
0
            return NXT_ERROR;
39
0
        }
40
41
0
        start = end;
42
0
    }
43
44
0
    return NXT_OK;
45
0
}
46
47
48
nxt_int_t
49
nxt_fs_mkdir_p_dirname(const u_char *path, mode_t mode)
50
0
{
51
0
    char       *ptr, *dir;
52
0
    nxt_int_t  ret;
53
54
0
    dir = nxt_strdup(path);
55
0
    if (nxt_slow_path(dir == NULL)) {
56
0
        return NXT_ERROR;
57
0
    }
58
59
0
    ret = NXT_OK;
60
61
0
    ptr = strrchr(dir, '/');
62
0
    if (ptr == dir || nxt_slow_path(ptr == NULL)) {
63
0
        goto out_free;
64
0
    }
65
66
0
    *ptr = '\0';
67
0
    ret = nxt_fs_mkdir_p((const u_char *) dir, mode);
68
69
0
out_free:
70
0
    nxt_free(dir);
71
72
0
    return ret;
73
0
}
74
75
76
static nxt_int_t
77
nxt_fs_mkdir(const u_char *dir, mode_t mode)
78
0
{
79
0
    if (nxt_fast_path(mkdir((const char *) dir, mode) == 0)) {
80
0
        return NXT_OK;
81
0
    }
82
83
0
    return NXT_ERROR;
84
0
}