Blender V4.3
path_utils.cc File Reference
#include <algorithm>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include "BLI_fileops.h"
#include "BLI_fnmatch.h"
#include "BLI_path_utils.hh"
#include "BLI_string.h"
#include "BLI_string_utils.hh"
#include "BLI_utildefines.h"
#include <unistd.h>
#include "MEM_guardedalloc.h"

Go to the source code of this file.

Macros

#define FILENAME_FRAME_CHARS_MAX   FILE_MAX
 
#define IS_PARENT_DIR(p)   ((p)[0] == '.' && (p)[1] == '.' && ELEM((p)[2], SEP, '\0'))
 
#define INVALID_CHARS
 
#define INVALID_TOKENS   "<>"
 

Functions

static int BLI_path_unc_prefix_len (const char *path)
 
int BLI_path_sequence_decode (const char *path, char *head, const size_t head_maxncpy, char *tail, const size_t tail_maxncpy, ushort *r_digits_len)
 
void BLI_path_sequence_encode (char *path, const size_t path_maxncpy, const char *head, const char *tail, ushort numlen, int pic)
 
static int path_normalize_impl (char *path, bool check_blend_relative_prefix)
 
int BLI_path_normalize (char *path)
 
int BLI_path_normalize_native (char *path)
 
int BLI_path_normalize_dir (char *dir, size_t dir_maxncpy)
 
int BLI_path_canonicalize_native (char *path, int path_maxncpy)
 
bool BLI_path_make_safe_filename_ex (char *filename, bool allow_tokens)
 
bool BLI_path_make_safe_filename (char *filename)
 
bool BLI_path_make_safe (char *path)
 
bool BLI_path_is_rel (const char *path)
 
bool BLI_path_is_unc (const char *path)
 
bool BLI_path_is_win32_drive (const char *path)
 
bool BLI_path_is_win32_drive_only (const char *path)
 
bool BLI_path_is_win32_drive_with_slash (const char *path)
 
void BLI_path_rel (char path[FILE_MAX], const char *basepath)
 
bool BLI_path_suffix (char *path, size_t path_maxncpy, const char *suffix, const char *sep)
 
const char * BLI_path_parent_dir_end (const char *path, size_t path_len)
 
bool BLI_path_parent_dir (char *path)
 
bool BLI_path_parent_dir_until_exists (char *path)
 
static bool path_frame_chars_find_range (const char *path, int *r_char_start, int *r_char_end)
 
static void ensure_digits (char *path, int digits)
 
bool BLI_path_frame (char *path, size_t path_maxncpy, int frame, int digits)
 
bool BLI_path_frame_range (char *path, size_t path_maxncpy, int sta, int end, int digits)
 
bool BLI_path_frame_get (const char *path, int *r_frame, int *r_digits_len)
 
void BLI_path_frame_strip (char *path, char *r_ext, const size_t ext_maxncpy)
 
bool BLI_path_frame_check_chars (const char *path)
 
void BLI_path_to_display_name (char *display_name, int display_name_maxncpy, const char *name)
 
bool BLI_path_abs (char path[FILE_MAX], const char *basepath)
 
bool BLI_path_is_abs_from_cwd (const char *path)
 
bool BLI_path_abs_from_cwd (char *path, const size_t path_maxncpy)
 
bool BLI_path_program_search (char *program_filepath, const size_t program_filepath_maxncpy, const char *program_name)
 
void BLI_setenv (const char *env, const char *val)
 
void BLI_setenv_if_new (const char *env, const char *val)
 
const char * BLI_getenv (const char *env)
 
static bool path_extension_check_ex (const char *path, const size_t path_len, const char *ext, const size_t ext_len)
 
bool BLI_path_extension_check (const char *path, const char *ext)
 
bool BLI_path_extension_check_n (const char *path,...)
 
bool BLI_path_extension_check_array (const char *path, const char **ext_array)
 
bool BLI_path_extension_check_glob (const char *path, const char *ext_fnmatch)
 
