Blender
V3.3
|
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.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_util.h"
#include "BLI_string.h"
#include "BLI_utildefines.h"
Go to the source code of this file.
Functions | |
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 *file) |
bool | BLI_is_file (const char *path) |
static void * | file_read_data_as_mem_impl (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.c.
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 59 of file storage.c.
References BLI_getenv(), BLI_strncpy_wchar_as_utf8(), BLI_strnlen(), and NULL.
Referenced by BLI_path_abs_from_cwd().
double BLI_dir_free_space | ( | const char * | dir | ) |
Returns the number of free bytes on the volume containing the specified pathname.
Definition at line 83 of file storage.c.
References 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 314 of file storage.c.
References alloc_utf16_from_8(), BLI_assert, BLI_path_is_rel(), ELEM, free(), L, len, and usdtokens::st().
Referenced by BKE_appdir_app_template_has_userpref(), BKE_appdir_font_folder_default(), BKE_appdir_program_python_search(), BKE_cachefile_filepath_get(), BKE_packedfile_compare_to_file(), BKE_packedfile_unpack_to_file(), BKE_ptcache_id_exist(), BKE_text_file_modified_check(), BKE_text_file_modified_ignore(), BKE_volume_load(), blf_dir_metrics_search(), blf_dir_search(), BLF_load_font_stack(), BLI_dir_create_recursive(), BLI_is_dir(), BLI_is_file(), BLI_path_program_search(), BLI_rename(), check_missing_files_foreach_path_cb(), blender::io::usd::copy_single_file(), blender::io::usd::copy_tiled_textures(), blender::compositor::DebugInfo::delete_operation_exports(), blender::io::alembic::AlembicExportTest::deleteArchive(), do_history(), blender::bke::AssetCatalogDefinitionFile::ensure_directory_exists(), blender::ed::asset::index::AbstractFile::exists(), blender::io::alembic::export_endjob(), blender::io::usd::export_endjob(), 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(), 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::bke::AssetCatalogService::load_directory_recursive(), missing_files_find_foreach_path_cb(), movieclip_calc_length(), namebutton_fn(), new_folder_path(), openanim(), blender::io::path_reference_copy(), RE_RenderAnim(), renamebutton_cb(), blender::bke::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::bke::tests::TEST_F(), txt_write_file(), where_am_i(), wm_autosave_delete(), wm_autosave_location(), wm_block_create_splash(), wm_file_write(), wm_homefile_read_ex(), WM_lib_reload(), wm_lib_relocate_exec_do(), workspace_config_file_read(), workspace_system_file_read(), blender::bke::AssetCatalogDefinitionFile::write_to_disk(), and DocumentImporter::writeImage().
bool BLI_file_alias_target | ( | const char * | filepath, |
char | r_targetpath[] | ||
) |
Definition at line 260 of file storage.c.
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 | ) |
size_t BLI_file_descriptor_size | ( | int | file | ) |
Returns the file size of an opened file descriptor.
Definition at line 178 of file storage.c.
References BLI_fstat(), file, and usdtokens::st().
Referenced by BKE_packedfile_new(), build_pict_list_ex(), IMB_loadifffile(), imb_loadtilefile(), IMMapStream::IMMapStream(), prefetch_read_file_to_memory(), and proxy_thread_next_frame().
Frees memory from a previous call to BLI_file_read_as_lines.
Definition at line 564 of file storage.c.
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 569 of file storage.c.
References BLI_stat().
Referenced by imb_cache_filename(), IMB_thumb_manage(), and blender::ed::asset::index::AssetIndexFile::is_older_than().
LinkNode* BLI_file_read_as_lines | ( | const char * | file | ) |
Reads the contents of a text file.
Definition at line 518 of file storage.c.
References BLI_fopen(), BLI_fseek(), BLI_ftell(), BLI_linklist_append(), BLI_strdupn(), LinkNodePair::list, MEM_freeN, MEM_mallocN, NULL, 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 477 of file storage.c.
References BLI_fopen(), file_read_data_as_mem_impl(), and NULL.
Referenced by BKE_icon_geom_from_file().
void* BLI_file_read_text_as_mem | ( | const char * | filepath, |
size_t | pad_bytes, | ||
size_t * | r_size | ||
) |
Definition at line 466 of file storage.c.
References BLI_fopen(), file_read_data_as_mem_impl(), and NULL.
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(), and blender::io::obj::read_temp_file_in_string().
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. |
Example looping over lines:
Definition at line 488 of file storage.c.
References BLI_file_read_text_as_mem(), ELEM, and NULL.
size_t BLI_file_size | ( | const char * | path | ) |
Returns the size of a file.
Definition at line 187 of file storage.c.
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(), blender::io::stl::importer_main(), RE_RenderAnim(), and blender::bke::tests::AssetCatalogTest::save_from_memory_into_existing_asset_lib().
int BLI_fseek | ( | FILE * | stream, |
int64_t | offset, | ||
int | whence | ||
) |
Definition at line 160 of file storage.c.
References offset.
Referenced by AVI_close_compress(), AVI_is_avi(), AVI_open_compress(), AVI_open_movie(), AVI_read_frame(), AVI_set_compress_option(), AVI_write_frame(), BLI_file_read_as_lines(), cdf_read_header(), cdf_read_layer(), file_read_data_as_mem_impl(), 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().
int BLI_fstat | ( | int | fd, |
struct stat * | buffer | ||
) |
Definition at line 386 of file storage.c.
References buffer.
Referenced by BLI_file_descriptor_size(), and file_read_data_as_mem_impl().
int64_t BLI_ftell | ( | FILE * | stream | ) |
Definition at line 151 of file storage.c.
Referenced by AVI_close_compress(), AVI_is_avi(), AVI_open_compress(), AVI_open_movie(), AVI_write_frame(), BLI_file_read_as_lines(), and file_read_data_as_mem_impl().
bool BLI_is_dir | ( | const char * | path | ) |
Does the specified path point to a directory?
fileops.c
except that it needs stat.h
so add here. Definition at line 397 of file storage.c.
References BLI_exists(), file, and S_ISDIR.
Referenced by BKE_appdir_folder_caches(), BKE_appdir_folder_documents(), BKE_tempdir_session_purge(), BLF_load_font_stack(), BLI_dir_create_recursive(), BLO_library_path_explode(), bookmark_cleanup_exec(), blender::bke::AssetCatalogDefinitionFile::ensure_directory_exists(), file_browse_exec(), file_sfile_filepath_set(), filelist_checkdir_dir(), filelist_checkdir_lib(), filelist_readjob_list_dir(), fsmenu_entry_refresh_valid(), blender::ed::asset::index::AssetLibraryIndex::init_unused_index_files(), seq_disk_cache_get_files(), seq_disk_cache_handle_versioning(), tempdir_session_create(), test_env_path(), blender::bke::tests::TEST_F(), test_path(), and where_is_temp().
bool BLI_is_file | ( | const char * | path | ) |
Does the specified path point to a non-directory?
Definition at line 402 of file storage.c.
References BLI_exists(), and S_ISDIR.
Referenced by BKE_preferences_asset_library_path_set(), BLO_library_path_explode(), blender::compositor::DebugInfo::delete_operation_exports(), file_directory_enter_handle(), file_draw_check_exists(), filelist_checkdir_lib(), lib_id_load_custom_preview_exec(), blender::bke::AssetCatalogService::reload_catalogs(), and blender::bke::tests::TEST_F().
Definition at line 169 of file storage.c.
References offset.
Referenced by BLI_filereader_new_mmap(), BLI_mmap_open(), and file_seek().
int BLI_stat | ( | const char * | path, |
struct stat * | buffer | ||
) |
Definition at line 391 of file storage.c.
References buffer.
Referenced by BLI_file_older(), and BLI_file_size().
|
static |
Use for both text and binary file reading.
Definition at line 411 of file storage.c.
References BLI_fseek(), BLI_fstat(), BLI_ftell(), L, MEM_freeN, MEM_mallocN, MEM_reallocN, NULL, S_ISDIR, and usdtokens::st().
Referenced by BLI_file_read_binary_as_mem(), and BLI_file_read_text_as_mem().