feat[utils]: Add split_path_file_inplace

Change-Id: I665c382152ac73865bd31b04ccf5fc0d5e942543
Signed-off-by: Xiaoxu Chen <xiaoxu.chen@rock-chips.com>
This commit is contained in:
Xiaoxu Chen 2025-12-24 10:27:55 +08:00 committed by Herman Chen
parent 2507e012c4
commit e8e44aa0bf
2 changed files with 30 additions and 0 deletions

View file

@ -1611,3 +1611,31 @@ MPP_RET str_to_frm_fmt(const char *nptr, long *number)
RET:
return ret;
}
MPP_RET split_path_file_inplace(char *fullpath, char **path, char **filename)
{
char *separator = NULL;
char *backslash = NULL;
if (fullpath == NULL)
return MPP_NOK;
// find last path separator
separator = strrchr(fullpath, '/');
backslash = strrchr(fullpath, '\\');
if (backslash && (!separator || backslash > separator)) {
separator = backslash;
}
if (separator) {
*separator = '\0';
*path = fullpath;
*filename = separator + 1;
} else {
*path = ".";
*filename = fullpath;
}
return MPP_OK;
}

View file

@ -94,6 +94,8 @@ MPP_RET fps_calc_inc(FpsCalc ctx);
MPP_RET str_to_frm_fmt(const char *nptr, long *number);
MPP_RET split_path_file_inplace(char *fullpath, char **path, char **filename);
#ifdef __cplusplus
}
#endif