Blender  V2.93
Macros | 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 <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.

Macros

#define CHUNK   (256 * 1024)
 

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

char * BLI_file_ungzip_to_mem (const char *from_file, int *r_size)
 
size_t BLI_gzip_mem_to_file_at_pos (void *buf, size_t len, FILE *file, size_t gz_stream_offset, int compression_level)
 
size_t BLI_ungzip_file_to_mem_at_pos (void *buf, size_t len, FILE *file, size_t gz_stream_offset)
 
bool BLI_file_is_writable (const char *filename)
 
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 *filename, const char *mode)
 
void * BLI_gzopen (const char *filename, const char *mode)
 
int BLI_open (const char *filename, int oflag, int pmode)
 
int BLI_access (const char *filename, 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)
 

Macro Definition Documentation

◆ CHUNK

#define CHUNK   (256 * 1024)

Definition at line 161 of file fileops.c.

Typedef Documentation

◆ RecursiveOp_Callback

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

Definition at line 711 of file fileops.c.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
RecursiveOp_Callback_OK 
RecursiveOp_Callback_StopRecurs 
RecursiveOp_Callback_Error 

Definition at line 700 of file fileops.c.

Function Documentation

◆ BLI_access()

int BLI_access ( const char *  filename,
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 1056 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 *  dirname)

◆ BLI_file_is_writable()

bool BLI_file_is_writable ( const char *  filename)

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 265 of file fileops.c.

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

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

◆ 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 294 of file fileops.c.

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

Referenced by RE_RenderAnim(), seq_disk_cache_read_file(), and sequencer_export_subtitles_exec().

◆ BLI_file_ungzip_to_mem()

char* BLI_file_ungzip_to_mem ( const char *  from_file,
int *  r_size 
)

Definition at line 117 of file fileops.c.

References BLI_gzopen(), MEM_callocN, MEM_freeN, MEM_reallocN, NULL, and size().

◆ BLI_fopen()

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

◆ BLI_gzip_mem_to_file_at_pos()

size_t BLI_gzip_mem_to_file_at_pos ( void *  buf,
size_t  len,
FILE *  file,
size_t  gz_stream_offset,
int  compression_level 
)

Definition at line 166 of file fileops.c.

References CHUNK, file, len, and ret.

Referenced by deflate_imbuf_to_file().

◆ BLI_gzopen()

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

◆ BLI_open()

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

◆ BLI_rename()

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

◆ BLI_ungzip_file_to_mem_at_pos()

size_t BLI_ungzip_file_to_mem_at_pos ( void *  buf,
size_t  len,
FILE *  file,
size_t  gz_stream_offset 
)

Definition at line 213 of file fileops.c.

References CHUNK, file, len, and ret.

Referenced by inflate_file_to_imbuf().

◆ check_destination()

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

Definition at line 1273 of file fileops.c.

References BLI_join_dirfile(), BLI_path_slash_rfind(), file, len, MEM_callocN, MEM_freeN, S_ISDIR, str, and strip_last_slash().

Referenced by BLI_copy().

◆ 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 1066 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 1101 of file fileops.c.

References check_the_same(), from, RecursiveOp_Callback_Error, and RecursiveOp_Callback_OK.

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 887 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 898 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 950 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 714 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 751 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, 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 1084 of file fileops.c.

References file.

Referenced by copy_single_file().

◆ strip_last_slash()

static char* strip_last_slash ( const char *  dir)
static

Definition at line 730 of file fileops.c.

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

Referenced by check_destination(), and recursive_operation().