Blender  V3.3
Macros | Functions | Variables
BLI_path_util.h File Reference
#include "BLI_compiler_attrs.h"
#include "BLI_utildefines.h"

Go to the source code of this file.

Macros

#define BLI_path_cmp   strcmp
 
#define BLI_path_ncmp   strncmp
 
#define FILE_MAXDIR   768
 
#define FILE_MAXFILE   256
 
#define FILE_MAX   1024
 
#define SEP   '/'
 
#define ALTSEP   '\\'
 
#define SEP_STR   "/"
 
#define ALTSEP_STR   "\\"
 
#define FILENAME_PARENT   ".."
 
#define FILENAME_CURRENT   "."
 
#define FILENAME_IS_PARENT(_n)   (((_n)[0] == '.') && ((_n)[1] == '.') && ((_n)[2] == '\0'))
 
#define FILENAME_IS_CURRENT(_n)   (((_n)[0] == '.') && ((_n)[1] == '\0'))
 
#define FILENAME_IS_CURRPAR(_n)    (((_n)[0] == '.') && (((_n)[1] == '\0') || (((_n)[1] == '.') && ((_n)[2] == '\0'))))
 

Functions

void BLI_setenv (const char *env, const char *val) ATTR_NONNULL(1)
 
void BLI_setenv_if_new (const char *env, const char *val) ATTR_NONNULL(1)
 
const char * BLI_getenv (const char *env) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
 
void BLI_make_file_string (const char *relabase, char *string, const char *dir, const char *file)
 
bool BLI_make_existing_file (const char *name)
 
void BLI_split_dirfile (const char *string, char *dir, char *file, size_t dirlen, size_t filelen)
 
void BLI_split_dir_part (const char *string, char *dir, size_t dirlen)
 
void BLI_split_file_part (const char *string, char *file, size_t filelen)
 
const char * BLI_path_extension (const char *filepath) ATTR_NONNULL()
 
void BLI_path_append (char *__restrict dst, size_t maxlen, const char *__restrict file) ATTR_NONNULL()
 
void BLI_join_dirfile (char *__restrict dst, size_t maxlen, const char *__restrict dir, const char *__restrict file) ATTR_NONNULL()
 