bool BLI_path_extension_glob_validate (char *ext_fnmatch)
 
bool BLI_path_extension_replace (char *path, size_t path_maxncpy, const char *ext)
 
bool BLI_path_extension_strip (char *path)
 
bool BLI_path_extension_ensure (char *path, size_t path_maxncpy, const char *ext)
 
bool BLI_path_filename_ensure (char *filepath, size_t filepath_maxncpy, const char *filename)
 
void BLI_path_split_dir_file (const char *filepath, char *dir, const size_t dir_maxncpy, char *file, const size_t file_maxncpy)
 
void BLI_path_split_dir_part (const char *filepath, char *dir, const size_t dir_maxncpy)
 
void BLI_path_split_file_part (const char *filepath, char *file, const size_t file_maxncpy)
 
const char * BLI_path_extension_or_end (const char *filepath)
 
const char * BLI_path_extension (const char *filepath)
 
size_t BLI_path_append (char *__restrict dst, const size_t dst_maxncpy, const char *__restrict file)
 
size_t BLI_path_append_dir (char *__restrict dst, const size_t dst_maxncpy, const char *__restrict dir)
 
size_t BLI_path_join_array (char *__restrict dst, const size_t dst_maxncpy, const char *path_array[], const int path_array_num)
 
const char * BLI_path_basename (const char *path)
 
static bool path_name_at_index_forward (const char *__restrict path, const int index, int *__restrict r_offset, int *__restrict r_len)
 
static bool path_name_at_index_backward (const char *__restrict path, const int index, int *__restrict r_offset, int *__restrict r_len)
 
bool BLI_path_name_at_index (const char *__restrict path, const int index, int *__restrict r_offset, int *__restrict r_len)
 
bool BLI_path_contains (const char *container_path, const char *containee_path)
 
const char * BLI_path_slash_find (const char *path)
 
const char * BLI_path_slash_rfind (const char *path)
 
int BLI_path_slash_ensure_ex (char *path, size_t path_maxncpy, size_t path_len)
 
int BLI_path_slash_ensure (char *path, size_t path_maxncpy)
 
void BLI_path_slash_rstrip (char *path)
 
const char * BLI_path_slash_skip (const char *path)
 
void BLI_path_slash_native (char *path)
 
int BLI_path_cmp_normalized (const char *p1, const char *p2)
 
bool BLI_path_has_hidden_component (const char *path)
 

Detailed Description

Various string, file, list operations.

Definition in file path_utils.cc.

Macro Definition Documentation

◆ FILENAME_FRAME_CHARS_MAX

#define FILENAME_FRAME_CHARS_MAX   FILE_MAX

The maximum number of # characters expanded for BLI_path_frame & BLI_path_frame_range Typically 12 is enough and even 16 is very large. Use a much larger value so hitting the upper limit is not an issue. Exceeding this limit won't fail either, it will just not insert so many leading zeros.

Definition at line 55 of file path_utils.cc.

Referenced by BLI_path_frame(), and BLI_path_frame_range().

◆ INVALID_CHARS

#define INVALID_CHARS
Value:
"\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f" \
"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f" \
"/\\?*:|\""

Referenced by BLI_path_make_safe_filename_ex().

◆ INVALID_TOKENS

#define INVALID_TOKENS   "<>"

◆ IS_PARENT_DIR

#define IS_PARENT_DIR ( p)    ((p)[0] == '.' && (p)[1] == '.' && ELEM((p)[2], SEP, '\0'))

Referenced by path_normalize_impl().

Function Documentation

◆ 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 1368 of file path_utils.cc.

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

Referenced by BKE_appdir_folder_home(), BLI_current_working_dir(), BLI_path_program_search(), BLI_setenv_if_new(), BLI_temp_directory_path_get(), BLT_lang_init(), BPY_python_start(), colormanagement_init(), fsmenu_read_system(), get_thumb_dir(), GHOST_WindowWin32::GHOST_WindowWin32(), imb_init_dds(), test_env_path(), and wm_block_splash_create().

