Blender  V3.3
Typedefs | Enumerations | Functions
fileops.c File Reference
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <errno.h>
#include <zlib.h>
#include <zstd.h>
#include <dirent.h>
#include <sys/param.h>
#include <sys/wait.h>
#include <unistd.h>
#include "MEM_guardedalloc.h"
#include "BLI_fileops.h"
#include "BLI_path_util.h"
#include "BLI_string.h"
#include "BLI_sys_types.h"
#include "BLI_utildefines.h"

Go to the source code of this file.

Typedefs

typedef int(* RecursiveOp_Callback) (const char *from, const char *to)
 

Enumerations

enum  { RecursiveOp_Callback_OK = 0 , RecursiveOp_Callback_StopRecurs = 1 , RecursiveOp_Callback_Error = 2 }
 

Functions

size_t BLI_file_zstd_from_mem_at_pos (void *buf, size_t len, FILE *file, size_t file_offset, int compression_level)
 
size_t BLI_file_unzstd_to_mem_at_pos (void *buf, size_t len, FILE *file, size_t file_offset)
 
bool BLI_file_magic_is_gzip (const char header[4])
 
bool BLI_file_magic_is_zstd (const char header[4])
 
bool BLI_file_is_writable (const char *filepath)
 
bool BLI_file_touch (const char *file)
 
static void join_dirfile_alloc (char **dst, size_t *alloc_len, const char *dir, const char *file)
 
static char * strip_last_slash (const char *dir)
 
static int recursive_operation (const char *startfrom, const char *startto, RecursiveOp_Callback callback_dir_pre, RecursiveOp_Callback callback_file, RecursiveOp_Callback callback_dir_post)
 
static int delete_callback_post (const char *from, const char *UNUSED(to))
 
static int delete_single_file (const char *from, const char *UNUSED(to))
 
static int delete_soft (const char *file, const char **error_message)
 
FILE * BLI_fopen (const char *filepath, const char *mode)
 
voidBLI_gzopen (const char *filepath, const char *mode)
 
int BLI_open (const char *filepath, int oflag, int pmode)
 
int BLI_access (const char *filepath, int mode)
 
int BLI_delete (const char *file, bool dir, bool recursive)
 
int BLI_delete_soft (const char *file, const char **error_message)
 
static bool check_the_same (const char *path_a, const char *path_b)
 
static int set_permissions (const char *file, const struct stat *st)
 
static int copy_callback_pre (const char *from, const char *to)
 
static int copy_single_file (const char *from, const char *to)
 
static const char * check_destination (const char *file, const char *to)
 
int BLI_copy (const char *file, const char *to)
 
bool BLI_dir_create_recursive (const char *dirname)
 
int BLI_rename (const char *from, const char *to)
 

Typedef Documentation

◆ RecursiveOp_Callback

typedef int(* RecursiveOp_Callback) (const char *from, const char *to)

Definition at line 614 of file fileops.c.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
RecursiveOp_Callback_OK 
RecursiveOp_Callback_StopRecurs 
RecursiveOp_Callback_Error 

Definition at line 603 of file fileops.c.

Function Documentation

◆ BLI_access()

int BLI_access ( const char *  filepath,
int  mode 
)

◆ BLI_copy()

int BLI_copy ( const char *  file,
const char *  to 
)

◆ BLI_delete()

int BLI_delete ( const char *  file,
bool  dir,
bool  recursive 
)

◆ BLI_delete_soft()

int BLI_delete_soft ( const char *  file,
const char **  error_message 
)

Soft deletes the specified file or directory (depending on dir) by moving the files to the recycling bin, optionally doing recursive delete of directory contents.

Returns
zero on success (matching 'remove' behavior).

Definition at line 947 of file fileops.c.

References BLI_assert, BLI_path_is_rel(), delete_soft(), and file.

Referenced by file_delete_single().

◆ BLI_dir_create_recursive()

bool BLI_dir_create_recursive ( const char *  dir)

◆ BLI_file_is_writable()

bool BLI_file_is_writable ( const char *  filepath)

