|
Blender V4.3
|
#include <cstdio>#include <cstdlib>#include <sys/types.h>#include <sys/stat.h>#include <cstring>#include <fcntl.h>#include <pwd.h>#include <sys/ioctl.h>#include <unistd.h>#include "MEM_guardedalloc.h"#include "BLI_fileops.h"#include "BLI_linklist.h"#include "BLI_path_utils.hh"#include "BLI_string.h"#include "BLI_threads.h"#include "BLI_utildefines.h"Go to the source code of this file.
Functions | |
| bool | BLI_change_working_dir (const char *dir) |
| char * | BLI_current_working_dir (char *dir, const size_t maxncpy) |
| double | BLI_dir_free_space (const char *dir) |
| int64_t | BLI_ftell (FILE *stream) |
| int | BLI_fseek (FILE *stream, int64_t offset, int whence) |
| int64_t | BLI_lseek (int fd, int64_t offset, int whence) |
| size_t | BLI_file_descriptor_size (int file) |
| size_t | BLI_file_size (const char *path) |
| eFileAttributes | BLI_file_attributes (const char *path) |
| bool | BLI_file_alias_target (const char *filepath, char r_targetpath[]) |
| int | BLI_exists (const char *path) |
| int | BLI_fstat (int fd, struct stat *buffer) |
| int | BLI_stat (const char *path, struct stat *buffer) |
| bool | BLI_is_dir (const char *path) |
| bool | BLI_is_file (const char *path) |
| void * | BLI_file_read_data_as_mem_from_handle (FILE *fp, bool read_size_exact, size_t pad_bytes, size_t *r_size) |
| void * | BLI_file_read_text_as_mem (const char *filepath, size_t pad_bytes, size_t *r_size) |
| void * | BLI_file_read_binary_as_mem (const char *filepath, size_t pad_bytes, size_t *r_size) |
| void * | BLI_file_read_text_as_mem_with_newline_as_nil (const char *filepath, bool trim_trailing_space, size_t pad_bytes, size_t *r_size) |
| LinkNode * | BLI_file_read_as_lines (const char *filepath) |
| void | BLI_file_free_lines (LinkNode *lines) |
| bool | BLI_file_older (const char *file1, const char *file2) |
Some really low-level file operations.
Definition in file storage.cc.
| bool BLI_change_working_dir | ( | const char * | dir | ) |
Changes the current working directory to the provided path.
Usage of this function is strongly discouraged as it is not thread safe. It will likely cause issues if there is an operation on another thread that does not expect the current working directory to change. This has been added to support USDZ export, which has a problematic "feature" described in this issue #99807. It will be removed if it is possible to resolve that issue upstream in the USD library.
Definition at line 63 of file storage.cc.
| char * BLI_current_working_dir | ( | char * | dir, |
| size_t | maxncpy ) |
Copies the current working directory into *dir (max size maxncpy), and returns a pointer to same.
Definition at line 85 of file storage.cc.
| double BLI_dir_free_space | ( | const char * | dir | ) |
Returns the number of free bytes on the volume containing the specified path.
Definition at line 110 of file storage.cc.
References dirname(), double(), ELEM, FILE_MAXDIR, and len.
| int BLI_exists | ( | const char * | path | ) |
Returns the st_mode from stat-ing the specified path name, or 0 if stat fails (most likely doesn't exist or no access).
Definition at line 350 of file storage.cc.
References alloc_utf16_from_8(), BLI_assert, BLI_path_is_rel(), ELEM, free(), L, and len.
Referenced by BKE_appdir_app_template_has_userpref(), BKE_appdir_font_folder_default(), BKE_appdir_program_python_search(), BKE_blendfile_userdef_write_app_template(), BKE_cachefile_filepath_get(), BKE_packedfile_unpack_to_file(), BKE_packedfile_write_to_file(), BKE_ptcache_id_exist(), BKE_text_file_modified_check(), BKE_text_file_modified_ignore(), BKE_volume_load(), blf_dir_metrics_search(), BLF_load_unique(), BLI_dir_create_recursive(), BLI_is_dir(), BLI_is_file(), BLI_path_program_search(), BLI_rename(), BLI_rename_overwrite(), blender::io::usd::cache_image_color(), blender::io::hydra::cache_image_file(), blender::seq::check_media_missing(), check_missing_files_foreach_path_cb(), blender::seq::check_sound_media_missing(), blender::io::usd::copy_single_file(), blender::io::usd::copy_tiled_textures(), blender::compositor::DebugInfo::delete_operation_exports(), blender::io::alembic::AlembicExportTest::deleteArchive(), dir_create_recursive(), do_history(), blender::asset_system::AssetCatalogDefinitionFile::ensure_directory_exists(), blender::ed::asset::index::AbstractFile::exists(), blender::io::alembic::export_endjob(), blender::io::usd::export_endjob(), blender::io::usd::export_endjob_usdz_cleanup(), blender::io::usd::export_in_memory_texture(), file_delete_single(), file_directory_new_exec(), file_execute(), file_sfile_filepath_set(), filepath_drop_exec(), fsmenu_read_bookmarks(), handle_load_file(), MANTA::hasConfig(), MANTA::hasData(), MANTA::hasGuiding(), MANTA::hasMesh(), MANTA::hasNoise(), MANTA::hasParticles(), image_save_exec(), IMB_anim_proxy_get_existing(), IMB_exr_begin_read(), IMB_thumb_delete(), IMB_thumb_manage(), blender::asset_system::AssetCatalogService::load_directory_recursive(), missing_files_find_foreach_path_cb(), movieclip_calc_length(), blender::ed::outliner::namebutton_fn(), new_folder_path(), openanim(), blender::io::path_reference_copy(), blender::io::usd::perform_usdz_conversion(), RE_RenderAnim(), blender::gpu::VKPipelinePool::read_from_disk(), blender::gpu::read_spirv_from_disk(), renamebutton_cb(), blender::asset_system::tests::AssetCatalogTest::save_from_memory_into_existing_asset_lib(), screen_opengl_render_anim_step(), seq_disk_cache_enforce_limits(), seq_disk_cache_handle_versioning(), seq_proxy_build_frame(), seq_proxy_fetch(), sequencer_export_subtitles_exec(), blender::tests::FileOpsTest::SetUp(), blender::io::usd::UsdCurvesTest::TearDown(), blender::io::usd::UsdExportTest::TearDown(), blender::tests::FileOpsTest::TearDown(), blender::tests::TEST(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::tests::TEST_F(), blender::tests::TEST_F(), blender::ed::object::bake_simulation::try_delete_bake(), txt_write_file(), ui_but_menu_add_path_operators(), ui_popup_context_menu_for_button(), ui_tooltip_from_vfont(), uiTemplateRecentFiles_tooltip_func(), where_am_i(), wm_autosave_delete(), wm_block_splash_create(), wm_clear_recent_files_exec(), wm_file_write(), wm_homefile_read_ex(), wm_init_splash_show_on_startup_check(), WM_lib_reload(), wm_lib_relocate_exec_do(), wm_save_as_mainfile_exec(), workspace_config_file_read(), workspace_system_file_read(), blender::ui::string_search::write_recent_searches_file(), blender::asset_system::AssetCatalogDefinitionFile::write_to_disk(), and DocumentImporter::writeImage().
| bool BLI_file_alias_target | ( | const char * | filepath, |
| char | r_targetpath[] ) |
Definition at line 296 of file storage.cc.
References ARRAY_SIZE, BLI_path_extension_check(), conv_utf_16_to_8(), conv_utf_8_to_16(), FILE_MAXDIR, NULL, and UNUSED_VARS.
| eFileAttributes BLI_file_attributes | ( | const char * | path | ) |
Definition at line 226 of file storage.cc.
| size_t BLI_file_descriptor_size | ( | int | file | ) |
Returns the file size of an opened file descriptor or size_t(-1) on failure.
Definition at line 206 of file storage.cc.
References BLI_fstat().
Referenced by BKE_packedfile_new(), buffer_from_filepath(), prefetch_read_file_to_memory(), and proxy_thread_next_frame().
| void BLI_file_free_lines | ( | struct LinkNode * | lines | ) |
Frees memory from a previous call to BLI_file_read_as_lines.
Definition at line 600 of file storage.cc.
References BLI_linklist_freeN().
Referenced by make(), studiolight_load_solid_light(), wm_history_file_read(), and wm_platform_support_check_approval().
| bool BLI_file_older | ( | const char * | file1, |
| const char * | file2 ) |
Compare if one was last modified before the other.
file1 older than file2. Definition at line 605 of file storage.cc.
References BLI_stat().
Referenced by IMB_thumb_manage(), and blender::ed::asset::index::AssetIndexFile::is_older_than().
| LinkNode * BLI_file_read_as_lines | ( | const char * | filepath | ) |
Reads the contents of a text file.
Definition at line 554 of file storage.cc.
References BLI_fopen(), BLI_fseek(), BLI_ftell(), BLI_linklist_append(), BLI_strdupn(), LinkNodePair::list, MEM_freeN(), size(), and UNLIKELY.
Referenced by make(), studiolight_load_solid_light(), wm_history_file_read(), and wm_platform_support_check_approval().
| void * BLI_file_read_binary_as_mem | ( | const char * | filepath, |
| size_t | pad_bytes, | ||
| size_t * | r_size ) |
Definition at line 513 of file storage.cc.
References BLI_file_read_data_as_mem_from_handle(), and BLI_fopen().
Referenced by BKE_icon_geom_from_file().
| void * BLI_file_read_data_as_mem_from_handle | ( | FILE * | fp, |
| bool | read_size_exact, | ||
| size_t | pad_bytes, | ||
| size_t * | r_size ) |
Use for both text and binary file reading.
Definition at line 447 of file storage.cc.
References BLI_fseek(), BLI_fstat(), BLI_ftell(), L, MEM_freeN(), MEM_mallocN, MEM_reallocN, and S_ISDIR.
Referenced by BLI_file_read_binary_as_mem(), BLI_file_read_text_as_mem(), and python_compat_wrapper_PyRun_FileExFlags().
| void * BLI_file_read_text_as_mem | ( | const char * | filepath, |
| size_t | pad_bytes, | ||
| size_t * | r_size ) |
Definition at line 502 of file storage.cc.
References BLI_file_read_data_as_mem_from_handle(), and BLI_fopen().
Referenced by BKE_text_load_ex(), BKE_text_reload(), BLI_file_read_text_as_mem_with_newline_as_nil(), blender::io::obj::MTLParser::parse_and_store(), paste_from_file(), blender::io::stl::read_stl_ascii(), blender::io::obj::read_temp_file_in_string(), blender::io::ply::read_temp_file_in_string(), blender::io::stl::read_temp_file_in_string(), and read_text_corpus().
| void * BLI_file_read_text_as_mem_with_newline_as_nil | ( | const char * | filepath, |
| bool | trim_trailing_space, | ||
| size_t | pad_bytes, | ||
| size_t * | r_size ) |
Return the text file data with:
This is an alternative to using BLI_file_read_as_lines, allowing us to loop over lines without converting it into a linked list with individual allocations.
| trim_trailing_space | Replace trailing spaces & tabs with nil. This arguments prevents the caller from counting blank lines (if that's important). |
| pad_bytes | When this is non-zero, the first byte is set to nil, to simplify parsing the file. It's recommended to pass in 1, so all text is nil terminated. |
| r_size | The size of the file contents read into the buffer (excluding pad_bytes). |
Example looping over lines:
Definition at line 524 of file storage.cc.
References BLI_file_read_text_as_mem(), and ELEM.
| size_t BLI_file_size | ( | const char * | path | ) |
Returns the size of a file or size_t(-1) on failure..
Definition at line 215 of file storage.cc.
References BLI_stat().
Referenced by blender::ed::asset::index::AbstractFile::get_file_size(), IMB_exr_begin_read(), imb_load_filepath_thumbnail_openexr(), IMB_thumb_load_image(), RE_RenderAnim(), blender::io::stl::read_stl_file(), and blender::asset_system::tests::AssetCatalogTest::save_from_memory_into_existing_asset_lib().
Definition at line 188 of file storage.cc.
Referenced by BLI_file_read_as_lines(), BLI_file_read_data_as_mem_from_handle(), cdf_read_header(), cdf_read_layer(), MOD_meshcache_read_mdd_frame(), MOD_meshcache_read_mdd_index(), MOD_meshcache_read_pc2_frame(), MOD_meshcache_read_pc2_index(), ptcache_file_header_begin_read(), seq_disk_cache_read_header(), and seq_disk_cache_write_header().
Definition at line 422 of file storage.cc.
Referenced by BLI_file_descriptor_size(), and BLI_file_read_data_as_mem_from_handle().
| int64_t BLI_ftell | ( | FILE * | stream | ) |
Definition at line 179 of file storage.cc.
Referenced by BLI_file_read_as_lines(), and BLI_file_read_data_as_mem_from_handle().
| bool BLI_is_dir | ( | const char * | path | ) |
Does the specified path point to a directory?
fileops.cc except that it needs stat.h so add here. Definition at line 433 of file storage.cc.
References BLI_exists(), and S_ISDIR.
Referenced by blender::asset_system::all_valid_asset_library_refs(), blender::ed::object::bake_simulation::bake_directory_has_data(), BKE_appdir_app_template_id_search(), BKE_appdir_folder_caches(), BKE_appdir_folder_documents(), BKE_blendfile_library_path_explode(), BKE_tempdir_session_purge(), BLI_change_working_dir(), BLI_rename_overwrite(), BLI_temp_directory_path_copy_if_valid(), bookmark_cleanup_exec(), blender::ed::asset::index::AssetLibraryIndex::collect_preexisting_file_indices(), blender::asset_system::AssetCatalogDefinitionFile::ensure_directory_exists(), file_browse_exec(), file_sfile_filepath_set(), filelist_checkdir_dir(), filelist_checkdir_lib(), filelist_readjob_list_dir(), filelist_readjob_recursive_dir_add_items(), blender::bke::bake::find_sorted_meta_files(), fsmenu_entry_refresh_valid(), fsmenu_read_system(), blender::io::usd::load_image(), blender::io::usd::USDMaterialReader::load_tex_image(), blender::bke::bake::pack_files_from_directory(), blender::io::usd::parent_dir_exists_on_file_system(), path_destination_ensure_filename(), preferences_extension_repo_remove_exec(), blender::io::usd::process_usdz_textures(), seq_disk_cache_get_files(), seq_disk_cache_handle_versioning(), tempdir_session_create(), blender::tests::TEST(), test_env_path(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), and test_path().
| bool BLI_is_file | ( | const char * | path | ) |
Does the specified path point to a non-directory?
Definition at line 438 of file storage.cc.
References BLI_exists(), and S_ISDIR.
Referenced by blender::bke::asset_blendfile_path_for_save(), BKE_blendfile_library_path_explode(), BKE_preferences_asset_library_path_set(), blender::ed::sculpt_paint::brush_asset_load_preview_exec(), blender::io::usd::copy_asset_to_directory(), blender::compositor::DebugInfo::delete_operation_exports(), file_directory_enter_handle(), file_draw_check_exists(), filelist_checkdir_lib(), blender::io::usd::get_relative_path(), lib_id_load_custom_preview_exec(), blender::asset_system::AssetCatalogService::reload_catalogs(), blender::io::usd::should_import_asset(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), and ui_but_menu_add_path_operators().
Definition at line 197 of file storage.cc.
Referenced by BLI_mmap_open(), and file_seek().
| int BLI_stat | ( | const char * | path, |
| struct stat * | buffer ) |
Definition at line 427 of file storage.cc.
Referenced by BLI_file_older(), and BLI_file_size().