◆ BLI_path_abs()

◆ BLI_path_abs_from_cwd()

bool BLI_path_abs_from_cwd ( char * path,
size_t path_maxncpy )

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 1217 of file path_utils.cc.

References BLI_current_working_dir(), BLI_path_is_abs_from_cwd(), BLI_path_join, BLI_string_debug_size_after_nil, PATH_MAX, printf, and STRNCPY.

Referenced by BLI_path_canonicalize_native(), BLI_temp_directory_path_copy_if_valid(), and where_am_i().

◆ BLI_path_append()

size_t BLI_path_append ( char *__restrict dst,
const size_t dst_maxncpy,
const char *__restrict file )

Definition at line 1655 of file path_utils.cc.

References BLI_path_slash_ensure(), and BLI_strncpy_rlen().

Referenced by BLI_path_append_dir(), and BLI_path_program_search().

◆ BLI_path_append_dir()

size_t BLI_path_append_dir ( char *__restrict dst,
const size_t dst_maxncpy,
const char *__restrict dir )

Definition at line 1665 of file path_utils.cc.

References BLI_path_append(), and BLI_path_slash_ensure_ex().

◆ BLI_path_basename()

const char * BLI_path_basename ( const char * path)

Like Python's os.path.basename()

Returns
The pointer into path string immediately after last slash, or start of path if none found.

Definition at line 1778 of file path_utils.cc.

References BLI_path_slash_rfind().

Referenced by blender::ed::asset::asset_bundle_install_exec(), blender::bke::asset_weak_reference_for_essentials(), BKE_image_add_from_imbuf(), BKE_image_ensure_tile_token(), BKE_image_is_filename_tokenized(), BKE_image_load_in_lib(), BKE_movieclip_file_add(), BKE_preferences_extension_remote_to_name(), BKE_sound_new_file(), BKE_text_load_ex(), BKE_volume_load(), blf_font_new_impl(), BLI_path_filename_ensure(), BLI_path_frame_get(), BLI_path_frame_strip(), BLI_path_split_dir_file(), BLI_path_split_dir_part(), BLI_path_split_file_part(), blo_find_main(), blender::io::hydra::cache_or_get_image_file(), cachefile_open_exec(), blender::ed::object::collection_exporter_export(), blender::io::obj::OBJExportRegressionTest::compare_obj_export_to_golden(), blender::io::stl::STLExportTest::compare_to_golden(), blender::io::obj::create_placeholder_image(), blender::io::usd::create_temp_path_for_usdz_export(), ensure_digits(), blender::io::stl::export_frame(), fileentry_uiname(), blender::io::obj::get_image_filepath(), import_file(), blender::io::ply::import_mesh(), blender::io::usd::import_startjob(), blender::io::ply::importer_main(), blender::io::stl::importer_main(), load_data_init_from_operator(), blender::io::obj::load_texture_image(), missing_files_find_foreach_path_cb(), blender::io::obj::OBJParser::parse(), path_destination_ensure_filename(), blender::io::path_reference(), preferences_extension_repo_add_exec(), report_duration(), report_duration(), seq_disk_cache_get_project_dir(), blender::ed::asset::set_filepath_for_asset_lib(), sig_handle_crash(), text_jump_to_file_at_point_external(), uiTemplateImageInfo(), uiTemplateMovieclipInformation(), uiTemplateRecentFiles(), wm_autosave_location(), wm_file_write(), WM_window_title(), and blender::io::obj::MTLWriter::write_header().

◆ BLI_path_canonicalize_native()

int BLI_path_canonicalize_native ( char * path,
int path_maxncpy )

Convert path to a canonical representation. This is intended for system paths (passed in as command-line arguments of via scripts) which are valid in that they resolve to a file/directory and but could be CWD relative or contain redundant slashes that cause absolute/relative conversion to fail. (specifically the "//" prefix used by Blender).