Returns true if the file with the specified name can be written. This implementation uses access(2), which makes the check according to the real UID and GID of the process, not its effective UID and GID. This shouldn't matter for Blender, which is not going to run privileged anyway.

Definition at line 167 of file fileops.c.

References BLI_access(), BLI_split_dirfile(), FILE_MAX, and NULL.

Referenced by image_save_exec(), sequencer_export_subtitles_exec(), txt_write_file(), and wm_file_write().

◆ BLI_file_magic_is_gzip()

bool BLI_file_magic_is_gzip ( const char  header[4])

◆ BLI_file_magic_is_zstd()

bool BLI_file_magic_is_zstd ( const char  header[4])

◆ BLI_file_touch()

bool BLI_file_touch ( const char *  file)

Creates the file with nothing in it, or updates its last-modified date if it already exists. Returns true if successful (like the unix touch command).

Definition at line 192 of file fileops.c.

References BLI_fopen(), Freestyle::c, file, and NULL.

Referenced by RE_RenderAnim(), blender::bke::tests::AssetCatalogTest::save_from_memory_into_existing_asset_lib(), seq_disk_cache_read_file(), and sequencer_export_subtitles_exec().

◆ BLI_file_unzstd_to_mem_at_pos()

size_t BLI_file_unzstd_to_mem_at_pos ( void buf,
size_t  len,
FILE *  file,
size_t  file_offset 
)

Definition at line 96 of file fileops.c.

References file, input, len, MEM_freeN, MEM_mallocN, output, and ret.

Referenced by inflate_file_to_imbuf().

◆ BLI_file_zstd_from_mem_at_pos()

size_t BLI_file_zstd_from_mem_at_pos ( void buf,
size_t  len,
FILE *  file,
size_t  file_offset,
int  compression_level 
)

Definition at line 49 of file fileops.c.

References file, input, len, MEM_freeN, MEM_mallocN, output, and ret.

Referenced by deflate_imbuf_to_file().

◆ BLI_fopen()

FILE* BLI_fopen ( const char *  filepath,
const char *  mode 
)

Definition at line 906 of file fileops.c.

References BLI_assert, and BLI_path_is_rel().

Referenced by arg_handle_log_file_set(), AVI_is_avi(), AVI_open_compress(), AVI_open_movie(), BKE_report_write_file(), BLI_file_read_as_lines(), BLI_file_read_binary_as_mem(), BLI_file_read_text_as_mem(), BLI_file_touch(), cdf_read_open(), cdf_write_open(), blender::io::obj::obj_mtl_parser_test::check_string(), cineonCreate(), cineonOpen(), dpxCreate(), dpxOpen(), EEVEE_lut_update_ggx_brdf(), EEVEE_lut_update_ggx_btdf(), fsmenu_read_bookmarks(), fsmenu_write_file(), fsmenu_xdg_user_dirs_parse(), blender::compositor::DebugInfo::graphviz(), IMB_index_builder_create(), IMB_indexer_open(), imb_savebmp(), imb_savehdr(), imb_savepng(), imb_savetarga(), imb_savewebp(), imb_thumbnail_jpeg(), blender::io::stl::importer_main(), logImageOpenFromFile(), make(), MOD_meshcache_read_mdd_times(), MOD_meshcache_read_pc2_times(), blender::io::obj::MTLWriter::MTLWriter(), blender::io::obj::OBJParser::OBJParser(), blender::io::obj::OBJWriter::OBJWriter(), opj_stream_create_from_file(), output_iris(), ptcache_file_open(), python_script_exec(), save_stdjpeg(), seq_disk_cache_create_version_file(), seq_disk_cache_handle_versioning(), seq_disk_cache_read_file(), seq_disk_cache_write_file(), sequencer_export_subtitles_exec(), sig_handle_crash(), studiolight_calculate_diffuse_light(), studiolight_load_spherical_harmonics_coefficients(), studiolight_write_solid_light(), txt_write_file(), wm_history_file_write(), and wm_platform_support_check_approval().

◆ BLI_gzopen()

