This was reported by the 'Clang Static Analyzer' as a 'dead nested assignment'. We set end outside the loop but the first time we use it is to assign it in the loop (not used anywhere else). Further cleanup could be to reduce the scope of end by moving its declaration inside the loop. Reviewed-by: Alejandro Colomar <alx@nginx.com> Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
85 lines
1.5 KiB
C
85 lines
1.5 KiB
C
/*
|
|
* Copyright (C) NGINX, Inc.
|
|
*/
|
|
|
|
#include <nxt_main.h>
|
|
|
|
|
|
static nxt_int_t nxt_fs_mkdir(const u_char *dir, mode_t mode);
|
|
|
|
|
|
nxt_int_t
|
|
nxt_fs_mkdir_all(const u_char *dir, mode_t mode)
|
|
{
|
|
char *start, *end, *dst;
|
|
size_t dirlen;
|
|
char path[PATH_MAX];
|
|
|
|
dirlen = nxt_strlen(dir);
|
|
|
|
nxt_assert(dirlen < PATH_MAX && dirlen > 1 && dir[0] == '/');
|
|
|
|
dst = path;
|
|
start = (char *) dir;
|
|
|
|
while (*start != '\0') {
|
|
if (*start == '/') {
|
|
*dst++ = *start++;
|
|
}
|
|
|
|
end = strchr(start, '/');
|
|
if (end == NULL) {
|
|
end = ((char *)dir + dirlen);
|
|
}
|
|
|
|
dst = nxt_cpymem(dst, start, end - start);
|
|
*dst = '\0';
|
|
|
|
if (nxt_slow_path(nxt_fs_mkdir((u_char *) path, mode) != NXT_OK
|
|
&& nxt_errno != EEXIST))
|
|
{
|
|
return NXT_ERROR;
|
|
}
|
|
|
|
start = end;
|
|
}
|
|
|
|
return NXT_OK;
|
|
}
|
|
|
|
|
|
nxt_int_t
|
|
nxt_fs_mkdir_parent(const u_char *path, mode_t mode)
|
|
{
|
|
char *ptr, *dir;
|
|
nxt_int_t ret;
|
|
|
|
dir = nxt_strdup(path);
|
|
if (nxt_slow_path(dir == NULL)) {
|
|
return NXT_ERROR;
|
|
}
|
|
|
|
ret = NXT_OK;
|
|
|
|
ptr = strrchr(dir, '/');
|
|
if (nxt_fast_path(ptr != NULL)) {
|
|
*ptr = '\0';
|
|
ret = nxt_fs_mkdir((const u_char *) dir, mode);
|
|
}
|
|
|
|
nxt_free(dir);
|
|
|
|
return ret;
|
|
}
|
|
|
|
|
|
static nxt_int_t
|
|
nxt_fs_mkdir(const u_char *dir, mode_t mode)
|
|
{
|
|
if (nxt_fast_path(mkdir((const char *) dir, mode) == 0)) {
|
|
return NXT_OK;
|
|
}
|
|
|
|
return NXT_ERROR;
|
|
}
|