Perform the following operations:

  • Make absolute (relative to the current working directory).
  • Convert slash direction (WIN32 only, as other systems may use back-slashes in filenames).
  • Normalize redundant slashes.
  • Strip trailing slashes.

Definition at line 388 of file path_utils.cc.

References ALTSEP, BLI_path_abs_from_cwd(), BLI_path_normalize_native(), BLI_path_slash_is_native_compat(), BLI_path_slash_native(), and SEP.

Referenced by arg_handle_python_file_run(), BKE_appdir_program_path_init(), handle_load_file(), wm_open_mainfile__open(), wm_recover_auto_save_exec(), and wm_save_as_mainfile_exec().

◆ BLI_path_cmp_normalized()

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

◆ 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)

◆ BLI_path_extension_check()

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

Definition at line 1409 of file path_utils.cc.

References path_extension_check_ex().

◆ BLI_path_extension_check_array()

bool BLI_path_extension_check_array ( const char * path,
const char ** ext_array )

Definition at line 1436 of file path_utils.cc.

References path_extension_check_ex().

◆ BLI_path_extension_check_glob()

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

Definition at line 1451 of file path_utils.cc.

References BLI_strncpy(), and STRNCPY_RLEN.

◆ BLI_path_extension_check_n()

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

◆ BLI_path_extension_ensure()

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

◆ 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 1477 of file path_utils.cc.

References ELEM.

Referenced by fileselect_ensure_updated_file_params().

◆ BLI_path_extension_or_end()

const char * BLI_path_extension_or_end ( const char * filepath)

Returns a pointer to the last extension (e.g. the position of the last period). Returns a pointer to the nil byte when no extension is found.

Definition at line 1612 of file path_utils.cc.

References ALTSEP, BLI_assert, and SEP.

Referenced by BLI_path_extension(), BLI_path_extension_ensure(), BLI_path_extension_replace(), BLI_path_frame_get(), BLI_path_frame_strip(), BLI_path_sequence_decode(), BLI_path_suffix(), blender::io::hydra::cache_image_file(), and WM_window_title().

◆ BLI_path_extension_replace()

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

Definition at line 1503 of file path_utils.cc.

References BLI_path_extension_or_end(), and BLI_string_debug_size_after_nil.

◆ BLI_path_extension_strip()

◆ BLI_path_filename_ensure()

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

Definition at line 1560 of file path_utils.cc.

References BLI_path_basename(), and BLI_string_debug_size_after_nil.

◆ BLI_path_frame()

