src/utils/system_utils/src/system_utils.c
int ADUC_SystemUtils_MkDir(const char* path, uid_t userId, gid_t groupId, mode_t mode)
{
    struct stat st = {};
    if (stat(path, &st) != 0)
    {
        /* Directory does not exist. EEXIST for race condition */
        if (mkdir(path, mode) != 0 && errno != EEXIST)
        {
            Log_Error("Could not create directory %s errno: %d", path, errno);
            return errno;
        }

        if (groupId != -1 || userId != -1)
        {
            // Now that we have created the directory, take ownership of it.
            // Note: getuid and getgid are always successful.
            // getuid(), getgid()
            if (chown(path, userId, groupId) != 0)
            {
                Log_Error("Could not change owner of directory %s errno: %d", path, errno);
                return errno;
            }
        }
    }
    else if (S_ISDIR(st.st_mode) == 0)
    {
        errno = ENOTDIR;
        Log_Error("Path was not a directory %s errno: %d", path, errno);
        return errno;
    }

    return 0;
}
/**
 * @brief Wrapper for mkdir that handles a number of common conditions, e.g. don't fail if directory already exists.
 *
 * @param path The path to the directory to create.
 * @param userId The uid_t of the user owner the new directory. -1 to indicate the system default behavior.
 * @param groupId The gid_t of the group owner of the new directory. -1 to indicate the system default behavior.
 * @param mode The mode_t of the desired permissions of the new directory.
 *
 * @return errno, zero on success.
 */
@brief Wrapper for mkdir that handles a number of common conditions, e.g. don't fail if directory already exists.
@param path The path to the directory to create.
@param userId The uid_t of the user owner the new directory. -1 to indicate the system default behavior.
@param groupId The gid_t of the group owner of the new directory. -1 to indicate the system default behavior.
@param mode The mode_t of the desired permissions of the new directory.

@return errno, zero on success.
@brief Wrapper for mkdir that handles a number of common conditions e . g . don ' t fail if directory already exists . @param path The path to the directory to create . @param userId The uid_t of the user owner the new directory . - 1 to indicate the system default behavior . @param groupId The gid_t of the group owner of the new directory . - 1 to indicate the system default behavior . @param mode The mode_t of the desired permissions of the new directory . @return errno zero on success .
int ADUC_SystemUtils_MkDir(const char* path, uid_t userId, gid_t groupId, mode_t mode)
{
    struct stat st = {};
    if (stat(path, &st) != 0)
    {
        if (mkdir(path, mode) != 0 && errno != EEXIST)
        {
            Log_Error("Could not create directory %s errno: %d", path, errno);
            return errno;
        }
        if (groupId != -1 || userId != -1)
        {
            if (chown(path, userId, groupId) != 0)
            {
                Log_Error("Could not change owner of directory %s errno: %d", path, errno);
                return errno;
            }
        }
    }
    else if (S_ISDIR(st.st_mode) == 0)
    {
        errno = ENOTDIR;
        Log_Error("Path was not a directory %s errno: %d", path, errno);
        return errno;
    }
    return 0;
}
int ADUC_SystemUtils_MkDir ( const char * path , uid_t userId , gid_t groupId , mode_t mode ) { struct stat st = { } ; if ( stat ( path , & st ) != 0 ) { if ( mkdir ( path , mode ) != 0 && errno != EEXIST ) { Log_Error ( " " , path , errno ) ; return errno ; } if ( groupId != -1 || userId != -1 ) { if ( chown ( path , userId , groupId ) != 0 ) { Log_Error ( " " , path , errno ) ; return errno ; } } } else if ( S_ISDIR ( st . st_mode ) == 0 ) { errno = ENOTDIR ; Log_Error ( " " , path , errno ) ; return errno ; } return 0 ; }
@brief Wrapper for mkdir that handles a number of common conditions, e.g.
@brief Wrapper for mkdir that handles a number of common conditions e . g .
/* Directory does not exist. EEXIST for race condition */ // Now that we have created the directory, take ownership of it. // Note: getuid and getgid are always successful. // getuid(), getgid()