void* BLI_gzopen ( const char *  filepath,
const char *  mode 
)

Definition at line 913 of file fileops.c.

References BLI_assert, and BLI_path_is_rel().

Referenced by MANTA::readConfiguration(), and MANTA::writeConfiguration().

◆ BLI_open()

int BLI_open ( const char *  filepath,
int  oflag,
int  pmode 
)

◆ BLI_rename()

int BLI_rename ( const char *  from,
const char *  to 
)

◆ check_destination()

static const char* check_destination ( const char *  file,
const char *  to 
)
static

◆ check_the_same()

static bool check_the_same ( const char *  path_a,
const char *  path_b 
)
static

Do the two paths denote the same file-system object?

Definition at line 957 of file fileops.c.

Referenced by copy_callback_pre(), and copy_single_file().

◆ copy_callback_pre()

static int copy_callback_pre ( const char *  from,
const char *  to 
)
static

Definition at line 992 of file fileops.c.

References check_the_same(), from, RecursiveOp_Callback_Error, RecursiveOp_Callback_OK, and usdtokens::st().

Referenced by BLI_copy().

◆ copy_single_file()

static int copy_single_file ( const char *  from,
const char *  to 
)
static

◆ delete_callback_post()

static int delete_callback_post ( const char *  from,
const char *  UNUSEDto 
)
static

Definition at line 790 of file fileops.c.

References from, RecursiveOp_Callback_Error, and RecursiveOp_Callback_OK.

Referenced by BLI_delete().

◆ delete_single_file()

static int delete_single_file ( const char *  from,
const char *  UNUSEDto 
)
static

Definition at line 801 of file fileops.c.

References from, RecursiveOp_Callback_Error, and RecursiveOp_Callback_OK.

Referenced by BLI_delete().

◆ delete_soft()

static int delete_soft ( const char *  file,
const char **  error_message 
)
static

Definition at line 853 of file fileops.c.

References file, NULL, and STREQ.

Referenced by BLI_delete_soft().

◆ join_dirfile_alloc()

static void join_dirfile_alloc ( char **  dst,
size_t *  alloc_len,
const char *  dir,
const char *  file 
)
static

Definition at line 617 of file fileops.c.

References BLI_join_dirfile(), file, len, MEM_mallocN, MEM_reallocN, and NULL.

Referenced by recursive_operation().

◆ recursive_operation()

static int recursive_operation ( const char *  startfrom,
const char *  startto,
RecursiveOp_Callback  callback_dir_pre,
RecursiveOp_Callback  callback_file,
RecursiveOp_Callback  callback_dir_post 
)
static

Scans startfrom, generating a corresponding destination name for each item found by prefixing it with startto, recursively scanning subdirectories, and invoking the specified callbacks for files and subdirectories found as appropriate.

Parameters
startfromTop-level source path.
starttoTop-level destination path.
callback_dir_preOptional, to be invoked before entering a subdirectory, can return RecursiveOp_Callback_StopRecurs to skip the subdirectory.
callback_fileOptional, to be invoked on each file found.
callback_dir_postoptional, to be invoked after leaving a subdirectory.
Returns

Definition at line 654 of file fileops.c.

References BLI_path_join(), dirent::d_name, FILE_MAX, FILENAME_IS_CURRPAR, free(), from, join_dirfile_alloc(), MEM_freeN, NULL, RecursiveOp_Callback_OK, RecursiveOp_Callback_StopRecurs, ret, S_ISDIR, usdtokens::st(), and strip_last_slash().

Referenced by BLI_copy(), and BLI_delete().

◆ set_permissions()

static int set_permissions ( const char *  file,
const struct stat *  st 
)
static

Sets the mode and ownership of file to the values from st.

Definition at line 975 of file fileops.c.

References file, and usdtokens::st().

Referenced by copy_single_file().

◆ strip_last_slash()

static char* strip_last_slash ( const char *  dir)
static

Definition at line 633 of file fileops.c.

References BLI_path_slash_rstrip(), BLI_strdup(), and result.

Referenced by check_destination(), and recursive_operation().