bool BLI_path_frame ( char * path,
size_t path_maxncpy,
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 955 of file path_utils.cc.

References BLI_string_debug_size_after_nil, BLI_string_replace_range(), ensure_digits(), FILENAME_FRAME_CHARS_MAX, path_frame_chars_find_range(), and SNPRINTF.

Referenced by blender::io::obj::append_frame_to_filename(), BKE_cachefile_filepath_get(), do_makepicstring(), dynamicPaint_bakeImageSequence(), get_proxy_filepath(), 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 1052 of file path_utils.cc.

References path_frame_chars_find_range().

◆ BLI_path_frame_get()

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

Definition at line 995 of file path_utils.cc.

References BLI_path_basename(), and BLI_path_extension_or_end().

◆ BLI_path_frame_range()

bool BLI_path_frame_range ( char * path,
size_t path_maxncpy,
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 975 of file path_utils.cc.

References BLI_string_debug_size_after_nil, BLI_string_replace_range(), ensure_digits(), FILENAME_FRAME_CHARS_MAX, path_frame_chars_find_range(), and SNPRINTF.

◆ BLI_path_frame_strip()

void BLI_path_frame_strip ( char * path,
char * r_ext,
const size_t ext_maxncpy )

◆ BLI_path_has_hidden_component()

bool BLI_path_has_hidden_component ( const char * path)

Return true if any path component starts with a dot.

Definition at line 2019 of file path_utils.cc.

References ELEM.

Referenced by filelist_readjob_list_dir(), and TEST().

◆ 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 1201 of file path_utils.cc.

Referenced by BLI_path_abs_from_cwd(), BLO_read_from_file(), BLO_write_file_impl(), blender::tests::TEST(), and TEST().

◆ 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 531 of file path_utils.cc.

Referenced by BLI_path_rel(), BLI_path_unc_prefix_len(), file_expand_directory(), TEST(), and uri_from_filename().

◆ BLI_path_is_win32_drive()

bool BLI_path_is_win32_drive ( const char * path)

Definition at line 566 of file path_utils.cc.

Referenced by path_normalize_impl(), TEST(), and uri_from_filename().

◆ BLI_path_is_win32_drive_only()

bool BLI_path_is_win32_drive_only ( const char * path)

Definition at line 571 of file path_utils.cc.

Referenced by dir_create_recursive(), file_expand_directory(), and TEST().

◆ BLI_path_is_win32_drive_with_slash()

bool BLI_path_is_win32_drive_with_slash ( const char * path)

Definition at line 576 of file path_utils.cc.

References ELEM.

Referenced by BLI_path_abs(), and TEST().

◆ BLI_path_join_array()

size_t BLI_path_join_array ( char *__restrict dst,
const size_t dst_maxncpy,
const char * path_array[],
const int path_array_num )

◆ BLI_path_make_safe()

bool BLI_path_make_safe ( char * path)

◆ BLI_path_make_safe_filename()

◆ BLI_path_make_safe_filename_ex()

bool BLI_path_make_safe_filename_ex ( char * filename,
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 filename 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 #45900). 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 411 of file path_utils.cc.

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

Referenced by BLI_path_make_safe_filename(), and file_filename_enter_handle().

◆ BLI_path_name_at_index()

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

Definition at line 1853 of file path_utils.cc.

References path_name_at_index_backward(), and path_name_at_index_forward().

Referenced by BLI_path_parent_dir().

◆ BLI_path_normalize()

int BLI_path_normalize ( char * path)

Remove redundant characters from path.

The following operations are performed:

  • Redundant path components such as //, /./ & ./ (prefix) are stripped. (with the exception of // prefix used for blend-file relative paths).
  • .. are resolved so <parent>/../<child>/ resolves to <child>/. Note that the resulting path may begin with .. if it's relative.

Details:

  • The slash direction is expected to be native (see SEP). When calculating a canonical paths you may need to run BLI_path_slash_native first. BLI_path_cmp_normalized can be used for canonical path comparison.
  • Trailing slashes are left intact (unlike Python which strips them).
  • Handling paths beginning with .. depends on them being absolute or relative. For absolute paths they are removed (e.g. /../path becomes /path). For relative paths they are kept as it's valid to reference paths above a relative location such as //../parent or ../parent.
Parameters
pathThe path to a file or directory which can be absolute or relative.
Returns
the length of path.

Definition at line 367 of file path_utils.cc.

References path_normalize_impl().

Referenced by blender::bke::asset_root_path_for_save(), BKE_preferences_extension_repo_add(), BLI_path_abs(), BLI_path_cmp_normalized(), BLI_path_contains(), BLI_path_normalize_dir(), BLI_path_rel(), blo_find_main(), BLO_write_file_impl(), blender::io::usd::copy_asset_to_directory(), direct_link_library(), blender::io::obj::export_frame(), blender::io::usd::get_absolute_path(), Freestyle::StringUtils::getPathName(), blender::io::usd::import_asset(), lib_id_library_local_paths_callback(), Freestyle::Controller::LoadMesh(), blender::asset_system::utils::normalize_path(), blender::ed::object::bake_simulation::PathStringHash::operator()(), blender::io::path_reference(), relative_rebase_foreach_path_cb(), and blender::io::obj::MTLWriter::write_materials().

◆ BLI_path_normalize_dir()

int BLI_path_normalize_dir ( char * dir,
size_t dir_maxncpy )

◆ BLI_path_normalize_native()

int BLI_path_normalize_native ( char * path)

A version of BLI_path_normalize without special handling of // blend file relative prefix.

Note
On UNIX //path is a valid path which gets normalized to /path.
Returns
the length of path.

Definition at line 372 of file path_utils.cc.

References path_normalize_impl().

Referenced by BKE_main_merge(), BLI_path_canonicalize_native(), file_execute(), get_path_local_ex(), and where_am_i().

◆ 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.

On success, the resulting path will always have a trailing slash.

Definition at line 859 of file path_utils.cc.

References BLI_assert, and BLI_path_name_at_index().

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

◆ BLI_path_parent_dir_end()

const char * BLI_path_parent_dir_end ( const char * path,
size_t path_len )

In the simple case this is similar to BLI_path_slash_rfind(dirname) however it behaves differently when there are redundant characters:

/test///dir/./file ^ /test/dir/subdir//file ^

Returns
The position after the parent paths last character or NULL on failure. Neither path or &path[path_len - 1] are ever returned.

Definition at line 832 of file path_utils.cc.

References BLI_path_slash_is_native_compat().

Referenced by dir_create_recursive().

◆ 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 885 of file path_utils.cc.

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 * program_filepath,
const size_t program_filepath_maxncpy,
const char * program_name )

◆ BLI_path_rel()

void BLI_path_rel ( char path[FILE_MAX],
const char * basepath )

◆ BLI_path_sequence_decode()

int BLI_path_sequence_decode ( const char * path,
char * head,
size_t head_maxncpy,
char * tail,
size_t tail_maxncpy,
unsigned short * r_digits_len )

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

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

Definition at line 57 of file path_utils.cc.

References BLI_path_extension_or_end(), BLI_path_slash_rfind(), BLI_string_debug_size, BLI_strncpy(), int, and ret.

Referenced by BKE_image_sequence_guess_offset(), BKE_image_user_file_path_ex(), build_pict_list_from_image_sequence(), filenum_newname(), blender::io::obj::get_image_filepath(), get_sequence_filepath(), image_sequence_get_frame_ranges(), movieclip_calc_length(), put_imbuf_cache(), user_frame_to_cache_frame(), and wm_save_as_mainfile_exec().

◆ BLI_path_sequence_encode()

void BLI_path_sequence_encode ( char * path,
size_t path_maxncpy,
const char * head,
const char * tail,
unsigned short numlen,
int pic )

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

Definition at line 127 of file path_utils.cc.

References BLI_snprintf(), and BLI_string_debug_size.

Referenced by BKE_image_user_file_path_ex(), build_pict_list_from_image_sequence(), filenum_newname(), blender::io::obj::get_image_filepath(), get_sequence_filepath(), and wm_save_as_mainfile_exec().

◆ BLI_path_slash_ensure()

◆ BLI_path_slash_ensure_ex()

int BLI_path_slash_ensure_ex ( char * path,
size_t path_maxncpy,
const size_t path_len )

Appends a slash to path if there isn't one there already.

Parameters
path_lenThe length of path.
Returns
the new length of the path.

Definition at line 1925 of file path_utils.cc.

References BLI_assert, BLI_path_slash_is_native_compat(), BLI_string_debug_size_after_nil, and SEP.

Referenced by BLI_path_append_dir(), BLI_path_normalize_dir(), and BLI_path_slash_ensure().

◆ BLI_path_slash_find()

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

Definition at line 1895 of file path_utils.cc.

Referenced by BKE_image_ensure_tile_token_filename_only(), BLI_path_make_safe(), blender::asset_system::AssetCatalogPath::iterate_components(), and TEST().

◆ BLI_path_slash_native()

◆ BLI_path_slash_rfind()

const char * BLI_path_slash_rfind ( const char * path)

◆ BLI_path_slash_rstrip()

void BLI_path_slash_rstrip ( char * path)

◆ BLI_path_slash_skip()

const char * BLI_path_slash_skip ( const char * path)
Returns
the next non-slash character or the null byte (when path only contains slashes).

Definition at line 1959 of file path_utils.cc.

References BLI_path_slash_is_native_compat().

Referenced by BLI_path_abs(), and uri_from_filename().

◆ BLI_path_split_dir_file()

void BLI_path_split_dir_file ( const char * filepath,
char * dir,
const size_t dir_maxncpy,
char * file,
const size_t file_maxncpy )

Definition at line 1572 of file path_utils.cc.

References BLI_path_basename(), BLI_string_debug_size, and BLI_strncpy().

◆ BLI_path_split_dir_part()

void BLI_path_split_dir_part ( const char * filepath,
char * dir,
const size_t dir_maxncpy )

Definition at line 1592 of file path_utils.cc.

References BLI_path_basename(), BLI_string_debug_size, and BLI_strncpy().

◆ BLI_path_split_file_part()

void BLI_path_split_file_part ( const char * filepath,
char * file,
const size_t file_maxncpy )

Definition at line 1605 of file path_utils.cc.

References BLI_path_basename(), BLI_string_debug_size, and BLI_strncpy().

◆ BLI_path_suffix()

bool BLI_path_suffix ( char * path,
size_t path_maxncpy,
const char * suffix,
const char * sep )

Definition at line 801 of file path_utils.cc.

References BLI_path_extension_or_end(), and BLI_string_debug_size_after_nil.

◆ BLI_path_to_display_name()

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

◆ BLI_path_unc_prefix_len()

static int BLI_path_unc_prefix_len ( const char * path)
static

Returns the length of the identifying prefix of a UNC path which can start with '\' (short version) or '\?\' (long version) If the path is not a UNC path, return 0

Definition at line 542 of file path_utils.cc.

References BLI_path_is_unc().

Referenced by BLI_path_abs(), BLI_path_rel(), BLI_path_slash_native(), and path_normalize_impl().

◆ 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 1345 of file path_utils.cc.

References uputenv().

Referenced by arg_handle_env_system_set(), BLI_change_working_dir(), BLI_setenv_if_new(), BPY_python_start(), and blender::render::hydra::Engine::Engine().

◆ 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 1361 of file path_utils.cc.

References BLI_getenv(), and BLI_setenv().

◆ ensure_digits()

static void ensure_digits ( char * path,
int digits )
static

Ensure path contains at least one "#" character in its last slash-separated component, appending one digits long if not.

Definition at line 942 of file path_utils.cc.

References BLI_path_basename(), and len.

Referenced by BLI_path_frame(), and BLI_path_frame_range().

◆ path_extension_check_ex()

static bool path_extension_check_ex ( const char * path,
const size_t path_len,
const char * ext,
const size_t ext_len )
static

◆ path_frame_chars_find_range()

static bool path_frame_chars_find_range ( const char * path,
int * r_char_start,
int * r_char_end )
static

Looks for a sequence of "#" characters in the last slash-separated component of path, returning the indexes of the first and one past the last character in the sequence in r_char_start and r_char_end respectively.

Parameters
r_char_startThe first # character.
r_char_endThe last # character +1.
Returns
true if a frame sequence range was found.

Definition at line 906 of file path_utils.cc.

References ELEM.

Referenced by BLI_path_frame(), BLI_path_frame_check_chars(), and BLI_path_frame_range().

◆ path_name_at_index_backward()

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

Definition at line 1818 of file path_utils.cc.

References BLI_assert, and BLI_path_slash_is_native_compat().

Referenced by BLI_path_name_at_index().

◆ path_name_at_index_forward()

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

Definition at line 1784 of file path_utils.cc.

References BLI_assert, and BLI_path_slash_is_native_compat().

Referenced by BLI_path_name_at_index().

◆ path_normalize_impl()

static int path_normalize_impl ( char * path,
bool check_blend_relative_prefix )
static