fs: Invert logic to reduce indentation in nxt_fs_mkdir_dirname()

This refactor isn't very appealing alone, but it prepares the code for
the following commits.

Link: <https://github.com/nginx/unit/issues/742>
Tested-by: Andy Postnikov <apostnikov@gmail.com>
Tested-by: Andrew Clayton <a.clayton@nginx.com>
Reviewed-by: Andrew Clayton <a.clayton@nginx.com>
Cc: Liam Crilly <liam@nginx.com>
Cc: Konstantin Pavlov <thresh@nginx.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
This commit is contained in:
Alejandro Colomar 2024-04-22 21:48:14 +02:00
parent 3873f98f7e
commit 7b7b303a72
No known key found for this signature in database
GPG key ID: 9E8C1AFBBEFFDB32

View file

@ -58,11 +58,14 @@ nxt_fs_mkdir_dirname(const u_char *path, mode_t mode)
ret = NXT_OK;
ptr = strrchr(dir, '/');
if (nxt_fast_path(ptr != NULL)) {
*ptr = '\0';
ret = nxt_fs_mkdir((const u_char *) dir, mode);
if (nxt_slow_path(ptr == NULL)) {
goto out_free;
}
*ptr = '\0';
ret = nxt_fs_mkdir((const u_char *) dir, mode);
out_free:
nxt_free(dir);
return ret;