size_t BLI_path_join (char *__restrict dst, size_t dst_len, const char *path_first,...) ATTR_NONNULL(1
 
size_t ATTR_SENTINEL (0)
 
const char * BLI_path_basename (const char *path) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT
 
bool BLI_path_name_at_index (const char *__restrict path, int index, int *__restrict r_offset, int *__restrict r_len) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT
 
bool BLI_path_contains (const char *container_path, const char *containee_path) ATTR_WARN_UNUSED_RESULT
 
const char * BLI_path_slash_find (const char *string) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT
 
const char * BLI_path_slash_rfind (const char *string) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT
 
int BLI_path_slash_ensure (char *string) ATTR_NONNULL()
 
void BLI_path_slash_rstrip (char *string) ATTR_NONNULL()
 
void BLI_path_slash_native (char *path) ATTR_NONNULL()
 
bool BLI_path_program_search (char *fullname, size_t maxlen, const char *name)
 
bool BLI_path_extension_check (const char *str, const char *ext) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT
 
bool BLI_path_extension_check_n (const char *str,...) ATTR_NONNULL(1) ATTR_SENTINEL(0)
 
bool BLI_path_extension_check_array (const char *str, const char **ext_array) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT
 
bool BLI_path_extension_check_glob (const char *str, const char *ext_fnmatch) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT
 
bool BLI_path_extension_glob_validate (char *ext_fnmatch) ATTR_NONNULL()
 
bool BLI_path_extension_replace (char *path, size_t maxlen, const char *ext) ATTR_NONNULL()
 
bool BLI_path_extension_ensure (char *path, size_t maxlen, const char *ext) ATTR_NONNULL()
 
bool BLI_path_filename_ensure (char *filepath, size_t maxlen, const char *filename) ATTR_NONNULL()
 
int BLI_path_sequence_decode (const char *string, char *head, char *tail, unsigned short *r_digits_len)
 
void BLI_path_sequence_encode (char *string, const char *head, const char *tail, unsigned short numlen, int pic)
 
void BLI_path_normalize (const char *relabase, char *path) ATTR_NONNULL(2)
 
void BLI_path_normalize_dir (const char *relabase, char *dir) ATTR_NONNULL(2)
 
bool BLI_filename_make_safe_ex (char *fname, bool allow_tokens) ATTR_NONNULL(1)
 
bool BLI_filename_make_safe (char *fname) ATTR_NONNULL(1)
 
bool BLI_path_make_safe (char *path) ATTR_NONNULL(1)
 
bool BLI_path_parent_dir (char *path) ATTR_NONNULL()
 
bool BLI_path_parent_dir_until_exists (char *path) ATTR_NONNULL()
 
bool BLI_path_abs (char *path, const char *basepath) ATTR_NONNULL()
 
bool BLI_path_frame (char *path, int frame, int digits) ATTR_NONNULL()
 
bool BLI_path_frame_range (char *path, int sta, int end, int digits) ATTR_NONNULL()
 
bool BLI_path_frame_get (char *path, int *r_frame, int *r_digits_len) ATTR_NONNULL()
 
void BLI_path_frame_strip (char *path, char *r_ext, size_t ext_maxlen) ATTR_NONNULL()
 
bool BLI_path_frame_check_chars (const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
 
bool BLI_path_is_abs_from_cwd (const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
 
bool BLI_path_abs_from_cwd (char *path, size_t maxlen) ATTR_NONNULL()
 
void BLI_path_rel (char *file, const char *relfile) ATTR_NONNULL()
 
bool BLI_path_is_rel (const char *path) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT
 
bool BLI_path_is_unc (const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
 
void BLI_path_to_display_name (char *display_name, int maxlen, const char *name) ATTR_NONNULL()
 
bool BLI_path_suffix (char *string, size_t maxlen, const char *suffix, const char *sep) ATTR_NONNULL()
 
int BLI_path_cmp_normalized (const char *p1, const char *p2) ATTR_NONNULL(1
 

Variables

int ATTR_WARN_UNUSED_RESULT
 

Macro Definition Documentation

◆ ALTSEP

#define ALTSEP   '\\'

Definition at line 420 of file BLI_path_util.h.

◆ ALTSEP_STR

#define ALTSEP_STR   "\\"

Definition at line 422 of file BLI_path_util.h.

◆ BLI_path_cmp

#define BLI_path_cmp   strcmp

Definition at line 387 of file BLI_path_util.h.

◆ BLI_path_ncmp

#define BLI_path_ncmp   strncmp

Definition at line 388 of file BLI_path_util.h.

◆ FILE_MAX

#define FILE_MAX   1024

Definition at line 410 of file BLI_path_util.h.

◆ FILE_MAXDIR

#define FILE_MAXDIR   768

Definition at line 408 of file BLI_path_util.h.

◆ FILE_MAXFILE

#define FILE_MAXFILE   256

Definition at line 409 of file BLI_path_util.h.

◆ FILENAME_CURRENT

#define FILENAME_CURRENT   "."

Definition at line 427 of file BLI_path_util.h.

◆ FILENAME_IS_CURRENT

#define FILENAME_IS_CURRENT (   _n)    (((_n)[0] == '.') && ((_n)[1] == '\0'))

Definition at line 431 of file BLI_path_util.h.

◆ FILENAME_IS_CURRPAR

#define FILENAME_IS_CURRPAR (   _n)     (((_n)[0] == '.') && (((_n)[1] == '\0') || (((_n)[1] == '.') && ((_n)[2] == '\0'))))

Definition at line 432 of file BLI_path_util.h.

◆ FILENAME_IS_PARENT

#define FILENAME_IS_PARENT (   _n)    (((_n)[0] == '.') && ((_n)[1] == '.') && ((_n)[2] == '\0'))

Definition at line 430 of file BLI_path_util.h.

◆ FILENAME_PARENT

#define FILENAME_PARENT   ".."

Definition at line 426 of file BLI_path_util.h.

◆ SEP

#define SEP   '/'

Definition at line 419 of file BLI_path_util.h.

◆ SEP_STR

#define SEP_STR   "/"

Definition at line 421 of file BLI_path_util.h.

Function Documentation

◆ ATTR_SENTINEL()

size_t ATTR_SENTINEL ( )

◆ BLI_filename_make_safe()

bool BLI_filename_make_safe ( char *  fname)

◆ BLI_filename_make_safe_ex()

bool BLI_filename_make_safe_ex ( char *  fname,
bool  allow_tokens 
)

Make given name safe to be used in paths.

Parameters
allow_tokensPermit the usage of '<' and '>' characters. This can be leveraged by higher layers to support "virtual filenames" which contain substitution markers delineated between the two characters.
Returns
true if fname was changed, false otherwise.

For now, simply replaces reserved chars (as listed in https://en.wikipedia.org/wiki/Filename#Reserved_characters_and_words ) by underscores ('_').

Note
Space case ' ' is a bit of an edge case here - in theory it is allowed, but again can be an issue in some cases, so we simply replace it by an underscore too (good practice anyway). REMOVED based on popular demand (see T45900). Percent '' char is a bit same case - not recommended to use it, but supported by all decent file-systems/operating-systems around.
On Windows, it also ensures there is no '.' (dot char) at the end of the file, this can lead to issues.
On Windows, it also checks for forbidden names (see https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247%28v=vs.85%29.aspx ).

Definition at line 232 of file path_util.c.

References BLI_str_tolower_ascii(), BLI_strdup(), INVALID_CHARS, INVALID_TOKENS, len, MEM_freeN, and NULL.

Referenced by BLI_filename_make_safe(), and file_filename_enter_handle().

◆ BLI_getenv()

const char* BLI_getenv ( const char *  env)

Get an environment variable, result has to be used immediately.

On windows #getenv gets its variables from a static copy of the environment variables taken at process start-up, causing it to not pick up on environment variables created during runtime. This function uses an alternative method to get environment variables that does pick up on runtime environment variables. The result will be UTF-8 encoded.

Definition at line 1168 of file path_util.c.

References alloc_utf16_from_8(), alloc_utf_8_from_16(), ARRAY_SIZE, buffer, free(), NULL, and result.

Referenced by BKE_appdir_folder_default(), BKE_appdir_folder_home(), BLI_current_working_dir(), BLI_path_program_search(), BLI_setenv_if_new(), BLT_lang_init(), colormanagement_init(), fsmenu_read_system(), get_thumb_dir(), test_env_path(), and where_is_temp().

◆ BLI_join_dirfile()

void BLI_join_dirfile ( char *__restrict  dst,
size_t  maxlen,
const char *__restrict  dir,
const char *__restrict  file 
)

Simple appending of filename to dir, does not check for valid path! Puts result into dst, which may be same area as dir.

Note
Consider using BLI_path_join for more general path joining that de-duplicates separators and can handle an arbitrary number of paths.

Definition at line 1531 of file path_util.c.

References ALTSEP, BLI_assert, BLI_strncpy(), BLI_strnlen(), ELEM, file, and SEP.

Referenced by blender::bke::asset_definition_default_file_path_from_dir(), autocomplete_directory(), BKE_appdir_app_template_id_search(), BKE_appdir_program_python_search(), BKE_bpath_foreach_path_dirfile_fixed_process(), BKE_image_get_tile_info(), BKE_memfile_undo_encode(), BKE_modifier_path_init(), BKE_ptcache_disk_cache_rename(), BKE_ptcache_id_clear(), blf_dir_search(), blf_load_font_default(), bli_builddir(), BLI_path_abs_from_cwd(), BLI_path_parent_dir(), bookmark_add_exec(), bookmark_cleanup_exec(), bookmark_delete_exec(), bookmark_move_exec(), check_destination(), colormanagement_init(), blender::compositor::OutputFileNode::convert_to_operations(), draw_seq_text_get_source(), dynamicPaint_bakeImageSequence(), ED_assetlist_asset_filepath_get(), ED_file_read_bookmarks(), ED_fsmenu_entry_set_name(), ED_fsmenu_entry_set_path(), file_delete_single(), file_draw_check_exists(), file_draw_list(), file_execute(), file_filename_enter_handle(), file_sfile_to_operator_ex(), fileentry_uiname(), filelist_cache_previews_push(), filelist_geticon_ex(), filelist_readjob_list_dir(), filelist_readjob_recursive_dir_add_items(), Freestyle_Init(), fsmenu_read_system(), get_proxy_filepath(), get_tc_filename(), blender::compositor::DebugInfo::graphviz(), image_foreach_path(), image_sequence_get_frame_ranges(), init_iconfile_list(), init_internal_icons(), is_filtered_lib_type(), join_dirfile_alloc(), load_data_init_from_operator(), make_temp_filepath(), missing_files_find__recursive(), new_folder_path(), open_exec(), outliner_id_copy_exec(), outliner_id_paste_exec(), pose_copy_exec(), pose_paste_exec(), renamebutton_cb(), reset_recent_exec(), SEQ_add_image_init_alpha_mode(), SEQ_add_reload_new_file(), seq_open_anim_file(), seq_proxy_get_custom_file_fname(), seq_proxy_multiview_context_invalid(), seq_render_image_strip(), seq_sound_proxy_update_cb(), sequencer_add_movie_multiple_strips(), sequencer_add_sound_multiple_strips(), sequencer_change_path_invoke(), set_filepath_for_asset_lib(), sig_handle_crash(), view3d_copybuffer_exec(), view3d_pastebuffer_exec(), wm_autosave_delete(), wm_autosave_location(), wm_block_splash_image(), WM_exit_ex(), WM_file_recover_last_session(), wm_history_file_read(), wm_history_file_write(), wm_lib_relocate_exec_do(), wm_link_append_exec(), wm_platform_support_check_approval(), workspace_config_file_read(), workspace_system_file_read(), and DocumentImporter::writeImage().

◆ BLI_make_existing_file()

bool BLI_make_existing_file ( const char *  name)

◆ BLI_make_file_string()

void BLI_make_file_string ( const char *  relabase,
char *  string,
const char *  dir,
const char *  file 
)

Returns in string the concatenation of dir and file (also with relabase on the front if specified and dir begins with "//"). Normalizes all occurrences of path separators, including ensuring there is exactly one between the copies of dir and file, and between the copies of relabase and dir.

Parameters
relabaseOptional prefix to substitute for "//" on front of dir.
stringArea to return result.

Definition at line 1206 of file path_util.c.

References BLI_path_is_unc(), BLI_path_slash_native(), BLI_path_slash_rfind(), BLI_strncpy(), BLI_strnlen(), BLI_windows_get_default_root_dir(), ELEM, file, and NULL.

Referenced by icon_preview_imbuf_from_brush(), render_result_exr_file_cache_path(), and wm_autosave_location().

◆ BLI_path_abs()

bool BLI_path_abs ( char *  path,
const char *  basepath 
)

If path begins with "//", strips that and replaces it with basepath directory.

Note
Also converts drive-letter prefix to something more sensible if this is a non-drive-letter-based system.
Parameters
pathThe path to convert.
basepathThe directory to base relative paths with.
Returns
true if the path was relative (started with "//").

Definition at line 897 of file path_util.c.

References BLI_path_is_rel(), BLI_path_normalize(), BLI_path_slash_rfind(), BLI_path_unc_prefix_len(), BLI_str_replace_char(), BLI_strncpy(), BLI_windows_get_default_root_dir(), ELEM, FILE_MAX, and NULL.

Referenced by absolute_convert_foreach_path_cb(), BKE_bpath_foreach_path_allocated_process(), BKE_bpath_foreach_path_dirfile_fixed_process(), BKE_bpath_foreach_path_fixed_process(), BKE_cachefile_filepath_get(), BKE_image_load(), BKE_image_load_exists_ex(), BKE_image_save_options_init(), BKE_image_signal(), BKE_image_user_file_path_ex(), BKE_library_filepath_set(), BKE_movieclip_file_add(), BKE_movieclip_file_add_exists_ex(), BKE_movieclip_filename_for_frame(), BKE_packedfile_compare_to_file(), BKE_packedfile_new(), BKE_packedfile_unpack_to_file(), BKE_sound_new_file(), BKE_sound_new_file_exists_ex(), BKE_text_file_modified_check(), BKE_text_file_modified_ignore(), BKE_text_load_ex(), BKE_text_reload(), BKE_vfont_load_exists_ex(), BLI_path_normalize(), bpy_lib_load(), bpy_lib_write(), customdata_external_filename(), detect_clip_source(), do_makepicstring(), dynamicPaint_outputSurfaceImage(), file_browse_exec(), file_expand_directory(), file_operator_to_sfile(), blender::io::gpencil::GpencilIO::filepath_set(), fileselect_ensure_updated_file_params(), fluid_bake_startjob(), fluid_validatepaths(), blender::io::usd::get_absolute_path(), get_drag_path(), get_proxy_fname(), get_sequence_fname(), icon_preview_imbuf_from_brush(), image_save_options_from_op(), image_save_sequence_exec(), image_update_views_format(), blender::io::usd::import_startjob(), lib_id_library_local_paths_callback(), meshcache_do(), movieclip_open_anim_file(), namebutton_fn(), open_invoke(), blender::io::path_reference(), ptcache_path(), relative_rebase_foreach_path_cb(), screenshot_exec(), SEQ_add_image_init_alpha_mode(), SEQ_add_image_strip(), SEQ_add_movie_strip(), SEQ_add_reload_new_file(), SEQ_effect_text_font_load(), seq_open_anim_file(), seq_proxy_get_custom_file_fname(), seq_proxy_get_fname(), seq_proxy_multiview_context_invalid(), seq_render_image_strip(), seq_sound_proxy_update_cb(), sequencer_generic_invoke_path__internal(), sound_mixdown_exec(), and txt_write_file().

◆ BLI_path_abs_from_cwd()

bool BLI_path_abs_from_cwd ( char *  path,
size_t  maxlen 
)

Checks for relative path, expanding them relative to the current working directory.

Returns
true if the expansion was performed.
Note
Should only be called with command line paths. This is not something Blender's internal paths support, instead they use the "//" prefix. In most cases BLI_path_abs should be used instead.

Definition at line 1015 of file path_util.c.

References BLI_current_working_dir(), BLI_join_dirfile(), BLI_path_is_abs_from_cwd(), BLI_strncpy(), and FILE_MAX.

Referenced by arg_handle_load_file(), arg_handle_python_file_run(), and where_am_i().

◆ BLI_path_append()

void BLI_path_append ( char *__restrict  dst,
size_t  maxlen,
const char *__restrict  file 
)

◆ BLI_path_basename()

const char* BLI_path_basename ( const char *  path)

◆ BLI_path_cmp_normalized()

int BLI_path_cmp_normalized ( const char *  p1,
const char *  p2 
)

Returns the result of BLI_path_cmp with both paths normalized and slashes made native.

Note
BLI_path_cmp is used for Blender's internal logic to consider paths to be the same BLI_path_cmp_normalized may be used in when handling other kinds of paths (e.g. importers/exporters) but should be used consistently.

Checking the normalized paths is not a guarantee the paths reference different files. An equivalent to Python's os.path.samefile could be supported for checking if paths point to the same location on the file-system (following symbolic-links).

Referenced by blender::io::usd::copy_single_file(), blender::io::usd::copy_tiled_textures(), blender::io::usd::export_in_memory_texture(), and blender::io::path_reference_copy().

◆ BLI_path_contains()

bool BLI_path_contains ( const char *  container_path,
const char *  containee_path 
)

◆ BLI_path_extension()

const char* BLI_path_extension ( const char *  filepath)

Returns a pointer to the last extension (e.g. the position of the last period). Returns NULL if there is no extension.

Definition at line 1500 of file path_util.c.

References BLI_path_slash_find(), and NULL.

Referenced by ED_text_is_syntax_highlight_supported(), seq_disk_cache_get_files(), and TEST().

◆ BLI_path_extension_check()

bool BLI_path_extension_check ( const char *  str,
const char *  ext 
)

◆ BLI_path_extension_check_array()

bool BLI_path_extension_check_array ( const char *  str,
const char **  ext_array 
)
Returns
true when str ends with any of the suffixes in ext_array.

Definition at line 1326 of file path_util.c.

References path_extension_check_ex(), and str.

Referenced by BKE_image_load(), BLO_has_bfile_extension(), do_add_image_extension(), ED_path_extension_type(), image_replace_exec(), imb_is_filepath_format(), and studiolight_add_file().

◆ BLI_path_extension_check_glob()

bool BLI_path_extension_check_glob ( const char *  str,
const char *  ext_fnmatch 
)

Semicolon separated wildcards, eg: *.zip;*.py;*.exe does str match any of the semicolon-separated glob patterns in #fnmatch.

Definition at line 1341 of file path_util.c.

References BLI_strncpy(), BLI_strncpy_rlen(), and str.

Referenced by BKE_cachefile_eval(), and filelist_readjob_list_dir().

◆ BLI_path_extension_check_n()

bool BLI_path_extension_check_n ( const char *  str,
  ... 
)

◆ BLI_path_extension_ensure()

bool BLI_path_extension_ensure ( char *  path,
size_t  maxlen,
const char *  ext 
)

Strip's trailing '.'s and adds the extension only when needed

Definition at line 1420 of file path_util.c.

References Freestyle::a, and STREQ.

Referenced by BKE_cachefile_filepath_get(), blend_save_check(), do_add_image_extension(), make_temp_filepath(), and sequencer_export_subtitles_exec().

◆ BLI_path_extension_glob_validate()

bool BLI_path_extension_glob_validate ( char *  ext_fnmatch)

Does basic validation of the given glob string, to prevent common issues from string truncation.

For now, only forbids last group to be a wildcard-only one, if there are more than one group (i.e. things like *.txt;*.cpp;* are changed to *.txt;*.cpp;)

Returns
true if it had to modify given ext_fnmatch pattern.

Definition at line 1367 of file path_util.c.

References ELEM.

Referenced by fileselect_ensure_updated_file_params().

◆ BLI_path_extension_replace()

bool BLI_path_extension_replace ( char *  path,
size_t  maxlen,
const char *  ext 
)

◆ BLI_path_filename_ensure()

bool BLI_path_filename_ensure ( char *  filepath,
size_t  maxlen,
const char *  filename 
)

Ensure filepath has a file component, adding filename when it's empty or ends with a slash.

Returns
true if the filename was appended to filepath.

Definition at line 1452 of file path_util.c.

References BLI_path_slash_rfind(), and Freestyle::c.

Referenced by wm_filepath_default().

◆ BLI_path_frame()

bool BLI_path_frame ( char *  path,
int  frame,
int  digits 
)

Replaces "#" character sequence in last slash-separated component of path with frame as decimal integer, with leading zeroes as necessary, to make digits.

Definition at line 709 of file path_util.c.

References BLI_snprintf(), BLI_strncpy(), ensure_digits(), FILE_MAX, and stringframe_chars().

Referenced by blender::io::obj::append_frame_to_filename(), BKE_cachefile_filepath_get(), do_makepicstring(), dynamicPaint_bakeImageSequence(), get_proxy_fname(), sequencer_image_seq_reserve_frames(), and TEST().

◆ BLI_path_frame_check_chars()

bool BLI_path_frame_check_chars ( const char *  path)

Check if we have '#' chars, usable for BLI_path_frame, BLI_path_frame_range

Definition at line 853 of file path_util.c.

References stringframe_chars().

◆ BLI_path_frame_get()

bool BLI_path_frame_get ( char *  path,
int *  r_frame,
int *  r_digits_len 
)

Get the frame from a filename formatted by blender's frame scheme

Definition at line 753 of file path_util.c.

References BLI_path_slash_rfind(), Freestyle::c, file, len, and NULL.

Referenced by BKE_cachefile_filepath_get(), sequencer_image_seq_get_minmax_frame(), and volume_sequence_frame().

◆ BLI_path_frame_range()

bool BLI_path_frame_range ( char *  path,
int  sta,
int  end,
int  digits 
)

Replaces "#" character sequence in last slash-separated component of path with sta and end as decimal integers, with leading zeroes as necessary, to make digits digits each, with a hyphen in-between.

Definition at line 727 of file path_util.c.

References BLI_snprintf(), BLI_strncpy(), ensure_digits(), FILE_MAX, and stringframe_chars().

◆ BLI_path_frame_strip()

void BLI_path_frame_strip ( char *  path,
char *  r_ext,
size_t  ext_maxlen 
)

Given a path with digits representing frame numbers, replace the digits with the '#' character and extract the extension. So: /some/path_123.jpeg Becomes: /some/path_### with r_ext set to .jpeg.

Definition at line 805 of file path_util.c.

References BLI_path_slash_rfind(), BLI_strncpy(), Freestyle::c, file, len, and NULL.

Referenced by BKE_cachefile_filepath_get(), and sequencer_image_seq_reserve_frames().

◆ BLI_path_is_abs_from_cwd()

bool BLI_path_is_abs_from_cwd ( const char *  path)

Checks for a relative path (ignoring Blender's "//") prefix (unlike !BLI_path_is_rel(path)). When false, BLI_path_abs_from_cwd would expand the absolute path.

Definition at line 998 of file path_util.c.

References BLI_path_is_unc(), and BLI_strnlen().

Referenced by BLI_path_abs_from_cwd(), BLO_write_file(), and wm_save_as_mainfile_exec().

◆ BLI_path_is_rel()

bool BLI_path_is_rel ( const char *  path)

◆ BLI_path_is_unc()

bool BLI_path_is_unc ( const char *  path)

Return true if the path is a UNC share.

Definition at line 352 of file path_util.c.

Referenced by BLI_make_file_string(), BLI_path_is_abs_from_cwd(), BLI_path_rel(), BLI_path_unc_prefix_len(), and file_expand_directory().

◆ BLI_path_join()

size_t BLI_path_join ( char *__restrict  dst,
size_t  dst_len,
const char *  path_first,
  ... 
)

◆ BLI_path_make_safe()

bool BLI_path_make_safe ( char *  path)

◆ BLI_path_name_at_index()

bool BLI_path_name_at_index ( const char *__restrict  path,
int  index,
int *__restrict  r_offset,
int *__restrict  r_len 
)

Get an element of the path at an index, eg: "/some/path/file.txt" where an index of:

  • 0 or -3: "some"
  • 1 or -2: "path"
  • 2 or -1: "file.txt"

Ignores multiple slashes at any point in the path (including start/end).

Definition at line 1659 of file path_util.c.

References ALTSEP, Freestyle::c, ELEM, blender::meshintersect::prev(), and SEP.

Referenced by fsmenu_entry_generate_name().

◆ BLI_path_normalize()

void BLI_path_normalize ( const char *  relabase,
char *  path 
)

Remove redundant characters from path and optionally make absolute.

Parameters
relabaseThe path this is relative to, or ignored when NULL.
pathCan be any input, and this function converts it to a regular full path. Also removes garbage from directory paths, like /../ or double slashes etc.
Note
path isn't protected for max string names.

Definition at line 131 of file path_util.c.

References Freestyle::a, BLI_path_abs(), and BLI_path_unc_prefix_len().

Referenced by arg_handle_load_file(), BLI_path_abs(), BLI_path_cmp_normalized(), BLI_path_contains(), BLI_path_normalize_dir(), BLI_path_parent_dir(), BLI_path_rel(), blo_find_main(), BLO_write_file(), direct_link_library(), blender::io::obj::export_frame(), file_execute(), blender::io::usd::get_absolute_path(), get_path_local_ex(), Freestyle::StringUtils::getPathName(), lib_id_library_local_paths_callback(), Freestyle::Controller::LoadMesh(), blender::io::path_reference(), relative_rebase_foreach_path_cb(), TEST(), where_am_i(), and blender::io::obj::MTLWriter::write_materials().

◆ BLI_path_normalize_dir()

void BLI_path_normalize_dir ( const char *  relabase,
char *  dir 
)

◆ BLI_path_parent_dir()

bool BLI_path_parent_dir ( char *  path)

Go back one directory.

Replaces path with the path of its parent directory, returning true if it was able to find a parent directory within the path.

Definition at line 623 of file path_util.c.

References BLI_join_dirfile(), BLI_path_extension_check(), BLI_path_normalize(), FILE_MAX, NULL, and SEP.

Referenced by BKE_preferences_asset_library_path_set(), bli_builddir(), BLI_path_parent_dir_until_exists(), file_execute(), file_parent_exec(), file_select_do(), open_invoke(), and wm_link_append_invoke().

◆ BLI_path_parent_dir_until_exists()

bool BLI_path_parent_dir_until_exists ( char *  path)

Go back until the directory is found.

Strips off nonexistent (or non-accessible) sub-directories from the end of dir, leaving the path of the lowest-level directory that does exist and we can read.

Definition at line 639 of file path_util.c.

References BLI_access(), and BLI_path_parent_dir().

Referenced by parent_dir_until_exists_or_default_root().

◆ BLI_path_program_search()

bool BLI_path_program_search ( char *  fullname,
size_t  maxlen,
const char *  name 
)

Search for a binary (executable)

Definition at line 1091 of file path_util.c.

References BLI_exists(), BLI_getenv(), BLI_path_append(), BLI_strncpy(), and FILE_MAX.

Referenced by BKE_appdir_program_python_search(), and where_am_i().

◆ BLI_path_rel()

void BLI_path_rel ( char *  file,
const char *  relfile 
)

◆ BLI_path_sequence_decode()

int BLI_path_sequence_decode ( const char *  string,
char *  head,
char *  tail,
unsigned short *  r_digits_len 
)

Looks for a sequence of decimal digits in string, preceding any filename extension, returning the integer value if found, or 0 if not.

Parameters
stringString to scan.
headOptional area to return copy of part of string prior to digits, or before dot if no digits.
tailOptional area to return copy of part of string following digits, or from dot if no digits.
r_digits_lenOptional to return number of digits found.

Definition at line 56 of file path_util.c.

References BLI_path_slash_rfind(), BLI_strncpy(), NULL, and ret.

Referenced by BKE_image_sequence_guess_offset(), BKE_image_user_file_path_ex(), build_pict_list_ex(), filenum_newname(), blender::io::obj::get_image_filepath(), get_sequence_fname(), image_sequence_get_frame_ranges(), movieclip_calc_length(), put_imbuf_cache(), and user_frame_to_cache_frame().

◆ BLI_path_sequence_encode()

void BLI_path_sequence_encode ( char *  string,
const char *  head,
const char *  tail,
unsigned short  numlen,
int  pic 
)

Returns in area pointed to by string a string of the form <head><pic><tail>, where pic is formatted as numlen digits with leading zeroes.

Definition at line 123 of file path_util.c.

References MAX2.

Referenced by an_stringenc(), BKE_image_user_file_path_ex(), build_pict_list_ex(), filenum_newname(), blender::io::obj::get_image_filepath(), and get_sequence_fname().

◆ BLI_path_slash_ensure()

int BLI_path_slash_ensure ( char *  string)

◆ BLI_path_slash_find()

const char* BLI_path_slash_find ( const char *  string)
Returns
pointer to the leftmost path separator in string (or NULL when not found).

Definition at line 1750 of file path_util.c.

Referenced by BKE_image_ensure_tile_token(), BLI_path_extension(), BLI_path_make_safe(), and blender::bke::AssetCatalogPath::iterate_components().

◆ BLI_path_slash_native()

void BLI_path_slash_native ( char *  path)

◆ BLI_path_slash_rfind()

const char* BLI_path_slash_rfind ( const char *  string)

◆ BLI_path_slash_rstrip()

void BLI_path_slash_rstrip ( char *  string)

Removes the last slash and everything after it to the end of string, if there is one.

Definition at line 1791 of file path_util.c.

References len, and SEP.

Referenced by BLI_dir_create_recursive(), file_path_to_ui_path(), preferences_asset_library_add_exec(), and strip_last_slash().

◆ BLI_path_suffix()

bool BLI_path_suffix ( char *  string,
size_t  maxlen,
const char *  suffix,
const char *  sep 
)

Appends a suffix to the string, fitting it before the extension

string = Foo.png, suffix = 123, separator = _ Foo.png -> Foo_123.png

Parameters
stringoriginal (and final) string
maxlenMaximum length of string
suffixString to append to the original string
sepOptional separator character
Returns
true if succeeded

Definition at line 588 of file path_util.c.

References Freestyle::a, BLI_strncpy(), ELEM, and FILE_MAX.

Referenced by bake_targets_output_external(), BKE_image_memorypack(), BKE_scene_multiview_filepath_get(), BKE_scene_multiview_view_filepath_get(), and do_makepicstring().

◆ BLI_path_to_display_name()

void BLI_path_to_display_name ( char *  display_name,
int  maxlen,
const char *  name 
)

Creates a display string from path to be used menus and the user interface. Like bpy.path.display_name().

Definition at line 859 of file path_util.c.

References BLI_path_extension_replace(), BLI_str_replace_char(), BLI_strncpy(), and ELEM.

Referenced by blender::io::usd::import_startjob(), and workspace_add_invoke().

◆ BLI_setenv()

void BLI_setenv ( const char *  env,
const char *  val 
)

Sets the specified environment variable to the specified value, and clears it if val == NULL.

Definition at line 1143 of file path_util.c.

References uputenv().

Referenced by arg_handle_env_system_set(), and BLI_setenv_if_new().

◆ BLI_setenv_if_new()

void BLI_setenv_if_new ( const char *  env,
const char *  val 
)

Only set an environment variable if already not there. Like Unix setenv(env, val, 0);

(not used anywhere).

Definition at line 1161 of file path_util.c.

References BLI_getenv(), BLI_setenv(), and NULL.

◆ BLI_split_dir_part()

void BLI_split_dir_part ( const char *  string,
char *  dir,
size_t  dirlen 
)

◆ BLI_split_dirfile()

void BLI_split_dirfile ( const char *  string,
char *  dir,
char *  file,
size_t  dirlen,
size_t  filelen 
)

◆ BLI_split_file_part()

void BLI_split_file_part ( const char *  string,
char *  file,
size_t  filelen 
)

Variable Documentation

◆ ATTR_WARN_UNUSED_RESULT

int ATTR_WARN_UNUSED_RESULT

Definition at line 403 of file BLI_path_util.h.